@@ -632,120 +632,124 @@ void DWARFRewriter::updateDebugInfo() {
632
632
std::mutex AccessMutex;
633
633
// Needs to be invoked in the same order as CUs are processed.
634
634
auto createRangeLocListAddressWriters =
635
- [&](DWARFUnit &CU) -> DebugLocWriter * {
636
- std::lock_guard<std::mutex> Lock (AccessMutex);
637
- const uint16_t DwarfVersion = CU.getVersion ();
638
- if (DwarfVersion >= 5 ) {
639
- auto AddrW = std::make_unique<DebugAddrWriterDwarf5>(
640
- &BC, CU.getAddressByteSize (), CU.getAddrOffsetSectionBase ());
641
- RangeListsSectionWriter->setAddressWriter (AddrW.get ());
642
- LocListWritersByCU[CUIndex] =
643
- std::make_unique<DebugLoclistWriter>(CU, DwarfVersion, false , *AddrW);
644
-
645
- if (std::optional<uint64_t > DWOId = CU.getDWOId ()) {
646
- assert (RangeListsWritersByCU.count (*DWOId) == 0 &&
647
- " RangeLists writer for DWO unit already exists." );
648
- auto DWORangeListsSectionWriter =
649
- std::make_unique<DebugRangeListsSectionWriter>();
650
- DWORangeListsSectionWriter->initSection (CU);
651
- DWORangeListsSectionWriter->setAddressWriter (AddrW.get ());
652
- RangeListsWritersByCU[*DWOId] = std::move (DWORangeListsSectionWriter);
653
- }
654
- AddressWritersByCU[CU.getOffset ()] = std::move (AddrW);
635
+ [&](DWARFUnit &CU,
636
+ llvm::DenseMap<uint64_t , uint64_t > &LocListWritersIndexByCU) {
637
+ std::lock_guard<std::mutex> Lock (AccessMutex);
655
638
656
- } else {
657
- auto AddrW =
658
- std::make_unique<DebugAddrWriter>(&BC, CU.getAddressByteSize ());
659
- AddressWritersByCU[CU.getOffset ()] = std::move (AddrW);
660
- LocListWritersByCU[CUIndex] = std::make_unique<DebugLocWriter>();
661
- if (std::optional<uint64_t > DWOId = CU.getDWOId ()) {
662
- assert (LegacyRangesWritersByCU.count (*DWOId) == 0 &&
663
- " LegacyRangeLists writer for DWO unit already exists." );
664
- auto LegacyRangesSectionWriterByCU =
665
- std::make_unique<DebugRangesSectionWriter>();
666
- LegacyRangesSectionWriterByCU->initSection (CU);
667
- LegacyRangesWritersByCU[*DWOId] =
668
- std::move (LegacyRangesSectionWriterByCU);
669
- }
670
- }
671
- return LocListWritersByCU[CUIndex++].get ();
672
- };
639
+ const uint16_t DwarfVersion = CU.getVersion ();
640
+ if (DwarfVersion >= 5 ) {
641
+ auto AddrW = std::make_unique<DebugAddrWriterDwarf5>(
642
+ &BC, CU.getAddressByteSize (), CU.getAddrOffsetSectionBase ());
643
+ RangeListsSectionWriter->setAddressWriter (AddrW.get ());
644
+ LocListWritersByCU[CUIndex] = std::make_unique<DebugLoclistWriter>(
645
+ CU, DwarfVersion, false , *AddrW);
646
+
647
+ if (std::optional<uint64_t > DWOId = CU.getDWOId ()) {
648
+ assert (RangeListsWritersByCU.count (*DWOId) == 0 &&
649
+ " RangeLists writer for DWO unit already exists." );
650
+ auto DWORangeListsSectionWriter =
651
+ std::make_unique<DebugRangeListsSectionWriter>();
652
+ DWORangeListsSectionWriter->initSection (CU);
653
+ DWORangeListsSectionWriter->setAddressWriter (AddrW.get ());
654
+ RangeListsWritersByCU[*DWOId] =
655
+ std::move (DWORangeListsSectionWriter);
656
+ }
657
+ AddressWritersByCU[CU.getOffset ()] = std::move (AddrW);
658
+
659
+ } else {
660
+ auto AddrW =
661
+ std::make_unique<DebugAddrWriter>(&BC, CU.getAddressByteSize ());
662
+ AddressWritersByCU[CU.getOffset ()] = std::move (AddrW);
663
+ LocListWritersByCU[CUIndex] = std::make_unique<DebugLocWriter>();
664
+ if (std::optional<uint64_t > DWOId = CU.getDWOId ()) {
665
+ assert (LegacyRangesWritersByCU.count (*DWOId) == 0 &&
666
+ " LegacyRangeLists writer for DWO unit already exists." );
667
+ auto LegacyRangesSectionWriterByCU =
668
+ std::make_unique<DebugRangesSectionWriter>();
669
+ LegacyRangesSectionWriterByCU->initSection (CU);
670
+ LegacyRangesWritersByCU[*DWOId] =
671
+ std::move (LegacyRangesSectionWriterByCU);
672
+ }
673
+ }
674
+ LocListWritersIndexByCU[CU.getOffset ()] = CUIndex++;
675
+ };
673
676
674
677
DWARF5AcceleratorTable DebugNamesTable (opts::CreateDebugNames, BC,
675
678
*StrWriter);
676
679
GDBIndex GDBIndexSection (BC);
677
680
DWPState State;
678
681
if (opts::WriteDWP)
679
682
initDWPState (State);
680
- auto processUnitDIE = [&](DWARFUnit *Unit, DIEBuilder *DIEBlder) {
681
- // Check if the unit is a skeleton and we need special updates for it and
682
- // its matching split/DWO CU.
683
+ auto processSplitCU = [&](DWARFUnit *Unit, DIEBuilder *DIEBlder,
684
+ std::optional<uint64_t > &RangesBase) {
683
685
std::optional<DWARFUnit *> SplitCU;
684
- std::optional<uint64_t > RangesBase;
685
686
std::optional<uint64_t > DWOId = Unit->getDWOId ();
686
687
if (DWOId)
687
688
SplitCU = BC.getDWOCU (*DWOId);
688
- DebugLocWriter *DebugLocWriter = createRangeLocListAddressWriters (*Unit);
689
- DebugRangesSectionWriter *RangesSectionWriter =
690
- Unit->getVersion () >= 5 ? RangeListsSectionWriter.get ()
691
- : LegacyRangesSectionWriter.get ();
692
- DebugAddrWriter *AddressWriter =
693
- AddressWritersByCU[Unit->getOffset ()].get ();
694
- // Skipping CUs that failed to load.
695
- if (SplitCU) {
696
- DIEBuilder DWODIEBuilder (BC, &(*SplitCU)->getContext (), DebugNamesTable,
697
- Unit);
698
- DWODIEBuilder.buildDWOUnit (**SplitCU);
699
- std::string DWOName = " " ;
700
- std::optional<std::string> DwarfOutputPath =
701
- opts::DwarfOutputPath.empty ()
702
- ? std::nullopt
703
- : std::optional<std::string>(opts::DwarfOutputPath.c_str ());
704
- {
705
- std::lock_guard<std::mutex> Lock (AccessMutex);
706
- DWOName = DIEBlder->updateDWONameCompDir (
707
- *StrOffstsWriter, *StrWriter, *Unit, DwarfOutputPath, std::nullopt);
708
- }
709
- DebugStrOffsetsWriter DWOStrOffstsWriter (BC);
710
- DebugStrWriter DWOStrWriter ((*SplitCU)->getContext (), true );
711
- DWODIEBuilder.updateDWONameCompDirForTypes (DWOStrOffstsWriter,
712
- DWOStrWriter, **SplitCU,
713
- DwarfOutputPath, DWOName);
714
- DebugLoclistWriter DebugLocDWoWriter (*Unit, Unit->getVersion (), true ,
715
- *AddressWriter);
716
- DebugRangesSectionWriter *TempRangesSectionWriter = RangesSectionWriter;
717
- if (Unit->getVersion () >= 5 ) {
718
- TempRangesSectionWriter = RangeListsWritersByCU[*DWOId].get ();
719
- } else {
720
- TempRangesSectionWriter = LegacyRangesWritersByCU[*DWOId].get ();
721
- RangesBase = RangesSectionWriter->getSectionOffset ();
722
- setDwoRangesBase (*DWOId, *RangesBase);
723
- }
724
-
725
- updateUnitDebugInfo (*(*SplitCU), DWODIEBuilder, DebugLocDWoWriter,
726
- *TempRangesSectionWriter, *AddressWriter);
727
- DebugLocDWoWriter.finalize (DWODIEBuilder,
728
- *DWODIEBuilder.getUnitDIEbyUnit (**SplitCU));
729
- if (Unit->getVersion () >= 5 )
730
- TempRangesSectionWriter->finalizeSection ();
731
-
732
- emitDWOBuilder (DWOName, DWODIEBuilder, *this , **SplitCU, *Unit, State,
733
- DebugLocDWoWriter, DWOStrOffstsWriter, DWOStrWriter,
734
- GDBIndexSection);
689
+ if (!SplitCU)
690
+ return ;
691
+ DebugAddrWriter &AddressWriter =
692
+ *AddressWritersByCU[Unit->getOffset ()].get ();
693
+ DIEBuilder DWODIEBuilder (BC, &(*SplitCU)->getContext (), DebugNamesTable,
694
+ Unit);
695
+ DWODIEBuilder.buildDWOUnit (**SplitCU);
696
+ std::string DWOName = " " ;
697
+ std::optional<std::string> DwarfOutputPath =
698
+ opts::DwarfOutputPath.empty ()
699
+ ? std::nullopt
700
+ : std::optional<std::string>(opts::DwarfOutputPath.c_str ());
701
+ {
702
+ DWOName = DIEBlder->updateDWONameCompDir (
703
+ *StrOffstsWriter, *StrWriter, *Unit, DwarfOutputPath, std::nullopt);
735
704
}
705
+ DebugStrOffsetsWriter DWOStrOffstsWriter (BC);
706
+ DebugStrWriter DWOStrWriter ((*SplitCU)->getContext (), true );
707
+ DWODIEBuilder.updateDWONameCompDirForTypes (
708
+ DWOStrOffstsWriter, DWOStrWriter, **SplitCU, DwarfOutputPath, DWOName);
709
+ DebugLoclistWriter DebugLocDWoWriter (*Unit, Unit->getVersion (), true ,
710
+ AddressWriter);
711
+ DebugRangesSectionWriter *TempRangesSectionWriter;
712
+ if (Unit->getVersion () >= 5 ) {
713
+ TempRangesSectionWriter = RangeListsWritersByCU[*DWOId].get ();
714
+ } else {
715
+ TempRangesSectionWriter = LegacyRangesWritersByCU[*DWOId].get ();
716
+ RangesBase = Unit->getVersion () >= 5
717
+ ? RangeListsSectionWriter.get ()->getSectionOffset ()
718
+ : LegacyRangesSectionWriter.get ()->getSectionOffset ();
719
+ setDwoRangesBase (*DWOId, *RangesBase);
720
+ }
721
+
722
+ updateUnitDebugInfo (*(*SplitCU), DWODIEBuilder, DebugLocDWoWriter,
723
+ *TempRangesSectionWriter, AddressWriter);
724
+ DebugLocDWoWriter.finalize (DWODIEBuilder,
725
+ *DWODIEBuilder.getUnitDIEbyUnit (**SplitCU));
726
+ if (Unit->getVersion () >= 5 )
727
+ TempRangesSectionWriter->finalizeSection ();
736
728
729
+ emitDWOBuilder (DWOName, DWODIEBuilder, *this , **SplitCU, *Unit, State,
730
+ DebugLocDWoWriter, DWOStrOffstsWriter, DWOStrWriter,
731
+ GDBIndexSection);
732
+ };
733
+ auto processMainBinaryCU = [&](DWARFUnit *Unit, DIEBuilder *DIEBlder,
734
+ DebugLocWriter *DebugLocWriter,
735
+ std::optional<uint64_t > &RangesBase) {
736
+ DebugAddrWriter &AddressWriter =
737
+ *AddressWritersByCU[Unit->getOffset ()].get ();
738
+ DebugRangesSectionWriter &RangesSectionWriter =
739
+ Unit->getVersion () >= 5 ? *RangeListsSectionWriter.get ()
740
+ : *LegacyRangesSectionWriter.get ();
737
741
if (Unit->getVersion () >= 5 ) {
738
- RangesBase = RangesSectionWriter-> getSectionOffset () +
742
+ RangesBase = RangesSectionWriter. getSectionOffset () +
739
743
getDWARF5RngListLocListHeaderSize ();
740
- RangesSectionWriter-> initSection (*Unit);
744
+ RangesSectionWriter. initSection (*Unit);
741
745
StrOffstsWriter->finalizeSection (*Unit, *DIEBlder);
742
746
}
743
747
744
- updateUnitDebugInfo (*Unit, *DIEBlder, *DebugLocWriter, * RangesSectionWriter,
745
- * AddressWriter, RangesBase);
748
+ updateUnitDebugInfo (*Unit, *DIEBlder, *DebugLocWriter, RangesSectionWriter,
749
+ AddressWriter, RangesBase);
746
750
DebugLocWriter->finalize (*DIEBlder, *DIEBlder->getUnitDIEbyUnit (*Unit));
747
751
if (Unit->getVersion () >= 5 )
748
- RangesSectionWriter-> finalizeSection ();
752
+ RangesSectionWriter. finalizeSection ();
749
753
};
750
754
751
755
DIEBuilder DIEBlder (BC, BC.DwCtx .get (), DebugNamesTable);
@@ -768,17 +772,35 @@ void DWARFRewriter::updateDebugInfo() {
768
772
CUPartitionVector PartVec = partitionCUs (*BC.DwCtx );
769
773
for (std::vector<DWARFUnit *> &Vec : PartVec) {
770
774
DIEBlder.buildCompileUnits (Vec);
771
- for (DWARFUnit *CU : DIEBlder.getProcessedCUs ())
772
- processUnitDIE (CU, &DIEBlder);
775
+ llvm::SmallVector<DWARFUnit *> CompileUnits (
776
+ std::begin (DIEBlder.getProcessedCUs ()),
777
+ std::end (DIEBlder.getProcessedCUs ()));
778
+ llvm::DenseMap<uint64_t , uint64_t > RangesBaseByCU;
779
+ llvm::DenseMap<uint64_t , uint64_t > LocListWritersIndexByCU;
780
+ for (DWARFUnit *CU : CompileUnits) {
781
+ createRangeLocListAddressWriters (*CU, LocListWritersIndexByCU);
782
+ std::optional<uint64_t > RangesBase;
783
+ processSplitCU (CU, &DIEBlder, RangesBase);
784
+ if (RangesBase)
785
+ RangesBaseByCU[CU->getOffset ()] = *RangesBase;
786
+ }
787
+ for (DWARFUnit *CU : CompileUnits) {
788
+ std::optional<uint64_t > RangesBase;
789
+ if (RangesBaseByCU.count (CU->getOffset ()))
790
+ RangesBase = RangesBaseByCU[CU->getOffset ()];
791
+ DebugLocWriter *DebugLocWriter =
792
+ LocListWritersByCU[LocListWritersIndexByCU[CU->getOffset ()]].get ();
793
+ processMainBinaryCU (CU, &DIEBlder, DebugLocWriter, RangesBase);
794
+ }
773
795
finalizeCompileUnits (DIEBlder, *Streamer, OffsetMap,
774
- DIEBlder.getProcessedCUs (), *FinalAddrWriter);
796
+ DIEBlder.getProcessedCUs (), *FinalAddrWriter);
775
797
}
776
798
} else {
777
799
// Update unit debug info in parallel
778
800
ThreadPoolInterface &ThreadPool = ParallelUtilities::getThreadPool ();
779
801
for (std::unique_ptr<DWARFUnit> &CU : BC.DwCtx ->compile_units ())
780
- ThreadPool.async (processUnitDIE, CU.get (), &DIEBlder);
781
- ThreadPool.wait ();
802
+ // ThreadPool.async(processUnitDIE, CU.get(), &DIEBlder);
803
+ ThreadPool.wait ();
782
804
}
783
805
784
806
DebugNamesTable.emitAccelTable ();
0 commit comments