36 return OS <<
"DW_ATOM_unknown_" <<
format(
"%x", A.Value);
48 if (!AccelSection.isValidOffset(
offsetof(Header, HeaderDataLength)+4))
49 return make_error<StringError>(
"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))
65 return make_error<StringError>(
66 "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;
89 ArrayRef<std::pair<AppleAcceleratorTable::HeaderData::AtomType,
96 for (
auto Atom : getAtomsDesc()) {
104 FormValue.
getForm() == dwarf::DW_FORM_sdata)
114 std::pair<uint32_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:
169 if (!AccelSection.isValidOffsetForDataOfSize(*DataOffset, 4)) {
173 unsigned 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) {
227 unsigned HashesBase = Offset + Hdr.BucketCount * 4;
228 unsigned 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 unsigned HashOffset = HashesBase + HashIdx*4;
241 unsigned OffsetsOffset = OffsetsBase + HashIdx*4;
242 uint32_t Hash = AccelSection.getU32(&HashOffset);
244 if (Hash % Hdr.BucketCount != Bucket)
247 unsigned 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 (
const 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 unsigned BucketBase =
sizeof(Hdr) + Hdr.HeaderDataLength;
337 unsigned HashesBase = BucketBase + Hdr.BucketCount * 4;
338 unsigned OffsetsBase = HashesBase + Hdr.HashCount * 4;
340 unsigned BucketOffset = BucketBase + Bucket * 4;
344 for (
unsigned HashIdx =
Index; HashIdx < Hdr.HashCount; ++HashIdx) {
345 unsigned HashOffset = HashesBase + HashIdx * 4;
346 unsigned 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";
383 return make_error<StringError>(
"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);
398 return make_error<StringError>(
399 "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(
uint32_t *Offset) {
441 if (*Offset >= EntriesBase) {
442 return make_error<StringError>(
"Incorrectly terminated abbreviation table.",
452 DWARFDebugNames::NameIndex::extractAttributeEncodings(
uint32_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(
uint32_t *Offset) {
467 if (*Offset >= EntriesBase) {
468 return make_error<StringError>(
"Incorrectly terminated abbreviation table.",
477 auto AttrEncOr = extractAttributeEncodings(Offset);
479 return AttrEncOr.takeError();
480 return Abbrev(Code,
dwarf::Tag(Tag), std::move(*AttrEncOr));
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;
504 return make_error<StringError>(
505 "Section too small: cannot read abbreviations.",
508 EntriesBase = Offset + Hdr.AbbrevTableSize;
511 auto AbbrevOr = extractAbbrev(&Offset);
513 return AbbrevOr.takeError();
517 if (!Abbrevs.insert(std::move(*AbbrevOr)).second) {
518 return make_error<StringError>(
"Duplicate abbreviation code.",
524 : NameIdx(&NameIdx), Abbr(&Abbr) {
529 Values.emplace_back(Attr.Form);
536 if (std::get<0>(Tuple).Index ==
Index)
537 return std::get<1>(Tuple);
544 return Off->getAsReferenceUVal();
550 return Off->getAsUnsignedConstant();
560 if (!Index || *Index >= NameIdx->
getCUCount())
582 assert(CU < Hdr.CompUnitCount);
584 return Section.AccelSection.getRelocatedValue(4, &Offset);
588 assert(TU < Hdr.LocalTypeUnitCount);
589 uint32_t Offset = CUsBase + Hdr.CompUnitCount * 4;
590 return Section.AccelSection.getRelocatedValue(4, &Offset);
594 assert(TU < Hdr.ForeignTypeUnitCount);
595 uint32_t Offset = CUsBase + (Hdr.CompUnitCount + Hdr.LocalTypeUnitCount) * 4;
596 return Section.AccelSection.getU64(&Offset);
603 return make_error<StringError>(
"Incorrectly terminated entry list.",
608 return make_error<SentinelError>();
610 const auto AbbrevIt = Abbrevs.find_as(AbbrevCode);
611 if (AbbrevIt == Abbrevs.end())
612 return make_error<StringError>(
"Invalid abbreviation.",
615 Entry E(*
this, *AbbrevIt);
618 for (
auto &Value : E.
Values) {
619 if (!Value.extractValue(AS, Offset, FormParams))
620 return make_error<StringError>(
"Error extracting index attribute values.",
628 assert(0 < Index && Index <= Hdr.NameCount);
629 uint32_t StringOffsetOffset = StringOffsetsBase + 4 * (Index - 1);
630 uint32_t EntryOffsetOffset = EntryOffsetsBase + 4 * (Index - 1);
633 uint32_t StringOffset = AS.getRelocatedValue(4, &StringOffsetOffset);
634 uint32_t EntryOffset = AS.getU32(&EntryOffsetOffset);
635 EntryOffset += EntriesBase;
636 return {
Section.StringSection,
Index, StringOffset, EntryOffset};
641 assert(Bucket < Hdr.BucketCount);
642 uint32_t BucketOffset = BucketsBase + 4 * Bucket;
643 return Section.AccelSection.getU32(&BucketOffset);
647 assert(0 < Index && Index <= Hdr.NameCount);
648 uint32_t HashOffset = HashesBase + 4 * (Index - 1);
649 return Section.AccelSection.getU32(&HashOffset);
659 auto EntryOr = getEntry(Offset);
682 while (dumpEntry(W, &EntryOffset))
686 void DWARFDebugNames::NameIndex::dumpCUs(
ScopedPrinter &W)
const {
687 ListScope CUScope(W,
"Compilation Unit offsets");
692 void DWARFDebugNames::NameIndex::dumpLocalTUs(
ScopedPrinter &W)
const {
693 if (Hdr.LocalTypeUnitCount == 0)
696 ListScope TUScope(W,
"Local Type Unit offsets");
697 for (
uint32_t TU = 0; TU < Hdr.LocalTypeUnitCount; ++TU)
698 W.
startLine() <<
format(
"LocalTU[%u]: 0x%08x\n", TU, 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 push_back(const T &Elt)
uint32_t getEntryOffset() const
Returns the offset of the first Entry in the list.
void dump(ScopedPrinter &W) const
uint32_t getNextUnitOffset() 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.
Compute iterated dominance frontiers using a linear time algorithm.
StringRef AtomTypeString(unsigned Atom)
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()
This class holds an abstract representation of an Accelerator Table, consisting of a sequence of buck...
uint32_t getStringOffset() const
Returns the offset of the name of the described entities.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
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)
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
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.
const NameIndex * getCUNameIndex(uint32_t CUOffset)
Return the Name Index covering the compile unit at CUOffset, or nullptr if there is no Name Index cov...
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
llvm::Error extract() override
Tagged union holding either a T or a Error.
Index attribute and its encoding.
static const uint16_t * lookup(unsigned opcode, unsigned domain, ArrayRef< uint16_t[3]> Table)
dwarf::Tag Tag
Dwarf Tag of the described entity.
raw_ostream & getOStream()
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Represents a single accelerator table within the Dwarf 5 .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)
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)
Expected< Entry > getEntry(uint32_t *Offset) const
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.
uint32_t getLocalTUOffset(uint32_t TU) const
Reads offset of local type unit TU, TU is 0-based.
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 5 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.
std::pair< uint32_t, dwarf::Tag > readAtoms(uint32_t &HashDataOffset)
Return information related to the DWARF DIE we're looking for when performing a lookup by name...
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...
void dump(ScopedPrinter &W) const
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.
llvm::Error extract() override
Marker as the end of a list of atoms.
for(unsigned i=Desc.getNumOperands(), e=OldMI.getNumOperands();i !=e;++i)
uint32_t getCUOffset(uint32_t CU) const
Reads offset of compilation unit CU. CU is 0-based.
iterator_range< ValueIterator > equal_range(StringRef Key) const
Look up all entries in this Name Index matching Key.
DataExtractor StringSection
uint32_t getHeaderDataLength()
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...