Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DWARF] Refactor findDebugNamesOffsets #88064

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -804,9 +804,11 @@ class DWARFDebugNames : public DWARFAcceleratorTable {

/// Calculates the starting offsets for various sections within the
/// .debug_names section.
void findDebugNamesOffsets(DWARFDebugNames::DWARFDebugNamesOffsets &Offsets,
uint64_t HdrSize, const dwarf::DwarfFormat Format,
const DWARFDebugNames::Header &Hdr);
namespace dwarf {
DWARFDebugNames::DWARFDebugNamesOffsets
findDebugNamesOffsets(uint64_t EndOfHeaderOffset,
const DWARFDebugNames::Header &Hdr);
}

/// If `Name` is the name of a templated function that includes template
/// parameters, returns a substring of `Name` containing no template
Expand Down
43 changes: 17 additions & 26 deletions llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,31 +552,22 @@ DWARFDebugNames::NameIndex::extractAbbrev(uint64_t *Offset) {
return Abbrev(Code, dwarf::Tag(Tag), AbbrevOffset, std::move(*AttrEncOr));
}

void llvm::findDebugNamesOffsets(
DWARFDebugNames::DWARFDebugNamesOffsets &Offsets, uint64_t HdrSize,
dwarf::DwarfFormat Format, const DWARFDebugNames::Header &Hdr) {
uint32_t DwarfSize = (Format == llvm::dwarf::DwarfFormat::DWARF64) ? 8 : 4;
uint64_t Offset = HdrSize;
Offsets.CUsBase = Offset;
Offset += Hdr.CompUnitCount * DwarfSize;
Offset += Hdr.LocalTypeUnitCount * DwarfSize;
Offset += Hdr.ForeignTypeUnitCount * 8;

Offsets.BucketsBase = Offset;
Offset += Hdr.BucketCount * 4;

Offsets.HashesBase = Offset;
if (Hdr.BucketCount > 0)
Offset += Hdr.NameCount * 4;

Offsets.StringOffsetsBase = Offset;
Offset += Hdr.NameCount * DwarfSize;

Offsets.EntryOffsetsBase = Offset;
Offset += Hdr.NameCount * DwarfSize;

Offset += Hdr.AbbrevTableSize;
Offsets.EntriesBase = Offset;
DWARFDebugNames::DWARFDebugNamesOffsets
dwarf::findDebugNamesOffsets(uint64_t EndOfHeaderOffset,
const DWARFDebugNames::Header &Hdr) {
DWARFDebugNames::DWARFDebugNamesOffsets Ret;
uint32_t DwarfSize = Hdr.Format == dwarf::DwarfFormat::DWARF64 ? 8 : 4;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a post-review comment in PR 82153, David suggested using dwarf::gerDwarfOffsetByteSize for the DwarfSize.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Adopted gerDwarfOffsetByteSize

Ret.CUsBase = EndOfHeaderOffset;
Ret.BucketsBase = Ret.CUsBase + Hdr.CompUnitCount * DwarfSize +
Hdr.LocalTypeUnitCount * DwarfSize +
Hdr.ForeignTypeUnitCount * 8;
Ret.HashesBase = Ret.BucketsBase + Hdr.BucketCount * 4;
Ret.StringOffsetsBase =
Ret.HashesBase + (Hdr.BucketCount > 0 ? Hdr.NameCount * 4 : 0);
Ret.EntryOffsetsBase = Ret.StringOffsetsBase + Hdr.NameCount * DwarfSize;
Ret.EntriesBase =
Ret.EntryOffsetsBase + Hdr.NameCount * DwarfSize + Hdr.AbbrevTableSize;
return Ret;
}

Error DWARFDebugNames::NameIndex::extract() {
Expand All @@ -586,7 +577,7 @@ Error DWARFDebugNames::NameIndex::extract() {
return E;

const unsigned SectionOffsetSize = dwarf::getDwarfOffsetByteSize(Hdr.Format);
findDebugNamesOffsets(Offsets, hdrSize, Hdr.Format, Hdr);
Offsets = dwarf::findDebugNamesOffsets(hdrSize, Hdr);

uint64_t Offset =
Offsets.EntryOffsetsBase + (Hdr.NameCount * SectionOffsetSize);
Expand Down
Loading