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.

Share:
12,631

Related videos on Youtube

Roman Plášil
Author by

Roman Plášil

Updated on July 23, 2022

Comments

  • Roman Plášil
    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?

  • inherithandle
    inherithandle almost 11 years
    How should I create another instance of lldb?
  • Roman Plášil
    Roman Plášil almost 11 years
    open another terminal window and run lldb in the command line
  • glennr
    glennr over 10 years
    The attach -w -n syntax is for gdb. In lldb it's process attach -n myapp -w, which can be abbreviated to pro at -n myapp -w. lldb.llvm.org/lldb-gdb.html
  • mbauman
    mbauman over 10 years
    I 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 a sleep call to slow things down gave lldb time to attach.
  • inherithandle
    inherithandle over 10 years
    I've found a good solution. read this thread
  • ahuigo
    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 command lldb; 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
    Paul J. Lucas over 8 years
    When I try this, I get "error: attach failed: lost connection."