[Lldb-commits] [PATCH] Make DynamicLoaderPOSIXDYLD::DidAttach to deduce a target executable by pid if no executable hasn't been assigned to a target so far.

Oleksiy Vyalov ovyalov at google.com
Tue Jan 6 16:12:08 PST 2015


Thank you for suggestions - I've made corresponding changes to handle such situations when a module file name and/or architecture changes.
Initially I tried to use AT_EXECFN but as I can see it's not reliable option - for example, when I start application from its binary directory (e.g., ./CppTest) AT_EXECFN will be set to "./CppTest" instead of providing a full path.


http://reviews.llvm.org/D6740

Files:
  source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
  source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h

Index: source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
===================================================================
--- source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -112,18 +112,26 @@
 DynamicLoaderPOSIXDYLD::DidAttach()
 {
     Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
-    ModuleSP executable_sp;
-    addr_t load_offset;
-
     if (log)
         log->Printf ("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64, __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID);
 
     m_auxv.reset(new AuxVector(m_process));
     if (log)
         log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " reloaded auxv data", __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID);
 
-    executable_sp = GetTargetExecutable();
-    load_offset = ComputeLoadOffset();
+    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);
+        }
+    }
+
+    addr_t load_offset = ComputeLoadOffset();
     if (log)
         log->Printf ("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " executable '%s', load_offset 0x%" PRIx64, __FUNCTION__, m_process ? m_process->GetID () : LLDB_INVALID_PROCESS_ID, executable_sp ? executable_sp->GetFileSpec().GetPath().c_str () : "<null executable>", load_offset);
 
@@ -613,3 +621,18 @@
 
     return tls_block;
 }
+
+bool
+DynamicLoaderPOSIXDYLD::GetProcessModuleSpec (ModuleSpec& module_spec)
+{
+    if (m_process == nullptr)
+        return false;
+
+    auto& target = m_process->GetTarget ();
+    ProcessInstanceInfo process_info;
+    if (!target.GetPlatform ()->GetProcessInfo (m_process->GetID (), process_info))
+        return false;
+
+    module_spec = ModuleSpec (process_info.GetExecutableFile (), process_info.GetArchitecture ());
+    return true;
+}
Index: source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
===================================================================
--- source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
+++ source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
@@ -168,6 +168,10 @@
     lldb::addr_t
     GetEntryPoint();
 
+    /// Loads ModuleSpec data from inferior process.
+    bool
+    GetProcessModuleSpec(lldb_private::ModuleSpec& module_spec);
+
 private:
     DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD);
 };

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6740.17846.patch
Type: text/x-patch
Size: 2791 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150107/5c5340a2/attachment.bin>


More information about the lldb-commits mailing list