• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ptrace PT_CONTINUE
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ptrace PT_CONTINUE


  • Subject: Re: ptrace PT_CONTINUE
  • From: Aron-Zvi <email@hidden>
  • Date: Thu, 9 Jul 2009 10:03:46 +0300

I'm trying to launch and trace a child process similar to what gdb does. i.e. gdb foo folowed by (gdb)run.
 
For the first step, I'd like to launch a child process, have it stop at its first instruction and then have it resume normal execution. The code I posted is supposed to do just that.

Ultimately, I'd like to control execution of the child process by reading / writing to it's memory and its thread's registers. I know ptrace() doesn't do any of that in OS X and that it must be done using the mach api, however, I thought a simple ptrace(PT_CONTINUE, ...) on a stopped, traced child process should work. I've seen references on the net of ptrace(PT_CONTINUE, ...) usage to continue a stopped process.      

I'm sure you don't need to see this:
http://developer.apple.com/documentation/Darwin/Reference/Manpages/man2/ptrace.2.html

So what's the verdict? Can ptrace(PT_CONTINUE, ...) be used to continue a stopped, traced child process? If not, how do I go about it?

Aron-Zvi


On Thu, Jul 9, 2009 at 8:35 AM, Terry Lambert <email@hidden> wrote:
You are expected to exec after the fork, not be tracing your own code.  See the system_cmds project for the sc_usage source.

What are you really trying to do here?

-- Terry


On Jul 8, 2009, at 7:10 PM, Aron-Zvi wrote:
Hey guys,

I'm trying to get started with basic ptrace functionality with the following:


#include <sys/types.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char **argv)
{
   int pid, status, ret;

   if((pid = fork()) == 0)
   {
       ptrace(PT_TRACE_ME,0,0,0);
       execl(argv[1],argv[1],0);
       printf("exec failed\n");
   }
   else{
       wait(&status);
       if(WIFSTOPPED(status))
           printf("child has stopped. child pid: %d\n", pid);
       errno = 0;
       ret = ptrace(PT_CONTINUE, pid, (caddr_t)1, 0);
       printf("ret: %d\n", ret);
       printf("errno: %s\n", strerror(errno));
   }

}

>From my basic understanding, what the above should do is fork a child process which will stop at exec and cause the parent-tracing process to exit wait(). The parent process should then have the child process continue execution normally by calling ptrace() with PT_CONTINUE.

When I run the code, The child process is created, however, ptrace() with PT_CONTINUE seems to fail as the child process does not continue normal execution. ptrace's return value is 0 and errno is "Unknown error: 0".

Running output:

aronzvis-macbook:ptrace_test aronzvi$ ./ptrace ../voidinc
child has stopped. child pid: 37959
ret: 0
errno: Unknown error: 0


I'm running OS X 10.5.7 and building the code with the 10.5 SDK.

Your help is much appreciated,

Aron-Zvi
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >ptrace PT_CONTINUE (From: Aron-Zvi <email@hidden>)
 >Re: ptrace PT_CONTINUE (From: Terry Lambert <email@hidden>)

  • Prev by Date: Re: ptrace PT_CONTINUE
  • Next by Date: Re: ptrace PT_CONTINUE
  • Previous by thread: Re: ptrace PT_CONTINUE
  • Next by thread: Re: ptrace PT_CONTINUE
  • Index(es):
    • Date
    • Thread