New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support 'west flash' with native_sim, add debugserver support #68835
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright (c) 2023 Nordic Semiconductor | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
"""This file provides a ZephyrBinaryRunner that launches GDB and enables | ||
flashing (running) a native application.""" | ||
|
||
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) | ||
self.gdb_port = gdb_port | ||
|
||
if cfg.gdb is None: | ||
self.gdb_cmd = None | ||
else: | ||
self.gdb_cmd = [cfg.gdb] + (['-tui'] if tui else []) | ||
|
||
if self.cfg.gdb is None: | ||
raise ValueError("The provided RunnerConfig is missing the required field 'gdb'.") | ||
|
||
if self.cfg.exe_file is None: | ||
raise ValueError("The provided RunnerConfig is missing the required field 'exe_file'.") | ||
|
||
|
||
@classmethod | ||
def name(cls): | ||
return 'native' | ||
|
||
@classmethod | ||
def capabilities(cls): | ||
return RunnerCaps(commands={'debug', 'debugserver', 'flash'}) | ||
|
||
@classmethod | ||
def do_add_parser(cls, parser: argparse.ArgumentParser): | ||
parser.add_argument('--tui', default=False, action='store_true', | ||
help='if given, GDB uses -tui') | ||
parser.add_argument('--gdb-port', default=DEFAULT_GDB_PORT, | ||
help='gdb port, defaults to {}'.format( | ||
DEFAULT_GDB_PORT)) | ||
|
||
@classmethod | ||
def do_create(cls, cfg: RunnerConfig, args: argparse.Namespace) -> ZephyrBinaryRunner: | ||
return NativeSimBinaryRunner(cfg, | ||
tui=args.tui, | ||
gdb_port=args.gdb_port) | ||
|
||
def do_run(self, command: str, **kwargs): | ||
if command == 'flash': | ||
self.do_flash(**kwargs) | ||
elif command == 'debug': | ||
self.do_debug(**kwargs) | ||
elif command == 'debugserver': | ||
self.do_debugserver(**kwargs) | ||
else: | ||
assert False | ||
|
||
def do_flash(self, **kwargs): | ||
cmd = [self.cfg.exe_file] | ||
self.check_call(cmd) | ||
|
||
def do_debug(self, **kwargs): | ||
# Clues to debug missing RunnerConfig values (in context of `west debug`): | ||
# build/zephyr/runners.yaml is missing `gdb` or `elf_file`. | ||
# board.cmake should have `board_finalize_runner_args(native)`. | ||
# build/CMakeCache.txt should have `CMAKE_GDB`. | ||
|
||
cmd = (self.gdb_cmd + ['--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) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
kwargs
are not used. Is it not better to remove them? Same applies todo_debug
anddo_debugserver
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the "interface" afaik, looking at all the runners:
No harm in leaving this allowing future expansions