[llvm] f027cfa - For --relativenames, ignore directory 0, which is the comp_dir.
Sterling Augustine via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 1 13:14:28 PDT 2020
Author: Sterling Augustine
Date: 2020-06-01T13:13:37-07:00
New Revision: f027cfa37e6757bb2d17ac3bea944df4e06bcff4
URL: https://github.com/llvm/llvm-project/commit/f027cfa37e6757bb2d17ac3bea944df4e06bcff4
DIFF: https://github.com/llvm/llvm-project/commit/f027cfa37e6757bb2d17ac3bea944df4e06bcff4.diff
LOG: For --relativenames, ignore directory 0, which is the comp_dir.
Update for upstream comments. Improve test by writing all the debug
info by hand.
Reviewers: dblaikie, jhenderson
Subscribers: hiraditya, MaskRay, rupprecht, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D80168
Added:
Modified:
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
llvm/test/tools/llvm-symbolizer/relativenames.s
Removed:
################################################################################
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index b2d368c096cc..df5941615b5a 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1230,13 +1230,17 @@ bool DWARFDebugLine::Prologue::getFileNameByIndex(
StringRef IncludeDir;
// Be defensive about the contents of Entry.
if (getVersion() >= 5) {
- if (Entry.DirIdx < IncludeDirectories.size())
+ // DirIdx 0 is the compilation directory, so 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.
diff --git a/llvm/test/tools/llvm-symbolizer/relativenames.s b/llvm/test/tools/llvm-symbolizer/relativenames.s
index 96b89cb004bf..4d45b686119f 100644
--- a/llvm/test/tools/llvm-symbolizer/relativenames.s
+++ b/llvm/test/tools/llvm-symbolizer/relativenames.s
@@ -1,18 +1,108 @@
# REQUIRES: x86-registered-target
-foo:
- nop
+## Test that the relative names option to llvm-symbolizer works properly.
+## See llvm/docs/CommandGuide/llvm-symbolizer.rst for commands
+## that would produce this test case
-# RUN: llvm-mc --filetype=obj --triple=x86_64-pc-linux %s -o %t.o -g
+# RUN: llvm-mc %s -filetype obj -triple x86_64-pc-linux -o %t.o
# RUN: llvm-symbolizer 0 --relativenames --obj=%t.o \
# RUN: | FileCheck %s -DDIR=%p --check-prefix=RELATIVENAMES
+## Sanity check for default.
+# RUN: llvm-symbolizer 0 --obj=%t.o \
+# RUN: | FileCheck %s -DDIR=%p --check-prefix=ABSOLUTENAMES
+
## Ensure last option wins.
# RUN: llvm-symbolizer 0 --basenames --relativenames --obj=%t.o \
# RUN: | FileCheck %s -DDIR=%p --check-prefix=RELATIVENAMES
# RUN: llvm-symbolizer 0 --relativenames --basenames --obj=%t.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
+
+## Provide just enough info in debug info for the symbolizer
+## to find the line table.
+.section .debug_abbrev,"", at progbits
+ .byte 0x01 ## Abbreviation Code
+ .byte 0x11 ## DW_TAG_compile_unit
+ .byte 0x01 ## DW_CHILDREN_yes
+ .byte 0x10 ## DW_AT_stmt_list
+ .byte 0x17 ## DW_FORM_sec_offset
+ .byte 0x11 ## DW_AT_low_pc
+ .byte 0x01 ## DW_FORM_addr
+ .byte 0x12 ## DW_AT_high_pc
+ .byte 0x01 ## DW_FORM_addr
+ .byte 0x1b ## DW_AT_comp_dir
+ .byte 0x08 ## DW_FORM_string
+ .byte 0x03 ## DW_AT_name
+ .byte 0x08 ## DW_FORM_string
+ .byte 0x00 ## EOM(1)
+ .byte 0x00 ## EOM(2)
+ .byte 0x02 ## Abbreviation Code
+ .byte 0x2e ## DW_TAG_subprogram
+ .byte 0x0 ## DW_CHILDREN_no
+ .byte 0x11 ## DW_AT_low_pc
+ .byte 0x01 ## DW_FORM_addr
+ .byte 0x12 ## DW_AT_high_pc
+ .byte 0x01 ## DW_FORM_addr
+ .byte 0x00 ## EOM(1)
+ .byte 0x00 ## EOM(2)
+ .byte 0x00 ## EOM(3)
+
+.section .debug_info,"", at progbits
+ .long .Ldebug_info_end-.Ldebug_info_start ## length
+.Ldebug_info_start:
+ .short 0x05 ## version
+ .byte 0x01 ## DW_TAG_compile_unit
+ .byte 0x08 ## address size
+ .long .debug_abbrev ## offset into abbrev section
+ .byte 0x01 ## cu abbrev code
+ .long .debug_line ## DW_AT_stmt_list
+ .quad 0x00 ## DW_AT_low_pc
+ .quad 0x01 ## DW_AT_high_pc
+ .asciz "/tmp" ## DW_AT_comp_dir
+ .asciz "foo/relativenames.s" ## DW_AT_name
+ .byte 0x02 ## subprog abbrev code
+ .quad 0x00 ## DW_AT_low_pc
+ .quad 0x01 ## DW_AT_high_pc
+.Ldebug_info_end:
+
+
+.section .debug_line,"", at progbits
+ .long .Lunit_end - .Lunit_begin ## unit_length
+.Lunit_begin:
+ .short 0x05 ## version
+ .byte 0x08 ## address_size
+ .byte 0x00 ## segment_selector_size
+ .long .Lheader_end - .Lheader_begin ## header_length
+.Lheader_begin:
+ .byte 0x01 ## minimum_instruction_length
+ .byte 0x01 ## maximum_operations_per_instruction
+ .byte 0x01 ## default_is_stmt
+ .byte 0xfb ## line_base
+ .byte 0x0e ## line_range
+ .byte 0x0d ## opcode_base and lengths
+ .byte 0x00, 0x01, 0x01, 0x01, 0x01, 0x00
+ .byte 0x00, 0x00, 0x01, 0x00, 0x00, 0x01
+ .byte 0x01 ## directory entry format count
+ .byte 0x01, 0x8 ## DW_LNCT_path, DW_FORM_string
+ .byte 0x01 ## directories count
+ .asciz "/tmp" ## directory entry 0
+ .byte 0x02 ## file_name_entry_format_count
+ .byte 0x02, 0x0B ## DW_LNCT_directory_index, DW_FORM_data1
+ .byte 0x01, 0x08 ## DW_LNCT_path, DW_FORM_string
+ .byte 0x01 ## filname count
+ .byte 0x00 ## directory index
+ .asciz "foo/relativenames.s"
+.Lheader_end:
+ .byte 0x04, 0x00 ## set file to zero
+ ## set address to 0x0
+ .byte 0x00, 0x09, 0x02, 0x00, 0x00, 0x00, 0x00
+ .byte 0x00, 0x00, 0x00, 0x00
+ .byte 0x15 ## Advance Address by 0 and line by 3
+ .byte 0x02, 0x01 ## Advance PC by 1
+ .byte 0x0, 0x1, 0x1 ## DW_LNE_end_sequence
+.Lunit_end:
More information about the llvm-commits
mailing list