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 suite in gdb, and have gdb exit normally if the program exits normally, or break (and show a debugging prompt) if it crashes. This way I can let the test suite run repeatedly, go grab a cup of coffee, come back, and be presented with a nice debugging prompt. How can I do this with gdb?
Share
This is a little hacky but you could do:
If a.out terminates normally, it will just drop you out of GDB. But if you crash, the program will still be active, so GDB will typically prompt if you really want to quit with an active inferior:
Like I said, not pretty, but it works, as long as you haven’t toggled off the prompt to quit with an active process. There is probably a way to use gdb’s
quitcommand too: it takes a numeric argument which is the exit code for the debugging session. So maybe you can use –eval-command=”quit stuff”, where stuff is some GDB expression that reflects whether the inferior is running or not.This program can be used to test it out: