[llvm] r360015 - DWARF v5: fix directory index in the line table

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon May 6 01:03:46 PDT 2019


Author: maskray
Date: Mon May  6 01:03:46 2019
New Revision: 360015

URL: http://llvm.org/viewvc/llvm-project?rev=360015&view=rev
Log:
DWARF v5: fix directory index in the line table

Summary:
Prior to DWARF v5, a directory index of 0 represents DW_AT_comp_dir.

In DWARF v5, the index starts with 0 and Entry.DirIdx is the index into
Prologue.IncludeDirectories.

Reviewed By: labath

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

Added:
    llvm/trunk/test/DebugInfo/symbolize-directory.s
Modified:
    llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp?rev=360015&r1=360014&r2=360015&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp Mon May  6 01:03:46 2019
@@ -1020,20 +1020,24 @@ bool DWARFDebugLine::LineTable::getFileN
   }
 
   SmallString<16> FilePath;
-  uint64_t IncludeDirIndex = Entry.DirIdx;
   StringRef IncludeDir;
   // Be defensive about the contents of Entry.
-  if (IncludeDirIndex > 0 &&
-      IncludeDirIndex <= Prologue.IncludeDirectories.size())
-    IncludeDir = Prologue.IncludeDirectories[IncludeDirIndex - 1]
-                     .getAsCString()
-                     .getValue();
+  if (Prologue.getVersion() >= 5) {
+    if (Entry.DirIdx < Prologue.IncludeDirectories.size())
+      IncludeDir =
+          Prologue.IncludeDirectories[Entry.DirIdx].getAsCString().getValue();
+  } else {
+    if (0 < Entry.DirIdx && Entry.DirIdx <= Prologue.IncludeDirectories.size())
+      IncludeDir = Prologue.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 && !isPathAbsoluteOnWindowsOrPosix(IncludeDir))
-    sys::path::append(FilePath, 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 && !isPathAbsoluteOnWindowsOrPosix(IncludeDir))
+      sys::path::append(FilePath, CompDir);
+  }
 
   // sys::path::append skips empty strings.
   sys::path::append(FilePath, IncludeDir, FileName);

Added: llvm/trunk/test/DebugInfo/symbolize-directory.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/symbolize-directory.s?rev=360015&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/symbolize-directory.s (added)
+++ llvm/trunk/test/DebugInfo/symbolize-directory.s Mon May  6 01:03:46 2019
@@ -0,0 +1,62 @@
+# REQUIRES: x86-registered-target
+
+# 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
+
+# CHECK: /home/0.cc:1:0
+# CHECK: /tmp/1.cc:2:1
+
+.Lfunc_begin0:
+  .file 0 "/home" "0.cc"
+  .file 1 "/tmp" "1.cc"
+  .loc 0 1 0                 # 0.cc:1:0
+  nop
+  .loc 1 2 1                 # 1.cc:2:1
+  nop
+  .loc 0 1 1 prologue_end    # 0.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 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 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
+  .byte 2                       # Abbrev [2] DW_TAG_subprogram
+  .asciz "0.c"                  # DW_AT_name
+  .quad 0                       # DW_AT_low_pc
+  .long 2                       # DW_AT_high_pc
+  .byte 0
+.Lcu_end0:




More information about the llvm-commits mailing list