c - Debugging signal handlers on Linux -
i've set signal handler sigchld. out of curiosity, i'd try , debug signal handler within gdb. there way that?
i tried setting breakpoint on handler , running binary within gdb; dont seem able debug handler instruction instruction. there way go doing that? tried setting hardware breakpoint did not either. code i'm playing around shown below.
i'm trying on 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 handler %d\n", val); return 0; }
the output printed "returned handler 1" showing sigchld handled process , not gdb; info signal
within gdb suggests same.
gdb’s handle command can used. handle command takes, argument, list of signals (to handled) followed actions. can use following gdb options nostop & pass (let program see signal).
http://sunsite.ualberta.ca/documentation/gnu/gdb-5.0/html_node/gdb_38.html
Comments
Post a Comment