36 return OS <<
"DW_ATOM_unknown_" <<
format(
"%x", A.Value);
48 if (!AccelSection.isValidOffset(
offsetof(Header, HeaderDataLength) + 4))
50 "Section too small: cannot read header.");
52 Hdr.Magic = AccelSection.getU32(&Offset);
53 Hdr.Version = AccelSection.getU16(&Offset);
54 Hdr.HashFunction = AccelSection.getU16(&Offset);
55 Hdr.BucketCount = AccelSection.getU32(&Offset);
56 Hdr.HashCount = AccelSection.getU32(&Offset);
57 Hdr.HeaderDataLength = AccelSection.getU32(&Offset);
63 if (!AccelSection.isValidOffset(
sizeof(Hdr) + Hdr.HeaderDataLength +
64 Hdr.BucketCount * 4 + Hdr.HashCount * 8 - 1))
67 "Section too small: cannot read buckets and hashes.");
69 HdrData.DIEOffsetBase = AccelSection.getU32(&Offset);
70 uint32_t NumAtoms = AccelSection.getU32(&Offset);
72 for (
unsigned i = 0; i < NumAtoms; ++i) {
73 uint16_t AtomType = AccelSection.getU16(&Offset);
74 auto AtomForm =
static_cast<dwarf::Form>(AccelSection.getU16(&Offset));
75 HdrData.Atoms.push_back(std::make_pair(AtomType, AtomForm));
86 return Hdr.HeaderDataLength;
96 for (
auto Atom : getAtomsDesc()) {
104 FormValue.
getForm() == dwarf::DW_FORM_sdata)
114 std::pair<uint64_t, dwarf::Tag>
120 for (
auto Atom : getAtomsDesc()) {
122 FormValue.
extractValue(AccelSection, HashDataOffset, FormParams);
123 switch (Atom.first) {
134 return {DieOffset, DieTag};
141 W.
printHex(
"Hash function", HashFunction);
144 W.
printNumber(
"HeaderData length", HeaderDataLength);
153 case dwarf::DW_FORM_ref1:
154 case dwarf::DW_FORM_ref2:
155 case dwarf::DW_FORM_ref4:
156 case dwarf::DW_FORM_ref8:
157 case dwarf::DW_FORM_ref_udata:
166 uint64_t *DataOffset)
const {
168 uint64_t NameOffset = *DataOffset;
169 if (!AccelSection.isValidOffsetForDataOfSize(*DataOffset, 4)) {
173 uint64_t StringOffset = AccelSection.getRelocatedValue(4, DataOffset);
179 W.
getOStream() <<
" \"" << StringSection.getCStr(&StringOffset) <<
"\"\n";
181 unsigned NumData = AccelSection.getU32(DataOffset);
185 for (
auto &Atom : AtomForms) {
187 if (Atom.extractValue(AccelSection, DataOffset, FormParams)) {
195 W.
getOStream() <<
"Error extracting the value";
211 W.
printNumber(
"DIE offset base", HdrData.DIEOffsetBase);
212 W.
printNumber(
"Number of atoms", uint64_t(HdrData.Atoms.size()));
217 for (
const auto &Atom : HdrData.Atoms) {
226 uint64_t
Offset =
sizeof(Hdr) + Hdr.HeaderDataLength;
227 uint64_t HashesBase = Offset + Hdr.BucketCount * 4;
228 uint64_t OffsetsBase = HashesBase + Hdr.HashCount * 4;
230 for (
unsigned Bucket = 0; Bucket < Hdr.BucketCount; ++Bucket) {
231 unsigned Index = AccelSection.getU32(&Offset);
234 if (Index == UINT32_MAX) {
239 for (
unsigned HashIdx = Index; HashIdx < Hdr.HashCount; ++HashIdx) {
240 uint64_t HashOffset = HashesBase + HashIdx*4;
241 uint64_t OffsetsOffset = OffsetsBase + HashIdx*4;
242 uint32_t Hash = AccelSection.getU32(&HashOffset);
244 if (Hash % Hdr.BucketCount != Bucket)
247 uint64_t DataOffset = AccelSection.getU32(&OffsetsOffset);
249 if (!AccelSection.isValidOffset(DataOffset)) {
253 while (dumpName(W, AtomForms, &DataOffset))
259 AppleAcceleratorTable::Entry::Entry(
260 const AppleAcceleratorTable::HeaderData &HdrData)
261 : HdrData(&HdrData) {
262 Values.reserve(HdrData.Atoms.size());
263 for (
const auto &Atom : HdrData.Atoms)
267 void AppleAcceleratorTable::Entry::extract(
272 for (
auto &Atom : Values)
273 Atom.extractValue(AccelTable.
AccelSection, Offset, FormParams);
278 assert(HdrData &&
"Dereferencing end iterator?");
279 assert(HdrData->Atoms.size() == Values.size());
280 for (
auto Tuple :
zip_first(HdrData->Atoms, Values)) {
281 if (std::get<0>(Tuple).first == Atom)
282 return std::get<1>(Tuple);
306 : AccelTable(&AccelTable), Current(AccelTable.HdrData), DataOffset(Offset) {
315 void AppleAcceleratorTable::ValueIterator::Next() {
316 assert(NumData > 0 &&
"attempted to increment iterator past the end");
318 if (Data >= NumData ||
324 Current.extract(*AccelTable, &DataOffset);
334 unsigned HashValue =
djbHash(Key);
335 unsigned Bucket = HashValue % Hdr.BucketCount;
336 uint64_t BucketBase =
sizeof(Hdr) + Hdr.HeaderDataLength;
337 uint64_t HashesBase = BucketBase + Hdr.BucketCount * 4;
338 uint64_t OffsetsBase = HashesBase + Hdr.HashCount * 4;
340 uint64_t BucketOffset = BucketBase + Bucket * 4;
344 for (
unsigned HashIdx =
Index; HashIdx < Hdr.HashCount; ++HashIdx) {
345 uint64_t HashOffset = HashesBase + HashIdx * 4;
346 uint64_t OffsetsOffset = OffsetsBase + HashIdx * 4;
349 if (Hash % Hdr.BucketCount != Bucket)
371 W.
printNumber(
"Local TU count", LocalTypeUnitCount);
372 W.
printNumber(
"Foreign TU count", ForeignTypeUnitCount);
375 W.
printHex(
"Abbreviations table size", AbbrevTableSize);
376 W.
startLine() <<
"Augmentation: '" << AugmentationString <<
"'\n";
384 "Section too small: cannot read header.");
386 UnitLength = AS.
getU32(Offset);
388 Padding = AS.
getU16(Offset);
389 CompUnitCount = AS.
getU32(Offset);
390 LocalTypeUnitCount = AS.
getU32(Offset);
391 ForeignTypeUnitCount = AS.
getU32(Offset);
392 BucketCount = AS.
getU32(Offset);
393 NameCount = AS.
getU32(Offset);
394 AbbrevTableSize = AS.
getU32(Offset);
400 "Section too small: cannot read header augmentation.");
401 AugmentationString.resize(AugmentationStringSize);
402 AS.
getU8(Offset, reinterpret_cast<uint8_t *>(AugmentationString.data()),
403 AugmentationStringSize);
411 for (
const auto &Attr : Attributes)
428 return Abbr.
Code == 0;
440 DWARFDebugNames::NameIndex::extractAttributeEncoding(uint64_t *Offset) {
441 if (*Offset >= EntriesBase) {
443 "Incorrectly terminated abbreviation table.");
452 DWARFDebugNames::NameIndex::extractAttributeEncodings(uint64_t *Offset) {
453 std::vector<AttributeEncoding> Result;
455 auto AttrEncOr = extractAttributeEncoding(Offset);
457 return AttrEncOr.takeError();
459 return std::move(Result);
461 Result.emplace_back(*AttrEncOr);
466 DWARFDebugNames::NameIndex::extractAbbrev(uint64_t *Offset) {
467 if (*Offset >= EntriesBase) {
469 "Incorrectly terminated abbreviation table.");
477 auto AttrEncOr = extractAttributeEncodings(Offset);
479 return AttrEncOr.takeError();
480 return Abbrev(Code,
dwarf::Tag(Tag), std::move(*AttrEncOr));
485 uint64_t Offset =
Base;
486 if (
Error E = Hdr.extract(AS, &Offset))
490 Offset += Hdr.CompUnitCount * 4;
491 Offset += Hdr.LocalTypeUnitCount * 4;
492 Offset += Hdr.ForeignTypeUnitCount * 8;
494 Offset += Hdr.BucketCount * 4;
496 if (Hdr.BucketCount > 0)
497 Offset += Hdr.NameCount * 4;
498 StringOffsetsBase =
Offset;
499 Offset += Hdr.NameCount * 4;
500 EntryOffsetsBase =
Offset;
501 Offset += Hdr.NameCount * 4;
505 "Section too small: cannot read abbreviations.");
507 EntriesBase = Offset + Hdr.AbbrevTableSize;
510 auto AbbrevOr = extractAbbrev(&Offset);
512 return AbbrevOr.takeError();
516 if (!Abbrevs.insert(std::move(*AbbrevOr)).second)
518 "Duplicate abbreviation code.");
523 : NameIdx(&NameIdx), Abbr(&Abbr) {
528 Values.emplace_back(Attr.Form);
535 if (std::get<0>(Tuple).Index ==
Index)
536 return std::get<1>(Tuple);
543 return Off->getAsReferenceUVal();
549 return Off->getAsUnsignedConstant();
559 if (!Index || *Index >= NameIdx->
getCUCount())
581 assert(CU < Hdr.CompUnitCount);
582 uint64_t Offset = CUsBase + 4 * CU;
583 return Section.AccelSection.getRelocatedValue(4, &Offset);
587 assert(TU < Hdr.LocalTypeUnitCount);
588 uint64_t Offset = CUsBase + 4 * (Hdr.CompUnitCount + TU);
589 return Section.AccelSection.getRelocatedValue(4, &Offset);
593 assert(TU < Hdr.ForeignTypeUnitCount);
595 CUsBase + 4 * (Hdr.CompUnitCount + Hdr.LocalTypeUnitCount) + 8 * TU;
596 return Section.AccelSection.getU64(&Offset);
604 "Incorrectly terminated entry list.");
608 return make_error<SentinelError>();
610 const auto AbbrevIt = Abbrevs.find_as(AbbrevCode);
611 if (AbbrevIt == Abbrevs.end())
614 Entry E(*
this, *AbbrevIt);
617 for (
auto &Value : E.
Values) {
618 if (!Value.extractValue(AS, Offset, FormParams))
620 "Error extracting index attribute values.");
627 assert(0 < Index && Index <= Hdr.NameCount);
628 uint64_t StringOffsetOffset = StringOffsetsBase + 4 * (Index - 1);
629 uint64_t EntryOffsetOffset = EntryOffsetsBase + 4 * (Index - 1);
632 uint64_t StringOffset = AS.getRelocatedValue(4, &StringOffsetOffset);
633 uint64_t EntryOffset = AS.getU32(&EntryOffsetOffset);
634 EntryOffset += EntriesBase;
635 return {
Section.StringSection,
Index, StringOffset, EntryOffset};
640 assert(Bucket < Hdr.BucketCount);
641 uint64_t BucketOffset = BucketsBase + 4 * Bucket;
642 return Section.AccelSection.getU32(&BucketOffset);
646 assert(0 < Index && Index <= Hdr.NameCount);
647 uint64_t HashOffset = HashesBase + 4 * (Index - 1);
648 return Section.AccelSection.getU32(&HashOffset);
656 uint64_t *Offset)
const {
657 uint64_t EntryId = *
Offset;
658 auto EntryOr = getEntry(Offset);
681 while (dumpEntry(W, &EntryOffset))
685 void DWARFDebugNames::NameIndex::dumpCUs(
ScopedPrinter &W)
const {
686 ListScope CUScope(W,
"Compilation Unit offsets");
691 void DWARFDebugNames::NameIndex::dumpLocalTUs(
ScopedPrinter &W)
const {
692 if (Hdr.LocalTypeUnitCount == 0)
695 ListScope TUScope(W,
"Local Type Unit offsets");
696 for (
uint32_t TU = 0; TU < Hdr.LocalTypeUnitCount; ++TU)
698 getLocalTUOffset(TU));
701 void DWARFDebugNames::NameIndex::dumpForeignTUs(
ScopedPrinter &W)
const {
702 if (Hdr.ForeignTypeUnitCount == 0)
705 ListScope TUScope(W,
"Foreign Type Unit signatures");
706 for (
uint32_t TU = 0; TU < Hdr.ForeignTypeUnitCount; ++TU) {
708 getForeignTUSignature(TU));
712 void DWARFDebugNames::NameIndex::dumpAbbreviations(
ScopedPrinter &W)
const {
713 ListScope AbbrevsScope(W,
"Abbreviations");
714 for (
const auto &Abbr : Abbrevs)
718 void DWARFDebugNames::NameIndex::dumpBucket(
ScopedPrinter &W,
726 if (Index > Hdr.NameCount) {
731 for (; Index <= Hdr.NameCount; ++
Index) {
732 uint32_t Hash = getHashArrayEntry(Index);
733 if (Hash % Hdr.BucketCount != Bucket)
736 dumpName(W, getNameTableEntry(Index), Hash);
746 dumpAbbreviations(W);
748 if (Hdr.BucketCount > 0) {
749 for (
uint32_t Bucket = 0; Bucket < Hdr.BucketCount; ++Bucket)
750 dumpBucket(W, Bucket);
754 W.
startLine() <<
"Hash table not present\n";
756 dumpName(W, NTE,
None);
766 NameIndices.push_back(std::move(Next));
783 DWARFDebugNames::ValueIterator::findEntryOffsetInCurrentIndex() {
784 const Header &Hdr = CurrentIndex->Hdr;
785 if (Hdr.BucketCount == 0) {
798 uint32_t Bucket = *Hash % Hdr.BucketCount;
803 for (; Index <= Hdr.NameCount; ++
Index) {
804 uint32_t Hash = CurrentIndex->getHashArrayEntry(Index);
805 if (Hash % Hdr.BucketCount != Bucket)
815 bool DWARFDebugNames::ValueIterator::getEntryAtCurrentOffset() {
816 auto EntryOr = CurrentIndex->getEntry(&DataOffset);
821 CurrentEntry = std::move(*EntryOr);
825 bool DWARFDebugNames::ValueIterator::findInCurrentIndex() {
830 return getEntryAtCurrentOffset();
833 void DWARFDebugNames::ValueIterator::searchFromStartOfCurrentIndex() {
834 for (
const NameIndex *End = CurrentIndex->Section.NameIndices.end();
835 CurrentIndex != End; ++CurrentIndex) {
836 if (findInCurrentIndex())
842 void DWARFDebugNames::ValueIterator::next() {
843 assert(CurrentIndex &&
"Incrementing an end() iterator?");
846 if (getEntryAtCurrentOffset())
850 if (IsLocal || CurrentIndex == &CurrentIndex->Section.NameIndices.back()) {
857 searchFromStartOfCurrentIndex();
862 : CurrentIndex(AccelTable.NameIndices.
begin()), IsLocal(
false), Key(Key) {
863 searchFromStartOfCurrentIndex();
868 : CurrentIndex(&NI), IsLocal(
true), Key(Key) {
869 if (!findInCurrentIndex())
875 if (NameIndices.empty())
882 if (CUToNameIndex.size() == 0 && NameIndices.size() > 0) {
883 for (
const auto &NI : *
this) {
885 CUToNameIndex.try_emplace(NI.getCUOffset(
CU), &NI);
888 return CUToNameIndex.lookup(CUOffset);
iterator_range< ValueIterator > equal_range(StringRef Key) const
Look up all entries in the accelerator table matching Key.
void dump(ScopedPrinter &W) const
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
iterator_range< ValueIterator > equal_range(StringRef Key) const
Look up all entries in the accelerator table matching Key.
This class represents lattice values for constants.
StringRef AtomTypeString(unsigned Atom)
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
std::vector< AttributeEncoding > Attributes
List of index attributes.
SmallVector< DWARFFormValue, 3 > Values
Optional< DWARFFormValue > lookup(dwarf::Index Index) const
Returns the value of the Index Attribute in this Accelerator Entry, if the Entry contains such Attrib...
static constexpr DWARFDebugNames::AttributeEncoding sentinelAttrEnc()
void push_back(const T &Elt)
static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)
A Lookup helper functions.
This class holds an abstract representation of an Accelerator Table, consisting of a sequence of buck...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
uint64_t getCUOffset(uint32_t CU) const
Reads offset of compilation unit CU. CU is 0-based.
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
static void dump(StringRef Title, SpillInfo const &Spills)
block Block Frequency true
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Optional< DWARFFormValue > lookup(HeaderData::AtomType Atom) const
Returns the value of the Atom in this Accelerator Entry, if the Entry contains such Atom...
Base class for error info classes.
Abbreviation describing the encoding of Name Index entries.
uint64_t getForeignTUSignature(uint32_t TU) const
Reads signature of foreign type unit TU. TU is 0-based.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
ArrayRef< std::pair< HeaderData::AtomType, HeaderData::Form > > getAtomsDesc()
Return the Atom description, which can be used to interpret the raw values of the Accelerator Entries...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
DWARFDataExtractor AccelSection
Tagged union holding either a T or a Error.
Index attribute and its encoding.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
dwarf::Tag Tag
Dwarf Tag of the described entity.
raw_ostream & getOStream()
uint64_t getLocalTUOffset(uint32_t TU) const
Reads offset of local type unit TU, TU is 0-based.
uint64_t getNextUnitOffset() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Represents a single accelerator table within the DWARF v5 .debug_names section.
Optional< uint64_t > getCUOffset() const override
Returns the Offset of the Compilation Unit associated with this Accelerator Entry or None if the Comp...
uint32_t getBucketArrayEntry(uint32_t Bucket) const
Reads an entry in the Bucket Array for the given Bucket.
Optional< uint64_t > getCUIndex() const
Returns the Index into the Compilation Unit list of the owning Name Index or None if this Accelerator...
static DWARFDebugNames::Abbrev sentinelAbbrev()
static Atom formatAtom(unsigned Atom)
Expected< Entry > getEntry(uint64_t *Offset) const
std::pair< uint64_t, dwarf::Tag > readAtoms(uint64_t *HashDataOffset)
Return information related to the DWARF DIE we're looking for when performing a lookup by name...
DWARF v5-specific implementation of an Accelerator Entry.
This implements the Apple accelerator table format, a precursor of the DWARF 5 accelerator table form...
const uint32_t DW_INVALID_OFFSET
Identifier of an invalid DIE offset in the .debug_info section.
virtual ~DWARFAcceleratorTable()
ValueIterator()=default
End marker.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
raw_ostream & startLine()
Optional< uint64_t > getDIEUnitOffset() const
Returns the Offset of the DIE within the containing CU or TU.
#define offsetof(TYPE, MEMBER)
NameTableEntry getNameTableEntry(uint32_t Index) const
Reads an entry in the Name Table for the given Index.
uint32_t getHashArrayEntry(uint32_t Index) const
Reads an entry in the Hash Array for the given Index.
void printHex(StringRef Label, T Value)
detail::zippy< detail::zip_first, T, U, Args... > zip_first(T &&t, U &&u, Args &&... args)
zip iterator that, for the sake of efficiency, assumes the first iteratee to be the shortest...
void consumeError(Error Err)
Consume a Error without doing anything.
uint32_t djbHash(StringRef Buffer, uint32_t H=5381)
The Bernstein hash function used by the DWARF accelerator tables.
static const char *const Magic
void printString(StringRef Value)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
const char * getString() const
Return the string referenced by this name table entry or nullptr if the string offset is not valid...
.debug_names section consists of one or more units.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
static ErrorSuccess success()
Create a success value.
void printNumber(StringRef Label, uint64_t Value)
void dump(ScopedPrinter &W) const
A single entry in the Name Table (DWARF v5 sect.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
uint32_t caseFoldingDjbHash(StringRef Buffer, uint32_t H=5381)
Computes the Bernstein hash after folding the input according to the Dwarf 5 standard case folding ru...
void dump(raw_ostream &OS) const override
static Twine utohexstr(const uint64_t &Val)
uint32_t getIndex() const
Return the index of this name in the parent Name Index.
A range adaptor for a pair of iterators.
This file contains constants used for implementing Dwarf debug support.
Optional< uint64_t > getDIESectionOffset() const
Returns the Section Offset of the Debug Info Entry associated with this Accelerator Entry or None if ...
Error returned by NameIndex::getEntry to report it has reached the end of the entry list...
StringRef AtomValueString(uint16_t Atom, unsigned Val)
Returns the symbolic string representing Val when used as a value for atom Atom.
Optional< uint64_t > getCUOffset() const override
Returns the Offset of the Compilation Unit associated with this Accelerator Entry or None if the Comp...
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
const NameIndex * getCUNameIndex(uint64_t CUOffset)
Return the Name Index covering the compile unit at CUOffset, or nullptr if there is no Name Index cov...
void dump(ScopedPrinter &W) const
uint64_t getEntryOffset() const
Returns the offset of the first Entry in the list.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
ValueIterator()=default
End marker.
void dump(raw_ostream &OS) const override
uint32_t getCUCount() const
uint32_t Code
Abbreviation code.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isSentinel(const DWARFDebugNames::AttributeEncoding &AE)
LLVM Value Representation.
Lightweight error class with error context and mandatory checking.
This class implements an extremely fast bulk output stream that can only output to a stream...
Optional< dwarf::Tag > getTag() const override
Returns the Tag of the Debug Info Entry associated with this Accelerator Entry or None if the Tag is ...
StringRef - Represent a constant reference to a string, i.e.
Marker as the end of a list of atoms.
for(unsigned i=Desc.getNumOperands(), e=OldMI.getNumOperands();i !=e;++i)
iterator_range< ValueIterator > equal_range(StringRef Key) const
Look up all entries in this Name Index matching Key.
uint64_t getStringOffset() const
Returns the offset of the name of the described entities.
DataExtractor StringSection
uint32_t getHeaderDataLength()
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...