[PATCH] D80168: For --relativenames, handle dwarf absolute include directories similarly to compilation directories.

Sterling Augustine via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 28 10:23:40 PDT 2020


saugustine updated this revision to Diff 266933.
saugustine added a comment.

Update for upstream comments.

Redo the test to better reflect the functionality.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80168/new/

https://reviews.llvm.org/D80168

Files:
  llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
  llvm/test/tools/llvm-symbolizer/Inputs/relativenames.o
  llvm/test/tools/llvm-symbolizer/relativenames.s


Index: llvm/test/tools/llvm-symbolizer/relativenames.s
===================================================================
--- llvm/test/tools/llvm-symbolizer/relativenames.s
+++ llvm/test/tools/llvm-symbolizer/relativenames.s
@@ -3,16 +3,28 @@
 foo:
     nop
 
-# RUN: llvm-mc --filetype=obj --triple=x86_64-pc-linux %s -o %t.o -g
 
-# RUN: llvm-symbolizer 0 --relativenames --obj=%t.o \
+## Build as:
+#   cd /tmp
+#   mkdir foo
+#   cp /path/to/relativenames.s foo/
+#   llvm-mc --filetype=obj --triple=x86_64-pc-linux foo/relativenames.s -o relativenames.o -g
+
+#### RUN: llvm-mc --filetype=obj --triple=x86_64-pc-linux %s -o %t.o -g
+
+# RUN: llvm-symbolizer 0 --relativenames --obj=%p/Inputs/relativenames.o \
 # RUN:    | FileCheck %s -DDIR=%p --check-prefix=RELATIVENAMES
 
+## Sanity check for default.
+# RUN: llvm-symbolizer 0 --obj=%p/Inputs/relativenames.o \
+# RUN:    | FileCheck %s -DDIR=%p --check-prefix=ABSOLUTENAMES
+
 ## Ensure last option wins.
-# RUN: llvm-symbolizer 0 --basenames --relativenames --obj=%t.o \
+# RUN: llvm-symbolizer 0 --basenames --relativenames --obj=%p/Inputs/relativenames.o \
 # RUN:    | FileCheck %s -DDIR=%p --check-prefix=RELATIVENAMES
-# RUN: llvm-symbolizer 0 --relativenames --basenames --obj=%t.o \
+# RUN: llvm-symbolizer 0 --relativenames --basenames --obj=%p/Inputs/relativenames.o \
 # RUN:    | FileCheck %s --check-prefix=BASENAMES
 
-# RELATIVENAMES: [[DIR]]{{\\|/}}relativenames.s:4
+# ABSOLUTENAMES: {{\\|/}}tmp{{\\|/}}foo{{\\|/}}relativenames.s:4
+# RELATIVENAMES: {{^}}foo{{\\|/}}relativenames.s:4
 # BASENAMES: {{^}}relativenames.s:4
Index: llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1227,13 +1227,17 @@
   StringRef IncludeDir;
   // Be defensive about the contents of Entry.
   if (getVersion() >= 5) {
-    if (Entry.DirIdx < IncludeDirectories.size())
+    // DirIdx 0 is the compilation directory, so for don't include it for
+    // relative names.
+    if ((Entry.DirIdx != 0 || Kind != FileLineInfoKind::RelativeFilePath) &&
+        Entry.DirIdx < IncludeDirectories.size())
       IncludeDir = IncludeDirectories[Entry.DirIdx].getAsCString().getValue();
   } else {
     if (0 < Entry.DirIdx && Entry.DirIdx <= IncludeDirectories.size())
       IncludeDir =
           IncludeDirectories[Entry.DirIdx - 1].getAsCString().getValue();
   }
+
   // For absolute paths only, include the compilation directory of compile unit.
   // We know that FileName is not absolute, the only way to have an absolute
   // path at this point would be if IncludeDir is absolute.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80168.266933.patch
Type: text/x-patch
Size: 2707 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200528/56ff2a60/attachment.bin>


More information about the llvm-commits mailing list