@@ -461,17 +461,11 @@ getUnitForOffset(DIEBuilder &Builder, DWARFContext &DWCtx,
461
461
return nullptr ;
462
462
}
463
463
464
- uint32_t
465
- DIEBuilder::finalizeDIEs (DWARFUnit &CU, DIE &Die,
466
- std::optional<BOLTDWARF5AccelTableData *> Parent,
467
- uint32_t NumberParentsInChain, uint32_t &CurOffset) {
464
+ uint32_t DIEBuilder::finalizeDIEs (DWARFUnit &CU, DIE &Die,
465
+ uint32_t &CurOffset) {
468
466
getState ().DWARFDieAddressesParsed .erase (Die.getOffset ());
469
467
uint32_t CurSize = 0 ;
470
468
Die.setOffset (CurOffset);
471
- std::optional<BOLTDWARF5AccelTableData *> NameEntry =
472
- DebugNamesTable.addAccelTableEntry (
473
- CU, Die, SkeletonCU ? SkeletonCU->getDWOId () : std::nullopt,
474
- NumberParentsInChain, Parent);
475
469
// It is possible that an indexed debugging information entry has a parent
476
470
// that is not indexed (for example, if its parent does not have a name
477
471
// attribute). In such a case, a parent attribute may point to a nameless
@@ -485,18 +479,13 @@ DIEBuilder::finalizeDIEs(DWARFUnit &CU, DIE &Die,
485
479
// If Parent is nullopt and NumberParentsInChain is not zero, then forward
486
480
// declaration was encountered in this DF traversal. Propagating nullopt for
487
481
// Parent to children.
488
- if (!Parent && NumberParentsInChain)
489
- NameEntry = std::nullopt;
490
- if (NameEntry)
491
- ++NumberParentsInChain;
492
482
for (DIEValue &Val : Die.values ())
493
483
CurSize += Val.sizeOf (CU.getFormParams ());
494
484
CurSize += getULEB128Size (Die.getAbbrevNumber ());
495
485
CurOffset += CurSize;
496
486
497
487
for (DIE &Child : Die.children ()) {
498
- uint32_t ChildSize =
499
- finalizeDIEs (CU, Child, NameEntry, NumberParentsInChain, CurOffset);
488
+ uint32_t ChildSize = finalizeDIEs (CU, Child, CurOffset);
500
489
CurSize += ChildSize;
501
490
}
502
491
// for children end mark.
@@ -514,10 +503,9 @@ void DIEBuilder::finish() {
514
503
DIE *UnitDIE = getUnitDIEbyUnit (CU);
515
504
uint32_t HeaderSize = CU.getHeaderSize ();
516
505
uint32_t CurOffset = HeaderSize;
517
- DebugNamesTable.setCurrentUnit (CU, UnitStartOffset);
518
506
std::vector<std::optional<BOLTDWARF5AccelTableData *>> Parents;
519
507
Parents.push_back (std::nullopt);
520
- finalizeDIEs (CU, *UnitDIE, std::nullopt, 0 , CurOffset);
508
+ finalizeDIEs (CU, *UnitDIE, CurOffset);
521
509
522
510
DWARFUnitInfo &CurUnitInfo = getUnitInfoByDwarfUnit (CU);
523
511
CurUnitInfo.UnitOffset = UnitStartOffset;
@@ -548,6 +536,48 @@ void DIEBuilder::finish() {
548
536
dbgs () << Twine::utohexstr (Address) << " \n " ;
549
537
}
550
538
}
539
+ }
540
+
541
+ void DIEBuilder::populateDebugNamesTable (
542
+ DWARFUnit &CU, const DIE &Die,
543
+ std::optional<BOLTDWARF5AccelTableData *> Parent,
544
+ uint32_t NumberParentsInChain) {
545
+ std::optional<BOLTDWARF5AccelTableData *> NameEntry =
546
+ DebugNamesTable.addAccelTableEntry (
547
+ CU, Die, SkeletonCU ? SkeletonCU->getDWOId () : std::nullopt,
548
+ NumberParentsInChain, Parent);
549
+ if (!Parent && NumberParentsInChain)
550
+ NameEntry = std::nullopt;
551
+ if (NameEntry)
552
+ ++NumberParentsInChain;
553
+
554
+ for (const DIE &Child : Die.children ())
555
+ populateDebugNamesTable (CU, Child, NameEntry, NumberParentsInChain);
556
+ }
557
+
558
+ void DIEBuilder::updateDebugNamesTable () {
559
+ auto finalizeDebugNamesTableForCU = [&](DWARFUnit &CU,
560
+ uint64_t &UnitStartOffset) -> void {
561
+ DIE *UnitDIE = getUnitDIEbyUnit (CU);
562
+ DebugNamesTable.setCurrentUnit (CU, UnitStartOffset);
563
+ populateDebugNamesTable (CU, *UnitDIE, std::nullopt, 0 );
564
+
565
+ DWARFUnitInfo &CurUnitInfo = getUnitInfoByDwarfUnit (CU);
566
+ UnitStartOffset += CurUnitInfo.UnitLength ;
567
+ };
568
+
569
+ uint64_t TypeUnitStartOffset = 0 ;
570
+ for (DWARFUnit *CU : getState ().DUList ) {
571
+ if (!(CU->getVersion () < 5 && CU->isTypeUnit ()))
572
+ break ;
573
+ finalizeDebugNamesTableForCU (*CU, TypeUnitStartOffset);
574
+ }
575
+
576
+ for (DWARFUnit *CU : getState ().DUList ) {
577
+ if (CU->getVersion () < 5 && CU->isTypeUnit ())
578
+ continue ;
579
+ finalizeDebugNamesTableForCU (*CU, DebugNamesUnitSize);
580
+ }
551
581
updateReferences ();
552
582
}
553
583
0 commit comments