[llvm] [LLVM][DebugInfo] Refactor some code for easier sharing. (PR #82153)
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 19 16:12:25 PST 2024
================
@@ -552,32 +552,52 @@ DWARFDebugNames::NameIndex::extractAbbrev(uint64_t *Offset) {
return Abbrev(Code, dwarf::Tag(Tag), AbbrevOffset, std::move(*AttrEncOr));
}
+uint64_t
+llvm::FindDebugNamesOffsets(DWARFDebugNames::DWARFDebugNamesOffsets &Offsets,
+ uint64_t HdrSize, dwarf::DwarfFormat Format,
+ const DWARFDebugNames::Header &Hdr) {
+ uint32_t DwarfSize = (Format == llvm::dwarf::DwarfFormat::DWARF32) ? 4 : 8;
+ 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;
+
+ return Offset;
+}
+
Error DWARFDebugNames::NameIndex::extract() {
const DWARFDataExtractor &AS = Section.AccelSection;
uint64_t Offset = Base;
if (Error E = Hdr.extract(AS, &Offset))
return E;
const unsigned SectionOffsetSize = dwarf::getDwarfOffsetByteSize(Hdr.Format);
- CUsBase = Offset;
- Offset += Hdr.CompUnitCount * SectionOffsetSize;
- Offset += Hdr.LocalTypeUnitCount * SectionOffsetSize;
- Offset += Hdr.ForeignTypeUnitCount * 8;
- BucketsBase = Offset;
- Offset += Hdr.BucketCount * 4;
- HashesBase = Offset;
- if (Hdr.BucketCount > 0)
- Offset += Hdr.NameCount * 4;
- StringOffsetsBase = Offset;
- Offset += Hdr.NameCount * SectionOffsetSize;
- EntryOffsetsBase = Offset;
- Offset += Hdr.NameCount * SectionOffsetSize;
+ Offset = FindDebugNamesOffsets(Offsets, Offset, Hdr.Format, Hdr);
----------------
dwblaikie wrote:
This is strange that we assign to `Offset`, but then overwrite it on the next line?
So what's the return value for? Perhaps if it's needed by the future callers but not right now - maybe it should be in the `Offsets` structure, and that `Offsets` structure should be returned by this function, rather than as an input parameter?
https://github.com/llvm/llvm-project/pull/82153
More information about the llvm-commits
mailing list