This post is from a tip that Michael Ballantyne passed along to me.
Occasionally we encounter tests that fail infrequently. Debugging these can be very frustrating. Here is one technique that can help.
to your cmake configure line to include debug symbols but still do optimization. Inlining means that backtraces may not show exactly where errors occur, but it’s close enough and more likely to correctly reproduce than a build without optimization.
Per this StackOverflow answer, put the following in a file (here named commandfile):
set $_exitcode = -999 run if $_exitcode != -999 quit end
Then loop until gdb stalls on an error. In bash:
while gdb ./heateqn -x commandfile; do :; done
Finally, once gdb breaks on the segfault give it the command
backtrace to see details of the error.
If you’d like to make sure the script works, make a program that
always segfaults; put the following in segfault.c:
Compile and run as:
while gdb ./a.out -x commandfile; do :; done
It should immediately halt in gdb. Type backtrace to see the trace,
or quit 1 to exit gdb with a non-zero exit code so that the while