Skip to content

Commit 095367a

Browse files
authored
[LLVM][DWARF] Chnage order for .debug_names abbrev print out (#80229)
This stemps from conversatin in: #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.
1 parent 06c14c0 commit 095367a

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,15 @@ class DWARFDebugNames : public DWARFAcceleratorTable {
412412

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

419-
Abbrev(uint32_t Code, dwarf::Tag Tag,
420+
Abbrev(uint32_t Code, dwarf::Tag Tag, uint64_t AbbrevOffset,
420421
std::vector<AttributeEncoding> Attributes)
421-
: Code(Code), Tag(Tag), Attributes(std::move(Attributes)) {}
422+
: AbbrevOffset(AbbrevOffset), Code(Code), Tag(Tag),
423+
Attributes(std::move(Attributes)) {}
422424

423425
void dump(ScopedPrinter &W) const;
424426
};

llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ static bool isSentinel(const DWARFDebugNames::AttributeEncoding &AE) {
493493
}
494494

495495
static DWARFDebugNames::Abbrev sentinelAbbrev() {
496-
return DWARFDebugNames::Abbrev(0, dwarf::Tag(0), {});
496+
return DWARFDebugNames::Abbrev(0, dwarf::Tag(0), 0, {});
497497
}
498498

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

507507
DWARFDebugNames::Abbrev DWARFDebugNames::AbbrevMapInfo::getTombstoneKey() {
508-
return DWARFDebugNames::Abbrev(~0, dwarf::Tag(0), {});
508+
return DWARFDebugNames::Abbrev(~0, dwarf::Tag(0), 0, {});
509509
}
510510

511511
Expected<DWARFDebugNames::AttributeEncoding>
@@ -540,7 +540,7 @@ DWARFDebugNames::NameIndex::extractAbbrev(uint64_t *Offset) {
540540
return createStringError(errc::illegal_byte_sequence,
541541
"Incorrectly terminated abbreviation table.");
542542
}
543-
543+
const uint64_t AbbrevOffset = *Offset;
544544
uint32_t Code = Section.AccelSection.getULEB128(Offset);
545545
if (Code == 0)
546546
return sentinelAbbrev();
@@ -549,7 +549,7 @@ DWARFDebugNames::NameIndex::extractAbbrev(uint64_t *Offset) {
549549
auto AttrEncOr = extractAttributeEncodings(Offset);
550550
if (!AttrEncOr)
551551
return AttrEncOr.takeError();
552-
return Abbrev(Code, dwarf::Tag(Tag), std::move(*AttrEncOr));
552+
return Abbrev(Code, dwarf::Tag(Tag), AbbrevOffset, std::move(*AttrEncOr));
553553
}
554554

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

848848
void DWARFDebugNames::NameIndex::dumpAbbreviations(ScopedPrinter &W) const {
849849
ListScope AbbrevsScope(W, "Abbreviations");
850-
for (const auto &Abbr : Abbrevs)
851-
Abbr.dump(W);
850+
std::vector<const Abbrev *> AbbrevsVect;
851+
for (const DWARFDebugNames::Abbrev &Abbr : Abbrevs)
852+
AbbrevsVect.push_back(&Abbr);
853+
llvm::sort(AbbrevsVect, [](const Abbrev *LHS, const Abbrev *RHS) {
854+
return LHS->AbbrevOffset < RHS->AbbrevOffset;
855+
});
856+
for (const DWARFDebugNames::Abbrev *Abbr : AbbrevsVect)
857+
Abbr->dump(W);
852858
}
853859

854860
void DWARFDebugNames::NameIndex::dumpBucket(ScopedPrinter &W,

0 commit comments

Comments
 (0)