Search code examples
iosmacosremote-debugginglldb

Remote debugging with lldb - wait for process


I know how to wait and attach to a local process (process attach --name procname --waitfor).
I also know how to run a remote debugserver and connect to it.

But how can I wait for a process to start on a remote host and attach to it?

EDIT

I have tried @Jim's suggestion, and it seems like the debug server is actually trying to attach but failing.
I am accepting his answer since it is correct, but I will be happy to know why I can't really debug the process.
FYI I am trying to debug mdmd (mdm daemon service) on a JB iPhone. The process launches for a few seconds to communicate with the mdm server, and then dies.

This is from the target's terminal:

~ root# debugserver *:1234
debugserver-310.2 for arm64.
Listening to port 1234 for a connection from *...
Got a connection, waiting for process information for launching or attaching.
Attach succeeded, ready to debug.
Exiting.

And this is from lldb's:

(lldb) process connect connect://localhost:1234
(lldb) process attach --name mdmd --waitfor
error: attach failed: unable to attach


Solution

  • The easiest way to do this is to start up the remote debugserver with only the port to connect to and no other arguments. In that mode it is driven completely by the lldb connected to it. So then just do:

    (lldb) process attach --name procname --waitfor
    

    and that will instruct the remote debugserver to wait for that process to show up and then it will attach to it.