Skip to content

Commit

Permalink
[LLVM][DWARF] Chnage order for .debug_names abbrev print out (llvm#80229
Browse files Browse the repository at this point in the history
)

This stemps from conversatin in:
llvm#77457 (comment).
Right now Abbrev code for abbrev is combination of DIE TAG and other
attributes.
In the future it will be changed to be an index. Since DenseSet does not
preserve an order, added a sort based on abbrev code. Once change to
index is
made, it will print out abbrevs in the order they are stored.
  • Loading branch information
ayermolo authored and agozillon committed Feb 5, 2024
1 parent b677358 commit c9da818
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
8 changes: 5 additions & 3 deletions llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,15 @@ class DWARFDebugNames : public DWARFAcceleratorTable {

/// Abbreviation describing the encoding of Name Index entries.
struct Abbrev {
uint32_t Code; ///< Abbreviation code
uint64_t AbbrevOffset; /// < Abbreviation offset in the .debug_names section
uint32_t Code; ///< Abbreviation code
dwarf::Tag Tag; ///< Dwarf Tag of the described entity.
std::vector<AttributeEncoding> Attributes; ///< List of index attributes.

Abbrev(uint32_t Code, dwarf::Tag Tag,
Abbrev(uint32_t Code, dwarf::Tag Tag, uint64_t AbbrevOffset,
std::vector<AttributeEncoding> Attributes)
: Code(Code), Tag(Tag), Attributes(std::move(Attributes)) {}
: AbbrevOffset(AbbrevOffset), Code(Code), Tag(Tag),
Attributes(std::move(Attributes)) {}

void dump(ScopedPrinter &W) const;
};
Expand Down
18 changes: 12 additions & 6 deletions llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ static bool isSentinel(const DWARFDebugNames::AttributeEncoding &AE) {
}

static DWARFDebugNames::Abbrev sentinelAbbrev() {
return DWARFDebugNames::Abbrev(0, dwarf::Tag(0), {});
return DWARFDebugNames::Abbrev(0, dwarf::Tag(0), 0, {});
}

static bool isSentinel(const DWARFDebugNames::Abbrev &Abbr) {
Expand All @@ -505,7 +505,7 @@ DWARFDebugNames::Abbrev DWARFDebugNames::AbbrevMapInfo::getEmptyKey() {
}

DWARFDebugNames::Abbrev DWARFDebugNames::AbbrevMapInfo::getTombstoneKey() {
return DWARFDebugNames::Abbrev(~0, dwarf::Tag(0), {});
return DWARFDebugNames::Abbrev(~0, dwarf::Tag(0), 0, {});
}

Expected<DWARFDebugNames::AttributeEncoding>
Expand Down Expand Up @@ -540,7 +540,7 @@ DWARFDebugNames::NameIndex::extractAbbrev(uint64_t *Offset) {
return createStringError(errc::illegal_byte_sequence,
"Incorrectly terminated abbreviation table.");
}

const uint64_t AbbrevOffset = *Offset;
uint32_t Code = Section.AccelSection.getULEB128(Offset);
if (Code == 0)
return sentinelAbbrev();
Expand All @@ -549,7 +549,7 @@ DWARFDebugNames::NameIndex::extractAbbrev(uint64_t *Offset) {
auto AttrEncOr = extractAttributeEncodings(Offset);
if (!AttrEncOr)
return AttrEncOr.takeError();
return Abbrev(Code, dwarf::Tag(Tag), std::move(*AttrEncOr));
return Abbrev(Code, dwarf::Tag(Tag), AbbrevOffset, std::move(*AttrEncOr));
}

Error DWARFDebugNames::NameIndex::extract() {
Expand Down Expand Up @@ -847,8 +847,14 @@ void DWARFDebugNames::NameIndex::dumpForeignTUs(ScopedPrinter &W) const {

void DWARFDebugNames::NameIndex::dumpAbbreviations(ScopedPrinter &W) const {
ListScope AbbrevsScope(W, "Abbreviations");
for (const auto &Abbr : Abbrevs)
Abbr.dump(W);
std::vector<const Abbrev *> AbbrevsVect;
for (const DWARFDebugNames::Abbrev &Abbr : Abbrevs)
AbbrevsVect.push_back(&Abbr);
llvm::sort(AbbrevsVect, [](const Abbrev *LHS, const Abbrev *RHS) {
return LHS->AbbrevOffset < RHS->AbbrevOffset;
});
for (const DWARFDebugNames::Abbrev *Abbr : AbbrevsVect)
Abbr->dump(W);
}

void DWARFDebugNames::NameIndex::dumpBucket(ScopedPrinter &W,
Expand Down

0 comments on commit c9da818

Please sign in to comment.