[lldb-dev] Loading symbols from location in memory

Greg Clayton gclayton at apple.com
Mon Dec 10 10:26:18 PST 2012


On Dec 9, 2012, at 4:49 AM, Benjamin Kemper <kemperbenny at gmail.com> wrote:

> Hi, 
> 
> I'm looking for a way to load symbol from a file from a specific address, the same as done in GDB using the "add-symbol-file" command.
> 
> The "target symbols add" lldb command only seems to accept the symbol file as the parameter, but I need to specify the area in the memory where the symbols exist (In GDB I usually point to the text section of the executable I want to add the symbols of). 
> 
> How can I do this in LLDB?

You don't set the load address on the symbols, you do this on the module. So first load the module (if it already isn't):

(lldb) target modules add /tmp/args/a.out

This assumes you have a target already. If you don't have a target you can just create one with the file:

(lldb) target create --arch x86_64 /tmp/args/a.out

Now you have a target is or contains /tmp/args/a.out, now you can set the __TEXT address using "target modules load":

(lldb) target modules load --file a.out __TEXT 0x100000
section '__TEXT' loaded at 0x100000

The arguments for "target modules load" are pairs of section names followed by a load address, so you could also set the __DATA and other sections:

(lldb) target modules load --file a.out __TEXT 0x100000 __DATA 0x333000
section '__TEXT' loaded at 0x100000
section '__DATA' loaded at 0x333000

Then add the symbols so you get debug info if they aren't found automatically. To see if LLDB already found your debug info use the "target modules list" command:

(lldb) target modules list a.out
[  0] A61A7AB0-1C2E-37D8-9FF8-347A6FAFF797 0x0000000000100000 /tmp/args/a.out 
      /tmp/args/a.out.dSYM/Contents/Resources/DWARF/a.out

Above we see that there is the file, and the next line shows it already found the dSYM file (the symbols).
If the dSYM file doesn't appear on the next line, you can add it:

(lldb) target symbols add /tmp/foo.dylib.dSYM





More information about the lldb-dev mailing list