Skip to content

Commit 49eb373

Browse files
committed
Address user feedback.
1 parent 6f786cc commit 49eb373

File tree

3 files changed

+30
-49
lines changed

3 files changed

+30
-49
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ DebugNamesDWARFIndex::GetForeignTypeUnit(const DebugNames::Entry &entry) const {
7070
// file from it and get the type unit by signature from there. If we find
7171
// the type unit in the .dwo file, we don't need to check that the
7272
// DW_AT_dwo_name matches because each .dwo file can have its own type unit.
73-
std::optional<uint64_t> cu_offset = entry.getForeignTUSkeletonCUOffset();
73+
std::optional<uint64_t> cu_offset = entry.getRelatedCUOffset();
7474
if (!cu_offset)
7575
return nullptr; // Return NULL, this is a type unit, but couldn't find it.
7676

llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,6 @@ class DWARFAcceleratorTable {
7272
return std::nullopt;
7373
}
7474

75-
// Returns the the CU offset for a foreign TU.
76-
//
77-
// Entries that represent foreign type units can have both a
78-
// DW_IDX_compile_unit and a DW_IDX_type_unit. In this case the
79-
// DW_IDX_compile_unit represents the skeleton CU offset for the .dwo file
80-
// that matches this foreign type unit entry. The type unit will have a
81-
// DW_AT_dwo_name attribute that must match the attribute in the skeleton
82-
// CU. This function is needed be because the getCUOffset() method will
83-
// return the first CU if there is no DW_IDX_compile_unit attribute in this
84-
// entry, and it won't return a value CU offset if there is a
85-
// DW_IDX_type_unit. But this function will return std::nullopt if there is
86-
// no DW_IDX_compile_unit attribute or if this doesn't represent a foreign
87-
// type unit.
88-
virtual std::optional<uint64_t> getForeignTUSkeletonCUOffset() const {
89-
// Default return for accelerator tables that don't support type units.
90-
return std::nullopt;
91-
}
92-
9375
/// Returns the Tag of the Debug Info Entry associated with this
9476
/// Accelerator Entry or std::nullopt if the Tag is not recorded in this
9577
/// Accelerator Entry.
@@ -463,10 +445,13 @@ class DWARFDebugNames : public DWARFAcceleratorTable {
463445
std::optional<uint64_t> getCUOffset() const override;
464446
std::optional<uint64_t> getLocalTUOffset() const override;
465447
std::optional<uint64_t> getForeignTUTypeSignature() const override;
466-
std::optional<uint64_t> getForeignTUSkeletonCUOffset() const override;
467-
468448
std::optional<dwarf::Tag> getTag() const override { return tag(); }
469449

450+
// Special function that will return the related CU offset needed type
451+
// units. This gets used to find the .dwo file that originated the entries
452+
// for a given type unit.
453+
std::optional<uint64_t> getRelatedCUOffset() const;
454+
470455
/// Returns the Index into the Compilation Unit list of the owning Name
471456
/// Index or std::nullopt if this Accelerator Entry does not have an
472457
/// associated Compilation Unit. It is up to the user to verify that the
@@ -478,6 +463,11 @@ class DWARFDebugNames : public DWARFAcceleratorTable {
478463
/// attribute.
479464
std::optional<uint64_t> getCUIndex() const;
480465

466+
/// Similar functionality to getCUIndex() but without the DW_IDX_type_unit
467+
/// restriction. This allows us to get the associated a compilation unit
468+
/// index for an entry that is a type unit.
469+
std::optional<uint64_t> getRelatedCUIndex() const;
470+
481471
/// Returns the Index into the Local Type Unit list of the owning Name
482472
/// Index or std::nullopt if this Accelerator Entry does not have an
483473
/// associated Type Unit. It is up to the user to verify that the

llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -630,26 +630,40 @@ std::optional<uint64_t> DWARFDebugNames::Entry::getDIEUnitOffset() const {
630630
return std::nullopt;
631631
}
632632

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.
634635
if (std::optional<DWARFFormValue> Off = lookup(dwarf::DW_IDX_compile_unit))
635636
return Off->getAsUnsignedConstant();
636637
// 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.
641639
if (NameIdx->getCUCount() == 1)
642640
return 0;
643641
return std::nullopt;
644642
}
645643

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+
646653
std::optional<uint64_t> DWARFDebugNames::Entry::getCUOffset() const {
647654
std::optional<uint64_t> Index = getCUIndex();
648655
if (!Index || *Index >= NameIdx->getCUCount())
649656
return std::nullopt;
650657
return NameIdx->getCUOffset(*Index);
651658
}
652659

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+
653667
std::optional<uint64_t> DWARFDebugNames::Entry::getLocalTUOffset() const {
654668
std::optional<uint64_t> Index = getLocalTUIndex();
655669
if (!Index || *Index >= NameIdx->getLocalTUCount())
@@ -670,29 +684,6 @@ DWARFDebugNames::Entry::getForeignTUTypeSignature() const {
670684
return NameIdx->getForeignTUSignature(ForeignTUIndex);
671685
}
672686

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-
696687
std::optional<uint64_t> DWARFDebugNames::Entry::getLocalTUIndex() const {
697688
if (std::optional<DWARFFormValue> Off = lookup(dwarf::DW_IDX_type_unit))
698689
return Off->getAsUnsignedConstant();

0 commit comments

Comments
 (0)