Spread and use Firefox
Advertise on this blog!
-->

Subscribe to my posts via Email


Delivered by FeedBurner

I'm an Indian
Darn proud of being an Indian!

Links...

Categories

Archives

Friends



Subscribe





External Links


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, &regs);
 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);
}

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image