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 | |
| parent | 29333c9de6c7ab6ad1ca09d19d011927704db0c5 (diff) | |
| download | bcm5719-llvm-d7d69f80836c8485c83ba55d2e5e5bac4154d975.tar.gz bcm5719-llvm-d7d69f80836c8485c83ba55d2e5e5bac4154d975.zip | |
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')
5 files changed, 84 insertions, 18 deletions
diff --git a/lldb/source/API/SBMemoryRegionInfo.cpp b/lldb/source/API/SBMemoryRegionInfo.cpp index 53b180787af..1e4dd769644 100644 --- a/lldb/source/API/SBMemoryRegionInfo.cpp +++ b/lldb/source/API/SBMemoryRegionInfo.cpp @@ -110,6 +110,11 @@ SBMemoryRegionInfo::IsMapped () { return m_opaque_ap->GetMapped() == MemoryRegionInfo::eYes; } +const char * +SBMemoryRegionInfo::GetName () { + return m_opaque_ap->GetName().AsCString(); +} + bool SBMemoryRegionInfo::GetDescription (SBStream &description) { diff --git a/lldb/source/Core/DynamicLoader.cpp b/lldb/source/Core/DynamicLoader.cpp index f41ff4a80c8..625cccc8e88 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; } diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp index ae32a777773..6d822ce200f 100644 --- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -1678,6 +1678,20 @@ ParseMemoryRegionInfoFromProcMapsLine (const std::string &maps_line, MemoryRegio else return Error ("unexpected /proc/{pid}/maps exec permission char"); + line_extractor.GetChar(); // Read the private bit + line_extractor.SkipSpaces(); // Skip the separator + line_extractor.GetHexMaxU64(false, 0); // Read the offset + line_extractor.GetHexMaxU64(false, 0); // Read the major device number + line_extractor.GetChar(); // Read the device id separator + line_extractor.GetHexMaxU64(false, 0); // Read the major device number + line_extractor.SkipSpaces(); // Skip the separator + line_extractor.GetU64(0, 10); // Read the inode number + + line_extractor.SkipSpaces(); + const char* name = line_extractor.Peek(); + if (name) + memory_region_info.SetName(name); + return Error (); } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index ac76889079a..ba018be812b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -2458,6 +2458,13 @@ GDBRemoteCommunicationClient::GetMemoryRegionInfo (lldb::addr_t addr, region_info.SetMapped(MemoryRegionInfo::eNo); } } + else if (name.compare ("name") == 0) + { + StringExtractorGDBRemote name_extractor; + name_extractor.GetStringRef().swap(value); + name_extractor.GetHexByteString(value); + region_info.SetName(value.c_str()); + } else if (name.compare ("error") == 0) { StringExtractorGDBRemote name_extractor; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index ede69769c79..4721e23f559 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -2221,6 +2221,15 @@ GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfo (StringExtractorGDBRe response.PutChar (';'); } + + // Name + ConstString name = region_info.GetName(); + if (name) + { + response.PutCString("name:"); + response.PutCStringAsRawHex8(name.AsCString()); + response.PutChar(';'); + } } return SendPacketNoLock(response.GetData(), response.GetSize()); |

