Search code examples
linuxdebuggingremote-debugginglldb

How to debug LLDB debugserver using itself


I'm trying to debug LLDB's debugserver whilst it's running remotely, using debugserver. Is there a proper way to do this?

For brevity lets call the debugserver I'm trying to debug D1, connected to LLDB L1. Debugserver debugging it D2 & L2, and inferior process P. D1 and D2 using different ports.

What I've tried so far is connecting D1 to P as usual then stop at a breakpoint. Before attaching D2 with -a PID. When I try to connect L2 to D2 however D1 gets sent a stop signal and is killed.

I've also tried running ./D2 localhost:4000 ./D1 localhost:1234 P which kind of works as both L2 and L1 connect. However D2 keeps on getting interrupted with stop signals from libc which aren't handled.

Sorry if that's not clear but has anyone else attempted this?


Solution

  • You might want to try running your inferior debugserver (D1) and then attaching to it with your superior debugserver (D2) and see if that helps. e.g.

    term1% ./D1 localhost:1234 P
    
    term2% ./D2 localhost:4000 --attach pid-of-D1
    

    Alternatively, if you need to catch the D1 debugserver early in its startup, debugserver has some command line args not documented by -help like -waitfor which tells debugserver to continuously poll the list of running processes, looking for a new process starting up with that name. e.g.

    term1% ./D2 localhost:4000 --waitfor D1
    
    term2% ./D1 localhost:1234 P