[llvm] 39c308f - DebugInfo: Use separate macinfo contributions for each CU
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 8 13:27:06 PST 2019
Author: David Blaikie
Date: 2019-11-08T13:27:00-08:00
New Revision: 39c308f6b8f06710b2b98d0b126c9175e4bafc20
URL: https://github.com/llvm/llvm-project/commit/39c308f6b8f06710b2b98d0b126c9175e4bafc20
DIFF: https://github.com/llvm/llvm-project/commit/39c308f6b8f06710b2b98d0b126c9175e4bafc20.diff
LOG: DebugInfo: Use separate macinfo contributions for each CU
The macinfo support was broken for LTO situations, by terminating
macinfo lists only once - multiple macinfo contributions were correctly
labeled, but they all continued/flowed into later contributions until
only one terminator appeared at the end of the section.
Correctly terminate each contribution & fix the parsing to handle this
situation too. The parsing fix is also necessary for dumping linked
binaries - the previous code would stop at the end of the first
contribution - missing all later contributions in a linked binary.
It'd be nice to improve the dumping to print the offsets of each
contribution so it'd be easier to know which CU AT_macro_info refers to
which macinfo contribution.
Added:
Modified:
llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp
llvm/test/DebugInfo/NVPTX/cu-range-hole.ll
llvm/test/DebugInfo/NVPTX/debug-addr-class.ll
llvm/test/DebugInfo/NVPTX/debug-file-loc.ll
llvm/test/DebugInfo/NVPTX/debug-info.ll
llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
llvm/test/DebugInfo/X86/debug-macro.ll
llvm/test/DebugInfo/X86/empty_macinfo.ll
llvm/test/MC/WebAssembly/debug-info.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h
index a6c125990ca7..7880bcdf6881 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugMacro.h
@@ -42,7 +42,7 @@ class DWARFDebugMacro {
using MacroList = SmallVector<Entry, 4>;
/// A list of all the macro entries in the debug_macinfo section.
- MacroList Macros;
+ std::vector<MacroList> MacroLists;
public:
DWARFDebugMacro() = default;
@@ -54,7 +54,7 @@ class DWARFDebugMacro {
void parse(DataExtractor data);
/// Return whether the section has any entries.
- bool empty() const { return Macros.empty(); }
+ bool empty() const { return MacroLists.empty(); }
};
} // end namespace llvm
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 97ef439b8a5f..d17dd4dc3f71 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2752,10 +2752,10 @@ void DwarfDebug::emitDebugMacinfo() {
if (!Macros.empty()) {
Asm->OutStreamer->EmitLabel(U.getMacroLabelBegin());
handleMacroNodes(Macros, U);
+ Asm->OutStreamer->AddComment("End Of Macro List Mark");
+ Asm->emitInt8(0);
}
}
- Asm->OutStreamer->AddComment("End Of Macro List Mark");
- Asm->emitInt8(0);
}
// DWARF5 Experimental Separate Dwarf emitters.
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp
index 9a0e770aed3d..8cb259ebc622 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp
@@ -17,36 +17,39 @@ using namespace dwarf;
void DWARFDebugMacro::dump(raw_ostream &OS) const {
unsigned IndLevel = 0;
- for (const Entry &E : Macros) {
- // There should not be DW_MACINFO_end_file when IndLevel is Zero. However,
- // this check handles the case of corrupted ".debug_macinfo" section.
- if (IndLevel > 0)
- IndLevel -= (E.Type == DW_MACINFO_end_file);
- // Print indentation.
- for (unsigned I = 0; I < IndLevel; I++)
- OS << " ";
- IndLevel += (E.Type == DW_MACINFO_start_file);
+ for (const auto &Macros : MacroLists) {
+ for (const Entry &E : Macros) {
+ // There should not be DW_MACINFO_end_file when IndLevel is Zero. However,
+ // this check handles the case of corrupted ".debug_macinfo" section.
+ if (IndLevel > 0)
+ IndLevel -= (E.Type == DW_MACINFO_end_file);
+ // Print indentation.
+ for (unsigned I = 0; I < IndLevel; I++)
+ OS << " ";
+ IndLevel += (E.Type == DW_MACINFO_start_file);
- WithColor(OS, HighlightColor::Macro).get() << MacinfoString(E.Type);
- switch (E.Type) {
- default:
- // Got a corrupted ".debug_macinfo" section (invalid macinfo type).
- break;
- case DW_MACINFO_define:
- case DW_MACINFO_undef:
- OS << " - lineno: " << E.Line;
- OS << " macro: " << E.MacroStr;
- break;
- case DW_MACINFO_start_file:
- OS << " - lineno: " << E.Line;
- OS << " filenum: " << E.File;
- break;
- case DW_MACINFO_end_file:
- break;
- case DW_MACINFO_vendor_ext:
- OS << " - constant: " << E.ExtConstant;
- OS << " string: " << E.ExtStr;
- break;
+ WithColor(OS, HighlightColor::Macro).get() << MacinfoString(E.Type);
+ switch (E.Type) {
+ default:
+ // Got a corrupted ".debug_macinfo" section (invalid macinfo type).
+ break;
+ case DW_MACINFO_define:
+ case DW_MACINFO_undef:
+ OS << " - lineno: " << E.Line;
+ OS << " macro: " << E.MacroStr;
+ break;
+ case DW_MACINFO_start_file:
+ OS << " - lineno: " << E.Line;
+ OS << " filenum: " << E.File;
+ break;
+ case DW_MACINFO_end_file:
+ break;
+ case DW_MACINFO_vendor_ext:
+ OS << " - constant: " << E.ExtConstant;
+ OS << " string: " << E.ExtStr;
+ break;
+ }
+ OS << "\n";
}
OS << "\n";
}
@@ -54,15 +57,21 @@ void DWARFDebugMacro::dump(raw_ostream &OS) const {
void DWARFDebugMacro::parse(DataExtractor data) {
uint64_t Offset = 0;
+ MacroList *M = nullptr;
while (data.isValidOffset(Offset)) {
+ if (!M) {
+ MacroLists.emplace_back();
+ M = &MacroLists.back();
+ }
// A macro list entry consists of:
- Entry E;
+ M->emplace_back();
+ Entry &E = M->back();
// 1. Macinfo type
E.Type = data.getULEB128(&Offset);
if (E.Type == 0) {
- // Reached end of ".debug_macinfo" section.
- return;
+ // Reached end of a ".debug_macinfo" section contribution.
+ continue;
}
switch (E.Type) {
@@ -70,7 +79,6 @@ void DWARFDebugMacro::parse(DataExtractor data) {
// Got a corrupted ".debug_macinfo" section (invalid macinfo type).
// Push the corrupted entry to the list and halt parsing.
E.Type = DW_MACINFO_invalid;
- Macros.push_back(E);
return;
case DW_MACINFO_define:
case DW_MACINFO_undef:
@@ -94,7 +102,5 @@ void DWARFDebugMacro::parse(DataExtractor data) {
E.ExtStr = data.getCStr(&Offset);
break;
}
-
- Macros.push_back(E);
}
}
diff --git a/llvm/test/DebugInfo/NVPTX/cu-range-hole.ll b/llvm/test/DebugInfo/NVPTX/cu-range-hole.ll
index e7852cc6d3b9..67dca931ca75 100644
--- a/llvm/test/DebugInfo/NVPTX/cu-range-hole.ll
+++ b/llvm/test/DebugInfo/NVPTX/cu-range-hole.ll
@@ -271,8 +271,8 @@ entry:
; CHECK-NEXT: }
; CHECK-NEXT: .section .debug_macinfo
; CHECK-NEXT: {
-; CHECK-NEXT: .b8 0 // End Of Macro List Mark
-; CHECK: }
+; CHECK-EMPTY:
+; CHECK-NEXT: }
attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { nounwind readnone }
diff --git a/llvm/test/DebugInfo/NVPTX/debug-addr-class.ll b/llvm/test/DebugInfo/NVPTX/debug-addr-class.ll
index e5ca8defc84e..2107e1cdc121 100644
--- a/llvm/test/DebugInfo/NVPTX/debug-addr-class.ll
+++ b/llvm/test/DebugInfo/NVPTX/debug-addr-class.ll
@@ -333,6 +333,6 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata)
; CHECK-NEXT: }
; CHECK-NEXT: .section .debug_macinfo
; CHECK-NEXT: {
-; CHECK-NEXT: .b8 0 // End Of Macro List Mark
-; CHECK: }
+; CHECK-EMPTY:
+; CHECK-NEXT: }
diff --git a/llvm/test/DebugInfo/NVPTX/debug-file-loc.ll b/llvm/test/DebugInfo/NVPTX/debug-file-loc.ll
index 36fb59c72716..b5fae18fbf7a 100644
--- a/llvm/test/DebugInfo/NVPTX/debug-file-loc.ll
+++ b/llvm/test/DebugInfo/NVPTX/debug-file-loc.ll
@@ -88,8 +88,8 @@ bb:
; CHECK-NEXT: }
; CHECK-NEXT: .section .debug_macinfo
; CHECK-NEXT: {
-; CHECK-NEXT: .b8 0 // End Of Macro List Mark
-; CHECK: }
+; CHECK-EMPTY:
+; CHECK-NEXT: }
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!8, !9}
diff --git a/llvm/test/DebugInfo/NVPTX/debug-info.ll b/llvm/test/DebugInfo/NVPTX/debug-info.ll
index 7164bc8ec426..00f96cfa8cf1 100644
--- a/llvm/test/DebugInfo/NVPTX/debug-info.ll
+++ b/llvm/test/DebugInfo/NVPTX/debug-info.ll
@@ -8403,8 +8403,8 @@ if.end: ; preds = %if.then, %entry
; CHECK-NEXT: }
; CHECK-NEXT: .section .debug_macinfo
; CHECK-NEXT: {
-; CHECK-NEXT: .b8 0 // End Of Macro List Mark
-; CHECK: }
+; CHECK-EMPTY:
+; CHECK-NEXT: }
; Function Attrs: nounwind readnone
declare i32 @llvm.nvvm.read.ptx.sreg.ctaid.x() #1
diff --git a/llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll b/llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
index f1510e1b4a9b..6ee63fff7e11 100644
--- a/llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
+++ b/llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
@@ -472,5 +472,5 @@ attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "n
; CHECK-NEXT: }
; CHECK-NEXT: .section .debug_macinfo
; CHECK-NEXT: {
-; CHECK-NEXT: .b8 0 // End Of Macro List Mark
-; CHECK: }
+; CHECK-EMPTY:
+; CHECK-NEXT: }
diff --git a/llvm/test/DebugInfo/X86/debug-macro.ll b/llvm/test/DebugInfo/X86/debug-macro.ll
index e286b8a733e5..6a5ae1e70216 100644
--- a/llvm/test/DebugInfo/X86/debug-macro.ll
+++ b/llvm/test/DebugInfo/X86/debug-macro.ll
@@ -9,7 +9,7 @@
; CHECK: DW_TAG_compile_unit
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name {{.*}}"debug-macro1.cpp")
-; CHECK: DW_AT_macro_info {{.*}}(0x00000044)
+; CHECK: DW_AT_macro_info {{.*}}(0x00000045)
; CHECK: DW_TAG_compile_unit
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name {{.*}}"debug-macro2.cpp")
@@ -24,7 +24,8 @@
; CHECK-NEXT: DW_MACINFO_end_file
; CHECK-NEXT: DW_MACINFO_undef - lineno: 10 macro: NameUndef2
; CHECK-NEXT: DW_MACINFO_end_file
-; CHECK-NEXT: DW_MACINFO_start_file - lineno: 0 filenum: 1
+
+; CHECK: DW_MACINFO_start_file - lineno: 0 filenum: 1
; CHECK-NEXT: DW_MACINFO_end_file
; CHECK-LABEL: .debug_line contents:
diff --git a/llvm/test/DebugInfo/X86/empty_macinfo.ll b/llvm/test/DebugInfo/X86/empty_macinfo.ll
index ec3c6a113311..40cd1449c87a 100644
--- a/llvm/test/DebugInfo/X86/empty_macinfo.ll
+++ b/llvm/test/DebugInfo/X86/empty_macinfo.ll
@@ -3,7 +3,6 @@
; Test that we don't pollute the start of the file with debug sections
; CHECK: .section .debug_macinfo,"", at progbits
-; CHECK-NEXT: .byte 0 # End Of Macro List Mark
; CHECK-NEXT: .section
; CHECK-NOT: .debug_macinfo
diff --git a/llvm/test/MC/WebAssembly/debug-info.ll b/llvm/test/MC/WebAssembly/debug-info.ll
index 0d78f97fbb2b..749184c548a1 100644
--- a/llvm/test/MC/WebAssembly/debug-info.ll
+++ b/llvm/test/MC/WebAssembly/debug-info.ll
@@ -71,68 +71,68 @@
; CHECK-NEXT: }
; CHECK-NEXT: Section {
; CHECK-NEXT: Type: CUSTOM (0x0)
-; CHECK-NEXT: Size: 1
+; CHECK-NEXT: Size: 0
; CHECK-NEXT: Offset: 511
; CHECK-NEXT: Name: .debug_macinfo
; CHECK-NEXT: }
; CHECK-NEXT: Section {
; CHECK-NEXT: Type: CUSTOM (0x0)
; CHECK-NEXT: Size: 42
-; CHECK-NEXT: Offset: 533
+; CHECK-NEXT: Offset: 532
; CHECK-NEXT: Name: .debug_pubnames
; CHECK-NEXT: }
; CHECK-NEXT: Section {
; CHECK-NEXT: Type: CUSTOM (0x0)
; CHECK-NEXT: Size: 26
-; CHECK-NEXT: Offset: 597
+; CHECK-NEXT: Offset: 596
; CHECK-NEXT: Name: .debug_pubtypes
; CHECK-NEXT: }
; CHECK-NEXT: Section {
; CHECK-NEXT: Type: CUSTOM (0x0)
; CHECK-NEXT: Size: 57
-; CHECK-NEXT: Offset: 645
+; CHECK-NEXT: Offset: 644
; CHECK-NEXT: Name: .debug_line
; CHECK-NEXT: }
; CHECK-NEXT: Section {
; CHECK-NEXT: Type: CUSTOM (0x0)
; CHECK-NEXT: Size: 88
-; CHECK-NEXT: Offset: 720
+; CHECK-NEXT: Offset: 719
; CHECK-NEXT: Name: linking
; CHECK-NEXT: }
; CHECK-NEXT: Section {
; CHECK-NEXT: Type: CUSTOM (0x0)
; CHECK-NEXT: Size: 9
-; CHECK-NEXT: Offset: 822
+; CHECK-NEXT: Offset: 821
; CHECK-NEXT: Name: reloc.DATA
; CHECK-NEXT: }
; CHECK-NEXT: Section {
; CHECK-NEXT: Type: CUSTOM (0x0)
; CHECK-NEXT: Size: 58
-; CHECK-NEXT: Offset: 848
+; CHECK-NEXT: Offset: 847
; CHECK-NEXT: Name: reloc..debug_info
; CHECK-NEXT: }
; CHECK-NEXT: Section {
; CHECK-NEXT: Type: CUSTOM (0x0)
; CHECK-NEXT: Size: 6
-; CHECK-NEXT: Offset: 930
+; CHECK-NEXT: Offset: 929
; CHECK-NEXT: Name: reloc..debug_pubnames
; CHECK-NEXT: }
; CHECK-NEXT: Section {
; CHECK-NEXT: Type: CUSTOM (0x0)
; CHECK-NEXT: Size: 6
-; CHECK-NEXT: Offset: 964
+; CHECK-NEXT: Offset: 963
; CHECK-NEXT: Name: reloc..debug_pubtypes
; CHECK-NEXT: }
; CHECK-NEXT: Section {
; CHECK-NEXT: Type: CUSTOM (0x0)
; CHECK-NEXT: Size: 6
-; CHECK-NEXT: Offset: 998
+; CHECK-NEXT: Offset: 997
; CHECK-NEXT: Name: reloc..debug_line
; CHECK-NEXT: }
; CHECK-NEXT: Section {
; CHECK-NEXT: Type: CUSTOM (0x0)
; CHECK-NEXT: Size: 77
-; CHECK-NEXT: Offset: 1028
+; CHECK-NEXT: Offset: 1027
; CHECK-NEXT: Name: producers
; CHECK-NEXT: }
; CHECK-NEXT:]
More information about the llvm-commits
mailing list