From 3f3d0f4f4be04f2dae219c0fe76562eb01ba06d2 Mon Sep 17 00:00:00 2001 From: Sourabh Singh Tomar Date: Mon, 11 Nov 2019 12:53:19 +0530 Subject: [PATCH] [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 --- llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h | 4 ++++ llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h | 1 + llvm/include/llvm/MC/MCObjectFileInfo.h | 4 ++++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 26 +++++++++++++++++++++-- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h | 2 ++ llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 17 +++++++++++++++ llvm/lib/MC/MCObjectFileInfo.cpp | 2 ++ llvm/test/DebugInfo/Inputs/dwarfdump-macro.dwo | Bin 0 -> 10840 bytes llvm/test/DebugInfo/debugmacinfo-dwo.test | 20 +++++++++++++++++ 9 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 llvm/test/DebugInfo/Inputs/dwarfdump-macro.dwo create mode 100644 llvm/test/DebugInfo/debugmacinfo-dwo.test 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 0000000000000000000000000000000000000000..5b0c16b745c409df034cc487826b5673305c1a21 GIT binary patch literal 10840 zcmcIqOLODK5!QO0e~_aOsy#_@B;!pmhm;`_q!9CE0+h75OhF_h!lp=u1lQVJlAn>E zo1W=;0+i@VRqWbbqPwTN=j+GJVDPVa(EH}YhcofthqJ$)sV6}_JNwV2`u!vO`QzC~ zkc2-U&p^S@JHN|Uhr&Di79MPTu+Khz^YNQ+hxXZrKLBl1{KjN#koh=tE?)oq_454U z;`Q?Ti?5e|!XeHjFwY2Ct-ibvat;`YLw7L`TA|Z^vL6@LyzRDIMd-F1F9_$0#na^{=3Rd@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cQHONK!$~xaNkm)WeKaBV?-O%=pP0ClKVekhMiU3_dfBb6cD)Io z2fcE8wV!-et8#r15{=(-=J27S{QbN>z$YazN>J!>k&b6m_%ux1WWd!jcY>8bnswR4*py+tp!D|Ip7e;CcdIInZH~3B0rJMKh?rQG8!})yZ!#nfh7QBhbwZ zE0hM^3u!|azjAcp3(D(7@pyP9FZsM&KW(lTzirO0;RBH>e^g&u{_ns32tz*}8UB@j d$N622SO4adK6Bc?b{|mM!MSTDO literal 0 HcmV?d00001 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 -- 2.7.4