Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB backtrace without stopping

I am trying to let my program run continously with GDB. Currently I have a bash script which starts GDB with my program and when it crashes it prints the backtrace and starts GDB again (endless loop).

Now I added a signal handler for my program which kills specific threads when the handler gets a signal from them. Now I can achieve that GDB does not stop by doing this:

handle SIGSEGV nostop

But this leads me to the problem that I do not get a GDB backtrace which I would like to print automatically without stopping the program (or at least continuing automatically).

Any help would be appreciated!

like image 975
user3245821 Avatar asked Sep 13 '25 01:09

user3245821


1 Answers

Continue to use handle to suppress ordinary stops from SEGV. Then set a catchpoint that does what you want:

(gdb) catch signal SIGSEGV
(gdb) commands
    >   silent  # this bit is optional
    >   bt
    >   continue
    >   end

This will print a backtrace on SIGSEGV but not otherwise interfere with normal operation. You may also want handle SIGSEGV noprint.

like image 81
Tom Tromey Avatar answered Sep 15 '25 15:09

Tom Tromey