Skip to content

Commit

Permalink
west: runner: native_sim: add debugserver support
Browse files Browse the repository at this point in the history
Support starting a gdb server on port 3333 for remote debugging.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
  • Loading branch information
nashif committed Feb 10, 2024
1 parent 5159b18 commit 8c2777e
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions scripts/west_commands/runners/native_sim.py
Expand Up @@ -6,16 +6,28 @@
import argparse
from runners.core import ZephyrBinaryRunner, RunnerCaps, RunnerConfig

DEFAULT_GDB_PORT = 3333

class NativeSimBinaryRunner(ZephyrBinaryRunner):
"""Runs the ELF binary under GDB."""

def __init__(self, cfg,
tui=False,
gdb_port=DEFAULT_GDB_PORT):
super().__init__(cfg)
if cfg.gdb is None:
self.gdb_cmd = None
else:
self.gdb_cmd = [cfg.gdb] + (['-tui'] if tui else [])
self.gdb_port = gdb_port

@classmethod
def name(cls):
return 'native_sim'

@classmethod
def capabilities(cls):
return RunnerCaps(commands={'debug', 'flash'})
return RunnerCaps(commands={'debug', 'debugserver', 'flash'})

@classmethod
def do_add_parser(cls, parser: argparse.ArgumentParser):
Expand All @@ -30,6 +42,8 @@ def do_run(self, command: str, **kwargs):
self.do_flash(**kwargs)
elif command == 'debug':
self.do_debug(**kwargs)
elif command == 'debugserver':
self.do_debugserver(**kwargs)
else:
assert False

Expand All @@ -49,8 +63,10 @@ def do_debug(self, **kwargs):
if self.cfg.exe_file is None:
raise ValueError("The provided RunnerConfig is missing the required field 'exe_file'.")

self.call([
self.cfg.gdb,
'--quiet',
self.cfg.exe_file,
])
cmd = ([self.cfg.gdb, '--quiet', self.cfg.exe_file])
self.check_call(cmd)

def do_debugserver(self, **kwargs):
cmd = (['gdbserver', ':{}'.format(self.gdb_port), self.cfg.exe_file])

self.check_call(cmd)

0 comments on commit 8c2777e

Please sign in to comment.