Inquiry about Load Address

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 ? secondly Can we obtain the dumps of the loaded Elf 's like in the remote case transporting them from the target to the host ?

BR,
A Ravi Theja

Hi,

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...

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
<http://lldb.llvm.org/cpp_reference/html/classlldb_1_1SBSection.html&gt;\.
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.

pl

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.

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);
if (addr.GetSection().IsValid())
{
    // Load address mapped to an address that is in a section from a SBModule
}
else
{
    // 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:

lldb::SBInstructionList instructions;
if (function.IsValid())
    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):

if (instructions.IsValid())
{
    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
            inst.Print(stdout);
        }
    }
}