@@ -461,32 +461,42 @@ getUnitForOffset(DIEBuilder &Builder, DWARFContext &DWCtx,
461
461
return nullptr ;
462
462
}
463
463
464
- uint32_t DIEBuilder::finalizeDIEs (
465
- DWARFUnit &CU, DIE &Die,
466
- std::vector<std:: optional<BOLTDWARF5AccelTableData *>> &Parents ,
467
- uint32_t &CurOffset) {
464
+ uint32_t
465
+ DIEBuilder::finalizeDIEs ( DWARFUnit &CU, DIE &Die,
466
+ std::optional<BOLTDWARF5AccelTableData *> Parent ,
467
+ uint32_t NumberParentsInChain, uint32_t &CurOffset) {
468
468
getState ().DWARFDieAddressesParsed .erase (Die.getOffset ());
469
469
uint32_t CurSize = 0 ;
470
470
Die.setOffset (CurOffset);
471
471
std::optional<BOLTDWARF5AccelTableData *> NameEntry =
472
472
DebugNamesTable.addAccelTableEntry (
473
473
CU, Die, SkeletonCU ? SkeletonCU->getDWOId () : std::nullopt,
474
- Parents. back () );
474
+ NumberParentsInChain, Parent );
475
475
// It is possible that an indexed debugging information entry has a parent
476
476
// that is not indexed (for example, if its parent does not have a name
477
477
// attribute). In such a case, a parent attribute may point to a nameless
478
478
// index entry (that is, one that cannot be reached from any entry in the name
479
479
// table), or it may point to the nearest ancestor that does have an index
480
480
// entry.
481
+ // Skipping entry is not very useful for LLDB. This follows clang where
482
+ // children of forward declaration won't have DW_IDX_parent.
483
+ // https://github.com/llvm/llvm-project/pull/91808
484
+
485
+ // If Parent is nullopt and NumberParentsInChain is not zero, then forward
486
+ // declaration was encountered in this DF traversal. Propagating nullopt for
487
+ // Parent to children.
488
+ if (!Parent && NumberParentsInChain)
489
+ NameEntry = std::nullopt;
481
490
if (NameEntry)
482
- Parents. push_back ( std::move (NameEntry)) ;
491
+ ++NumberParentsInChain ;
483
492
for (DIEValue &Val : Die.values ())
484
493
CurSize += Val.sizeOf (CU.getFormParams ());
485
494
CurSize += getULEB128Size (Die.getAbbrevNumber ());
486
495
CurOffset += CurSize;
487
496
488
497
for (DIE &Child : Die.children ()) {
489
- uint32_t ChildSize = finalizeDIEs (CU, Child, Parents, CurOffset);
498
+ uint32_t ChildSize =
499
+ finalizeDIEs (CU, Child, NameEntry, NumberParentsInChain, CurOffset);
490
500
CurSize += ChildSize;
491
501
}
492
502
// for children end mark.
@@ -496,9 +506,6 @@ uint32_t DIEBuilder::finalizeDIEs(
496
506
}
497
507
498
508
Die.setSize (CurSize);
499
- if (NameEntry)
500
- Parents.pop_back ();
501
-
502
509
return CurSize;
503
510
}
504
511
@@ -510,7 +517,7 @@ void DIEBuilder::finish() {
510
517
DebugNamesTable.setCurrentUnit (CU, UnitStartOffset);
511
518
std::vector<std::optional<BOLTDWARF5AccelTableData *>> Parents;
512
519
Parents.push_back (std::nullopt);
513
- finalizeDIEs (CU, *UnitDIE, Parents , CurOffset);
520
+ finalizeDIEs (CU, *UnitDIE, std::nullopt, 0 , CurOffset);
514
521
515
522
DWARFUnitInfo &CurUnitInfo = getUnitInfoByDwarfUnit (CU);
516
523
CurUnitInfo.UnitOffset = UnitStartOffset;
0 commit comments