summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Baltieri <fabiobaltieri@google.com>2023-03-30 17:00:54 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-04-03 19:03:53 +0000
commitc1624d1d6a1c9e05cf7dd898c63047f8095f6ec2 (patch)
tree1ccdd0fe4cd383472c77dcd189b3bfb508e0aefd
parentfef3763f1534f2e01423e4b44a13cc2efefc48cf (diff)
downloadchrome-ec-c1624d1d6a1c9e05cf7dd898c63047f8095f6ec2.tar.gz
ec_openocd: handle sigint properly
Currently sigint is passed to everything here, openocd, gdb, the python interpreter. This makes it impossible to interrupt the current execution without a breakpoint. Fix that by ignoring the signal for the python interpreter using signal, and ignoring it for openocd using setsid. BRANCH=none BUG=b:276311425 TEST=./util/ec_openocd.py --board rex debug TEST=./util/ec_openocd.py --board rex debug -x Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Change-Id: I4d73561985a19bcfe92bf1a85f8fda272ec36cb7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4386298 Reviewed-by: Robert Zieba <robertzieba@google.com>
-rwxr-xr-xutil/ec_openocd.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/util/ec_openocd.py b/util/ec_openocd.py
index 76348c6329..325e1ab7c8 100755
--- a/util/ec_openocd.py
+++ b/util/ec_openocd.py
@@ -7,7 +7,9 @@
import argparse
import dataclasses
import distutils.spawn
+import os
import pathlib
+import signal
import socket
import subprocess
import sys
@@ -111,6 +113,7 @@ def debug(interface, board, port, executable, attach):
encoding="utf-8",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
+ preexec_fn=os.setsid,
)
# Wait for OpenOCD to start, it'll open a port for GDB connections
@@ -130,8 +133,10 @@ def debug(interface, board, port, executable, attach):
sock.close()
- gdb_args = create_gdb_args(board, port, executable, attach)
+ old_sigint = signal.signal(signal.SIGINT, signal.SIG_IGN)
+
# Start GDB
+ gdb_args = create_gdb_args(board, port, executable, attach)
gdb = subprocess.Popen(
gdb_args, stdout=sys.stdout, stderr=subprocess.STDOUT, stdin=sys.stdin
)
@@ -141,6 +146,8 @@ def debug(interface, board, port, executable, attach):
(output, _) = openocd.communicate()
openocd_out += output
+ signal.signal(signal.SIGINT, old_sigint)
+
# Wait for OpenOCD to shutdown
print("Waiting for OpenOCD to finish...")
if openocd.poll() == None:
@@ -160,6 +167,9 @@ def debug(interface, board, port, executable, attach):
def debug_external(board, port, executable, attach):
"""Run GDB against an external gdbserver."""
gdb_args = create_gdb_args(board, port, executable, attach)
+
+ old_sigint = signal.signal(signal.SIGINT, signal.SIG_IGN)
+
subprocess.run(
gdb_args,
stdout=sys.stdout,
@@ -168,6 +178,8 @@ def debug_external(board, port, executable, attach):
check=True,
)
+ signal.signal(signal.SIGINT, old_sigint)
+
def get_flash_file(board):
return (