From 7cb18bf537ed319eaa06f12ed39f85594bed641a Mon Sep 17 00:00:00 2001 From: Tamas Berghammer Date: Tue, 24 Mar 2015 11:15:23 +0000 Subject: Fetch module specification from remote process also Previously the remote module sepcification was fetched only from the remote platform. With this CL if we have a remote process then we ask it if it have any information from a given module. It is required because on android the dynamic linker only reports the name of the SO file and the platform can't always find it without a full path (the process can do it based on /proc//maps). Differential revision: http://reviews.llvm.org/D8547 llvm-svn: 233061 --- .../Plugins/Process/Linux/NativeProcessLinux.cpp | 48 +++++++++++++++++++--- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp') diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp index fd3a62eab428..bdf1d7205f6f 100644 --- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -136,12 +136,13 @@ PtraceWrapper((req), (pid), (addr), (data), (data_size), (error)) #endif +using namespace lldb; +using namespace lldb_private; +using namespace llvm; + // Private bits we only need internally. namespace { - using namespace lldb; - using namespace lldb_private; - static void * const EXIT_OPERATION = nullptr; const UnixSignals& @@ -1051,8 +1052,6 @@ namespace } -using namespace lldb_private; - // Simple helper function to ensure flags are enabled on the given file // descriptor. static bool @@ -3979,3 +3978,42 @@ NativeProcessLinux::RequestThreadStop (const lldb::pid_t pid, const lldb::tid_t return err; } + +Error +NativeProcessLinux::GetLoadedModuleFileSpec(const char* module_path, FileSpec& file_spec) +{ + char maps_file_name[32]; + snprintf(maps_file_name, sizeof(maps_file_name), "/proc/%" PRIu64 "/maps", GetID()); + + FileSpec maps_file_spec(maps_file_name, false); + if (!maps_file_spec.Exists()) { + file_spec.Clear(); + return Error("/proc/%" PRIu64 "/maps file doesn't exists!", GetID()); + } + + FileSpec module_file_spec(module_path, true); + + std::ifstream maps_file(maps_file_name); + std::string maps_data_str((std::istreambuf_iterator(maps_file)), std::istreambuf_iterator()); + StringRef maps_data(maps_data_str.c_str()); + + while (!maps_data.empty()) + { + StringRef maps_row; + std::tie(maps_row, maps_data) = maps_data.split('\n'); + + SmallVector maps_columns; + maps_row.split(maps_columns, StringRef(" "), -1, false); + + if (maps_columns.size() >= 6) + { + file_spec.SetFile(maps_columns[5].str().c_str(), false); + if (file_spec.GetFilename() == module_file_spec.GetFilename()) + return Error(); + } + } + + file_spec.Clear(); + return Error("Module file (%s) not found in /proc/%" PRIu64 "/maps file!", + module_file_spec.GetFilename().AsCString(), GetID()); +} -- cgit v1.2.3