[PATCH] D131804: [DebugInfo] Don't join DW_AT_comp_dir and directories[0] for DWARF v5 line tables
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 12 13:34:13 PDT 2022
MaskRay created this revision.
MaskRay added a reviewer: debug-info.
Herald added subscribers: StephenFan, hiraditya, emaste.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, sstefan1.
Herald added a project: LLVM.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D131804
Files:
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
llvm/test/DebugInfo/X86/symbolize_function_start_v5.s
llvm/test/MC/ELF/debug-prefix-map.s
Index: llvm/test/MC/ELF/debug-prefix-map.s
===================================================================
--- llvm/test/MC/ELF/debug-prefix-map.s
+++ llvm/test/MC/ELF/debug-prefix-map.s
@@ -33,14 +33,12 @@
# MAP_V5: DW_AT_name [DW_FORM_string] ("src.s")
# MAP_V5: DW_AT_comp_dir [DW_FORM_string] ("src_root")
-## FIXME llvm-dwarfdump incorrectly joins include_directories[0] to DW_AT_comp_dir,
-## so there are two src_root path components.
-# MAP_V5: DW_AT_decl_file [DW_FORM_data4] ("src_root{{(/|\\)+}}src_root{{(/|\\)+}}src.s")
+# MAP_V5: DW_AT_decl_file [DW_FORM_data4] ("src_root{{(/|\\)+}}src.s")
# MAP_V5: include_directories[ 0] = .debug_line_str[0x00000000] = "src_root"
# MAPABS_V4: DW_AT_name [DW_FORM_string] ("src.s")
# MAPABS_V4: DW_AT_comp_dir [DW_FORM_string] ("{{(/|\\)+}}src_root")
-# MAPABS_V4: DW_AT_decl_file [DW_FORM_data4] ("{{(/|\\)+}}src_root{{(/|\\)+}}src.s")
+# MAPABS_V4: DW_AT_decl_file [DW_FORM_data4] ("/src_root{{(/|\\)+}}src.s")
# MAPABS_V4-NOT: .foo
# MAPABS_V5: DW_AT_name [DW_FORM_string] ("src.s")
Index: llvm/test/DebugInfo/X86/symbolize_function_start_v5.s
===================================================================
--- llvm/test/DebugInfo/X86/symbolize_function_start_v5.s
+++ llvm/test/DebugInfo/X86/symbolize_function_start_v5.s
@@ -5,8 +5,8 @@
# RUN: llvm-symbolizer --verbose 0x0 --obj=test.o | FileCheck --check-prefix=SYM %s
# RUN: llvm-dwarfdump -lookup=0x1 test.o | FileCheck --check-prefix=LOOKUP %s
-# SYM: Filename: .{{[/\\]}}.{{[/\\]}}test.c
-# SYM: Function start filename: .{{[/\\]}}.{{[/\\]}}test.c
+# SYM: Filename: .{{[/\\]}}test.c
+# SYM: Function start filename: .{{[/\\]}}test.c
# LOOKUP: Line info: line 0, column 0, start file 'test.c', start line 1
Index: llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1382,10 +1382,12 @@
IncludeDir = dwarf::toStringRef(IncludeDirectories[Entry.DirIdx - 1]);
}
- // 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.
- if (Kind == FileLineInfoKind::AbsoluteFilePath && !CompDir.empty() &&
+ // For absolute paths only, include the compilation directory of compile unit,
+ // unless v5 DirIdx == 0 (IncludeDir indicates the compilation directory). 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 (Kind == FileLineInfoKind::AbsoluteFilePath &&
+ (getVersion() < 5 || Entry.DirIdx != 0) && !CompDir.empty() &&
!isPathAbsoluteOnWindowsOrPosix(IncludeDir))
sys::path::append(FilePath, Style, CompDir);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131804.452292.patch
Type: text/x-patch
Size: 2944 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220812/5997d736/attachment.bin>
More information about the llvm-commits
mailing list