[PATCH] D131848: [DebugInfo] -fdebug-prefix-map: handle '#line "file"' for asm source

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 14 00:36:31 PDT 2022


MaskRay created this revision.
MaskRay added reviewers: debug-info, dblaikie, probinson, raj.khem.
Herald added subscribers: StephenFan, hiraditya, emaste.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

`getContext().setMCLineTableRootFile` (from D62074 <https://reviews.llvm.org/D62074>) sets `RootFile.Name` to
`FirstCppHashFilename`. `RootFile.Name` is not processed by -fdebug-prefix-map
and will go to DW_TAG_compile_unit's DT_AT_name and DW_TAG_label's
DW_AT_decl_file. Remap `RootFile.Name`.

Fix another issue reported by https://github.com/llvm/llvm-project/issues/56609


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131848

Files:
  llvm/include/llvm/MC/MCDwarf.h
  llvm/lib/MC/MCContext.cpp
  llvm/test/MC/ELF/debug-hash-file.s


Index: llvm/test/MC/ELF/debug-hash-file.s
===================================================================
--- llvm/test/MC/ELF/debug-hash-file.s
+++ llvm/test/MC/ELF/debug-hash-file.s
@@ -23,6 +23,26 @@
 // DWARF5-NEXT:      dir_index: 0
 // DWARF5-NOT:  file_names[ 1]:
 
+// RUN: llvm-mc -triple=x86_64 -filetype=obj -g -dwarf-version=4 -fdebug-prefix-map=/MyTest=/src_root %s -o %t.4.o
+// RUN: llvm-dwarfdump -debug-info -debug-line %t.4.o | FileCheck %s --check-prefixes=MAP,MAP_V4
+// RUN: llvm-mc -triple=x86_64 -filetype=obj -g -dwarf-version=5 -fdebug-prefix-map=/MyTest=/src_root %s -o %t.5.o
+// RUN: llvm-dwarfdump -debug-info -debug-line %t.5.o | FileCheck %s --check-prefixes=MAP,MAP_V5
+
+// MAP-LABEL:   DW_TAG_compile_unit
+// MAP:           DW_AT_name      ("/src_root{{(/|\\)+}}Inputs/other.S")
+// MAP-LABEL:     DW_TAG_label
+// MAP:             DW_AT_decl_file      ("/src_root{{(/|\\)+}}Inputs/other.S")
+
+// MAP_V4:      include_directories[  1] = "/src_root{{(/|\\)+}}Inputs"
+// MAP_V4-NEXT: file_names[  1]:
+// MAP_V4-NEXT:            name: "other.S"
+// MAP_V4-NEXT:       dir_index: 1
+
+// MAP_V5:      include_directories[  0] = "{{.*}}"
+// MAP_V5-NEXT: file_names[  0]:
+// MAP_V5-NEXT:            name: "/src_root{{(/|\\)+}}Inputs/other.S"
+// MAP_V5-NEXT:       dir_index: 0
+
 # 1 "/MyTest/Inputs/other.S"
 
 foo:
Index: llvm/lib/MC/MCContext.cpp
===================================================================
--- llvm/lib/MC/MCContext.cpp
+++ llvm/lib/MC/MCContext.cpp
@@ -869,7 +869,7 @@
   // Remap compilation directory.
   remapDebugPath(CompilationDir);
 
-  // Remap MCDwarfDirs in all compilation units.
+  // Remap MCDwarfDirs and RootFile.Name in all compilation units.
   SmallString<256> P;
   for (auto &CUIDTablePair : MCDwarfLineTablesCUMap) {
     for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs()) {
@@ -877,6 +877,12 @@
       remapDebugPath(P);
       Dir = std::string(P);
     }
+
+    // Used by DW_TAG_compile_unit's DT_AT_name and DW_TAG_label's
+    // DW_AT_decl_file for DWARF v5 generated for assembly source.
+    P = CUIDTablePair.second.getRootFile().Name;
+    remapDebugPath(P);
+    CUIDTablePair.second.getRootFile().Name = std::string(P);
   }
 }
 
Index: llvm/include/llvm/MC/MCDwarf.h
===================================================================
--- llvm/include/llvm/MC/MCDwarf.h
+++ llvm/include/llvm/MC/MCDwarf.h
@@ -387,6 +387,7 @@
 
   bool hasRootFile() const { return !Header.RootFile.Name.empty(); }
 
+  MCDwarfFile &getRootFile() { return Header.RootFile; }
   const MCDwarfFile &getRootFile() const { return Header.RootFile; }
 
   // Report whether MD5 usage has been consistent (all-or-none).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131848.452488.patch
Type: text/x-patch
Size: 2703 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220814/b31f3561/attachment.bin>


More information about the llvm-commits mailing list