When running gdb cmd
I can manually stop cmd
via Ctrl-C. This invokes the debugger and lets me inspect memory.
In pwntools, I can attach gdb, and can manually stop the process by hitting Ctrl-C in the gdb window. I'd like to be able to do this programatically from pwntools script: something like:
if output != expected:
io.gdb.ctrlc() # break, let me use gdb
This doesn't necessarily require a pwntools answer. GDB has a powerful Python API, but I can't find in it the equivalent of a "Interrupt the process, as if someone hit Ctrl-C". Is there a way to do that, either via the GDB Python API or via a pwntools method?
We can send a signal to gdb to simulate hitting Ctrl-C in the gdb window
prepare a file gdb_run3s:
#let shell send a signal to the parent process, which is the gdb, after 3 seconds
shell sleep 3 && kill -SIGINT $PPID &
#continue, should break by signal SIGINT 3 seconds later
c
#now can read/write register/memory
set $pc=xxx
then source it in gdb
(gdb) source gdb_run3s