[Lldb-commits] [PATCH] D11357: Resolve DW_AT_comp_dir path if it contains a symlink

Oleksiy Vyalov ovyalov at google.com
Mon Jul 20 09:24:56 PDT 2015


ovyalov created this revision.
ovyalov added reviewers: clayborg, chaoren.
ovyalov added a subscriber: lldb-commits.

Value of DW_AT_comp_dir entry can be enforced by PWD environment variable and set with symbolic link.
If DW_AT_comp_dir is a symlink use FileSystem::Readlink to get full path.

http://reviews.llvm.org/D11357

Files:
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -41,6 +41,7 @@
 
 #include "lldb/Expression/ClangModulesDeclVendor.h"
 
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/Host.h"
 
 #include "lldb/Symbol/Block.h"
@@ -146,6 +147,31 @@
     return colon_pos + 1;
 }
 
+static const char*
+resolveCompDir(const char* path_from_dwarf)
+{
+    if (!path_from_dwarf)
+        return nullptr;
+
+    // DWARF2/3 suggests the form hostname:pathname for compilation directory.
+    // Remove the host part if present.
+    const char* local_path = removeHostnameFromPathname(path_from_dwarf);
+    if (!local_path)
+        return nullptr;
+
+    const FileSpec local_path_spec(local_path, true);
+    if (!local_path_spec.IsSymbolicLink())
+        return local_path;
+
+    FileSpec resolved_local_path_spec;
+    const auto error = FileSystem::Readlink(local_path_spec, resolved_local_path_spec);
+    if (error.Success())
+        return resolved_local_path_spec.GetCString();
+
+    return nullptr;
+}
+
+
 #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
 
 class DIEStack
@@ -979,10 +1005,8 @@
                             // the file.  This can be expensive e.g. when the source files are NFS mounted.
                             if (cu_file_spec.IsRelative())
                             {
-                                // DWARF2/3 suggests the form hostname:pathname for compilation directory.
-                                // Remove the host part if present.
                                 const char *cu_comp_dir{cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, nullptr)};
-                                cu_file_spec.PrependPathComponent(removeHostnameFromPathname(cu_comp_dir));
+                                cu_file_spec.PrependPathComponent(resolveCompDir(cu_comp_dir));
                             }
 
                             std::string remapped_file;
@@ -1247,11 +1271,7 @@
 
         if (cu_die)
         {
-            const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
-
-            // DWARF2/3 suggests the form hostname:pathname for compilation directory.
-            // Remove the host part if present.
-            cu_comp_dir = removeHostnameFromPathname(cu_comp_dir);
+            const char * cu_comp_dir = resolveCompDir(cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, nullptr));
 
             dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11357.30164.patch
Type: text/x-patch
Size: 2764 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150720/e6e3bddc/attachment.bin>


More information about the lldb-commits mailing list