I've set a signal handler for SIGCHLD. Out of curiosity, I'd like to try and debug the signal handler from within gdb. Is there any way I could do that?
I tried setting a breakpoint on the handler and running the binary from within gdb; however I dont seem to be able to debug the handler instruction by instruction. Is there any way I could go about doing that? I tried setting a hardware breakpoint but that did not help either. The code I'm playing around with is shown below.
I'm trying this on a 64 bit Ubuntu machine.
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int VAL = 0;
void handler(int sig) {
VAL=1;
}
int main(int argc, const char *argv[]) {
int pid, status;
signal(SIGCHLD, handler);
pid = fork();
if ( pid == 0 ) exit(0);
wait(&status);
printf("Returned from handler %d\n", VAL);
return 0;
}
The output printed is "Returned from handler 1" showing that SIGCHLD is handled by the process and not gdb; info signal
from within gdb also suggests the same.