[lldb-dev] How to get the entry point of a target like the one in --stop-at-entry

jingham at apple.com jingham at apple.com
Mon Feb 17 13:00:00 PST 2014


Ah, turns out you are asking a slightly different question there.  You want the entry point of the code in an object file, which isn't actually where "process launch --stop-at-entry" will stop you.  The -stop-at-entry actually stops before the first instruction of the program is executed - which is usually well before the entry point (e.g. main) of an object file.  

Anyway, there is an API - ObjectFile::GetEntryPointAddress that will return the "place the dynamic loader will jump to when it starts to execute code from a main executable."  It isn't currently available through the SB API's, but it would be trivial to make it available.  Feel free to do this if you need it.

Jim

On Feb 17, 2014, at 12:46 PM, Yin Ma <yin at affinic.com> wrote:

> Hi Jim,
> 
> In gdb, after an executable is loaded, if you run
> Info target, it will tell the information of its entry point. 
> I believe the Mach-O/ELF/PE should have this defined so OS
> Knows where to start the text section.
> 
> Our debugger GUI uses this information to help users do 
> Better to analyze an executable in assembly level when
> Debugger symbol is not available. So I am wondering if lldb can 
> provide this information also by some ways.
> 
> Thanks,
> 
> Yin 
> 
> -----Original Message-----
> From: jingham at apple.com [mailto:jingham at apple.com] 
> Sent: Monday, February 17, 2014 11:15 AM
> To: Yin Ma
> Cc: lldb-dev at cs.uiuc.edu
> Subject: Re: [lldb-dev] How to get the entry point of a target like the one in --stop-at-entry
> 
> lldb doesn't implement "stop at entry" by putting a breakpoint on some function and hitting it.  Traditionally on ptrace based systems this was implemented using the "PT_TRACEME" ptrace argument run in the child side of the fork that will create the target process, and on MacOS X, we use a posix_spawn option to start a process suspended that does basically the same thing.
> 
> So we don't know in advance where this entry point will be.  We just tell the OS to start the target suspended and then assume when it starts, that's where it is...
> 
> I note that in one place (following exec's on OS X) we hard code the knowledge that _dyld_start is where "start suspended" is expected to end up.  That's informally done there, it's not a property of the dynamic linker plugin.  If this is generally determinable in advance, we could make this an API on the dynamic linker plugin.
> 
> Anyway, maybe we could be more help if we knew why you wanted to know this.
> 
> Jim
> 
> On Feb 16, 2014, at 3:17 PM, Yin Ma <yin at affinic.com> wrote:
> 
>> Hi,
>> 
>> LLDB has provided an option to –stop-at-entry. I would like to
>> Get the address of this entry point by a way. I checked API
>> I didn’t found a function that could get this information. Could
>> Anyone help me on this?
>> 
>> Thanks,
>> 
>> Yin
>> _______________________________________________
>> lldb-dev mailing list
>> lldb-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev
> 





More information about the lldb-dev mailing list