@@ -630,26 +630,40 @@ std::optional<uint64_t> DWARFDebugNames::Entry::getDIEUnitOffset() const {
630
630
return std::nullopt;
631
631
}
632
632
633
- std::optional<uint64_t > DWARFDebugNames::Entry::getCUIndex () const {
633
+ std::optional<uint64_t > DWARFDebugNames::Entry::getRelatedCUIndex () const {
634
+ // Return the DW_IDX_compile_unit attribute value if it is specified.
634
635
if (std::optional<DWARFFormValue> Off = lookup (dwarf::DW_IDX_compile_unit))
635
636
return Off->getAsUnsignedConstant ();
636
637
// In a per-CU index, the entries without a DW_IDX_compile_unit attribute
637
- // implicitly refer to the single CU, but only if we don't have a
638
- // DW_IDX_type_unit.
639
- if (lookup (dwarf::DW_IDX_type_unit).has_value ())
640
- return std::nullopt;
638
+ // implicitly refer to the single CU.
641
639
if (NameIdx->getCUCount () == 1 )
642
640
return 0 ;
643
641
return std::nullopt;
644
642
}
645
643
644
+ std::optional<uint64_t > DWARFDebugNames::Entry::getCUIndex () const {
645
+ // Return the DW_IDX_compile_unit attribute value but only if we don't have a
646
+ // DW_IDX_type_unit attribute. Use Entry::getRelatedCUIndex() to get the
647
+ // associated CU index if this behaviour is not desired.
648
+ if (lookup (dwarf::DW_IDX_type_unit).has_value ())
649
+ return std::nullopt;
650
+ return getRelatedCUIndex ();
651
+ }
652
+
646
653
std::optional<uint64_t > DWARFDebugNames::Entry::getCUOffset () const {
647
654
std::optional<uint64_t > Index = getCUIndex ();
648
655
if (!Index || *Index >= NameIdx->getCUCount ())
649
656
return std::nullopt;
650
657
return NameIdx->getCUOffset (*Index);
651
658
}
652
659
660
+ std::optional<uint64_t > DWARFDebugNames::Entry::getRelatedCUOffset () const {
661
+ std::optional<uint64_t > Index = getRelatedCUIndex ();
662
+ if (!Index || *Index >= NameIdx->getCUCount ())
663
+ return std::nullopt;
664
+ return NameIdx->getCUOffset (*Index);
665
+ }
666
+
653
667
std::optional<uint64_t > DWARFDebugNames::Entry::getLocalTUOffset () const {
654
668
std::optional<uint64_t > Index = getLocalTUIndex ();
655
669
if (!Index || *Index >= NameIdx->getLocalTUCount ())
@@ -670,29 +684,6 @@ DWARFDebugNames::Entry::getForeignTUTypeSignature() const {
670
684
return NameIdx->getForeignTUSignature (ForeignTUIndex);
671
685
}
672
686
673
- std::optional<uint64_t >
674
- DWARFDebugNames::Entry::getForeignTUSkeletonCUOffset () const {
675
- // Must have a DW_IDX_type_unit and it must be a foreign type unit.
676
- if (!getForeignTUTypeSignature ())
677
- return std::nullopt;
678
- // Lookup the DW_IDX_compile_unit and make sure we have one, if we don't
679
- // we don't default to returning the first compile unit like getCUOffset().
680
- std::optional<uint64_t > CUIndex;
681
- std::optional<DWARFFormValue> Off = lookup (dwarf::DW_IDX_compile_unit);
682
- if (Off) {
683
- CUIndex = Off->getAsUnsignedConstant ();
684
- } else {
685
- // Check if there is only 1 CU and return that. Most .o files generate one
686
- // .debug_names table per source file where there is 1 CU and many TUs.
687
- if (NameIdx->getCUCount () == 1 )
688
- CUIndex = 0 ;
689
- }
690
- // Extract the CU index and return the right CU offset.
691
- if (CUIndex && *CUIndex < NameIdx->getCUCount ())
692
- return NameIdx->getCUOffset (*CUIndex);
693
- return std::nullopt;
694
- }
695
-
696
687
std::optional<uint64_t > DWARFDebugNames::Entry::getLocalTUIndex () const {
697
688
if (std::optional<DWARFFormValue> Off = lookup (dwarf::DW_IDX_type_unit))
698
689
return Off->getAsUnsignedConstant ();
0 commit comments