diff options
| author | Tamas Berghammer <tberghammer@google.com> | 2016-07-22 12:55:35 +0000 |
|---|---|---|
| committer | Tamas Berghammer <tberghammer@google.com> | 2016-07-22 12:55:35 +0000 |
| commit | d7d69f80836c8485c83ba55d2e5e5bac4154d975 (patch) | |
| tree | cf5d46fb847e559bcfaaaf892a908de4a9736aa4 /lldb/source/Core/DynamicLoader.cpp | |
| parent | 29333c9de6c7ab6ad1ca09d19d011927704db0c5 (diff) | |
Support loading files even when incorrect file name specified by the linker
"Incorrect" file name seen on Android whene the main executable is
called "app_process32" (or 64) but the linker specifies the package
name (e.g. com.android.calculator2). Additionally it can be present
in case of some linker bugs.
This CL adds logic to try to fetch the correct file name from the proc
file system based on the base address sepcified by the linker in case
we are failed to load the module by name.
Differential revision: http://reviews.llvm.org/D22219
llvm-svn: 276411
Diffstat (limited to 'lldb/source/Core/DynamicLoader.cpp')
| -rw-r--r-- | lldb/source/Core/DynamicLoader.cpp | 67 |
1 files changed, 49 insertions, 18 deletions
diff --git a/lldb/source/Core/DynamicLoader.cpp b/lldb/source/Core/DynamicLoader.cpp index f41ff4a80c83..625cccc8e88e 100644 --- a/lldb/source/Core/DynamicLoader.cpp +++ b/lldb/source/Core/DynamicLoader.cpp @@ -12,13 +12,14 @@ // Other libraries and framework includes // Project includes #include "lldb/lldb-private.h" -#include "lldb/Target/DynamicLoader.h" -#include "lldb/Target/Process.h" -#include "lldb/Target/Target.h" -#include "lldb/Core/PluginManager.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" +#include "lldb/Core/PluginManager.h" #include "lldb/Core/Section.h" +#include "lldb/Target/DynamicLoader.h" +#include "lldb/Target/MemoryRegionInfo.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/Target.h" using namespace lldb; using namespace lldb_private; @@ -177,37 +178,67 @@ DynamicLoader::LoadModuleAtAddress(const FileSpec &file, { Target &target = m_process->GetTarget(); ModuleList &modules = target.GetImages(); + ModuleSpec module_spec (file, target.GetArchitecture()); ModuleSP module_sp; - ModuleSpec module_spec (file, target.GetArchitecture()); if ((module_sp = modules.FindFirstModule (module_spec))) { UpdateLoadedSections(module_sp, link_map_addr, base_addr, base_addr_is_offset); + return module_sp; } - else if ((module_sp = target.GetSharedModule(module_spec))) + + if ((module_sp = target.GetSharedModule(module_spec))) { UpdateLoadedSections(module_sp, link_map_addr, base_addr, base_addr_is_offset); + return module_sp; } - else + + bool check_alternative_file_name = true; + if (base_addr_is_offset) { - if (base_addr_is_offset) + // Try to fetch the load address of the file from the process as we need absolute load + // address to read the file out of the memory instead of a load bias. + bool is_loaded = false; + lldb::addr_t load_addr; + Error error = m_process->GetFileLoadAddress(file, is_loaded, load_addr); + if (error.Success() && is_loaded) { - // Try to fetch the load address of the file from the process as we need absolute load - // address to read the file out of the memory instead of a load bias. - bool is_loaded = false; - lldb::addr_t load_addr; - Error error = m_process->GetFileLoadAddress(file, is_loaded, load_addr); - if (error.Success() && is_loaded) - base_addr = load_addr; + check_alternative_file_name = false; + base_addr = load_addr; } + } - if ((module_sp = m_process->ReadModuleFromMemory(file, base_addr))) + // We failed to find the module based on its name. Lets try to check if we can find a + // different name based on the memory region info. + if (check_alternative_file_name) + { + MemoryRegionInfo memory_info; + Error error = m_process->GetMemoryRegionInfo(base_addr, memory_info); + if (error.Success() && memory_info.GetMapped() && memory_info.GetRange().GetRangeBase() == base_addr) { - UpdateLoadedSections(module_sp, link_map_addr, base_addr, false); - target.GetImages().AppendIfNeeded(module_sp); + ModuleSpec new_module_spec(FileSpec(memory_info.GetName().AsCString(), false), + target.GetArchitecture()); + + if ((module_sp = modules.FindFirstModule(new_module_spec))) + { + UpdateLoadedSections(module_sp, link_map_addr, base_addr, false); + return module_sp; + } + + if ((module_sp = target.GetSharedModule(new_module_spec))) + { + UpdateLoadedSections(module_sp, link_map_addr, base_addr, false); + return module_sp; + } } } + if ((module_sp = m_process->ReadModuleFromMemory(file, base_addr))) + { + UpdateLoadedSections(module_sp, link_map_addr, base_addr, false); + target.GetImages().AppendIfNeeded(module_sp); + } + return module_sp; } |
