Skip to content

Commit 2024fb5

Browse files
mbolivar-nordicdleach02
authored andcommitted
scripts: runners: fix blackmagicprobe SIGINT behavior
The blackmagicprobe runner's Python process fails to ignore SIGINT when it runs GDB from the debug and flash callbacks, which is wrong. The other runners tend to use run_server_and_client() to properly handle this, since they start a GDB server and connect to it with a client. The BMP USB device presents itself as a serial device which speaks the GDB serial protocol instead, so there's no server/client, and thus no call to run_server_and_client(). The problem is that blackmagicprobe essentially uses subprocess.check_call() to start GDB directly, without ignoring SIGINT in the python process. Easy fix. Fixes: #21139 Signed-off-by: Martí Bolívar <[email protected]>
1 parent 38db500 commit 2024fb5

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

scripts/west_commands/runners/blackmagicprobe.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
'''Runner for flashing with Black Magic Probe.'''
66
# https://github.com/blacksphere/blackmagic/wiki
77

8-
from runners.core import ZephyrBinaryRunner, RunnerCaps
8+
import signal
99

10+
from runners.core import ZephyrBinaryRunner, RunnerCaps
1011

1112
class BlackMagicProbeRunner(ZephyrBinaryRunner):
1213
'''Runner front-end for Black Magic probe.'''
@@ -48,6 +49,13 @@ def bmp_flash(self, command, **kwargs):
4849
'-silent'])
4950
self.check_call(command)
5051

52+
def check_call_ignore_sigint(self, command):
53+
previous = signal.signal(signal.SIGINT, signal.SIG_IGN)
54+
try:
55+
self.check_call(command)
56+
finally:
57+
signal.signal(signal.SIGINT, previous)
58+
5159
def bmp_attach(self, command, **kwargs):
5260
if self.elf_file is None:
5361
command = (self.gdb +
@@ -64,7 +72,7 @@ def bmp_attach(self, command, **kwargs):
6472
'-ex', "monitor swdp_scan",
6573
'-ex', "attach 1",
6674
'-ex', "file {}".format(self.elf_file)])
67-
self.check_call(command)
75+
self.check_call_ignore_sigint(command)
6876

6977
def bmp_debug(self, command, **kwargs):
7078
if self.elf_file is None:
@@ -76,7 +84,7 @@ def bmp_debug(self, command, **kwargs):
7684
'-ex', "attach 1",
7785
'-ex', "file {}".format(self.elf_file),
7886
'-ex', "load {}".format(self.elf_file)])
79-
self.check_call(command)
87+
self.check_call_ignore_sigint(command)
8088

8189
def do_run(self, command, **kwargs):
8290
if self.gdb is None:

0 commit comments

Comments
 (0)