Skip to content

Commit 3329cec

Browse files
committed
[DebugInfo] Don't join DW_AT_comp_dir and directories[0] for DWARF v5 line tables
DWARF v5 6.2.4 The Line Number Program Header says: > The first entry is the current directory of the compilation. Each additional > path entry is either a full path name or is relative to the current directory of > the compilation. When forming a path, relative DW_AT_comp_dir and directories[0] are not supposed to be joined together. Fix getFileNameByIndex to special case DWARF v5 DirIdx == 0. Reviewed By: #debug-info, dblaikie Differential Revision: https://reviews.llvm.org/D131804
1 parent 4d7f9b7 commit 3329cec

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,10 +1382,12 @@ bool DWARFDebugLine::Prologue::getFileNameByIndex(
13821382
IncludeDir = dwarf::toStringRef(IncludeDirectories[Entry.DirIdx - 1]);
13831383
}
13841384

1385-
// For absolute paths only, include the compilation directory of compile unit.
1386-
// We know that FileName is not absolute, the only way to have an absolute
1387-
// path at this point would be if IncludeDir is absolute.
1388-
if (Kind == FileLineInfoKind::AbsoluteFilePath && !CompDir.empty() &&
1385+
// For absolute paths only, include the compilation directory of compile unit,
1386+
// unless v5 DirIdx == 0 (IncludeDir indicates the compilation directory). We
1387+
// know that FileName is not absolute, the only way to have an absolute path
1388+
// at this point would be if IncludeDir is absolute.
1389+
if (Kind == FileLineInfoKind::AbsoluteFilePath &&
1390+
(getVersion() < 5 || Entry.DirIdx != 0) && !CompDir.empty() &&
13891391
!isPathAbsoluteOnWindowsOrPosix(IncludeDir))
13901392
sys::path::append(FilePath, Style, CompDir);
13911393

llvm/test/DebugInfo/X86/symbolize_function_start_v5.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# RUN: llvm-symbolizer --verbose 0x0 --obj=test.o | FileCheck --check-prefix=SYM %s
66
# RUN: llvm-dwarfdump -lookup=0x1 test.o | FileCheck --check-prefix=LOOKUP %s
77

8-
# SYM: Filename: .{{[/\\]}}.{{[/\\]}}test.c
9-
# SYM: Function start filename: .{{[/\\]}}.{{[/\\]}}test.c
8+
# SYM: Filename: .{{[/\\]}}test.c
9+
# SYM: Function start filename: .{{[/\\]}}test.c
1010

1111
# LOOKUP: Line info: line 0, column 0, start file 'test.c', start line 1
1212

llvm/test/MC/ELF/debug-prefix-map.s

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ f:
3333

3434
# MAP_V5: DW_AT_name [DW_FORM_string] ("src.s")
3535
# MAP_V5: DW_AT_comp_dir [DW_FORM_string] ("src_root")
36-
## FIXME llvm-dwarfdump incorrectly joins include_directories[0] to DW_AT_comp_dir,
37-
## so there are two src_root path components.
38-
# MAP_V5: DW_AT_decl_file [DW_FORM_data4] ("src_root{{(/|\\)+}}src_root{{(/|\\)+}}src.s")
36+
# MAP_V5: DW_AT_decl_file [DW_FORM_data4] ("src_root{{(/|\\)+}}src.s")
3937
# MAP_V5: include_directories[ 0] = .debug_line_str[0x00000000] = "src_root"
4038

4139
# MAPABS_V4: DW_AT_name [DW_FORM_string] ("src.s")
4240
# MAPABS_V4: DW_AT_comp_dir [DW_FORM_string] ("{{(/|\\)+}}src_root")
43-
# MAPABS_V4: DW_AT_decl_file [DW_FORM_data4] ("{{(/|\\)+}}src_root{{(/|\\)+}}src.s")
41+
# MAPABS_V4: DW_AT_decl_file [DW_FORM_data4] ("/src_root{{(/|\\)+}}src.s")
4442
# MAPABS_V4-NOT: .foo
4543

4644
# MAPABS_V5: DW_AT_name [DW_FORM_string] ("src.s")

0 commit comments

Comments
 (0)