views:

379

answers:

3

I have a process that spawns a helper process. Sometimes I need to debug start-up failures in the second process.

On Windows, I would use Image File Execution Options, or ntsd -o. However, I have no idea how to do this with gdb on OS X.

+2  A: 

I don't think that you can have gdb launch in the same manner. Instead, run your parent process from within gdb or attach to the running process before it forks the helper off. There is a setting called follow-fork-mode that controls which process the debugger follows. Take a look at the GDB Manual for a nice description.

D.Shawley
Ah, that indeed seems like something I would need. It seems to imply the parent process is no longer debugged after the vfork(), but I'll try it. That would be sad, however, if it is the case.
jeffamaphone
Well, that was a quick acceptance. :-) See my answer. gdb --wait does what you want.
Ken
@jeff: you can always attach to the parent again with a different instance of gdb. I'm not sure if it detaches from the parent or not. It has been a while since I debugged an Apache module using this.
D.Shawley
+2  A: 

Use gdb --wait. For example, try

gdb --wait TextEdit

from the command line, then launch TextEdit.

Ken
That's a good idea too.
jeffamaphone
This works best.
jeffamaphone
+2  A: 

If you're using launchd to spawn processes, then there's a WaitForDebugger boolean key which goes in the job's plist file. If it's yes, then launchd waits (surprisingly!) for the debugger before exec()ing the job.

Graham Lee
Also interesting. How does one use launchd to spawn a process? I've been using fork() and exec().
jeffamaphone
I'll let Quinn answer for me: http://developer.apple.com/mac/library/technotes/tn2005/tn2083.htmlAlso check out the man page for launchd.plist(5)
Graham Lee