[Lldb-commits] [lldb] r232194 - 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.
Oleksiy Vyalov
ovyalov at google.com
Fri Mar 13 11:44:56 PDT 2015
Author: ovyalov
Date: Fri Mar 13 13:44:56 2015
New Revision: 232194
URL: http://llvm.org/viewvc/llvm-project?rev=232194&view=rev
Log:
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
Modified:
lldb/trunk/include/lldb/Target/Platform.h
lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.cpp
lldb/trunk/source/Target/Platform.cpp
Modified: lldb/trunk/include/lldb/Target/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Platform.h?rev=232194&r1=232193&r2=232194&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Platform.h (original)
+++ lldb/trunk/include/lldb/Target/Platform.h Fri Mar 13 13:44:56 2015
@@ -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);
};
Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp?rev=232194&r1=232193&r2=232194&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp Fri Mar 13 13:44:56 2015
@@ -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::GetThreadLocalDa
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);
}
Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h?rev=232194&r1=232193&r2=232194&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h Fri Mar 13 13:44:56 2015
@@ -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);
Modified: lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp?rev=232194&r1=232193&r2=232194&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp Fri Mar 13 13:44:56 2015
@@ -232,9 +232,7 @@ PlatformFreeBSD::ResolveExecutable (cons
{
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
{
Modified: lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp?rev=232194&r1=232193&r2=232194&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp Fri Mar 13 13:44:56 2015
@@ -307,9 +307,7 @@ PlatformLinux::ResolveExecutable (const
{
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
{
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=232194&r1=232193&r2=232194&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Fri Mar 13 13:44:56 2015
@@ -212,9 +212,7 @@ PlatformDarwin::ResolveExecutable (const
{
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
{
Modified: lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.cpp?rev=232194&r1=232193&r2=232194&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.cpp Fri Mar 13 13:44:56 2015
@@ -247,9 +247,7 @@ PlatformWindows::ResolveExecutable (cons
{
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
{
Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=232194&r1=232193&r2=232194&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Fri Mar 13 13:44:56 2015
@@ -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)
More information about the lldb-commits
mailing list