Here is some reference:
http://nirbhay.in/2012/09/debug-signal-handlers-using-gdb/
Let's do some experiment with this program:
/*
@file : sig.c
*/
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
void signalhandler(int signum) {
printf("\n SIGINT caught : %d", signum);
}
int main() {
signal(SIGINT, signalhandler);
while (1) {
printf("\n looping : inside main()");
sleep(1);
}
}
in this case you can do this way:
(gdb) handle SIGINT stop pass
after that, you step forward to get the signal handler function. Here I got:
$ gdb ./a
...
(gdb) handle SIGINT stop pass
SIGINT is used by the debugger.
Are you sure you want to change it? (y or n) y
Signal Stop Print Pass to program Description
SIGINT Yes Yes Yes Interrupt
(gdb) r
Starting program: /home/arc/a
looping : inside main()
looping : inside main()
^C
Program received signal SIGINT, Interrupt.
0x00007ffff7aef900 in __nanosleep_nocancel () from /usr/lib/libc.so.6
(gdb) s
Single stepping until exit from function __nanosleep_nocancel,
which has no line number information.
0x0000000000400596 in signalhandler(int) ()