user3245821
user3245821

Reputation: 167

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!

Upvotes: 4

Views: 2239

Answers (1)

Tom Tromey
Tom Tromey

Reputation: 22519

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.

Upvotes: 6

Related Questions