From 6474721c10394e88fa631df644563da2d6ca55c0 Mon Sep 17 00:00:00 2001 From: Oleksiy Vyalov Date: Fri, 13 Mar 2015 18:44:56 +0000 Subject: [PATCH] Extend Platform(s) in order to cache remote executables using ModuleCache and make POSIX dynamic loader to use this flow when attaching to a remote target. http://reviews.llvm.org/D8306 llvm-svn: 232194 --- lldb/include/lldb/Target/Platform.h | 12 +++++ .../POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp | 55 +++++++++++++++------- .../POSIX-DYLD/DynamicLoaderPOSIXDYLD.h | 6 +-- .../Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp | 4 +- .../Plugins/Platform/Linux/PlatformLinux.cpp | 4 +- .../Plugins/Platform/MacOSX/PlatformDarwin.cpp | 4 +- .../Plugins/Platform/Windows/PlatformWindows.cpp | 4 +- lldb/source/Target/Platform.cpp | 37 +++++++++++++++ 8 files changed, 93 insertions(+), 33 deletions(-) diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h index 31c8202..ab4b03d 100644 --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -1123,6 +1123,12 @@ class ModuleCache; m_gid_map.clear(); } + Error + GetCachedExecutable (ModuleSpec &module_spec, + lldb::ModuleSP &module_sp, + const FileSpecList *module_search_paths_ptr, + Platform &remote_platform); + bool GetCachedSharedModule (const ModuleSpec &module_spec, lldb::ModuleSP &module_sp); @@ -1140,6 +1146,12 @@ class ModuleCache; FileSpec GetModuleCacheRoot (); private: + Error + LoadCachedExecutable (const ModuleSpec &module_spec, + lldb::ModuleSP &module_sp, + const FileSpecList *module_search_paths_ptr, + Platform &remote_platform); + DISALLOW_COPY_AND_ASSIGN (Platform); }; diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp index 1cebdca..061e8e9 100644 --- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp @@ -121,16 +121,7 @@ DynamicLoaderPOSIXDYLD::DidAttach() log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " reloaded auxv data", __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID); ModuleSP executable_sp = GetTargetExecutable(); - ModuleSpec process_module_spec; - if (GetProcessModuleSpec(process_module_spec)) - { - if (executable_sp == nullptr || !executable_sp->MatchesModuleSpec(process_module_spec)) - { - executable_sp.reset(new Module(process_module_spec)); - assert(m_process != nullptr); - m_process->GetTarget().SetExecutableModule(executable_sp, false); - } - } + ResolveExecutableModule(executable_sp); addr_t load_offset = ComputeLoadOffset(); if (log) @@ -626,17 +617,45 @@ DynamicLoaderPOSIXDYLD::GetThreadLocalData (const lldb::ModuleSP module, const l return tls_block; } -bool -DynamicLoaderPOSIXDYLD::GetProcessModuleSpec (ModuleSpec& module_spec) +void +DynamicLoaderPOSIXDYLD::ResolveExecutableModule (lldb::ModuleSP &module_sp) { + Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); + if (m_process == nullptr) - return false; + return; + + auto &target = m_process->GetTarget (); + const auto platform_sp = target.GetPlatform (); - auto& target = m_process->GetTarget (); ProcessInstanceInfo process_info; - if (!target.GetPlatform ()->GetProcessInfo (m_process->GetID (), process_info)) - return false; + if (!platform_sp->GetProcessInfo (m_process->GetID (), process_info)) + { + if (log) + log->Printf ("DynamicLoaderPOSIXDYLD::%s - failed to get process info for pid %" PRIu64, + __FUNCTION__, m_process->GetID ()); + return; + } + + if (log) + log->Printf ("DynamicLoaderPOSIXDYLD::%s - got executable by pid %" PRIu64 ": %s", + __FUNCTION__, m_process->GetID (), process_info.GetExecutableFile ().GetPath ().c_str ()); + + ModuleSpec module_spec (process_info.GetExecutableFile (), process_info.GetArchitecture ()); + if (module_sp && module_sp->MatchesModuleSpec (module_spec)) + return; + + auto error = platform_sp->ResolveExecutable (module_spec, module_sp, nullptr); + if (error.Fail ()) + { + StreamString stream; + module_spec.Dump (stream); + + if (log) + log->Printf ("DynamicLoaderPOSIXDYLD::%s - failed to resolve executable with module spec \"%s\": %s", + __FUNCTION__, stream.GetString ().c_str (), error.AsCString ()); + return; + } - module_spec = ModuleSpec (process_info.GetExecutableFile (), process_info.GetArchitecture ()); - return true; + target.SetExecutableModule (module_sp, false); } diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h index 747ff3f..68d3059 100644 --- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h +++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h @@ -168,9 +168,9 @@ protected: lldb::addr_t GetEntryPoint(); - /// Loads ModuleSpec data from inferior process. - bool - GetProcessModuleSpec(lldb_private::ModuleSpec& module_spec); + /// Loads Module from inferior process. + void + ResolveExecutableModule(lldb::ModuleSP &module_sp); private: DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD); diff --git a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp index 2fdebe1..cd52f05 100644 --- a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp +++ b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp @@ -232,9 +232,7 @@ PlatformFreeBSD::ResolveExecutable (const ModuleSpec &module_spec, { if (m_remote_platform_sp) { - error = m_remote_platform_sp->ResolveExecutable (module_spec, - exe_module_sp, - module_search_paths_ptr); + error = GetCachedExecutable (resolved_module_spec, exe_module_sp, module_search_paths_ptr, *m_remote_platform_sp); } else { diff --git a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp index 2672b32..62f58d4 100644 --- a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp +++ b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp @@ -307,9 +307,7 @@ PlatformLinux::ResolveExecutable (const ModuleSpec &ms, { if (m_remote_platform_sp) { - error = m_remote_platform_sp->ResolveExecutable (ms, - exe_module_sp, - NULL); + error = GetCachedExecutable (resolved_module_spec, exe_module_sp, nullptr, *m_remote_platform_sp); } else { diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index d7b6cd4..02ff14f 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -212,9 +212,7 @@ PlatformDarwin::ResolveExecutable (const ModuleSpec &module_spec, { if (m_remote_platform_sp) { - error = m_remote_platform_sp->ResolveExecutable (module_spec, - exe_module_sp, - module_search_paths_ptr); + error = GetCachedExecutable (resolved_module_spec, exe_module_sp, module_search_paths_ptr, *m_remote_platform_sp); } else { diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp index 9f59adb..c08feef 100644 --- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp +++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp @@ -247,9 +247,7 @@ PlatformWindows::ResolveExecutable (const ModuleSpec &ms, { if (m_remote_platform_sp) { - error = m_remote_platform_sp->ResolveExecutable (ms, - exe_module_sp, - NULL); + error = GetCachedExecutable (resolved_module_spec, exe_module_sp, nullptr, *m_remote_platform_sp); } else { diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index f594170..d8ad8c7 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -1752,6 +1752,43 @@ Platform::GetTrapHandlerSymbolNames () return m_trap_handlers; } +Error +Platform::GetCachedExecutable (ModuleSpec &module_spec, + lldb::ModuleSP &module_sp, + const FileSpecList *module_search_paths_ptr, + Platform &remote_platform) +{ + const auto platform_spec = module_spec.GetFileSpec (); + const auto error = LoadCachedExecutable (module_spec, + module_sp, + module_search_paths_ptr, + remote_platform); + if (error.Success ()) + { + module_spec.GetFileSpec () = module_sp->GetFileSpec (); + module_spec.GetPlatformFileSpec () = platform_spec; + } + + return error; +} + +Error +Platform::LoadCachedExecutable (const ModuleSpec &module_spec, + lldb::ModuleSP &module_sp, + const FileSpecList *module_search_paths_ptr, + Platform &remote_platform) +{ + if (GetGlobalPlatformProperties ()->GetUseModuleCache ()) + { + if (GetCachedSharedModule (module_spec, module_sp)) + return Error (); + } + + return remote_platform.ResolveExecutable (module_spec, + module_sp, + module_search_paths_ptr); +} + bool Platform::GetCachedSharedModule (const ModuleSpec &module_spec, lldb::ModuleSP &module_sp) -- 2.7.4