[llvm] 0758ac4 - Handle non-absolute include dirs properly for both dwarf4 and dwarf5.

Sterling Augustine via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 10:52:08 PST 2020


Author: Sterling Augustine
Date: 2020-01-29T10:51:51-08:00
New Revision: 0758ac4e0cfbce67223ce2304e3b4b96c5006010

URL: https://github.com/llvm/llvm-project/commit/0758ac4e0cfbce67223ce2304e3b4b96c5006010
DIFF: https://github.com/llvm/llvm-project/commit/0758ac4e0cfbce67223ce2304e3b4b96c5006010.diff

LOG: Handle non-absolute include dirs properly for both dwarf4 and dwarf5.

Summary:
Add test case for the same. This test case will also serve as a
starting point for later symbolizer tests.

Reviewers: dblaikie, jdoerfert

Subscribers: hiraditya, llvm-commits, jhenderson

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73583

Added: 
    llvm/test/DebugInfo/symbolize-paths.s

Modified: 
    llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index 4ca84f34b96c..4217ac10a9fb 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1090,13 +1090,12 @@ bool DWARFDebugLine::Prologue::getFileNameByIndex(
     if (0 < Entry.DirIdx && Entry.DirIdx <= IncludeDirectories.size())
       IncludeDir =
           IncludeDirectories[Entry.DirIdx - 1].getAsCString().getValue();
-
-    // We may still need to append 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.
-    if (!CompDir.empty() && !isPathAbsoluteOnWindowsOrPosix(IncludeDir))
-      sys::path::append(FilePath, Style, CompDir);
   }
+  // We may still need to append 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.
+  if (!CompDir.empty() && !isPathAbsoluteOnWindowsOrPosix(IncludeDir))
+    sys::path::append(FilePath, Style, CompDir);
 
   // sys::path::append skips empty strings.
   sys::path::append(FilePath, Style, IncludeDir, FileName);

diff  --git a/llvm/test/DebugInfo/symbolize-paths.s b/llvm/test/DebugInfo/symbolize-paths.s
new file mode 100644
index 000000000000..304aae228b2a
--- /dev/null
+++ b/llvm/test/DebugInfo/symbolize-paths.s
@@ -0,0 +1,72 @@
+# REQUIRES: x86-registered-target
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64 -dwarf-version=4 %s -o %t.o
+# RUN: llvm-symbolizer --obj=%t.o --functions=none 0 1 | FileCheck %s
+# RUN: llvm-mc -filetype=obj -triple=x86_64 -dwarf-version=5 %s -o %t.o
+# RUN: llvm-symbolizer --obj=%t.o --functions=none 0 1 | FileCheck %s
+
+# Absolute include-dirs should not have comp-dir prepended
+# CHECK: /absolute{{/|\\|\\\\}}1.cc:1:0
+# Relative include-dirs should have comp-dir prepended	
+# CHECK: /comp_dir/relative{{/|\\|\\\\}}2.cc:2:1
+
+.Lfunc_begin0:
+  .file 1 "/absolute" "1.cc"
+  .file 2 "relative" "2.cc"
+  .loc 1 1 0                 # 1.cc:1:0
+  nop
+  .loc 2 2 1                 # 2.cc:2:1
+  nop
+  .loc 1 1 1 prologue_end    # 1.cc:1:1
+.Lfunc_end0:
+
+.section .debug_abbrev,"", at progbits
+  .byte 1     # Abbreviation Code
+  .byte 17    # DW_TAG_compile_unit
+  .byte 1     # DW_children_yes
+  .byte 16    # DW_AT_stmt_list
+  .byte 23    # DW_FROM_sec_offset
+  .byte 17    # DW_AT_low_pc
+  .byte 1     # DW_FORM_addr
+  .byte 18    # DW_AT_high_pc
+  .byte 6     # DW_FORM_data4
+  .byte 27    # DW_AT_comp_dir
+  .byte 8     # DW_FORM_string	
+  .byte 0     # EOM(1)
+  .byte 0     # EOM(2)
+
+  .byte 2     # Abbreviation Code
+  .byte 46    # DW_TAG_subprogram
+  .byte 0     # DW_children_no
+  .byte 3     # DW_AT_name
+  .byte 8     # DW_FORM_string
+  .byte 17    # DW_AT_low_pc
+  .byte 1     # DW_FORM_addr
+  .byte 18    # DW_AT_high_pc
+  .byte 6     # DW_FORM_data4
+  .byte 27    # DW_AT_comp_dir
+  .byte 8     # DW_FORM_string	
+  .byte 0     # EOM(1)
+  .byte 0     # EOM(2)
+
+  .byte 0     # EOM(3)
+
+.section .debug_info,"", at progbits
+.Lcu_begin0:
+  .long .Lcu_end0-.Lcu_begin0-4 # Length of Unit
+  .short 5                      # DWARF version number
+  .byte 1                       # DWARF Unit Type
+  .byte 8                       # Address Size (in bytes)
+  .long .debug_abbrev           # Offset Into Abbrev.
+  .byte 1                       # Abbrev [1]
+  .long 0                       # DW_AT_stmt_list
+  .quad 0                       # DW_AT_low_pc
+  .long 2                       # DW_AT_high_pc
+  .asciz "/comp_dir"            # DW_AT_comp_dir	
+  .byte 2                       # Abbrev [2] DW_TAG_subprogram
+  .asciz "1.c"                  # DW_AT_name
+  .quad 0                       # DW_AT_low_pc
+  .long 2                       # DW_AT_high_pc
+  .asciz "/comp_dir"            # DW_AT_comp_dir	
+  .byte 0
+.Lcu_end0:


        


More information about the llvm-commits mailing list