diff options
author | David Blaikie <dblaikie@gmail.com> | 2019-11-08 12:56:49 -0800 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2019-11-08 13:27:00 -0800 |
commit | 39c308f6b8f06710b2b98d0b126c9175e4bafc20 (patch) | |
tree | dde9c7aeb84a866efbf078d8bc5cc5f259a36ceb /llvm/lib | |
parent | 860ee4f3ebf56f4d2e387ceec9b8028636e72d2c (diff) | |
download | bcm5719-llvm-39c308f6b8f06710b2b98d0b126c9175e4bafc20.tar.gz bcm5719-llvm-39c308f6b8f06710b2b98d0b126c9175e4bafc20.zip |
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.
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp | 76 |
2 files changed, 43 insertions, 37 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 97ef439b8a5..d17dd4dc3f7 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 9a0e770aed3..8cb259ebc62 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); } } |