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);
}
}
}