@@ -620,10 +620,9 @@ void DWARFRewriter::updateDebugInfo() {
620
620
uint32_t CUIndex = 0 ;
621
621
std::mutex AccessMutex;
622
622
// Needs to be invoked in the same order as CUs are processed.
623
- llvm::DenseMap< uint64_t , uint64_t > LocListWritersIndexByCU;
624
- auto createRangeLocListAddressWriters = [&](DWARFUnit &CU) {
623
+ auto createRangeLocListAddressWriters =
624
+ [&](DWARFUnit &CU) -> DebugLocWriter * {
625
625
std::lock_guard<std::mutex> Lock (AccessMutex);
626
-
627
626
const uint16_t DwarfVersion = CU.getVersion ();
628
627
if (DwarfVersion >= 5 ) {
629
628
auto AddrW = std::make_unique<DebugAddrWriterDwarf5>(
@@ -642,6 +641,7 @@ void DWARFRewriter::updateDebugInfo() {
642
641
RangeListsWritersByCU[*DWOId] = std::move (DWORangeListsSectionWriter);
643
642
}
644
643
AddressWritersByCU[CU.getOffset ()] = std::move (AddrW);
644
+
645
645
} else {
646
646
auto AddrW =
647
647
std::make_unique<DebugAddrWriter>(&BC, CU.getAddressByteSize ());
@@ -657,7 +657,7 @@ void DWARFRewriter::updateDebugInfo() {
657
657
std::move (LegacyRangesSectionWriterByCU);
658
658
}
659
659
}
660
- LocListWritersIndexByCU[CU. getOffset ()] = CUIndex++;
660
+ return LocListWritersByCU[ CUIndex++]. get () ;
661
661
};
662
662
663
663
DWARF5AcceleratorTable DebugNamesTable (opts::CreateDebugNames, BC,
@@ -666,68 +666,74 @@ void DWARFRewriter::updateDebugInfo() {
666
666
DWPState State;
667
667
if (opts::WriteDWP)
668
668
initDWPState (State);
669
- auto processSplitCU = [&](DWARFUnit &Unit, DWARFUnit &SplitCU,
670
- DIEBuilder &DIEBlder,
671
- DebugRangesSectionWriter &TempRangesSectionWriter,
672
- DebugAddrWriter &AddressWriter) {
673
- DIEBuilder DWODIEBuilder (BC, &(SplitCU).getContext (), DebugNamesTable,
674
- &Unit);
675
- DWODIEBuilder.buildDWOUnit (SplitCU);
676
- std::string DWOName = " " ;
677
- std::optional<std::string> DwarfOutputPath =
678
- opts::DwarfOutputPath.empty ()
679
- ? std::nullopt
680
- : std::optional<std::string>(opts::DwarfOutputPath.c_str ());
681
- {
682
- std::lock_guard<std::mutex> Lock (AccessMutex);
683
- DWOName = DIEBlder.updateDWONameCompDir (
684
- *StrOffstsWriter, *StrWriter, Unit, DwarfOutputPath, std::nullopt);
685
- }
686
- DebugStrOffsetsWriter DWOStrOffstsWriter (BC);
687
- DebugStrWriter DWOStrWriter ((SplitCU).getContext (), true );
688
- DWODIEBuilder.updateDWONameCompDirForTypes (
689
- DWOStrOffstsWriter, DWOStrWriter, SplitCU, DwarfOutputPath, DWOName);
690
- DebugLoclistWriter DebugLocDWoWriter (Unit, Unit.getVersion (), true ,
691
- AddressWriter);
692
-
693
- updateUnitDebugInfo (SplitCU, DWODIEBuilder, DebugLocDWoWriter,
694
- TempRangesSectionWriter, AddressWriter);
695
- DebugLocDWoWriter.finalize (DWODIEBuilder,
696
- *DWODIEBuilder.getUnitDIEbyUnit (SplitCU));
697
- if (Unit.getVersion () >= 5 )
698
- TempRangesSectionWriter.finalizeSection ();
699
-
700
- emitDWOBuilder (DWOName, DWODIEBuilder, *this , SplitCU, Unit, State,
701
- DebugLocDWoWriter, DWOStrOffstsWriter, DWOStrWriter,
702
- GDBIndexSection);
703
- };
704
- auto processMainBinaryCU = [&](DWARFUnit &Unit, DIEBuilder &DIEBlder) {
705
- DebugAddrWriter &AddressWriter =
706
- *AddressWritersByCU[Unit.getOffset ()].get ();
707
- DebugRangesSectionWriter &RangesSectionWriter =
708
- Unit.getVersion () >= 5 ? *RangeListsSectionWriter.get ()
709
- : *LegacyRangesSectionWriter.get ();
710
- DebugLocWriter &DebugLocWriter =
711
- *LocListWritersByCU[LocListWritersIndexByCU[Unit.getOffset ()]].get ();
712
- std::optional<uint64_t > RangesBase;
669
+ auto processUnitDIE = [&](DWARFUnit *Unit, DIEBuilder *DIEBlder) {
670
+ // Check if the unit is a skeleton and we need special updates for it and
671
+ // its matching split/DWO CU.
713
672
std::optional<DWARFUnit *> SplitCU;
714
- std::optional<uint64_t > DWOId = Unit.getDWOId ();
673
+ std::optional<uint64_t > RangesBase;
674
+ std::optional<uint64_t > DWOId = Unit->getDWOId ();
715
675
if (DWOId)
716
676
SplitCU = BC.getDWOCU (*DWOId);
717
- if (Unit.getVersion () >= 5 ) {
718
- RangesBase = RangesSectionWriter.getSectionOffset () +
677
+ DebugLocWriter *DebugLocWriter = createRangeLocListAddressWriters (*Unit);
678
+ DebugRangesSectionWriter *RangesSectionWriter =
679
+ Unit->getVersion () >= 5 ? RangeListsSectionWriter.get ()
680
+ : LegacyRangesSectionWriter.get ();
681
+ DebugAddrWriter *AddressWriter =
682
+ AddressWritersByCU[Unit->getOffset ()].get ();
683
+ // Skipping CUs that failed to load.
684
+ if (SplitCU) {
685
+ DIEBuilder DWODIEBuilder (BC, &(*SplitCU)->getContext (), DebugNamesTable,
686
+ Unit);
687
+ DWODIEBuilder.buildDWOUnit (**SplitCU);
688
+ std::string DWOName = " " ;
689
+ std::optional<std::string> DwarfOutputPath =
690
+ opts::DwarfOutputPath.empty ()
691
+ ? std::nullopt
692
+ : std::optional<std::string>(opts::DwarfOutputPath.c_str ());
693
+ {
694
+ std::lock_guard<std::mutex> Lock (AccessMutex);
695
+ DWOName = DIEBlder->updateDWONameCompDir (
696
+ *StrOffstsWriter, *StrWriter, *Unit, DwarfOutputPath, std::nullopt);
697
+ }
698
+ DebugStrOffsetsWriter DWOStrOffstsWriter (BC);
699
+ DebugStrWriter DWOStrWriter ((*SplitCU)->getContext (), true );
700
+ DWODIEBuilder.updateDWONameCompDirForTypes (DWOStrOffstsWriter,
701
+ DWOStrWriter, **SplitCU,
702
+ DwarfOutputPath, DWOName);
703
+ DebugLoclistWriter DebugLocDWoWriter (*Unit, Unit->getVersion (), true ,
704
+ *AddressWriter);
705
+ DebugRangesSectionWriter *TempRangesSectionWriter = RangesSectionWriter;
706
+ if (Unit->getVersion () >= 5 ) {
707
+ TempRangesSectionWriter = RangeListsWritersByCU[*DWOId].get ();
708
+ } else {
709
+ TempRangesSectionWriter = LegacyRangesWritersByCU[*DWOId].get ();
710
+ RangesBase = RangesSectionWriter->getSectionOffset ();
711
+ }
712
+
713
+ updateUnitDebugInfo (*(*SplitCU), DWODIEBuilder, DebugLocDWoWriter,
714
+ *TempRangesSectionWriter, *AddressWriter);
715
+ DebugLocDWoWriter.finalize (DWODIEBuilder,
716
+ *DWODIEBuilder.getUnitDIEbyUnit (**SplitCU));
717
+ if (Unit->getVersion () >= 5 )
718
+ TempRangesSectionWriter->finalizeSection ();
719
+
720
+ emitDWOBuilder (DWOName, DWODIEBuilder, *this , **SplitCU, *Unit, State,
721
+ DebugLocDWoWriter, DWOStrOffstsWriter, DWOStrWriter,
722
+ GDBIndexSection);
723
+ }
724
+
725
+ if (Unit->getVersion () >= 5 ) {
726
+ RangesBase = RangesSectionWriter->getSectionOffset () +
719
727
getDWARF5RngListLocListHeaderSize ();
720
- RangesSectionWriter.initSection (Unit);
721
- StrOffstsWriter->finalizeSection (Unit, DIEBlder);
722
- } else if (SplitCU) {
723
- RangesBase = LegacyRangesSectionWriter.get ()->getSectionOffset ();
728
+ RangesSectionWriter->initSection (*Unit);
729
+ StrOffstsWriter->finalizeSection (*Unit, *DIEBlder);
724
730
}
725
731
726
- updateUnitDebugInfo (Unit, DIEBlder, DebugLocWriter, RangesSectionWriter,
727
- AddressWriter, RangesBase);
728
- DebugLocWriter. finalize (DIEBlder, *DIEBlder. getUnitDIEbyUnit (Unit));
729
- if (Unit. getVersion () >= 5 )
730
- RangesSectionWriter. finalizeSection ();
732
+ updateUnitDebugInfo (* Unit, * DIEBlder, * DebugLocWriter, * RangesSectionWriter,
733
+ * AddressWriter, RangesBase);
734
+ DebugLocWriter-> finalize (* DIEBlder, *DIEBlder-> getUnitDIEbyUnit (* Unit));
735
+ if (Unit-> getVersion () >= 5 )
736
+ RangesSectionWriter-> finalizeSection ();
731
737
};
732
738
733
739
DIEBuilder DIEBlder (BC, BC.DwCtx .get (), DebugNamesTable);
@@ -745,24 +751,8 @@ void DWARFRewriter::updateDebugInfo() {
745
751
CUPartitionVector PartVec = partitionCUs (*BC.DwCtx );
746
752
for (std::vector<DWARFUnit *> &Vec : PartVec) {
747
753
DIEBlder.buildCompileUnits (Vec);
748
- for (DWARFUnit *CU : DIEBlder.getProcessedCUs ()) {
749
- createRangeLocListAddressWriters (*CU);
750
- std::optional<DWARFUnit *> SplitCU;
751
- std::optional<uint64_t > DWOId = CU->getDWOId ();
752
- if (DWOId)
753
- SplitCU = BC.getDWOCU (*DWOId);
754
- if (!SplitCU)
755
- continue ;
756
- DebugAddrWriter &AddressWriter =
757
- *AddressWritersByCU[CU->getOffset ()].get ();
758
- DebugRangesSectionWriter *TempRangesSectionWriter =
759
- CU->getVersion () >= 5 ? RangeListsWritersByCU[*DWOId].get ()
760
- : LegacyRangesWritersByCU[*DWOId].get ();
761
- processSplitCU (*CU, **SplitCU, DIEBlder, *TempRangesSectionWriter,
762
- AddressWriter);
763
- }
764
754
for (DWARFUnit *CU : DIEBlder.getProcessedCUs ())
765
- processMainBinaryCU (* CU, DIEBlder);
755
+ processUnitDIE ( CU, & DIEBlder);
766
756
finalizeCompileUnits (DIEBlder, *Streamer, OffsetMap,
767
757
DIEBlder.getProcessedCUs (), *FinalAddrWriter);
768
758
}
0 commit comments