@@ -292,6 +292,36 @@ static void dumpRnglistsSection(
292292 }
293293}
294294
295+ std::unique_ptr<DWARFDebugMacro>
296+ DWARFContext::parseMacroOrMacinfo (MacroSecType SectionType) {
297+ auto Macro = std::make_unique<DWARFDebugMacro>();
298+ auto ParseAndDump = [&](DWARFDataExtractor &Data, bool IsMacro) {
299+ if (Error Err = Macro->parse (getStringExtractor (), Data, IsMacro)) {
300+ RecoverableErrorHandler (std::move (Err));
301+ Macro = nullptr ;
302+ }
303+ };
304+ switch (SectionType) {
305+ case MacinfoSection: {
306+ DWARFDataExtractor Data (DObj->getMacinfoSection (), isLittleEndian (), 0 );
307+ ParseAndDump (Data, /* IsMacro=*/ false );
308+ break ;
309+ }
310+ case MacinfoDwoSection: {
311+ DWARFDataExtractor Data (DObj->getMacinfoDWOSection (), isLittleEndian (), 0 );
312+ ParseAndDump (Data, /* IsMacro=*/ false );
313+ break ;
314+ }
315+ case MacroSection: {
316+ DWARFDataExtractor Data (*DObj, DObj->getMacroSection (), isLittleEndian (),
317+ 0 );
318+ ParseAndDump (Data, /* IsMacro=*/ true );
319+ break ;
320+ }
321+ }
322+ return std::move (Macro);
323+ }
324+
295325static void dumpLoclistsSection (raw_ostream &OS, DIDumpOptions DumpOpts,
296326 DWARFDataExtractor Data,
297327 const MCRegisterInfo *MRI,
@@ -444,14 +474,22 @@ void DWARFContext::dump(
444474 DObj->getEHFrameSection ().Data ))
445475 getEHFrame ()->dump (OS, getRegisterInfo (), *Off);
446476
477+ if (shouldDump (Explicit, " .debug_macro" , DIDT_ID_DebugMacro,
478+ DObj->getMacroSection ().Data )) {
479+ if (auto Macro = getDebugMacro ())
480+ Macro->dump (OS);
481+ }
482+
447483 if (shouldDump (Explicit, " .debug_macinfo" , DIDT_ID_DebugMacro,
448484 DObj->getMacinfoSection ())) {
449- getDebugMacinfo ()->dump (OS);
485+ if (auto Macinfo = getDebugMacinfo ())
486+ Macinfo->dump (OS);
450487 }
451488
452489 if (shouldDump (Explicit, " .debug_macinfo.dwo" , DIDT_ID_DebugMacro,
453490 DObj->getMacinfoDWOSection ())) {
454- getDebugMacinfoDWO ()->dump (OS);
491+ if (auto MacinfoDWO = getDebugMacinfoDWO ())
492+ MacinfoDWO->dump (OS);
455493 }
456494
457495 if (shouldDump (Explicit, " .debug_aranges" , DIDT_ID_DebugAranges,
@@ -815,27 +853,24 @@ const DWARFDebugFrame *DWARFContext::getEHFrame() {
815853 return DebugFrame.get ();
816854}
817855
818- const DWARFDebugMacro *DWARFContext::getDebugMacinfoDWO () {
819- if (MacinfoDWO)
820- return MacinfoDWO.get ();
821-
822- DataExtractor MacinfoDWOData (DObj->getMacinfoDWOSection (), isLittleEndian (),
823- 0 );
824- MacinfoDWO.reset (new DWARFDebugMacro ());
825- MacinfoDWO->parse (MacinfoDWOData);
826- return MacinfoDWO.get ();
856+ const DWARFDebugMacro *DWARFContext::getDebugMacro () {
857+ if (!Macro)
858+ Macro = parseMacroOrMacinfo (MacroSection);
859+ return Macro.get ();
827860}
828861
829862const DWARFDebugMacro *DWARFContext::getDebugMacinfo () {
830- if (Macinfo)
831- return Macinfo.get ();
832-
833- DataExtractor MacinfoData (DObj->getMacinfoSection (), isLittleEndian (), 0 );
834- Macinfo.reset (new DWARFDebugMacro ());
835- Macinfo->parse (MacinfoData);
863+ if (!Macinfo)
864+ Macinfo = parseMacroOrMacinfo (MacinfoSection);
836865 return Macinfo.get ();
837866}
838867
868+ const DWARFDebugMacro *DWARFContext::getDebugMacinfoDWO () {
869+ if (!MacinfoDWO)
870+ MacinfoDWO = parseMacroOrMacinfo (MacinfoDwoSection);
871+ return MacinfoDWO.get ();
872+ }
873+
839874template <typename T>
840875static T &getAccelTable (std::unique_ptr<T> &Cache, const DWARFObject &Obj,
841876 const DWARFSection &Section, StringRef StringSection,
@@ -1476,6 +1511,7 @@ class DWARFObjInMemory final : public DWARFObject {
14761511 DWARFSectionMap PubtypesSection;
14771512 DWARFSectionMap GnuPubnamesSection;
14781513 DWARFSectionMap GnuPubtypesSection;
1514+ DWARFSectionMap MacroSection;
14791515
14801516 DWARFSectionMap *mapNameToDWARFSection (StringRef Name) {
14811517 return StringSwitch<DWARFSectionMap *>(Name)
@@ -1503,6 +1539,7 @@ class DWARFObjInMemory final : public DWARFObject {
15031539 .Case (" apple_namespaces" , &AppleNamespacesSection)
15041540 .Case (" apple_namespac" , &AppleNamespacesSection)
15051541 .Case (" apple_objc" , &AppleObjCSection)
1542+ .Case (" debug_macro" , &MacroSection)
15061543 .Default (nullptr );
15071544 }
15081545
@@ -1847,6 +1884,7 @@ class DWARFObjInMemory final : public DWARFObject {
18471884 const DWARFSection &getRnglistsSection () const override {
18481885 return RnglistsSection;
18491886 }
1887+ const DWARFSection &getMacroSection () const override { return MacroSection; }
18501888 StringRef getMacinfoSection () const override { return MacinfoSection; }
18511889 StringRef getMacinfoDWOSection () const override { return MacinfoDWOSection; }
18521890 const DWARFSection &getPubnamesSection () const override { return PubnamesSection; }
0 commit comments