diff --git a/scripts/west_commands/runners/native_sim.py b/scripts/west_commands/runners/native_sim.py index 1ce436779d367fe..7f6d827151db103 100644 --- a/scripts/west_commands/runners/native_sim.py +++ b/scripts/west_commands/runners/native_sim.py @@ -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): @@ -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 @@ -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)