I seem to have some kind of multithreading bug in my code that makes it crash once every 30 runs of its test suite. The test suite is non-interactive. I want to run my test
The easiest way is to use the Python API offered by gdb
:
def exit_handler(event):
gdb.execute("quit")
gdb.events.exited.connect(exit_handler)
You can even do it with one line:
(gdb) gdb.events.exited.connect(lambda x : gdb.execute("quit")
You can also examine the return code to ensure it's the "normal" code you expected with event.exit_code
.
You can use it in conjuction with --eval-command
or --command
as mentioned by @acm to register the event handler from the command line, or with a .gdbinit
file.