// ezptrace.c // source: http://stackoverflow.com/questions/7697344/why-doesnt-ptrace-singlestep-work-properly #include #include #include #include #include #include int main() { pid_t child; child = fork(); if (child == 0) { char *argv[] = { "ezptraceme", NULL }; ptrace(PTRACE_TRACEME, 0, NULL, NULL); execv(argv[0], argv); } else { int status; wait(&status); // struct user_regs_struct regs; int stepno = 0; while (1) { // ptrace(PTRACE_GETREGS, child, NULL, ®s); // printf("eip: %x\n", (unsigned int) regs.eip); printf("step %d\n", stepno++); ptrace(PTRACE_SINGLESTEP, child, NULL, NULL); waitpid(child, &status, 0); if(WIFEXITED(status)) break; } printf("end\n"); } return 0; }