Extend Platform(s) in order to cache remote executables using ModuleCache and make...
authorOleksiy Vyalov <ovyalov@google.com>
Fri, 13 Mar 2015 18:44:56 +0000 (18:44 +0000)
committerOleksiy Vyalov <ovyalov@google.com>
Fri, 13 Mar 2015 18:44:56 +0000 (18:44 +0000)
http://reviews.llvm.org/D8306

llvm-svn: 232194

lldb/include/lldb/Target/Platform.h
lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
lldb/source/Target/Platform.cpp

index 31c8202..ab4b03d 100644 (file)
@@ -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);
     };
 
index 1cebdca..061e8e9 100644 (file)
@@ -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);
 }
index 747ff3f..68d3059 100644 (file)
@@ -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);
index 2fdebe1..cd52f05 100644 (file)
@@ -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
         {
index 2672b32..62f58d4 100644 (file)
@@ -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
         {
index d7b6cd4..02ff14f 100644 (file)
@@ -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
         {
index 9f59adb..c08feef 100644 (file)
@@ -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
         {
index f594170..d8ad8c7 100644 (file)
@@ -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)