Closed nickdesaulniers closed 1 year ago
Ugh... I am not really sure how to fix this. We can intercept Ctrl-C via the KeyboardInterrupt
exception and pass it along to gdb
via send_signal(signal.SIGINT)
, keeping control of the script, but QEMU gets killed by gdb
when it receives SIGINT
it seems. I found https://bugzilla.kernel.org/show_bug.cgi?id=9039 from https://stackoverflow.com/questions/30925198/how-to-pass-sigint-to-child-process-with-python-subprocess-popen-using-shell, which makes it seem like this is expected behavior...
In the meantime, we could either suggest using kill -2
or just stop running gdb
altogether, instead printing the gdb
command that should be run in a separate terminal.
but QEMU gets killed by gdb when it receives SIGINT it seems
That's not what happened when I ran kill -SIGINT <pid of gdb>
above; I was able to run bt
in gdb
after.
Sorry I did not make myself clear enough. That is what happened when I was able to intercept Ctrl-C from Python and pass it to the gdb
process. I tried something like this:
if gdb:
utils.check_cmd(gdb_bin)
gdb_cmd = [
gdb_bin,
kernel_location.joinpath('vmlinux'),
'-ex', 'target remote :1234'
] # yapf: disable
while True:
utils.check_cmd("lsof")
lsof = subprocess.run(["lsof", "-i:1234"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=False)
if lsof.returncode == 0:
utils.die("Port 1234 is already in use, is QEMU running?")
utils.green("Starting QEMU with GDB connection on port 1234...")
qemu_process = subprocess.Popen(qemu_cmd + ['-s', '-S'])
utils.green("Starting GDB...")
gdb_process = subprocess.Popen(gdb_cmd)
while True:
try:
gdb_process.wait()
except KeyboardInterrupt:
gdb_process.send_signal(signal.SIGINT)
else:
break
utils.red("Killing QEMU...")
qemu_process.kill()
answer = input("Re-run QEMU + gdb? [y/n] ")
if answer.lower() == "n":
break
if I use
ctrl+c
in gdb mode, I get a crash:but if I
ps -ef | grep gdb
then send that process a SIGINTkill -SIGINT <pid>
I get the expected output:This is important because it's common to halt the machine to grab a back trace via
ctrl+c
thenbt
in gdb.