Skip to content

Commit d0a2150

Browse files
[llvm][DebugNames] Implement Entry::GetParentEntry query
1 parent 7a382cd commit d0a2150

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ class DWARFDebugNames : public DWARFAcceleratorTable {
460460
/// Returns the Offset of the DIE within the containing CU or TU.
461461
std::optional<uint64_t> getDIEUnitOffset() const;
462462

463+
/// Returns the Entry corresponding to the parent of the DIE represented by
464+
/// `this` Entry. If the parent DIE is not indexed by this table, or if this
465+
/// table does not track parents through IDX_parent, an error is returned.
466+
Expected<DWARFDebugNames::Entry> getParentDIEEntry() const;
467+
463468
/// Return the Abbreviation that can be used to interpret the raw values of
464469
/// this Accelerator Entry.
465470
const Abbrev &getAbbrev() const { return *Abbr; }
@@ -609,6 +614,13 @@ class DWARFDebugNames : public DWARFAcceleratorTable {
609614

610615
Expected<Entry> getEntry(uint64_t *Offset) const;
611616

617+
// Returns the Entry at the relative `Offset` from the start of the Entry
618+
// pool.
619+
Expected<Entry> getEntryAtRelativeOffset(uint64_t Offset) const {
620+
auto OffsetFromSection = Offset + this->EntriesBase;
621+
return getEntry(&OffsetFromSection);
622+
}
623+
612624
/// Look up all entries in this Name Index matching \c Key.
613625
iterator_range<ValueIterator> equal_range(StringRef Key) const;
614626

llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,16 @@ std::optional<uint64_t> DWARFDebugNames::Entry::getLocalTUIndex() const {
650650
return std::nullopt;
651651
}
652652

653+
Expected<DWARFDebugNames::Entry>
654+
DWARFDebugNames::Entry::getParentDIEEntry() const {
655+
// The offset of the accelerator table entry for the parent.
656+
std::optional<DWARFFormValue> ParentEntryOff = lookup(dwarf::DW_IDX_parent);
657+
if (!ParentEntryOff)
658+
return createStringError(errc::illegal_byte_sequence,
659+
"Incorrectly terminated entry list.");
660+
return NameIdx->getEntryAtRelativeOffset(ParentEntryOff->getRawUValue());
661+
}
662+
653663
void DWARFDebugNames::Entry::dump(ScopedPrinter &W) const {
654664
W.startLine() << formatv("Abbrev: {0:x}\n", Abbr->Code);
655665
W.startLine() << formatv("Tag: {0}\n", Abbr->Tag);

llvm/test/CodeGen/X86/dwarf-headers.o

Whitespace-only changes.

0 commit comments

Comments
 (0)