December 22, 2005
(Posted at 5:51 am)PTRACE_SINGLESTEP
ptrace() needs to be reminded again & again that in what mode is it operating. So if you have to single-step through all the instructions in a program, you need to constantly call (or set) ptrace request to PTRACE_SINGLESTEP
For example, this code will just single-step through first 10 instructions.
while(1)
{
wait(&status);
if(WIFEXITED(status))
{
printf("Breaking\n");
break;
}
ptrace(PTRACE_GETREGS, child, NULL, ®s);
ins = ptrace(PTRACE_PEEKTEXT, child, regs.eip, NULL);
printf("(i = %d) EIP : 0x%X (%X)\n", i, regs.eip, ins);
i++;
if(i < 10 )
ptrace(PTRACE_SINGLESTEP, child, NULL, NULL);
}


