[lldb-dev] Inquiry about Load Address
Greg Clayton via lldb-dev
lldb-dev at lists.llvm.org
Tue Mar 8 10:58:11 PST 2016
If you are connected to a live process, you just need to look up the lldb::SBAddress for a load address using the SBTarget
lldb::SBTarget target = ...;
lldb::addr_t load_addr = ...;
lldb::SBAddress addr = target.ResolveLoadAddress (load_addr);
// Load address mapped to an address that is in a section from a SBModule
// Address doesn't map to a known section and is probably on the stack or heap
Also note that once you have an SBAddress (which is a section + offset address) you can easily find all of the things it maps to (executable (SBModule), source file (SBCompileUnit), function (SBFunction), etc).
Using the "addr" we looked up above you can find out what "addr" maps to:
lldb::SBModule module = addr.GetModule();
The following items will be available if you have debug info for your executable:
lldb::SBCompileUnit cu = addr.GetCompileUnit ();
lldb::SBFunction function = addr.GetFunction ();
lldb::SBBlock block = addr.GetBlock();
lldb::SBLineEntry line_entry = addr.GetLineEntry ();
And the following will be available if you have a valid symbol table (you haven't stripped your binary):
lldb::SBSymbol symbol = addr.GetSymbol();
Any of the objects above might be invalid, just use "IsValid()" on them to test if they are valid. A load address might be in a section (.data + 10023) but it might not map to a compile unit, function, block or line entry...
Also note that you can easily get to the disassembly instructions for the function or symbol very easily:
instructions = function.GetInstructions(target);
else if (symbol.IsValid())
instructions = symbol.GetInstructions(target);
Now you have a list of all instructions for a given function (if you have debug info) or symbol (if you don't have debug info):
const size_t num_instructions = instructions.GetSize();
if (num_instructions > 0)
for (size_t inst_idx=0; inst_idx<num_instructions; ++inst_idx)
lldb::SBInstruction inst = instructions.GetInstructionAtIndex(idx);
lldb::Address inst_addr = inst.GetAddress();
const char *mnemonic = inst.GetMnemonic (target);
const char *operands = inst.GetOperands (target);
const char *comment = inst.GetComment (target);
lldb::SBData inst_bytes = inst.GetData (target);
// Just print to stdout
> On Mar 8, 2016, at 4:53 AM, Ravitheja Addepally via lldb-dev <lldb-dev at lists.llvm.org> wrote:
> Ok, I am currently in the process of developing Intel Processor trace support for LLDB , I need the virtual address mappings for the Elf's for decoding the trace data. I will check if SBSection.GetSectionData will work or not , Thanks for the info.
> On Tue, Mar 8, 2016 at 12:11 PM, Pavel Labath <labath at google.com> wrote:
> could you give us a bit more background about what are you trying to
> do? It's hard to answer the question without knowing a bit more...
> On 8 March 2016 at 10:42, Ravitheja Addepally via lldb-dev
> <lldb-dev at lists.llvm.org> wrote:
> > Hello,
> > I wanted to know if there is any existing API or a set of API's that
> > could be used to retrieve the load addresses of the Modules ?
> There is a GetLoadAddress function on SBSection
> I don't see one on SBModule though. What do you need this for?
> > secondly Can
> > we obtain the dumps of the loaded Elf 's like in the remote case
> > transporting them from the target to the host ?
> What kind of "dumps" are you looking for? Will
> SBSection.GetSectionData() work? A lot of other data is available in
> the other SB classes, but it's hard to answer this without knowing
> what exactly you are looking for.
> lldb-dev mailing list
> lldb-dev at lists.llvm.org
More information about the lldb-dev