Gdb: Passing Signals to Your Application

In some situations you need to debug your signal handler code. When using gdb, you soon notice, that gdb’s default behaviour is to consume the signals itself. you can change the default behaviour by issuing the following command as an example:

(gdb) handle SIGINT pass

This instructs gdb to pass over the signal to your application where further signal handling occurs (in your signal handler code). Set a breakpoint there and we’re up and running again.

Important: Don’t forget to set a breakpoint in your signal handler code. After gdb receives the SIGINT signal, a message will appear like this:

Program received signal SIGINT, Interrupt.
0x00007ffff7bcd4dd in accept () from /lib/

Now issue this command in gdb to continue with debugging. Gdb will then enter your signal handler code:

(gdb) c

In my case, gdb showed the following output after pressing “c”, which is fine:

Breakpoint 1, shutdown_server (sig=2) at chatsrv.c:190
190			for (i = 0; i < llist_get_count(&ll_clients); i++)

Leave a Reply

Your email address will not be published. Required fields are marked *