From 4beafc64c00538a30c988de39082ab06659c9284 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Fri, 16 Dec 2022 11:45:59 -0800 Subject: [PATCH] boot-qemu.py: fix ctrl+c in gdb Detach QEMU from the process group so that SIGINT isn't also delivered to it. Ignore SIGINT in python when running GDB subprocess. Link: https://stackoverflow.com/a/13737455 Link: https://stackoverflow.com/q/30925198 Fixes: https://github.com/ClangBuiltLinux/boot-utils/issues/86 --- boot-qemu.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/boot-qemu.py b/boot-qemu.py index f4faec2..eaa86a6 100755 --- a/boot-qemu.py +++ b/boot-qemu.py @@ -755,6 +755,7 @@ def launch_qemu(cfg): if gdb: utils.check_cmd(gdb_bin) + qemu_cmd += ["-s", "-S"] while True: utils.check_cmd("lsof") @@ -766,12 +767,18 @@ def launch_qemu(cfg): utils.die("Port 1234 is already in use, is QEMU running?") utils.green("Starting QEMU with GDB connection on port 1234...") - with subprocess.Popen(qemu_cmd + ["-s", "-S"]) as qemu_process: + with subprocess.Popen(qemu_cmd, + preexec_fn=os.setpgrp) as qemu_process: utils.green("Starting GDB...") gdb_cmd = [gdb_bin] gdb_cmd += [kernel_location.joinpath("vmlinux")] gdb_cmd += ["-ex", "target remote :1234"] - subprocess.run(gdb_cmd, check=False) + + with subprocess.Popen(gdb_cmd) as gdb_process: + try: + gdb_process.wait() + except KeyboardInterrupt: + pass utils.red("Killing QEMU...") qemu_process.kill()