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

`getContext().setMCLineTableRootFile` (from 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

Reviewed By: #debug-info, dblaikie, raj.khem

Differential Revision: https://reviews.llvm.org/D131848
This commit is contained in:
Fangrui Song 2022-08-14 20:58:23 -07:00
parent eeac9e9232
commit d797c2ffdb
3 changed files with 28 additions and 1 deletions

View File

@ -387,6 +387,7 @@ public:
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).

View File

@ -869,7 +869,7 @@ void MCContext::RemapDebugPaths() {
// 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 @@ void MCContext::RemapDebugPaths() {
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);
}
}

View File

@ -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: