How to attach to child process in LLDB
12,631
Solution 1
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.
Solution 2
https://bugs.llvm.org/show_bug.cgi?id=17972 seems to be a relevant LLDB issue.
Related videos on Youtube
Author by
Roman Plášil
Updated on July 23, 2022Comments
-
Roman Plášil over 1 year
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?
-
Alexander O'Mara over 2 years
-
-
inherithandle almost 11 yearsHow should I create another instance of
lldb
? -
Roman Plášil almost 11 yearsopen another terminal window and run lldb in the command line
-
glennr over 10 yearsThe
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 -
mbauman over 10 yearsI 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. -
inherithandle over 10 yearsI've found a good solution. read this thread
-
ahuigo over 9 years@inherithandle You can open two terminal tabs, one is for parent process and the other is for child process. Execute commands
lldb a.out; lldb> b fork; lldb> run
to start parent process. when the parent process stop at breakpoint(before it spins off children) , you can use commandlldb; pro at -n a.out -w
in the second terminal tab. The second lldb will catch the children process forked from parent process. -
Paul J. Lucas over 8 yearsWhen I try this, I get "error: attach failed: lost connection."