[Lldb-commits] [PATCH] ComputeSupportExeDirectory for Linux

Chaoren Lin chaorenl at google.com
Mon Mar 23 17:36:25 PDT 2015


Hi ovyalov, vharron, clayborg,

Fixes http://reviews.llvm.org/D8511

The original method of using dladdr() could return the incorrect relative
path if not linked against liblldb and the working directory has changed.
This is not a problem when built with python, since
ScriptInterpreterPython::InitializePrivate calls
HostInfo::GetLLDBPath(ePathTypeLLDBShlibDir, ...) and caches the
correct path before any changes to the working directory.

The /proc/self/exe approach fails if run using Python, but works for all other
cases (including for android, which doesn't have dladdr()).

So if we combine the two, we should reasonably cover all corner cases.

http://reviews.llvm.org/D8570

Files:
  include/lldb/Host/android/HostInfoAndroid.h
  include/lldb/Host/linux/HostInfoLinux.h
  source/Host/android/HostInfoAndroid.cpp
  source/Host/common/Host.cpp
  source/Host/linux/HostInfoLinux.cpp

Index: include/lldb/Host/android/HostInfoAndroid.h
===================================================================
--- include/lldb/Host/android/HostInfoAndroid.h
+++ include/lldb/Host/android/HostInfoAndroid.h
@@ -25,7 +25,6 @@
 
   protected:
     static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64);
-    static bool ComputeSupportExeDirectory(FileSpec &file_spec);
 };
 
 } // end of namespace lldb_private
Index: include/lldb/Host/linux/HostInfoLinux.h
===================================================================
--- include/lldb/Host/linux/HostInfoLinux.h
+++ include/lldb/Host/linux/HostInfoLinux.h
@@ -40,7 +40,7 @@
     static FileSpec GetProgramFileSpec();
 
   protected:
-    static bool ComputeSharedLibraryDirectory(FileSpec &file_spec);
+    static bool ComputeSupportExeDirectory(FileSpec &file_spec);
     static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
     static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
     static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64);
Index: source/Host/android/HostInfoAndroid.cpp
===================================================================
--- source/Host/android/HostInfoAndroid.cpp
+++ source/Host/android/HostInfoAndroid.cpp
@@ -30,13 +30,6 @@
     }
 }
 
-bool
-HostInfoAndroid::ComputeSupportExeDirectory(FileSpec &file_spec)
-{
-    file_spec.GetDirectory() = HostInfoLinux::GetProgramFileSpec().GetDirectory();
-    return (bool)file_spec.GetDirectory();
-}
-
 FileSpec
 HostInfoAndroid::GetDefaultShell()
 {
Index: source/Host/common/Host.cpp
===================================================================
--- source/Host/common/Host.cpp
+++ source/Host/common/Host.cpp
@@ -487,8 +487,6 @@
         if (info.dli_fname)
             module_filespec.SetFile(info.dli_fname, true);
     }
-#else
-    assert(false && "dladdr() not supported on Android");
 #endif
     return module_filespec;
 }
Index: source/Host/linux/HostInfoLinux.cpp
===================================================================
--- source/Host/linux/HostInfoLinux.cpp
+++ source/Host/linux/HostInfoLinux.cpp
@@ -222,12 +222,12 @@
 }
 
 bool
-HostInfoLinux::ComputeSharedLibraryDirectory(FileSpec &file_spec)
+HostInfoLinux::ComputeSupportExeDirectory(FileSpec &file_spec)
 {
-    if (HostInfoPosix::ComputeSharedLibraryDirectory(file_spec))
+    if (HostInfoPosix::ComputeSupportExeDirectory(file_spec) && file_spec.Exists())
         return true;
     file_spec.GetDirectory() = GetProgramFileSpec().GetDirectory();
-    return (bool)file_spec.GetDirectory();
+    return !file_spec.GetDirectory().IsEmpty();
 }
 
 bool

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8570.22532.patch
Type: text/x-patch
Size: 2666 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150324/62533df7/attachment.bin>


More information about the lldb-commits mailing list