diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h @@ -27,12 +27,15 @@ class DWARFAbbreviationDeclaration { public: struct AttributeSpec { - AttributeSpec(dwarf::Attribute A, dwarf::Form F, int64_t Value) - : Attr(A), Form(F), Value(Value) { + AttributeSpec(dwarf::Attribute A, dwarf::Form F, int64_t Value, + uint32_t AttrOffset = -1U, uint32_t FormOffset = -1U) + : Attr(A), Form(F), AttrOffset(AttrOffset), FormOffset(FormOffset), + Value(Value) { assert(isImplicitConst()); } - AttributeSpec(dwarf::Attribute A, dwarf::Form F, Optional ByteSize) - : Attr(A), Form(F) { + AttributeSpec(dwarf::Attribute A, dwarf::Form F, Optional ByteSize, + uint32_t AttrOffset = -1U, uint32_t FormOffset = -1U) + : Attr(A), Form(F), AttrOffset(AttrOffset), FormOffset(FormOffset) { assert(!isImplicitConst()); this->ByteSize.HasByteSize = ByteSize.hasValue(); if (this->ByteSize.HasByteSize) @@ -41,6 +44,8 @@ dwarf::Attribute Attr; dwarf::Form Form; + uint32_t AttrOffset; + uint32_t FormOffset; private: /// The following field is used for ByteSize for non-implicit_const @@ -121,6 +126,8 @@ return AttributeSpecs[idx].getImplicitConstValue(); } + const AttributeSpec *findAttribute(dwarf::Attribute Attr) const; + /// Get the index of the specified attribute. /// /// Searches the this abbreviation declaration for the index of the specified diff --git a/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp b/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp @@ -60,13 +60,15 @@ // Read all of the abbreviation attributes and forms. while (true) { + uint32_t AOff = *OffsetPtr; auto A = static_cast(Data.getULEB128(OffsetPtr)); + uint32_t FOff = *OffsetPtr; auto F = static_cast
(Data.getULEB128(OffsetPtr)); if (A && F) { bool IsImplicitConst = (F == DW_FORM_implicit_const); if (IsImplicitConst) { int64_t V = Data.getSLEB128(OffsetPtr); - AttributeSpecs.push_back(AttributeSpec(A, F, V)); + AttributeSpecs.push_back(AttributeSpec(A, F, V, AOff, FOff)); continue; } Optional ByteSize; @@ -108,7 +110,7 @@ break; } // Record this attribute and its fixed size if it has one. - AttributeSpecs.push_back(AttributeSpec(A, F, ByteSize)); + AttributeSpecs.push_back(AttributeSpec(A, F, ByteSize, AOff, FOff)); } else if (A == 0 && F == 0) { // We successfully reached the end of this abbreviation declaration // since both attribute and form are zero. @@ -138,6 +140,15 @@ OS << '\n'; } +const DWARFAbbreviationDeclaration::AttributeSpec * +DWARFAbbreviationDeclaration::findAttribute(dwarf::Attribute Attr) const { + for (uint32_t I = 0, E = AttributeSpecs.size(); I != E; ++I) { + if (AttributeSpecs[I].Attr == Attr) + return &AttributeSpecs[I]; + } + return nullptr; +} + Optional DWARFAbbreviationDeclaration::findAttributeIndex(dwarf::Attribute Attr) const { for (uint32_t i = 0, e = AttributeSpecs.size(); i != e; ++i) {