Skip to content

Commit

Permalink
[DWARF] Refactor findDebugNamesOffsets
Browse files Browse the repository at this point in the history
Address some post-review comments in #82153 and move the function inside
llvm::dwarf, used by certain free functions.

Pull Request: #88064
  • Loading branch information
MaskRay authored Apr 9, 2024
1 parent e248f0d commit 9797a7e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 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 @@ -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) {
uint64_t DwarfSize = getDwarfOffsetByteSize(Hdr.Format);
DWARFDebugNames::DWARFDebugNamesOffsets Ret;
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

0 comments on commit 9797a7e

Please sign in to comment.