Index: llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h =================================================================== --- llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h +++ llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -72,6 +72,7 @@ DWARFUnitVector DWOUnits; std::unique_ptr AbbrevDWO; std::unique_ptr MacinfoDWO; + std::unique_ptr MacroDWO; /// The maximum DWARF version of all units. unsigned MaxVersion = 0; @@ -110,8 +111,8 @@ enum MacroSecType { MacinfoSection, MacinfoDwoSection, - MacroSection - // FIXME: Add support for.debug_macro.dwo section. + MacroSection, + MacroDwoSection }; public: @@ -291,6 +292,9 @@ /// Get a pointer to the parsed DebugMacro information object. const DWARFDebugMacro *getDebugMacro(); + /// Get a pointer to the parsed DebugMacroDWO information object. + const DWARFDebugMacro *getDebugMacroDWO(); + /// Get a reference to the parsed accelerator table object. const DWARFDebugNames &getDebugNames(); @@ -316,9 +320,14 @@ getLineTableForUnit(DWARFUnit *U, function_ref RecoverableErrorHandler); + DataExtractor getStringDWOExtractor() const { + return DataExtractor(DObj->getStrDWOSection(), false, 0); + } + DataExtractor getStringExtractor() const { return DataExtractor(DObj->getStrSection(), false, 0); } + DataExtractor getLineStringExtractor() const { return DataExtractor(DObj->getLineStrSection(), false, 0); } Index: llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h =================================================================== --- llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h +++ llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h @@ -48,6 +48,7 @@ virtual const DWARFSection &getRangesSection() const { return Dummy; } virtual const DWARFSection &getRnglistsSection() const { return Dummy; } virtual const DWARFSection &getMacroSection() const { return Dummy; } + virtual StringRef getMacroDWOSection() const { return ""; } virtual StringRef getMacinfoSection() const { return ""; } virtual StringRef getMacinfoDWOSection() const { return ""; } virtual const DWARFSection &getPubnamesSection() const { return Dummy; } Index: llvm/include/llvm/MC/MCObjectFileInfo.h =================================================================== --- llvm/include/llvm/MC/MCObjectFileInfo.h +++ llvm/include/llvm/MC/MCObjectFileInfo.h @@ -113,6 +113,7 @@ MCSection *DwarfLocDWOSection = nullptr; MCSection *DwarfStrOffDWOSection = nullptr; MCSection *DwarfMacinfoDWOSection = nullptr; + MCSection *DwarfMacroDWOSection = nullptr; /// The DWARF v5 string offset and address table sections. MCSection *DwarfStrOffSection = nullptr; Index: llvm/lib/DebugInfo/DWARF/DWARFContext.cpp =================================================================== --- llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -299,11 +299,13 @@ Optional Units; Optional StringExtractor; if (IsMacro) { - StringExtractor = getStringExtractor(); - // FIXME: Add support for debug_macro.dwo section. - Units = compile_units(); + StringExtractor = SectionType != MacroDwoSection + ? getStringExtractor() + : getStringDWOExtractor(); + Units = SectionType != MacroDwoSection ? compile_units() : dwo_units(); } - if (Error Err = Macro->parse(Units, StringExtractor, Data, IsMacro)) { + if (Error Err = Macro->parse(Units,StringExtractor, + Data, IsMacro)) { RecoverableErrorHandler(std::move(Err)); Macro = nullptr; } @@ -325,6 +327,11 @@ ParseAndDump(Data, /*IsMacro=*/true); break; } + case MacroDwoSection: { + DWARFDataExtractor Data(DObj->getMacroDWOSection(), isLittleEndian(), 0); + ParseAndDump(Data, /*IsMacro=*/true); + break; + } } return Macro; } @@ -487,6 +494,12 @@ Macro->dump(OS); } + if (shouldDump(Explicit, ".debug_macro.dwo", DIDT_ID_DebugMacro, + DObj->getMacroDWOSection())) { + if (auto MacroDWO = getDebugMacroDWO()) + MacroDWO->dump(OS); + } + if (shouldDump(Explicit, ".debug_macinfo", DIDT_ID_DebugMacro, DObj->getMacinfoSection())) { if (auto Macinfo = getDebugMacinfo()) @@ -866,6 +879,12 @@ return Macro.get(); } +const DWARFDebugMacro *DWARFContext::getDebugMacroDWO() { + if (!MacroDWO) + MacroDWO = parseMacroOrMacinfo(MacroDwoSection); + return MacroDWO.get(); +} + const DWARFDebugMacro *DWARFContext::getDebugMacinfo() { if (!Macinfo) Macinfo = parseMacroOrMacinfo(MacinfoSection); @@ -1555,6 +1574,7 @@ StringRef StrSection; StringRef MacinfoSection; StringRef MacinfoDWOSection; + StringRef MacroDWOSection; StringRef AbbrevDWOSection; StringRef StrDWOSection; StringRef CUIndexSection; @@ -1575,6 +1595,7 @@ .Case("debug_str", &StrSection) .Case("debug_macinfo", &MacinfoSection) .Case("debug_macinfo.dwo", &MacinfoDWOSection) + .Case("debug_macro.dwo", &MacroDWOSection) .Case("debug_abbrev.dwo", &AbbrevDWOSection) .Case("debug_str.dwo", &StrDWOSection) .Case("debug_cu_index", &CUIndexSection) @@ -1893,6 +1914,7 @@ return RnglistsSection; } const DWARFSection &getMacroSection() const override { return MacroSection; } + StringRef getMacroDWOSection() const override { return MacroDWOSection; } StringRef getMacinfoSection() const override { return MacinfoSection; } StringRef getMacinfoDWOSection() const override { return MacinfoDWOSection; } const DWARFSection &getPubnamesSection() const override { return PubnamesSection; } Index: llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp =================================================================== --- llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp +++ llvm/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp @@ -86,9 +86,10 @@ } } -Error DWARFDebugMacro::parse(Optional Units, - Optional StringExtractor, - DWARFDataExtractor Data, bool IsMacro) { +Error DWARFDebugMacro::parse( + Optional Units, + Optional StringExtractor, DWARFDataExtractor Data, + bool IsMacro) { uint64_t Offset = 0; MacroList *M = nullptr; using MacroToUnitsMap = DenseMap; Index: llvm/lib/MC/MCObjectFileInfo.cpp =================================================================== --- llvm/lib/MC/MCObjectFileInfo.cpp +++ llvm/lib/MC/MCObjectFileInfo.cpp @@ -473,6 +473,8 @@ Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE); DwarfMacinfoDWOSection = Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE); + DwarfMacroDWOSection = + Ctx->getELFSection(".debug_macro.dwo", DebugSecType, ELF::SHF_EXCLUDE); DwarfLoclistsDWOSection = Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE); @@ -649,6 +651,11 @@ COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ, SectionKind::getMetadata(), "debug_macinfo.dwo"); + DwarfMacroDWOSection = Ctx->getCOFFSection( + ".debug_macro.dwo", + COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | + COFF::IMAGE_SCN_MEM_READ, + SectionKind::getMetadata(), "debug_macro.dwo"); DwarfInfoDWOSection = Ctx->getCOFFSection( ".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | Index: llvm/test/DebugInfo/X86/debug-macro-dwo.s =================================================================== --- /dev/null +++ llvm/test/DebugInfo/X86/debug-macro-dwo.s @@ -0,0 +1,65 @@ +## This test checks that llvm-dwarfdump can dump debug_macro.dwo +## section present in a dwo object. + +# RUN: llvm-mc -triple x86_64-unknown-linux -filetype=obj %s -o -| \ +# RUN: llvm-dwarfdump -debug-macro - | FileCheck -strict-whitespace -match-full-lines %s + +# CHECK:.debug_macro.dwo contents: +# CHECK-NEXT:0x00000000: +# CHECK-NEXT:macro header: version = 0x0005, flags = 0x02, debug_line_offset = 0x0000 +# CHECK-NEXT:DW_MACRO_start_file - lineno: 0 filenum: 0 +# CHECK-NEXT: DW_MACRO_define_strx - lineno: 1 macro: DWARF_VERSION 5 +# CHECK-NEXT: DW_MACRO_undef_strx - lineno: 4 macro: DWARF_VERSION +# CHECK-NEXT:DW_MACRO_end_file + + .section .debug_macro.dwo,"e",@progbits +.Lcu_macro_begin0: + .short 5 # Macro information version + .byte 2 # Flags: 32 bit, debug_line_offset present + .long 0 # debug_line_offset + .byte 3 # DW_MACRO_start_file + .byte 0 # Line Number + .byte 0 # File Number + .byte 11 # DW_MACRO_define_strx + .byte 1 # Line Number + .byte 0 # Macro String Index + .byte 12 # DW_MACRO_undef_strx + .byte 4 # Line Number + .byte 1 # Macro String Index + .byte 4 # DW_MACRO_end_file + .byte 0 # End Of Macro List Mark + + .section .debug_str_offsets.dwo,"e",@progbits + .long .Lcu_str_off_end0-.Lcu_str_off_start0 + .short 5 + .short 0 + .section .debug_str.dwo,"eMS",@progbits,1 +.Linfo_string0: + .asciz "DWARF_VERSION 5" # string offset=49 +.Linfo_string1: + .asciz "DWARF_VERSION" # string offset=65 + .section .debug_str_offsets.dwo,"e",@progbits +.Lcu_str_off_start0: + .long .Linfo_string0-.debug_str.dwo + .long .Linfo_string1-.debug_str.dwo +.Lcu_str_off_end0: + .section .debug_info.dwo,"e",@progbits + .long .Ldebug_info_dwo_end0-.Ldebug_info_dwo_start0 # Length of Unit +.Ldebug_info_dwo_start0: + .short 5 # DWARF version number + .byte 5 # DWARF Unit Type + .byte 8 # Address Size (in bytes) + .long 0 # Offset Into Abbrev. Section + .quad 1536875774479801980 + .byte 1 # Abbrev [1] 0x14:0x1a DW_TAG_compile_unit + .long .Lcu_macro_begin0-.debug_macro.dwo # DW_AT_macros + .byte 0 # End Of Children Mark +.Ldebug_info_dwo_end0: + .section .debug_abbrev.dwo,"e",@progbits + .byte 1 # Abbreviation Code + .byte 17 # DW_TAG_compile_unit + .byte 1 # DW_CHILDREN_yes + .byte 121 # DW_AT_macros + .byte 23 # DW_FORM_sec_offset + .byte 0 # EOM(1) + .byte 0 # EOM(2)