I'm new to ptrace and I'm not able to solve this problem. I've copied and edited a simple debugger made with the ptrace system call and I'm trying to debug a test program that just makes use of a SIGSEGV handler... basically what I'm doing with the dummy program is:
void segv_handler(int signum){ printf("I'm inside the routine\n"); } void main(){ int h; signal(SIGSEGV, segv_handler); printf("Hello\n"); raise(SIGSEGV); printf("Hello2\n"); }
Easy.. The point is that my debugger gets notified of the SIGSEGV, in fact I get on the screen the result of the SIGSEGV printf, while the program doesn't print "I'm inside the routine", meaning that the segv_handler is beeing ignored. How is this possible? And how can I solve this problem?
if(WIFSTOPPED(status)){
switch(WSTOPSIG(status)){
case SIGTRAP:
//printf("SIGTRAP\n");
break;
case SIGSTOP:
printf("SIGSTOP\n");
break;
case SIGSEGV:
printf("SIGSEGV\n");
//ptrace();
break;
default:
printf("else\n");
break;
}
}