[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]
Re: ptrace problems
On Mon, 28 Feb 2000, Shourya Sarcar wrote:
>
> Programmerz,
> This is a little pair of programs I wrote. The father tries to behave
> like a debugger and get the register values of the child. But I keep on
> getting incorrect results. Rather no results at all.
> Help, someone. Anyone .
hello,
Your code worked with two modifications which I am giving below.
> err=ptrace(PTRACE_ATTACH,child_pid,0,0);
> if (err<0)
> fatal_error("Invalid Ptrace in PTRACE_ATTACH");
> else
> printf("Successful ptrace ATTACH\n");
>
sleep(1); /* Wait for some time. I have not dug up
the source to find out why this works.
But it works! If you find the reason,
please inform me. I am curious. */
> /*Get the regs */
> err=ptrace(PT_GETREGS,child_pid,NULL,gpregs);
> printf ("Err = %d\n",err);
> if (err<0) fatal_error("Invalid Ptrace in GETREGS");
> printf("EAX : 0x%lx\n",gpregs[EAX]);
> printf("CS : 0x%lx\n",gpregs[CS]);
> printf("EIP : 0x%lx\n",gpregs[EIP]);
Modification in execed process.
>
> for (i=0;i<1000000000L;i+=5);
> printf("Program new stopped\n");
for(;;); /* just to make extra sure no premature death
occurs */
>
> return 0;
> }
regards,
pramode.