How to get SBTarget before AttachToProcessWithID?


Normally if you want to attach to a process you only have the pid/name of the process. How do you get SBTarget? Am I supposed to call SBDebugger.CreateTargetWithFileAndArch() against a dummy executable? Why do we require a dummy SBTarget before attaching? This seems to be a wrong design to me… Thanks.


it's a bit un-intuitive, but you should be able to create a target
with a null pointer for the executable, and use that to attach (see

BTW, if you find the existing API documentation too vague, we'd be
happy to accept any improvements.


Often when attaching, you know the executable you are planning to attach to. So the "normal" workflow is to create a target, then attach to the process with that target's executable. This is particularly useful for remote debugging, since having a local copy of the binary will mean less data lldb has to ship over the remote connection. It also means you can prep the target with breakpoints & settings prior to attach.

The case where you don't know the binary before you attach is a degenerate case of this, and so the sensible thing is to create an empty target, and use that to attach. Then attaching will fill in this empty target.

That makes more sense to me than having the debugger - which is the only thing above the target - support "Attach to anonymous app" but the target do "attach to known app".

BTW, the most straightforward way to create an empty target is to call SBDebugger.CreateTarget(""). I added a note to this effect in the SBDebugger help preamble.


Thanks guys, will give empty target a try.