@@ -292,6 +292,36 @@ static void dumpRnglistsSection(
292
292
}
293
293
}
294
294
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
+
295
325
static void dumpLoclistsSection (raw_ostream &OS, DIDumpOptions DumpOpts,
296
326
DWARFDataExtractor Data,
297
327
const MCRegisterInfo *MRI,
@@ -444,14 +474,22 @@ void DWARFContext::dump(
444
474
DObj->getEHFrameSection ().Data ))
445
475
getEHFrame ()->dump (OS, getRegisterInfo (), *Off);
446
476
477
+ if (shouldDump (Explicit, " .debug_macro" , DIDT_ID_DebugMacro,
478
+ DObj->getMacroSection ().Data )) {
479
+ if (auto Macro = getDebugMacro ())
480
+ Macro->dump (OS);
481
+ }
482
+
447
483
if (shouldDump (Explicit, " .debug_macinfo" , DIDT_ID_DebugMacro,
448
484
DObj->getMacinfoSection ())) {
449
- getDebugMacinfo ()->dump (OS);
485
+ if (auto Macinfo = getDebugMacinfo ())
486
+ Macinfo->dump (OS);
450
487
}
451
488
452
489
if (shouldDump (Explicit, " .debug_macinfo.dwo" , DIDT_ID_DebugMacro,
453
490
DObj->getMacinfoDWOSection ())) {
454
- getDebugMacinfoDWO ()->dump (OS);
491
+ if (auto MacinfoDWO = getDebugMacinfoDWO ())
492
+ MacinfoDWO->dump (OS);
455
493
}
456
494
457
495
if (shouldDump (Explicit, " .debug_aranges" , DIDT_ID_DebugAranges,
@@ -815,27 +853,24 @@ const DWARFDebugFrame *DWARFContext::getEHFrame() {
815
853
return DebugFrame.get ();
816
854
}
817
855
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 ();
827
860
}
828
861
829
862
const 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);
836
865
return Macinfo.get ();
837
866
}
838
867
868
+ const DWARFDebugMacro *DWARFContext::getDebugMacinfoDWO () {
869
+ if (!MacinfoDWO)
870
+ MacinfoDWO = parseMacroOrMacinfo (MacinfoDwoSection);
871
+ return MacinfoDWO.get ();
872
+ }
873
+
839
874
template <typename T>
840
875
static T &getAccelTable (std::unique_ptr<T> &Cache, const DWARFObject &Obj,
841
876
const DWARFSection &Section, StringRef StringSection,
@@ -1476,6 +1511,7 @@ class DWARFObjInMemory final : public DWARFObject {
1476
1511
DWARFSectionMap PubtypesSection;
1477
1512
DWARFSectionMap GnuPubnamesSection;
1478
1513
DWARFSectionMap GnuPubtypesSection;
1514
+ DWARFSectionMap MacroSection;
1479
1515
1480
1516
DWARFSectionMap *mapNameToDWARFSection (StringRef Name) {
1481
1517
return StringSwitch<DWARFSectionMap *>(Name)
@@ -1503,6 +1539,7 @@ class DWARFObjInMemory final : public DWARFObject {
1503
1539
.Case (" apple_namespaces" , &AppleNamespacesSection)
1504
1540
.Case (" apple_namespac" , &AppleNamespacesSection)
1505
1541
.Case (" apple_objc" , &AppleObjCSection)
1542
+ .Case (" debug_macro" , &MacroSection)
1506
1543
.Default (nullptr );
1507
1544
}
1508
1545
@@ -1847,6 +1884,7 @@ class DWARFObjInMemory final : public DWARFObject {
1847
1884
const DWARFSection &getRnglistsSection () const override {
1848
1885
return RnglistsSection;
1849
1886
}
1887
+ const DWARFSection &getMacroSection () const override { return MacroSection; }
1850
1888
StringRef getMacinfoSection () const override { return MacinfoSection; }
1851
1889
StringRef getMacinfoDWOSection () const override { return MacinfoDWOSection; }
1852
1890
const DWARFSection &getPubnamesSection () const override { return PubnamesSection; }
0 commit comments