Understand absolute base addresses in ProcessGDBRemote::GetLoadedModuleList.

Summary:
This is useful when dealing with Windows remote that use only the
qXfer:libraries command which returns absolute base addresses, as
opposed to qXfer:libraries-svr4 which returns relative offsets for
module bases.

Reviewers: clayborg, zturner, ADodds

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D12204

llvm-svn: 245625
This commit is contained in:
Stephane Sezer 2015-08-20 22:07:48 +00:00
parent 4268d39436
commit c6845a0ddd
2 changed files with 28 additions and 8 deletions

View File

@ -216,6 +216,16 @@ public:
return m_has[e_has_base];
}
void set_base_is_offset (bool is_offset)
{
m_base_is_offset = is_offset;
}
bool get_base_is_offset(bool & out) const
{
out = m_base_is_offset;
return m_has[e_has_base];
}
void set_link_map (const lldb::addr_t addr)
{
m_link_map = addr;
@ -250,6 +260,7 @@ public:
std::string m_name;
lldb::addr_t m_link_map;
lldb::addr_t m_base;
bool m_base_is_offset;
lldb::addr_t m_dynamic;
};
@ -4594,7 +4605,8 @@ ProcessGDBRemote::GetLoadedModuleList (GDBLoadedModuleInfoList & list)
{
// the displacement as read from the field 'l_addr' of the link_map struct.
module.set_base(StringConvert::ToUInt64(value.data(), LLDB_INVALID_ADDRESS, 0));
// base address is always a displacement, not an absolute value.
module.set_base_is_offset(true);
}
else if (name == "l_ld")
{
@ -4609,13 +4621,15 @@ ProcessGDBRemote::GetLoadedModuleList (GDBLoadedModuleInfoList & list)
{
std::string name;
lldb::addr_t lm=0, base=0, ld=0;
bool base_is_offset;
module.get_name (name);
module.get_link_map (lm);
module.get_base (base);
module.get_base_is_offset (base_is_offset);
module.get_dynamic (ld);
log->Printf ("found (link_map:0x%08" PRIx64 ", base:0x%08" PRIx64 ", ld:0x%08" PRIx64 ", name:'%s')", lm, base, ld, name.c_str());
log->Printf ("found (link_map:0x%08" PRIx64 ", base:0x%08" PRIx64 "[%s], ld:0x%08" PRIx64 ", name:'%s')", lm, base, (base_is_offset ? "offset" : "absolute"), ld, name.c_str());
}
list.add (module);
@ -4657,15 +4671,19 @@ ProcessGDBRemote::GetLoadedModuleList (GDBLoadedModuleInfoList & list)
const XMLNode &section = library.FindFirstChildElementWithName("section");
llvm::StringRef address = section.GetAttributeValue("address");
module.set_base(StringConvert::ToUInt64(address.data(), LLDB_INVALID_ADDRESS, 0));
// These addresses are absolute values.
module.set_base_is_offset(false);
if (log)
{
std::string name;
lldb::addr_t base = 0;
bool base_is_offset;
module.get_name (name);
module.get_base (base);
module.get_base_is_offset (base_is_offset);
log->Printf ("found (base:0x%08" PRIx64 ", name:'%s')", base, name.c_str());
log->Printf ("found (base:0x%08" PRIx64 "[%s], name:'%s')", base, (base_is_offset ? "offset" : "absolute"), name.c_str());
}
list.add (module);
@ -4682,7 +4700,7 @@ ProcessGDBRemote::GetLoadedModuleList (GDBLoadedModuleInfoList & list)
}
lldb::ModuleSP
ProcessGDBRemote::LoadModuleAtAddress (const FileSpec &file, lldb::addr_t base_addr)
ProcessGDBRemote::LoadModuleAtAddress (const FileSpec &file, lldb::addr_t base_addr, bool value_is_offset)
{
Target &target = m_process->GetTarget();
ModuleList &modules = target.GetImages();
@ -4693,11 +4711,11 @@ ProcessGDBRemote::LoadModuleAtAddress (const FileSpec &file, lldb::addr_t base_a
ModuleSpec module_spec (file, target.GetArchitecture());
if ((module_sp = modules.FindFirstModule (module_spec)))
{
module_sp->SetLoadAddress (target, base_addr, true, changed);
module_sp->SetLoadAddress (target, base_addr, value_is_offset, changed);
}
else if ((module_sp = target.GetSharedModule (module_spec)))
{
module_sp->SetLoadAddress (target, base_addr, true, changed);
module_sp->SetLoadAddress (target, base_addr, value_is_offset, changed);
}
return module_sp;
@ -4720,10 +4738,12 @@ ProcessGDBRemote::LoadModules ()
{
std::string mod_name;
lldb::addr_t mod_base;
bool mod_base_is_offset;
bool valid = true;
valid &= modInfo.get_name (mod_name);
valid &= modInfo.get_base (mod_base);
valid &= modInfo.get_base_is_offset (mod_base_is_offset);
if (!valid)
continue;
@ -4735,7 +4755,7 @@ ProcessGDBRemote::LoadModules ()
marker += 1;
FileSpec file (mod_name.c_str()+marker, true);
lldb::ModuleSP module_sp = LoadModuleAtAddress (file, mod_base);
lldb::ModuleSP module_sp = LoadModuleAtAddress (file, mod_base, mod_base_is_offset);
if (module_sp.get())
new_modules.Append (module_sp);

View File

@ -452,7 +452,7 @@ protected:
GetLoadedModuleList (GDBLoadedModuleInfoList &);
lldb::ModuleSP
LoadModuleAtAddress (const FileSpec &file, lldb::addr_t base_addr);
LoadModuleAtAddress (const FileSpec &file, lldb::addr_t base_addr, bool value_is_offset);
private:
//------------------------------------------------------------------