I have a custom test binary, which I use to run specific system tests (e.g. ./test test_case_1.yaml.
The exit code of ./testindicates if the system test succeeded.
I want to guard myself against future cases of segfaults that are extremely hard to reproduce segfaults by wrapping the program call with gdb. In case the program crashes I can then automatically (no user input: see this question) print the stacktrace and see where the error originated from.
My current issue is that once started with gdb, and with no segmentation fault occurring, I cannot retrieve the exit code of the system test and use it with my gitlab-ci runner. How can I get the gdb backtrace if the program crashes and otherwise just the exit code of ./test (as if gdb wasn't used)?
exit $_exitcodeat the end of your script to exit gdb with the exit code of the program.gdb -batch -ex bt ./test /path/to/coredumpshould work.