Skip to content

Commit a472923

Browse files
runners: stlink_gdbserver: add --no-load argument to skip flash
Add new argument "--no-load" for debug sessions ("west debug" only) which skips flashing binary before debugging. This flag functions exactly like its identically-named counterpart in the OpenOCD runner: when present, the "load" command is not added to the GDB client's command line. This allows starting a debug session from reset but without flashing a binary, which is useful to avoid unnecessary write cycles. Functionally, this could already be achieved by running "west debugserver" in a terminal and "west attach" in another, but using this flag is a more convenient method. Signed-off-by: Mathieu Choplain <[email protected]>
1 parent a3aa513 commit a472923

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

scripts/west_commands/runners/stlink_gdbserver.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,23 @@ def do_add_parser(cls, parser: argparse.ArgumentParser):
110110
help="Port number for GDB client",
111111
)
112112

113+
# Additional arguments
114+
parser.add_argument(
115+
"--no-load",
116+
action='store_true',
117+
help="Don't flash binary before debug (no GDB 'load' command)"
118+
)
119+
113120
@classmethod
114121
def do_create(cls, cfg: RunnerConfig, args: argparse.Namespace) -> "STLinkGDBServerRunner":
115122
return STLinkGDBServerRunner(
116-
cfg, args.swd, args.apid, args.dev_id, args.port_number, args.extload
123+
cfg,
124+
args.swd,
125+
args.apid,
126+
args.dev_id,
127+
args.port_number,
128+
args.extload,
129+
args.no_load,
117130
)
118131

119132
def __init__(
@@ -124,6 +137,7 @@ def __init__(
124137
stlink_serial: str | None,
125138
gdb_port: int,
126139
external_loader: str | None,
140+
no_load: bool,
127141
):
128142
super().__init__(cfg)
129143
self.ensure_output('elf')
@@ -133,6 +147,7 @@ def __init__(
133147
self._stlink_serial = stlink_serial
134148
self._ap_id = ap_id
135149
self._external_loader = external_loader
150+
self._no_load = no_load
136151

137152
def do_run(self, command: str, **kwargs):
138153
if command in ["attach", "debug", "debugserver"]:
@@ -165,7 +180,8 @@ def do_attach_debug_debugserver(self, command: str):
165180
gdbserver_cmd += ["--attach"]
166181
else: # debug/debugserver
167182
gdbserver_cmd += ["--initialize-reset"]
168-
gdb_args += ["-ex", f"load {elf_path}"]
183+
if not self._no_load:
184+
gdb_args += ["-ex", f"load {elf_path}"]
169185

170186
if self._stlink_serial:
171187
gdbserver_cmd += ["--serial-number", self._stlink_serial]

0 commit comments

Comments
 (0)