From: Sourabh Singh Tomar Date: Mon, 11 Nov 2019 07:23:19 +0000 (+0530) Subject: [DebugInfo] Support for debug_macinfo.dwo section in llvm and llvm-dwarfdump. X-Git-Tag: llvmorg-11-init~3121 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3f3d0f4f4be04f2dae219c0fe76562eb01ba06d2;p=platform%2Fupstream%2Fllvm.git [DebugInfo] Support for debug_macinfo.dwo section in llvm and llvm-dwarfdump. This patch adds support for debug_macinfo.dwo section[pre-standardized] to llvm and llvm-dwarfdump. Reviewers: probinson, dblaikie, aprantl, jini.susan.george, alok Differential Revision: https://reviews.llvm.org/D70705 Tags: #debug-info #llvm --- diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h index 2dec107..f0896b1 100644 --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -75,6 +75,7 @@ class DWARFContext : public DIContext { DWARFUnitVector DWOUnits; std::unique_ptr AbbrevDWO; + std::unique_ptr MacroDWO; /// The maximum DWARF version of all units. unsigned MaxVersion = 0; @@ -271,6 +272,9 @@ public: /// Get a pointer to the parsed DebugMacro object. const DWARFDebugMacro *getDebugMacro(); + /// Get a pointer to the parsed DebugMacroDWO object. + const DWARFDebugMacro *getDebugMacroDWO(); + /// Get a reference to the parsed accelerator table object. const DWARFDebugNames &getDebugNames(); diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h index 9cd34a5..fbcde7d 100644 --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h @@ -48,6 +48,7 @@ public: virtual const DWARFSection &getRangesSection() const { return Dummy; } virtual const DWARFSection &getRnglistsSection() const { return Dummy; } virtual StringRef getMacinfoSection() const { return ""; } + virtual StringRef getMacinfoDWOSection() const { return ""; } virtual const DWARFSection &getPubnamesSection() const { return Dummy; } virtual const DWARFSection &getPubtypesSection() const { return Dummy; } virtual const DWARFSection &getGnuPubnamesSection() const { return Dummy; } diff --git a/llvm/include/llvm/MC/MCObjectFileInfo.h b/llvm/include/llvm/MC/MCObjectFileInfo.h index 12d681f..2f7f5d6 100644 --- a/llvm/include/llvm/MC/MCObjectFileInfo.h +++ b/llvm/include/llvm/MC/MCObjectFileInfo.h @@ -111,6 +111,7 @@ protected: MCSection *DwarfLineDWOSection = nullptr; MCSection *DwarfLocDWOSection = nullptr; MCSection *DwarfStrOffDWOSection = nullptr; + MCSection *DwarfMacinfoDWOSection = nullptr; /// The DWARF v5 string offset and address table sections. MCSection *DwarfStrOffSection = nullptr; @@ -303,6 +304,9 @@ public: MCSection *getDwarfLoclistsDWOSection() const { return DwarfLoclistsDWOSection; } + MCSection *getDwarfMacinfoDWOSection() const { + return DwarfMacinfoDWOSection; + } MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; } MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; } MCSection *getDwarfSwiftASTSection() const { return DwarfSwiftASTSection; } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 551e8a2..e689c08 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1169,7 +1169,7 @@ void DwarfDebug::finalizeModuleInfo() { auto *CUNode = cast(P.first); // If compile Unit has macros, emit "DW_AT_macro_info" attribute. - if (CUNode->getMacros()) + if (CUNode->getMacros() && !useSplitDwarf()) U.addSectionLabel(U.getUnitDie(), dwarf::DW_AT_macro_info, U.getMacroLabelBegin(), TLOF.getDwarfMacinfoSection()->getBeginSymbol()); @@ -1227,8 +1227,12 @@ void DwarfDebug::endModule() { // Emit info into a debug ranges section. emitDebugRanges(); + if (useSplitDwarf()) + // Emit info into a debug macinfo.dwo section. + emitDebugMacinfoDWO(); + else // Emit info into a debug macinfo section. - emitDebugMacinfo(); + emitDebugMacinfo(); if (useSplitDwarf()) { emitDebugStrDWO(); @@ -2783,6 +2787,24 @@ void DwarfDebug::emitDebugMacinfo() { } } +void DwarfDebug::emitDebugMacinfoDWO() { + for (const auto &P : CUMap) { + auto &TheCU = *P.second; + auto *SkCU = TheCU.getSkeleton(); + DwarfCompileUnit &U = SkCU ? *SkCU : TheCU; + auto *CUNode = cast(P.first); + DIMacroNodeArray Macros = CUNode->getMacros(); + if (Macros.empty()) + continue; + Asm->OutStreamer->SwitchSection( + Asm->getObjFileLowering().getDwarfMacinfoDWOSection()); + Asm->OutStreamer->EmitLabel(U.getMacroLabelBegin()); + handleMacroNodes(Macros, U); + Asm->OutStreamer->AddComment("End Of Macro List Mark"); + Asm->emitInt8(0); + } +} + // DWARF5 Experimental Separate Dwarf emitters. void DwarfDebug::initSkeletonUnit(const DwarfUnit &U, DIE &Die, diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h index 8501607..03949db 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -508,6 +508,8 @@ class DwarfDebug : public DebugHandlerBase { /// Emit macros into a debug macinfo section. void emitDebugMacinfo(); + /// Emit macros into a debug macinfo.dwo section. + void emitDebugMacinfoDWO(); void emitMacro(DIMacro &M); void emitMacroFile(DIMacroFile &F, DwarfCompileUnit &U); void handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U); diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp index 4e70e23..9d662da 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -441,6 +441,9 @@ void DWARFContext::dump( if (Explicit || !getDebugMacro()->empty()) { OS << "\n.debug_macinfo contents:\n"; getDebugMacro()->dump(OS); + } else if (ExplicitDWO || !getDebugMacroDWO()->empty()) { + OS << "\n.debug_macinfo.dwo contents:\n"; + getDebugMacroDWO()->dump(OS); } } @@ -797,6 +800,17 @@ const DWARFDebugFrame *DWARFContext::getEHFrame() { return DebugFrame.get(); } +const DWARFDebugMacro *DWARFContext::getDebugMacroDWO() { + if (MacroDWO) + return MacroDWO.get(); + + DataExtractor MacinfoDWOData(DObj->getMacinfoDWOSection(), isLittleEndian(), + 0); + MacroDWO.reset(new DWARFDebugMacro()); + MacroDWO->parse(MacinfoDWOData); + return MacroDWO.get(); +} + const DWARFDebugMacro *DWARFContext::getDebugMacro() { if (Macro) return Macro.get(); @@ -1500,6 +1514,7 @@ class DWARFObjInMemory final : public DWARFObject { StringRef ArangesSection; StringRef StrSection; StringRef MacinfoSection; + StringRef MacinfoDWOSection; StringRef AbbrevDWOSection; StringRef StrDWOSection; StringRef CUIndexSection; @@ -1519,6 +1534,7 @@ class DWARFObjInMemory final : public DWARFObject { .Case("debug_aranges", &ArangesSection) .Case("debug_str", &StrSection) .Case("debug_macinfo", &MacinfoSection) + .Case("debug_macinfo.dwo", &MacinfoDWOSection) .Case("debug_abbrev.dwo", &AbbrevDWOSection) .Case("debug_str.dwo", &StrDWOSection) .Case("debug_cu_index", &CUIndexSection) @@ -1845,6 +1861,7 @@ public: return RnglistsSection; } StringRef getMacinfoSection() const override { return MacinfoSection; } + StringRef getMacinfoDWOSection() const override { return MacinfoDWOSection; } const DWARFSection &getPubnamesSection() const override { return PubnamesSection; } const DWARFSection &getPubtypesSection() const override { return PubtypesSection; } const DWARFSection &getGnuPubnamesSection() const override { diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp index 5b4da19..9aee0a5 100644 --- a/llvm/lib/MC/MCObjectFileInfo.cpp +++ b/llvm/lib/MC/MCObjectFileInfo.cpp @@ -463,6 +463,8 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) { DebugSecType, ELF::SHF_EXCLUDE); DwarfRnglistsDWOSection = Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE); + DwarfMacinfoDWOSection = + Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE); DwarfLoclistsDWOSection = Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE); diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-macro.dwo b/llvm/test/DebugInfo/Inputs/dwarfdump-macro.dwo new file mode 100644 index 0000000..5b0c16b Binary files /dev/null and b/llvm/test/DebugInfo/Inputs/dwarfdump-macro.dwo differ diff --git a/llvm/test/DebugInfo/debugmacinfo-dwo.test b/llvm/test/DebugInfo/debugmacinfo-dwo.test new file mode 100644 index 0000000..7c5f7ef --- /dev/null +++ b/llvm/test/DebugInfo/debugmacinfo-dwo.test @@ -0,0 +1,20 @@ +RUN: llvm-dwarfdump -debug-macro %p/Inputs/dwarfdump-macro.dwo \ +RUN: | FileCheck %s -check-prefix TEST_MACINFODWO + +; This test verifies that llvm-dwarfdump tools know how to read .debug_macinfo.dwo +; section. +; dwarfdump-macro.dwo has been generated from Inputs/dwarfdump-macro.cc +; clang++ -c -O0 -DM3=Value3 -include dwarfdump-macro-cmd.h dwarfdump-macro.cc -fdebug-macro -gsplit-dwarf + +TEST_MACINFODWO: .debug_macinfo.dwo contents: +TEST_MACINFODWO: DW_MACINFO_start_file - lineno: 0 filenum: 1 +TEST_MACINFODWO: DW_MACINFO_start_file - lineno: 0 filenum: 2 +TEST_MACINFODWO: DW_MACINFO_define - lineno: 1 macro: M4 Value4 +TEST_MACINFODWO: DW_MACINFO_end_file +TEST_MACINFODWO: DW_MACINFO_define - lineno: 1 macro: M1 Value1 +TEST_MACINFODWO: DW_MACINFO_start_file - lineno: 2 filenum: 3 +TEST_MACINFODWO: DW_MACINFO_undef - lineno: 4 macro: M1 +TEST_MACINFODWO: DW_MACINFO_define - lineno: 5 macro: M1 NewValue1 +TEST_MACINFODWO: DW_MACINFO_end_file +TEST_MACINFODWO: DW_MACINFO_define - lineno: 3 macro: M2(x,y) ((x)+(y)* Value2) +TEST_MACINFODWO: DW_MACINFO_end_file