-
Notifications
You must be signed in to change notification settings - Fork 12k
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
[LLVM][DebugInfo] Refactor some code for easier sharing. #82153
Changes from all commits
a25058a
7106757
7c3d097
2a4edad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -510,7 +510,7 @@ DWARFDebugNames::Abbrev DWARFDebugNames::AbbrevMapInfo::getTombstoneKey() { | |
|
||
Expected<DWARFDebugNames::AttributeEncoding> | ||
DWARFDebugNames::NameIndex::extractAttributeEncoding(uint64_t *Offset) { | ||
if (*Offset >= EntriesBase) { | ||
if (*Offset >= Offsets.EntriesBase) { | ||
return createStringError(errc::illegal_byte_sequence, | ||
"Incorrectly terminated abbreviation table."); | ||
} | ||
|
@@ -536,7 +536,7 @@ DWARFDebugNames::NameIndex::extractAttributeEncodings(uint64_t *Offset) { | |
|
||
Expected<DWARFDebugNames::Abbrev> | ||
DWARFDebugNames::NameIndex::extractAbbrev(uint64_t *Offset) { | ||
if (*Offset >= EntriesBase) { | ||
if (*Offset >= Offsets.EntriesBase) { | ||
return createStringError(errc::illegal_byte_sequence, | ||
"Incorrectly terminated abbreviation table."); | ||
} | ||
|
@@ -552,32 +552,50 @@ 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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
(the issue here is that while |
||
dwarf::DwarfFormat Format, const DWARFDebugNames::Header &Hdr) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably remove the |
||
uint32_t DwarfSize = (Format == llvm::dwarf::DwarfFormat::DWARF64) ? 8 : 4; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should use |
||
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; | ||
} | ||
|
||
Error DWARFDebugNames::NameIndex::extract() { | ||
const DWARFDataExtractor &AS = Section.AccelSection; | ||
uint64_t Offset = Base; | ||
if (Error E = Hdr.extract(AS, &Offset)) | ||
uint64_t hdrSize = Base; | ||
if (Error E = Hdr.extract(AS, &hdrSize)) | ||
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; | ||
findDebugNamesOffsets(Offsets, hdrSize, Hdr.Format, Hdr); | ||
|
||
uint64_t Offset = | ||
Offsets.EntryOffsetsBase + (Hdr.NameCount * SectionOffsetSize); | ||
|
||
if (!AS.isValidOffsetForDataOfSize(Offset, Hdr.AbbrevTableSize)) | ||
return createStringError(errc::illegal_byte_sequence, | ||
"Section too small: cannot read abbreviations."); | ||
|
||
EntriesBase = Offset + Hdr.AbbrevTableSize; | ||
Offsets.EntriesBase = Offset + Hdr.AbbrevTableSize; | ||
|
||
for (;;) { | ||
auto AbbrevOr = extractAbbrev(&Offset); | ||
|
@@ -679,7 +697,7 @@ void DWARFDebugNames::Entry::dumpParentIdx( | |
return; | ||
} | ||
|
||
auto AbsoluteOffset = NameIdx->EntriesBase + FormValue.getRawUValue(); | ||
auto AbsoluteOffset = NameIdx->Offsets.EntriesBase + FormValue.getRawUValue(); | ||
W.getOStream() << "Entry @ 0x" + Twine::utohexstr(AbsoluteOffset); | ||
} | ||
|
||
|
@@ -708,22 +726,23 @@ std::error_code DWARFDebugNames::SentinelError::convertToErrorCode() const { | |
uint64_t DWARFDebugNames::NameIndex::getCUOffset(uint32_t CU) const { | ||
assert(CU < Hdr.CompUnitCount); | ||
const unsigned SectionOffsetSize = dwarf::getDwarfOffsetByteSize(Hdr.Format); | ||
uint64_t Offset = CUsBase + SectionOffsetSize * CU; | ||
uint64_t Offset = Offsets.CUsBase + SectionOffsetSize * CU; | ||
return Section.AccelSection.getRelocatedValue(SectionOffsetSize, &Offset); | ||
} | ||
|
||
uint64_t DWARFDebugNames::NameIndex::getLocalTUOffset(uint32_t TU) const { | ||
assert(TU < Hdr.LocalTypeUnitCount); | ||
const unsigned SectionOffsetSize = dwarf::getDwarfOffsetByteSize(Hdr.Format); | ||
uint64_t Offset = CUsBase + SectionOffsetSize * (Hdr.CompUnitCount + TU); | ||
uint64_t Offset = | ||
Offsets.CUsBase + SectionOffsetSize * (Hdr.CompUnitCount + TU); | ||
return Section.AccelSection.getRelocatedValue(SectionOffsetSize, &Offset); | ||
} | ||
|
||
uint64_t DWARFDebugNames::NameIndex::getForeignTUSignature(uint32_t TU) const { | ||
assert(TU < Hdr.ForeignTypeUnitCount); | ||
const unsigned SectionOffsetSize = dwarf::getDwarfOffsetByteSize(Hdr.Format); | ||
uint64_t Offset = | ||
CUsBase + | ||
Offsets.CUsBase + | ||
SectionOffsetSize * (Hdr.CompUnitCount + Hdr.LocalTypeUnitCount) + 8 * TU; | ||
return Section.AccelSection.getU64(&Offset); | ||
} | ||
|
@@ -759,28 +778,28 @@ DWARFDebugNames::NameIndex::getNameTableEntry(uint32_t Index) const { | |
assert(0 < Index && Index <= Hdr.NameCount); | ||
const unsigned SectionOffsetSize = dwarf::getDwarfOffsetByteSize(Hdr.Format); | ||
uint64_t StringOffsetOffset = | ||
StringOffsetsBase + SectionOffsetSize * (Index - 1); | ||
Offsets.StringOffsetsBase + SectionOffsetSize * (Index - 1); | ||
uint64_t EntryOffsetOffset = | ||
EntryOffsetsBase + SectionOffsetSize * (Index - 1); | ||
Offsets.EntryOffsetsBase + SectionOffsetSize * (Index - 1); | ||
const DWARFDataExtractor &AS = Section.AccelSection; | ||
|
||
uint64_t StringOffset = | ||
AS.getRelocatedValue(SectionOffsetSize, &StringOffsetOffset); | ||
uint64_t EntryOffset = AS.getUnsigned(&EntryOffsetOffset, SectionOffsetSize); | ||
EntryOffset += EntriesBase; | ||
EntryOffset += Offsets.EntriesBase; | ||
return {Section.StringSection, Index, StringOffset, EntryOffset}; | ||
} | ||
|
||
uint32_t | ||
DWARFDebugNames::NameIndex::getBucketArrayEntry(uint32_t Bucket) const { | ||
assert(Bucket < Hdr.BucketCount); | ||
uint64_t BucketOffset = BucketsBase + 4 * Bucket; | ||
uint64_t BucketOffset = Offsets.BucketsBase + 4 * Bucket; | ||
return Section.AccelSection.getU32(&BucketOffset); | ||
} | ||
|
||
uint32_t DWARFDebugNames::NameIndex::getHashArrayEntry(uint32_t Index) const { | ||
assert(0 < Index && Index <= Hdr.NameCount); | ||
uint64_t HashOffset = HashesBase + 4 * (Index - 1); | ||
uint64_t HashOffset = Offsets.HashesBase + 4 * (Index - 1); | ||
return Section.AccelSection.getU32(&HashOffset); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably return the offsets from this function, rather than taking them as an out parameter? It's then clearer that they aren't in/out parameters, or something else more interesting.