[ptrace] PTRACE_SINGLESTEP

Xie&Tian mftian@gmail.com
Fri Sep 5 17:17:00 GMT 2008


hi everybody

I'm new to debugger and am confused by this PTRACE_SINGLESTEP param.
It seems that with PTRACE_SINGLESTEP, the child process traced doesn't
stop after every execution of an instruction. And according to
comments in linux-low.c in GDB, we can get only one SIGTRAP signal.
Can anybody tells more about PTRACE_SINGLESTEP?

Thanks

------------------
My test program is here(dummy is a target program for test):

#include <stdio.h>
#include <sys/ptrace.h>
#include <asm/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <linux/user.h>
#include <sys/syscall.h>
int main()
{
    pid_t child;

    child = fork();
    if(child == 0)
    {
        ptrace(PTRACE_TRACEME, 0, NULL, NULL);
        execl("./dummy1", "dummy1", NULL);
    }
    else
    {
        int status;
        struct user_regs_struct regs;
        long ins;

        while(1)
        {
            wait(&status);
            if(WIFEXITED(status))
                break;
            ptrace(PTRACE_GETREGS, child, NULL, &regs);
            ins = ptrace(PTRACE_PEEKTEXT, child, regs.eip, NULL);
            printf("EIP: %lx Instruction executed: %lx\n", regs.eip, ins);
            ptrace(PTRACE_SINGLESTEP, child, NULL, NULL);
      // here we can substitute PTRACE_SINGLESTEP with

                                     // PTRACE_CONT or PTRACE_SYSCALL
to see

                                     // their different behaviors
        }
    }
    return 0;
}



More information about the Gdb mailing list