Differential D9471 Diff 25292 lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
Changeset View
Changeset View
Standalone View
Standalone View
lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
Show First 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | DynamicLoaderPOSIXDYLD::DidAttach() | ||||
Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); | Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); | ||||
if (log) | if (log) | ||||
log->Printf ("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64, __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID); | log->Printf ("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64, __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID); | ||||
m_auxv.reset(new AuxVector(m_process)); | m_auxv.reset(new AuxVector(m_process)); | ||||
if (log) | if (log) | ||||
log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " reloaded auxv data", __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID); | log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " reloaded auxv data", __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID); | ||||
// ask the process if it can load any of its own modules | |||||
m_process->LoadModules (); | |||||
ModuleSP executable_sp = GetTargetExecutable(); | ModuleSP executable_sp = GetTargetExecutable (); | ||||
ResolveExecutableModule(executable_sp); | ResolveExecutableModule (executable_sp); | ||||
// find the main process load offset | |||||
addr_t load_offset = ComputeLoadOffset(); | addr_t load_offset = ComputeLoadOffset (); | ||||
if (log) | if (log) | ||||
log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " executable '%s', load_offset 0x%" PRIx64, __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID, executable_sp ? executable_sp->GetFileSpec().GetPath().c_str () : "<null executable>", load_offset); | log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " executable '%s', load_offset 0x%" PRIx64, __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID, executable_sp ? executable_sp->GetFileSpec().GetPath().c_str () : "<null executable>", load_offset); | ||||
// if we dont have a load address we cant re-base | |||||
bool rebase_exec = (load_offset == LLDB_INVALID_ADDRESS) ? false : true; | |||||
if (executable_sp && load_offset != LLDB_INVALID_ADDRESS) | // if we have a valid executable | ||||
if (executable_sp.get()) | |||||
{ | |||||
lldb_private::ObjectFile * obj = executable_sp->GetObjectFile(); | |||||
if (obj) | |||||
{ | |||||
// don't rebase if the module is not an executable | |||||
if (obj->GetType() != ObjectFile::Type::eTypeExecutable) | |||||
rebase_exec = false; | |||||
// don't rebase if the module already has a load address | |||||
Target & target = m_process->GetTarget (); | |||||
Address addr = obj->GetImageInfoAddress (&target); | |||||
if (addr.GetLoadAddress (&target) != LLDB_INVALID_ADDRESS) | |||||
rebase_exec = false; | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
// no executable, nothing to re-base | |||||
rebase_exec = false; | |||||
} | |||||
// if the target executable should be re-based | |||||
if (rebase_exec) | |||||
{ | { | ||||
ModuleList module_list; | ModuleList module_list; | ||||
module_list.Append(executable_sp); | module_list.Append(executable_sp); | ||||
if (log) | if (log) | ||||
log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " added executable '%s' to module load list", | log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " added executable '%s' to module load list", | ||||
__FUNCTION__, | __FUNCTION__, | ||||
m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID, | m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID, | ||||
▲ Show 20 Lines • Show All 392 Lines • ▼ Show 20 Lines | DynamicLoaderPOSIXDYLD::ComputeLoadOffset() | ||||
ModuleSP module = m_process->GetTarget().GetExecutableModule(); | ModuleSP module = m_process->GetTarget().GetExecutableModule(); | ||||
if (!module) | if (!module) | ||||
return LLDB_INVALID_ADDRESS; | return LLDB_INVALID_ADDRESS; | ||||
ObjectFile *exe = module->GetObjectFile(); | ObjectFile *exe = module->GetObjectFile(); | ||||
if (!exe) | if (!exe) | ||||
return LLDB_INVALID_ADDRESS; | return LLDB_INVALID_ADDRESS; | ||||
if (exe->GetType() != ObjectFile::Type::eTypeExecutable) | |||||
return LLDB_INVALID_ADDRESS; | |||||
Address file_entry = exe->GetEntryPointAddress(); | Address file_entry = exe->GetEntryPointAddress(); | ||||
if (!file_entry.IsValid()) | if (!file_entry.IsValid()) | ||||
return LLDB_INVALID_ADDRESS; | return LLDB_INVALID_ADDRESS; | ||||
m_load_offset = virt_entry - file_entry.GetFileAddress(); | m_load_offset = virt_entry - file_entry.GetFileAddress(); | ||||
return m_load_offset; | return m_load_offset; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 114 Lines • Show Last 20 Lines |