title: Remote debugging with lldb - wait for process
body: <p>I know how to wait and attach to a local process (<code>process attach --name procname --waitfor</code>).<br>
  I also know how to run a remote <code>debugserver</code> and connect to it.</p>
  
  <p>But how can I wait for a process to start on a remote host and attach to it?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have tried <a href="https://stackoverflow.com/a/36460888/1609201">@Jim's suggestion</a>, and it seems like the debug server is actually <em>trying</em> to attach but <em>failing</em>.<br>
  I am accepting his answer since it is correct, but I will be happy to know why I can't really debug the process.<br>
  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.</p>
  
  <p>This is from the target's terminal:</p>
  
  <blockquote>
    <p>~ root# debugserver *:1234<br>
    debugserver-310.2 for arm64.<br>
    Listening to port 1234 for a connection from *...<br>
    Got a connection, waiting for process information for launching or attaching.<br>
    Attach succeeded, ready to debug.<br>
    Exiting.</p>
  </blockquote>
  
  <p>And this is from lldb's:</p>
  
  <blockquote>
    <p>(lldb) process connect connect://localhost:1234<br>
    (lldb) process attach --name mdmd --waitfor<br>
    error: attach failed: unable to attach  </p>
  </blockquote>