[lldb-dev] How to get SBTarget before AttachToProcessWithID?

Jim Ingham via lldb-dev lldb-dev at lists.llvm.org
Mon Feb 1 12:10:18 PST 2016


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.

Jim

> On Feb 1, 2016, at 2:02 AM, Pavel Labath via lldb-dev <lldb-dev at lists.llvm.org> wrote:
> 
> Hi,
> 
> 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
> CommandObjectProcessAttach::DoExecute).
> 
> BTW, if you find the existing API documentation too vague, we'd be
> happy to accept any improvements.
> 
> cheers,
> pl
> 
> 
> On 30 January 2016 at 05:42, Jeffrey Tan via lldb-dev
> <lldb-dev at lists.llvm.org> wrote:
>> Hi,
>> 
>> 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.
>> 
>> 
>> 
>> _______________________________________________
>> lldb-dev mailing list
>> lldb-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev
>> 
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev



More information about the lldb-dev mailing list