How to automate gdb core dumping when receiving signal

407 views Asked by At

I want to avoid the situation in which you forget to generate the core dump file after application got SIGSEGV, you leave gdb and you lost the information about that crash.

What I'm looking for is the analogue to commands (for breakpoints), so I can script a set of commands to execute when my app receives a signal.

Something beeing executed after each command could work too, just like display does. The point here is that I couldn't find how to check if X signal was generated.

At first, I prefer it to be something to configure inside gdb. By that, I mean not having to change how app/gdb are beeing launched.

Thanks in advance.

1

There are 1 answers

0
Mark Plotnick On BEST ANSWER

If your gdb supports the catch signal command, you can script it just like a breakpoint.

$ gdb ab
(gdb) list
1   main()
2   {
3       abort();
4   }
(gdb) catch signal SIGABRT
Catchpoint 1 (signal SIGABRT)
(gdb) commands
Type commands for breakpoint(s) 1, one per line.
>generate-core-file 
>end
(gdb) run
Catchpoint 1 (signal SIGABRT), 0x00007ffff7a4692f in raise ()
   from /lib64/libc.so.6
Saved corefile core.2097