[Lldb-commits] [PATCH] D12984: Resolve symlinks when looking for the LLDB shlib

Sean Callanan via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 18 14:36:22 PDT 2015


spyffe updated this revision to Diff 35138.
spyffe added a comment.

Updated to reflect Greg's comments.


http://reviews.llvm.org/D12984

Files:
  include/lldb/Host/FileSpec.h
  source/Host/common/FileSpec.cpp
  source/Host/common/HostInfoBase.cpp

Index: source/Host/common/HostInfoBase.cpp
===================================================================
--- source/Host/common/HostInfoBase.cpp
+++ source/Host/common/HostInfoBase.cpp
@@ -306,7 +306,10 @@
 
     FileSpec lldb_file_spec(
         Host::GetModuleFileSpecForHostAddress(reinterpret_cast<void *>(reinterpret_cast<intptr_t>(HostInfoBase::GetLLDBPath))));
-
+    
+    // This is necessary because when running the testsuite the shlib might be a symbolic link inside the Python resource dir.
+    lldb_file_spec = lldb_file_spec.ResolveSymbolicLink();
+    
     // Remove the filename so that this FileSpec only represents the directory.
     file_spec.GetDirectory() = lldb_file_spec.GetDirectory();
 
Index: source/Host/common/FileSpec.cpp
===================================================================
--- source/Host/common/FileSpec.cpp
+++ source/Host/common/FileSpec.cpp
@@ -811,6 +811,32 @@
 #endif
 }
 
+FileSpec
+FileSpec::ResolveSymbolicLink () const {
+    if (!IsSymbolicLink())
+    {
+        return *this;
+    }
+        
+    char resolved_path[PATH_MAX];
+    if (!GetPath (resolved_path, sizeof (resolved_path)))
+    {
+        return *this;
+    }
+        
+#ifdef _WIN32
+    return *this; // TODO make this work on win32
+#else
+    char real_path[PATH_MAX + 1];
+    if (realpath(resolved_path, real_path) == nullptr)
+    {
+        return *this;
+    }
+    
+    return FileSpec(real_path, false);
+#endif
+}
+
 uint32_t
 FileSpec::GetPermissions () const
 {
Index: include/lldb/Host/FileSpec.h
===================================================================
--- include/lldb/Host/FileSpec.h
+++ include/lldb/Host/FileSpec.h
@@ -73,7 +73,7 @@
     ///     The full or partial path to a file.
     ///
     /// @param[in] resolve_path
-    ///     If \b true, then we resolve the path with realpath,
+    ///     If \b true, then we resolve the path, removing stray ../.. and so forth,
     ///     if \b false we trust the path is in canonical form already.
     ///
     /// @see FileSpec::SetFile (const char *path, bool resolve)
@@ -511,6 +511,9 @@
 
     bool
     IsSymbolicLink () const;
+    
+    FileSpec
+    ResolveSymbolicLink () const;
 
     //------------------------------------------------------------------
     /// Get the memory cost of this object.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12984.35138.patch
Type: text/x-patch
Size: 2326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150918/127460b7/attachment-0001.bin>


More information about the lldb-commits mailing list