1

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;
        }
    }
  • GDB has ability to pass custom signals to the traced process. May be GDB sources will show you how it is achieved ? –  May 06 '15 at 14:54
  • 2
    The SIGSEGV handler isn't being ignored, it just hasn't been invoked yet because ptrace has told the OS to stop the target when a signal is delivered to it. You might want to try `ptrace(PTRACE_CONT, target, 0, SIGSEGV)` to continue the target while delivering the signal to it. – Mark Plotnick May 06 '15 at 16:25
  • thank you! I solved it!I was doing instead: ptrace(PTRACE_CONT, target, 0, 0) – Giacomo Travaglini May 07 '15 at 07:07

0 Answers0