My process starts child processes and I want to debug these as well, using LLDB on OS X. I can't find any option in the debugger to auto-attach. How to do it?
2 Answers
Google is really silent on this issue, but I found a workaround.
Run your main process and stop it before it spins off any children. Then put a breakpoint on the function fork
:
b fork
and let the program continue. When it is about to launch a child process, the breakpoint will be hit. At this moment, run another instance of LLDB and let it wait and autoattach to your process:
attach -w -n yourapp
Now let the parent program continue.
-
2
-
-
10The
attach -w -n
syntax is for gdb. In lldb it'sprocess attach -n myapp -w
, which can be abbreviated topro at -n myapp -w
. lldb.llvm.org/lldb-gdb.html– glennrAug 29, 2013 at 20:17 -
3I had difficulty getting lldb to attach because my child process was crashing immediately (
attach failed: process did not stop (no such process or permission problem?
). Adding asleep
call to slow things down gave lldb time to attach.– mbaumanNov 21, 2013 at 17:37 -
2When I try this, I get "error: attach failed: lost connection." Sep 3, 2015 at 16:46