Index: include/llvm/DebugInfo/DWARF/DWARFDie.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFDie.h +++ include/llvm/DebugInfo/DWARF/DWARFDie.h @@ -123,76 +123,9 @@ /// \param Attr the attribute to extract. /// \returns an optional DWARFFormValue that will have the form value if the /// attribute was successfully extracted. - Optional getAttributeValue(dwarf::Attribute Attr) const; - - /// Extract the specified attribute from this DIE as a C string. - /// - /// Extract an attribute value from this DIE only. This call doesn't look - /// for the attribute value in any DW_AT_specification or - /// DW_AT_abstract_origin referenced DIEs. - /// - /// \param Attr the attribute to extract. - /// \param FailValue the value to return if this DIE doesn't have this - /// attribute. - /// \returns the NULL terminated C string value owned by the DWARF section - /// that contains the string or FailValue if the attribute doesn't exist or - /// if the attribute's form isn't a form that describes an string. - const char *getAttributeValueAsString(dwarf::Attribute Attr, - const char *FailValue) const; - - /// Extract the specified attribute from this DIE as an address. - /// - /// Extract an attribute value from this DIE only. This call doesn't look - /// for the attribute value in any DW_AT_specification or - /// DW_AT_abstract_origin referenced DIEs. - /// - /// \param Attr the attribute to extract. - /// \returns an optional value for the attribute. - Optional getAttributeValueAsAddress(dwarf::Attribute Attr) const; - - /// Extract the specified attribute from this DIE as a signed integer. - /// - /// Extract an attribute value from this DIE only. This call doesn't look - /// for the attribute value in any DW_AT_specification or - /// DW_AT_abstract_origin referenced DIEs. - /// - /// \param Attr the attribute to extract. - /// \returns an optional value for the attribute. - Optional - getAttributeValueAsSignedConstant(dwarf::Attribute Attr) const; - - /// Extract the specified attribute from this DIE as an unsigned integer. - /// - /// Extract an attribute value from this DIE only. This call doesn't look - /// for the attribute value in any DW_AT_specification or - /// DW_AT_abstract_origin referenced DIEs. - /// - /// \param Attr the attribute to extract. - /// \returns an optional value for the attribute. - Optional - getAttributeValueAsUnsignedConstant(dwarf::Attribute Attr) const; + DWARFFormValue find(dwarf::Attribute Attr) const; + DWARFFormValue findRecursively(dwarf::Attribute Attr) const; - /// Extract the specified attribute from this DIE as absolute DIE Offset. - /// - /// Extract an attribute value from this DIE only. This call doesn't look - /// for the attribute value in any DW_AT_specification or - /// DW_AT_abstract_origin referenced DIEs. - /// - /// \param Attr the attribute to extract. - /// \returns an optional value for the attribute. - Optional getAttributeValueAsReference(dwarf::Attribute Attr) const; - - /// Extract the specified attribute from this DIE as absolute section offset. - /// - /// Extract an attribute value from this DIE only. This call doesn't look - /// for the attribute value in any DW_AT_specification or - /// DW_AT_abstract_origin referenced DIEs. - /// - /// \param Attr the attribute to extract. - /// \returns an optional value for the attribute. - Optional - getAttributeValueAsSectionOffset(dwarf::Attribute Attr) const; - /// Extract the specified attribute from this DIE as the referenced DIE. /// /// Regardless of the reference type, return the correct DWARFDie instance if @@ -207,6 +140,7 @@ /// \returns a valid DWARFDie instance if the attribute exists, or an invalid /// DWARFDie object if it doesn't. DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const; + /// Extract the range base attribute from this DIE as absolute section offset. /// Index: include/llvm/DebugInfo/DWARF/DWARFFormValue.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFFormValue.h +++ include/llvm/DebugInfo/DWARF/DWARFFormValue.h @@ -50,16 +50,19 @@ }; dwarf::Form Form; // Form for this value. + bool Valid; ValueType Value; // Contains all data for the form. const DWARFUnit *U; // Remember the DWARFUnit at extract time. public: - DWARFFormValue(dwarf::Form F = dwarf::Form(0)) : Form(F), U(nullptr) {} + DWARFFormValue(dwarf::Form F = dwarf::Form(0)) : Form(F), Valid(false), U(nullptr) {} + bool isValid() const { return Valid; } + operator bool() const { return Valid; } dwarf::Form getForm() const { return Form; } - void setForm(dwarf::Form F) { Form = F; } - void setUValue(uint64_t V) { Value.uval = V; } - void setSValue(int64_t V) { Value.sval = V; } - void setPValue(const char *V) { Value.cstr = V; } + void setForm(dwarf::Form F) { Valid = Form == F; Form = F;} + void setUValue(uint64_t V) { Value.uval = V; Valid = true; } + void setSValue(int64_t V) { Value.sval = V; Valid = true; } + void setPValue(const char *V) { Value.cstr = V; Valid = true; } bool isFormClass(FormClass FC) const; const DWARFUnit *getUnit() const { return U; } void dump(raw_ostream &OS) const; Index: lib/DebugInfo/DWARF/DWARFContext.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFContext.cpp +++ lib/DebugInfo/DWARF/DWARFContext.cpp @@ -127,8 +127,7 @@ auto CUDIE = CU->getUnitDIE(); if (!CUDIE) continue; - if (auto StmtOffset = - CUDIE.getAttributeValueAsSectionOffset(DW_AT_stmt_list)) { + if (auto StmtOffset = CUDIE.find(DW_AT_stmt_list).getAsSectionOffset()) { DataExtractor lineData(getLineSection().Data, isLittleEndian(), savedAddressByteSize); DWARFDebugLine::LineTable LineTable; @@ -386,7 +385,7 @@ if (!UnitDIE) return nullptr; - auto Offset = UnitDIE.getAttributeValueAsSectionOffset(DW_AT_stmt_list); + auto Offset = UnitDIE.find(DW_AT_stmt_list).getAsSectionOffset(); if (!Offset) return nullptr; // No line table for this compile unit. Index: lib/DebugInfo/DWARF/DWARFDie.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFDie.cpp +++ lib/DebugInfo/DWARF/DWARFDie.cpp @@ -133,64 +133,35 @@ return Tag == DW_TAG_subprogram || Tag == DW_TAG_inlined_subroutine; } -Optional -DWARFDie::getAttributeValue(dwarf::Attribute Attr) const { +DWARFFormValue +DWARFDie::find(dwarf::Attribute Attr) const { if (!isValid()) - return None; + return DWARFFormValue(); auto AbbrevDecl = getAbbreviationDeclarationPtr(); if (AbbrevDecl) - return AbbrevDecl->getAttributeValue(getOffset(), Attr, *U); - return None; + if (auto FormValueOpt = AbbrevDecl->getAttributeValue(getOffset(), Attr, *U)) + return *FormValueOpt; + return DWARFFormValue(); } -const char *DWARFDie::getAttributeValueAsString(dwarf::Attribute Attr, - const char *FailValue) const { - auto FormValue = getAttributeValue(Attr); - if (!FormValue) - return FailValue; - Optional Result = FormValue->getAsCString(); - return Result.hasValue() ? Result.getValue() : FailValue; +DWARFFormValue +DWARFDie::findRecursively(dwarf::Attribute Attr) const { + if (!isValid()) + return DWARFFormValue(); + if (auto Value = find(Attr)) + return Value; + if (auto Die = getAttributeValueAsReferencedDie(DW_AT_abstract_origin)) + if (auto Value = Die.find(Attr)) + return Value; + if (auto Die = getAttributeValueAsReferencedDie(DW_AT_specification)) + if (auto Value = Die.find(Attr)) + return Value; + return DWARFFormValue(); } -Optional -DWARFDie::getAttributeValueAsAddress(dwarf::Attribute Attr) const { - if (auto FormValue = getAttributeValue(Attr)) - return FormValue->getAsAddress(); - return None; -} - -Optional -DWARFDie::getAttributeValueAsSignedConstant(dwarf::Attribute Attr) const { - if (auto FormValue = getAttributeValue(Attr)) - return FormValue->getAsSignedConstant(); - return None; -} - -Optional -DWARFDie::getAttributeValueAsUnsignedConstant(dwarf::Attribute Attr) const { - if (auto FormValue = getAttributeValue(Attr)) - return FormValue->getAsUnsignedConstant(); - return None; -} - -Optional -DWARFDie::getAttributeValueAsReference(dwarf::Attribute Attr) const { - if (auto FormValue = getAttributeValue(Attr)) - return FormValue->getAsReference(); - return None; -} - -Optional -DWARFDie::getAttributeValueAsSectionOffset(dwarf::Attribute Attr) const { - if (auto FormValue = getAttributeValue(Attr)) - return FormValue->getAsSectionOffset(); - return None; -} - - DWARFDie DWARFDie::getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const { - auto SpecRef = getAttributeValueAsReference(Attr); + auto SpecRef = find(Attr).getAsReference(); if (SpecRef) { auto SpecUnit = U->getUnitSection().getUnitForOffset(*SpecRef); if (SpecUnit) @@ -201,19 +172,19 @@ Optional DWARFDie::getRangesBaseAttribute() const { - auto Result = getAttributeValueAsSectionOffset(DW_AT_rnglists_base); + auto Result = find(DW_AT_rnglists_base).getAsSectionOffset(); if (Result) return Result; - return getAttributeValueAsSectionOffset(DW_AT_GNU_ranges_base); + return find(DW_AT_GNU_ranges_base).getAsSectionOffset(); } Optional DWARFDie::getHighPC(uint64_t LowPC) const { - if (auto FormValue = getAttributeValue(DW_AT_high_pc)) { - if (auto Address = FormValue->getAsAddress()) { + if (auto FormValue = find(DW_AT_high_pc)) { + if (auto Address = FormValue.getAsAddress()) { // High PC is an address. return Address; } - if (auto Offset = FormValue->getAsUnsignedConstant()) { + if (auto Offset = FormValue.getAsUnsignedConstant()) { // High PC is an offset from LowPC. return LowPC + *Offset; } @@ -222,7 +193,7 @@ } bool DWARFDie::getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC) const { - auto LowPcAddr = getAttributeValueAsAddress(DW_AT_low_pc); + auto LowPcAddr = find(DW_AT_low_pc).getAsAddress(); if (!LowPcAddr) return false; if (auto HighPcAddr = getHighPC(*LowPcAddr)) { @@ -243,7 +214,7 @@ return DWARFAddressRangesVector(1, std::make_pair(LowPC, HighPC)); } // Multiple ranges from .debug_ranges section. - auto RangesOffset = getAttributeValueAsSectionOffset(DW_AT_ranges); + auto RangesOffset = find(DW_AT_ranges).getAsSectionOffset(); if (RangesOffset) { DWARFDebugRangeList RangeList; if (U->extractRangeList(*RangesOffset, RangeList)) @@ -284,33 +255,24 @@ DWARFDie::getName(DINameKind Kind) const { if (!isValid() || Kind == DINameKind::None) return nullptr; - const char *name = nullptr; + Optional Name; // Try to get mangled name only if it was asked for. if (Kind == DINameKind::LinkageName) { - if ((name = getAttributeValueAsString(DW_AT_MIPS_linkage_name, nullptr))) - return name; - if ((name = getAttributeValueAsString(DW_AT_linkage_name, nullptr))) - return name; + if ((Name = findRecursively(DW_AT_MIPS_linkage_name).getAsCString())) + return *Name; + if ((Name = findRecursively(DW_AT_linkage_name).getAsCString())) + return *Name; } - if ((name = getAttributeValueAsString(DW_AT_name, nullptr))) - return name; - // Try to get name from specification DIE. - DWARFDie SpecDie = getAttributeValueAsReferencedDie(DW_AT_specification); - if (SpecDie && (name = SpecDie.getName(Kind))) - return name; - // Try to get name from abstract origin DIE. - DWARFDie AbsDie = getAttributeValueAsReferencedDie(DW_AT_abstract_origin); - if (AbsDie && (name = AbsDie.getName(Kind))) - return name; + if ((Name = findRecursively(DW_AT_name).getAsCString())) + return *Name; return nullptr; } void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine, uint32_t &CallColumn) const { - CallFile = getAttributeValueAsUnsignedConstant(DW_AT_call_file).getValueOr(0); - CallLine = getAttributeValueAsUnsignedConstant(DW_AT_call_line).getValueOr(0); - CallColumn = - getAttributeValueAsUnsignedConstant(DW_AT_call_column).getValueOr(0); + CallFile = find(DW_AT_call_file).getAsUnsignedConstant().getValueOr(0); + CallLine = find(DW_AT_call_line).getAsUnsignedConstant().getValueOr(0); + CallColumn = find(DW_AT_call_column).getAsUnsignedConstant().getValueOr(0); } void DWARFDie::dump(raw_ostream &OS, unsigned RecurseDepth, Index: lib/DebugInfo/DWARF/DWARFFormValue.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFFormValue.cpp +++ lib/DebugInfo/DWARF/DWARFFormValue.cpp @@ -299,6 +299,7 @@ bool indirect = false; bool is_block = false; Value.data = nullptr; + Valid = false; // Read the value for the form into value and follow and DW_FORM_indirect // instances we run into do { @@ -412,7 +413,7 @@ *offset_ptr += Value.uval; } } - + Valid = true; return true; } @@ -572,7 +573,7 @@ } Optional DWARFFormValue::getAsCString() const { - if (!isFormClass(FC_String)) + if (!isValid() || !isFormClass(FC_String)) return None; if (Form == DW_FORM_string) return Value.cstr; @@ -593,7 +594,7 @@ } Optional DWARFFormValue::getAsAddress() const { - if (!isFormClass(FC_Address)) + if (!isValid() || !isFormClass(FC_Address)) return None; if (Form == DW_FORM_GNU_addr_index) { uint32_t Index = Value.uval; @@ -606,7 +607,7 @@ } Optional DWARFFormValue::getAsReference() const { - if (!isFormClass(FC_Reference)) + if (!isValid() || !isFormClass(FC_Reference)) return None; switch (Form) { case DW_FORM_ref1: @@ -627,20 +628,20 @@ } Optional DWARFFormValue::getAsSectionOffset() const { - if (!isFormClass(FC_SectionOffset)) + if (!isValid() || !isFormClass(FC_SectionOffset)) return None; return Value.uval; } Optional DWARFFormValue::getAsUnsignedConstant() const { - if ((!isFormClass(FC_Constant) && !isFormClass(FC_Flag)) + if (!isValid() || (!isFormClass(FC_Constant) && !isFormClass(FC_Flag)) || Form == DW_FORM_sdata) return None; return Value.uval; } Optional DWARFFormValue::getAsSignedConstant() const { - if ((!isFormClass(FC_Constant) && !isFormClass(FC_Flag)) || + if (!isValid() || (!isFormClass(FC_Constant) && !isFormClass(FC_Flag)) || (Form == DW_FORM_udata && uint64_t(std::numeric_limits::max()) < Value.uval)) return None; switch (Form) { @@ -658,19 +659,19 @@ } Optional> DWARFFormValue::getAsBlock() const { - if (!isFormClass(FC_Block) && !isFormClass(FC_Exprloc)) + if (!isValid() || !isFormClass(FC_Block) && !isFormClass(FC_Exprloc)) return None; return makeArrayRef(Value.data, Value.uval); } Optional DWARFFormValue::getAsCStringOffset() const { - if (!isFormClass(FC_String) && Form == DW_FORM_string) + if (!isValid() || !isFormClass(FC_String) && Form == DW_FORM_string) return None; return Value.uval; } Optional DWARFFormValue::getAsReferenceUVal() const { - if (!isFormClass(FC_Reference)) + if (!isValid() || !isFormClass(FC_Reference)) return None; return Value.uval; } Index: lib/DebugInfo/DWARF/DWARFTypeUnit.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFTypeUnit.cpp +++ lib/DebugInfo/DWARF/DWARFTypeUnit.cpp @@ -26,7 +26,7 @@ void DWARFTypeUnit::dump(raw_ostream &OS, bool SummarizeTypes) { DWARFDie TD = getDIEForOffset(TypeOffset + getOffset()); - const char *Name = TD.getAttributeValueAsString(llvm::dwarf::DW_AT_name, ""); + const char *Name = TD.find(llvm::dwarf::DW_AT_name).getAsCString().getValueOr(""); if (SummarizeTypes) { OS << "name = '" << Name << "'" Index: lib/DebugInfo/DWARF/DWARFUnit.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFUnit.cpp +++ lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -13,6 +13,7 @@ #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h" +#include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/DebugInfo/DWARF/DWARFUnit.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/Casting.h" @@ -151,11 +152,11 @@ } const char *DWARFUnit::getCompilationDir() { - return getUnitDIE().getAttributeValueAsString(DW_AT_comp_dir, nullptr); + return getUnitDIE().find(DW_AT_comp_dir).getAsCString().getValueOr(nullptr); } Optional DWARFUnit::getDWOId() { - return getUnitDIE().getAttributeValueAsUnsignedConstant(DW_AT_GNU_dwo_id); + return getUnitDIE().find(DW_AT_GNU_dwo_id).getAsUnsignedConstant(); } void DWARFUnit::extractDIEsToVector( @@ -225,17 +226,15 @@ // If CU DIE was just parsed, copy several attribute values from it. if (!HasCUDie) { DWARFDie UnitDie = getUnitDIE(); - auto BaseAddr = UnitDie.getAttributeValueAsAddress(DW_AT_low_pc); + auto BaseAddr = UnitDie.find(DW_AT_low_pc).getAsAddress(); if (!BaseAddr) - BaseAddr = UnitDie.getAttributeValueAsAddress(DW_AT_entry_pc); + BaseAddr = UnitDie.find(DW_AT_entry_pc).getAsAddress(); if (BaseAddr) setBaseAddress(*BaseAddr); AddrOffsetSectionBase = - UnitDie.getAttributeValueAsSectionOffset(DW_AT_GNU_addr_base) - .getValueOr(0); + UnitDie.find(DW_AT_GNU_addr_base).getAsSectionOffset().getValueOr(0); RangeSectionBase = - UnitDie.getAttributeValueAsSectionOffset(DW_AT_rnglists_base) - .getValueOr(0); + UnitDie.find(DW_AT_rnglists_base).getAsSectionOffset().getValueOr(0); // Don't fall back to DW_AT_GNU_ranges_base: it should be ignored for // skeleton CU DIE, so that DWARF users not aware of it are not broken. } @@ -267,11 +266,11 @@ if (!UnitDie) return false; const char *DWOFileName = - UnitDie.getAttributeValueAsString(DW_AT_GNU_dwo_name, nullptr); + UnitDie.find(DW_AT_GNU_dwo_name).getAsCString().getValueOr(nullptr); if (!DWOFileName) return false; const char *CompilationDir = - UnitDie.getAttributeValueAsString(DW_AT_comp_dir, nullptr); + UnitDie.find(DW_AT_comp_dir).getAsCString().getValueOr(nullptr); SmallString<16> AbsolutePath; if (sys::path::is_relative(DWOFileName) && CompilationDir != nullptr) { sys::path::append(AbsolutePath, CompilationDir); Index: tools/dsymutil/DwarfLinker.cpp =================================================================== --- tools/dsymutil/DwarfLinker.cpp +++ tools/dsymutil/DwarfLinker.cpp @@ -206,8 +206,7 @@ auto CUDie = OrigUnit.getUnitDIE(false); unsigned Lang = - CUDie.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_language) - .getValueOr(0); + CUDie.find(dwarf::DW_AT_language).getAsUnsignedConstant().getValueOr(0); HasODR = CanUseODR && (Lang == dwarf::DW_LANG_C_plus_plus || Lang == dwarf::DW_LANG_C_plus_plus_03 || Lang == dwarf::DW_LANG_C_plus_plus_11 || @@ -843,7 +842,7 @@ DWARFUnit &OrigUnit = Unit.getOrigUnit(); auto OrigUnitDie = OrigUnit.getUnitDIE(false); int64_t UnitPcOffset = 0; - auto OrigLowPc = OrigUnitDie.getAttributeValueAsAddress(dwarf::DW_AT_low_pc); + auto OrigLowPc = OrigUnitDie.find(dwarf::DW_AT_low_pc).getAsAddress(); if (OrigLowPc) UnitPcOffset = int64_t(*OrigLowPc) - Unit.getLowPc(); @@ -1558,8 +1557,7 @@ // Do not unique anything inside CU local functions. if ((Context.getTag() == dwarf::DW_TAG_namespace || Context.getTag() == dwarf::DW_TAG_compile_unit) && - !DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_external) - .getValueOr(0)) + !DIE.find(dwarf::DW_AT_external).getAsUnsignedConstant().getValueOr(0)) return PointerIntPair(nullptr); LLVM_FALLTHROUGH; case dwarf::DW_TAG_member: @@ -1573,8 +1571,7 @@ // created on demand. For example implicitely defined constructors // are ambiguous because of the way we identify contexts, and they // won't be generated everytime everywhere. - if (DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_artificial) - .getValueOr(0)) + if (DIE.find(dwarf::DW_AT_artificial).getAsUnsignedConstant().getValueOr(0)) return PointerIntPair(nullptr); break; } @@ -1614,11 +1611,11 @@ // namespaces, use these additional data points to make the process // safer. This is disabled for clang modules, because forward // declarations of module-defined types do not have a file and line. - ByteSize = DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_byte_size) + ByteSize = DIE.find(dwarf::DW_AT_byte_size).getAsUnsignedConstant() .getValueOr(UINT64_MAX); if (Tag != dwarf::DW_TAG_namespace || !Name) { if (unsigned FileNum = - DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_decl_file) + DIE.find(dwarf::DW_AT_decl_file).getAsUnsignedConstant() .getValueOr(0)) { if (const auto *LT = U.getOrigUnit().getContext().getLineTableForUnit( &U.getOrigUnit())) { @@ -1633,7 +1630,7 @@ // it this way to match dsymutil-classic. if (LT->hasFileAtIndex(FileNum)) { Line = - DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_decl_line) + DIE.find(dwarf::DW_AT_decl_line).getAsUnsignedConstant() .getValueOr(0); // Cache the resolved paths, because calling realpath is expansive. StringRef ResolvedPath = U.getResolvedPath(FileNum); @@ -1782,8 +1779,8 @@ // // We treat non-C++ modules like namespaces for this reason. if (DIE.getTag() == dwarf::DW_TAG_module && ParentIdx == 0 && - DIE.getAttributeValueAsString(dwarf::DW_AT_name, - "") != CU.getClangModuleName()) { + DIE.find(dwarf::DW_AT_name).getAsCString().getValueOr("") != + CU.getClangModuleName()) { InImportedModule = true; } @@ -1811,8 +1808,7 @@ // forward declarations. Info.Prune &= (DIE.getTag() == dwarf::DW_TAG_module) || - DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_declaration) - .getValueOr(0); + DIE.find(dwarf::DW_AT_declaration).getAsUnsignedConstant().getValueOr(0); // Don't prune it if there is no definition for the DIE. Info.Prune &= Info.Ctxt && Info.Ctxt->getCanonicalDIEOffset(); @@ -2129,7 +2125,7 @@ std::tie(LowPcOffset, LowPcEndOffset) = getAttributeOffsets(Abbrev, *LowPcIdx, Offset, OrigUnit); - auto LowPc = DIE.getAttributeValueAsAddress(dwarf::DW_AT_low_pc); + auto LowPc = DIE.find(dwarf::DW_AT_low_pc).getAsAddress(); assert(LowPc.hasValue() && "low_pc attribute is not an address."); if (!LowPc || !RelocMgr.hasValidRelocation(LowPcOffset, LowPcEndOffset, MyInfo)) @@ -2747,13 +2743,12 @@ // independantly by the linker). The computation of the actual // high_pc value is done in cloneAddressAttribute(). AttrInfo.OrigHighPc = - InputDIE.getAttributeValueAsAddress(dwarf::DW_AT_high_pc).getValueOr(0); + InputDIE.find(dwarf::DW_AT_high_pc).getAsAddress().getValueOr(0); // Also store the low_pc. It might get relocated in an // inline_subprogram that happens at the beginning of its // inlining function. AttrInfo.OrigLowPc = - InputDIE.getAttributeValueAsAddress(dwarf::DW_AT_low_pc) - .getValueOr(UINT64_MAX); + InputDIE.find(dwarf::DW_AT_low_pc).getAsAddress().getValueOr(UINT64_MAX); } // Reset the Offset to 0 as we will be working on the local copy of @@ -2873,8 +2868,7 @@ DWARFUnit &OrigUnit = Unit.getOrigUnit(); auto OrigUnitDie = OrigUnit.getUnitDIE(false); uint64_t OrigLowPc = - OrigUnitDie.getAttributeValueAsAddress(dwarf::DW_AT_low_pc) - .getValueOr(-1ULL); + OrigUnitDie.find(dwarf::DW_AT_low_pc).getAsAddress().getValueOr(-1ULL); // Ranges addresses are based on the unit's low_pc. Compute the // offset we need to apply to adapt to the new unit's low_pc. int64_t UnitPcOffset = 0; @@ -2969,7 +2963,7 @@ void DwarfLinker::patchLineTableForUnit(CompileUnit &Unit, DWARFContext &OrigDwarf) { DWARFDie CUDie = Unit.getOrigUnit().getUnitDIE(); - auto StmtList = CUDie.getAttributeValueAsSectionOffset(dwarf::DW_AT_stmt_list); + auto StmtList = CUDie.find(dwarf::DW_AT_stmt_list).getAsSectionOffset(); if (!StmtList) return; @@ -3201,10 +3195,10 @@ static uint64_t getDwoId(const DWARFDie &CUDie, const DWARFUnit &Unit) { - auto DwoId = CUDie.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_dwo_id); + auto DwoId = CUDie.find(dwarf::DW_AT_dwo_id).getAsUnsignedConstant(); if (DwoId) return *DwoId; - DwoId = CUDie.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_GNU_dwo_id); + DwoId = CUDie.find(dwarf::DW_AT_GNU_dwo_id).getAsUnsignedConstant(); if (DwoId) return *DwoId; return 0; @@ -3214,20 +3208,20 @@ const DWARFDie &CUDie, const DWARFUnit &Unit, DebugMap &ModuleMap, unsigned Indent) { std::string PCMfile = - CUDie.getAttributeValueAsString(dwarf::DW_AT_dwo_name, ""); + CUDie.find(dwarf::DW_AT_dwo_name).getAsCString().getValueOr(""); if (PCMfile.empty()) PCMfile = - CUDie.getAttributeValueAsString(dwarf::DW_AT_GNU_dwo_name, ""); + CUDie.find(dwarf::DW_AT_GNU_dwo_name).getAsCString().getValueOr(""); if (PCMfile.empty()) return false; // Clang module DWARF skeleton CUs abuse this for the path to the module. std::string PCMpath = - CUDie.getAttributeValueAsString(dwarf::DW_AT_comp_dir, ""); + CUDie.find(dwarf::DW_AT_comp_dir).getAsCString().getValueOr(""); uint64_t DwoId = getDwoId(CUDie, Unit); std::string Name = - CUDie.getAttributeValueAsString(dwarf::DW_AT_name, ""); + CUDie.find(dwarf::DW_AT_name).getAsCString().getValueOr(""); if (Name.empty()) { reportWarning("Anonymous module skeleton CU for " + PCMfile); return true; Index: tools/obj2yaml/dwarf2yaml.cpp =================================================================== --- tools/obj2yaml/dwarf2yaml.cpp +++ tools/obj2yaml/dwarf2yaml.cpp @@ -126,17 +126,17 @@ DWARFYAML::FormValue NewValue; NewValue.Value = 0xDEADBEEFDEADBEEF; DWARFDie DIEWrapper(CU.get(), &DIE); - auto FormValue = DIEWrapper.getAttributeValue(AttrSpec.Attr); + auto FormValue = DIEWrapper.find(AttrSpec.Attr); if (!FormValue) return; - auto Form = FormValue.getValue().getForm(); + auto Form = FormValue.getForm(); bool indirect = false; do { indirect = false; switch (Form) { case dwarf::DW_FORM_addr: case dwarf::DW_FORM_GNU_addr_index: - if (auto Val = FormValue.getValue().getAsAddress()) + if (auto Val = FormValue.getAsAddress()) NewValue.Value = Val.getValue(); break; case dwarf::DW_FORM_ref_addr: @@ -146,7 +146,7 @@ case dwarf::DW_FORM_ref8: case dwarf::DW_FORM_ref_udata: case dwarf::DW_FORM_ref_sig8: - if (auto Val = FormValue.getValue().getAsReferenceUVal()) + if (auto Val = FormValue.getAsReferenceUVal()) NewValue.Value = Val.getValue(); break; case dwarf::DW_FORM_exprloc: @@ -154,7 +154,7 @@ case dwarf::DW_FORM_block1: case dwarf::DW_FORM_block2: case dwarf::DW_FORM_block4: - if (auto Val = FormValue.getValue().getAsBlock()) { + if (auto Val = FormValue.getAsBlock()) { auto BlockData = Val.getValue(); std::copy(BlockData.begin(), BlockData.end(), std::back_inserter(NewValue.BlockData)); @@ -168,16 +168,16 @@ case dwarf::DW_FORM_data8: case dwarf::DW_FORM_sdata: case dwarf::DW_FORM_udata: - if (auto Val = FormValue.getValue().getAsUnsignedConstant()) + if (auto Val = FormValue.getAsUnsignedConstant()) NewValue.Value = Val.getValue(); break; case dwarf::DW_FORM_string: - if (auto Val = FormValue.getValue().getAsCString()) + if (auto Val = FormValue.getAsCString()) NewValue.CStr = Val.getValue(); break; case dwarf::DW_FORM_indirect: indirect = true; - if (auto Val = FormValue.getValue().getAsUnsignedConstant()) { + if (auto Val = FormValue.getAsUnsignedConstant()) { NewValue.Value = Val.getValue(); NewEntry.Values.push_back(NewValue); Form = static_cast(Val.getValue()); @@ -191,7 +191,7 @@ case dwarf::DW_FORM_strp_sup: case dwarf::DW_FORM_ref_sup: case dwarf::DW_FORM_GNU_str_index: - if (auto Val = FormValue.getValue().getAsCStringOffset()) + if (auto Val = FormValue.getAsCStringOffset()) NewValue.Value = Val.getValue(); break; case dwarf::DW_FORM_flag_present: @@ -228,7 +228,7 @@ if (!CUDIE) continue; if (auto StmtOffset = - CUDIE.getAttributeValueAsSectionOffset(dwarf::DW_AT_stmt_list)) { + CUDIE.find(dwarf::DW_AT_stmt_list).getAsSectionOffset()) { DWARFYAML::LineTable DebugLines; DataExtractor LineData(DCtx.getLineSection().Data, DCtx.isLittleEndian(), CU->getAddressByteSize()); Index: unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp =================================================================== --- unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp +++ unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp @@ -228,7 +228,7 @@ //---------------------------------------------------------------------- // Test address forms //---------------------------------------------------------------------- - EXPECT_EQ(DieDG.getAttributeValueAsAddress(Attr_DW_FORM_addr).getValueOr(0), + EXPECT_EQ(DieDG.find(Attr_DW_FORM_addr).getAsAddress().getValueOr(0), AddrValue); //---------------------------------------------------------------------- @@ -238,7 +238,7 @@ ArrayRef ExtractedBlockData; Optional> BlockDataOpt; - FormValue = DieDG.getAttributeValue(Attr_DW_FORM_block); + FormValue = DieDG.find(Attr_DW_FORM_block); EXPECT_TRUE((bool)FormValue); BlockDataOpt = FormValue->getAsBlock(); EXPECT_TRUE(BlockDataOpt.hasValue()); @@ -246,7 +246,7 @@ EXPECT_EQ(ExtractedBlockData.size(), BlockSize); EXPECT_TRUE(memcmp(ExtractedBlockData.data(), BlockData, BlockSize) == 0); - FormValue = DieDG.getAttributeValue(Attr_DW_FORM_block1); + FormValue = DieDG.find(Attr_DW_FORM_block1); EXPECT_TRUE((bool)FormValue); BlockDataOpt = FormValue->getAsBlock(); EXPECT_TRUE(BlockDataOpt.hasValue()); @@ -254,7 +254,7 @@ EXPECT_EQ(ExtractedBlockData.size(), BlockSize); EXPECT_TRUE(memcmp(ExtractedBlockData.data(), BlockData, BlockSize) == 0); - FormValue = DieDG.getAttributeValue(Attr_DW_FORM_block2); + FormValue = DieDG.find(Attr_DW_FORM_block2); EXPECT_TRUE((bool)FormValue); BlockDataOpt = FormValue->getAsBlock(); EXPECT_TRUE(BlockDataOpt.hasValue()); @@ -262,7 +262,7 @@ EXPECT_EQ(ExtractedBlockData.size(), BlockSize); EXPECT_TRUE(memcmp(ExtractedBlockData.data(), BlockData, BlockSize) == 0); - FormValue = DieDG.getAttributeValue(Attr_DW_FORM_block4); + FormValue = DieDG.find(Attr_DW_FORM_block4); EXPECT_TRUE((bool)FormValue); BlockDataOpt = FormValue->getAsBlock(); EXPECT_TRUE(BlockDataOpt.hasValue()); @@ -273,29 +273,25 @@ //---------------------------------------------------------------------- // Test data forms //---------------------------------------------------------------------- - EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data1) - .getValueOr(0), + EXPECT_EQ(DieDG.find(Attr_DW_FORM_data1).getAsUnsignedConstant().getValueOr(0), Data1); - EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data2) - .getValueOr(0), + EXPECT_EQ(DieDG.find(Attr_DW_FORM_data2).getAsUnsignedConstant().getValueOr(0), Data2); - EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data4) - .getValueOr(0), + EXPECT_EQ(DieDG.find(Attr_DW_FORM_data4).getAsUnsignedConstant().getValueOr(0), Data4); - EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data8) - .getValueOr(0), + EXPECT_EQ(DieDG.find(Attr_DW_FORM_data8).getAsUnsignedConstant().getValueOr(0), Data8); //---------------------------------------------------------------------- // Test string forms //---------------------------------------------------------------------- const char *ExtractedStringValue = - DieDG.getAttributeValueAsString(Attr_DW_FORM_string, nullptr); + DieDG.find(Attr_DW_FORM_string).getAsCString().getValueOr(nullptr); EXPECT_TRUE(ExtractedStringValue != nullptr); EXPECT_TRUE(strcmp(StringValue, ExtractedStringValue) == 0); const char *ExtractedStrpValue = - DieDG.getAttributeValueAsString(Attr_DW_FORM_strp, nullptr); + DieDG.find(Attr_DW_FORM_strp).getAsCString().getValueOr(nullptr); EXPECT_TRUE(ExtractedStrpValue != nullptr); EXPECT_TRUE(strcmp(StrpValue, ExtractedStrpValue) == 0); @@ -303,69 +299,64 @@ // Test reference forms //---------------------------------------------------------------------- EXPECT_EQ( - DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref_addr).getValueOr(0), + DieDG.find(Attr_DW_FORM_ref_addr).getAsReference().getValueOr(0), RefAddr); - EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref1).getValueOr(0), + EXPECT_EQ(DieDG.find(Attr_DW_FORM_ref1).getAsReference().getValueOr(0), Data1); - EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref2).getValueOr(0), + EXPECT_EQ(DieDG.find(Attr_DW_FORM_ref2).getAsReference().getValueOr(0), Data2); - EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref4).getValueOr(0), + EXPECT_EQ(DieDG.find(Attr_DW_FORM_ref4).getAsReference().getValueOr(0), Data4); - EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref8).getValueOr(0), + EXPECT_EQ(DieDG.find(Attr_DW_FORM_ref8).getAsReference().getValueOr(0), Data8); EXPECT_EQ( - DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref_sig8).getValueOr(0), + DieDG.find(Attr_DW_FORM_ref_sig8).getAsReference().getValueOr(0), Data8_2); EXPECT_EQ( - DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref_udata).getValueOr(0), + DieDG.find(Attr_DW_FORM_ref_udata).getAsReference().getValueOr(0), UData[0]); //---------------------------------------------------------------------- // Test flag forms //---------------------------------------------------------------------- - EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_flag_true) - .getValueOr(0), + EXPECT_EQ(DieDG.find(Attr_DW_FORM_flag_true).getAsUnsignedConstant().getValueOr(0), 1ULL); - EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_flag_false) - .getValueOr(1), + EXPECT_EQ(DieDG.find(Attr_DW_FORM_flag_false).getAsUnsignedConstant().getValueOr(1), 0ULL); - EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_flag_present) - .getValueOr(0ULL), + EXPECT_EQ(DieDG.find(Attr_DW_FORM_flag_present).getAsUnsignedConstant().getValueOr(0ULL), 1ULL); //---------------------------------------------------------------------- // Test SLEB128 based forms //---------------------------------------------------------------------- EXPECT_EQ( - DieDG.getAttributeValueAsSignedConstant(Attr_DW_FORM_sdata).getValueOr(0), + DieDG.find(Attr_DW_FORM_sdata).getAsSignedConstant().getValueOr(0), SData); if (Version >= 5) EXPECT_EQ( - DieDG.getAttributeValueAsSignedConstant(Attr_DW_FORM_implicit_const) + DieDG.find(Attr_DW_FORM_implicit_const).getAsSignedConstant() .getValueOr(0), ICSData); //---------------------------------------------------------------------- // Test ULEB128 based forms //---------------------------------------------------------------------- - EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_udata) - .getValueOr(0), + EXPECT_EQ(DieDG.find(Attr_DW_FORM_udata).getAsUnsignedConstant().getValueOr(0), UData[0]); //---------------------------------------------------------------------- // Test DWARF32/DWARF64 forms //---------------------------------------------------------------------- - EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_GNU_ref_alt) - .getValueOr(0), + EXPECT_EQ(DieDG.find(Attr_DW_FORM_GNU_ref_alt).getAsReference().getValueOr(0), Dwarf32Values[0]); - EXPECT_EQ(DieDG.getAttributeValueAsSectionOffset(Attr_DW_FORM_sec_offset) + EXPECT_EQ(DieDG.find(Attr_DW_FORM_sec_offset).getAsSectionOffset() .getValueOr(0), Dwarf32Values[1]); //---------------------------------------------------------------------- // Add an address at the end to make sure we can decode this value //---------------------------------------------------------------------- - EXPECT_EQ(DieDG.getAttributeValueAsAddress(Attr_Last).getValueOr(0), + EXPECT_EQ(DieDG.find(Attr_Last).getAsAddress().getValueOr(0), AddrValue); } @@ -672,7 +663,7 @@ auto CU1TypeDieDG = Unit1DieDG.getFirstChild(); EXPECT_TRUE(CU1TypeDieDG.isValid()); EXPECT_EQ(CU1TypeDieDG.getTag(), DW_TAG_base_type); - EXPECT_EQ(CU1TypeDieDG.getAttributeValueAsUnsignedConstant(DW_AT_encoding) + EXPECT_EQ(CU1TypeDieDG.find(DW_AT_encoding).getAsUnsignedConstant() .getValueOr(0), DW_ATE_signed); @@ -680,7 +671,7 @@ auto CU2TypeDieDG = Unit2DieDG.getFirstChild(); EXPECT_TRUE(CU2TypeDieDG.isValid()); EXPECT_EQ(CU2TypeDieDG.getTag(), DW_TAG_base_type); - EXPECT_EQ(CU2TypeDieDG.getAttributeValueAsUnsignedConstant(DW_AT_encoding) + EXPECT_EQ(CU2TypeDieDG.find(DW_AT_encoding).getAsUnsignedConstant() .getValueOr(0), DW_ATE_float); @@ -690,7 +681,7 @@ EXPECT_TRUE(CU1Ref1DieDG.isValid()); EXPECT_EQ(CU1Ref1DieDG.getTag(), DW_TAG_variable); EXPECT_EQ( - CU1Ref1DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL), + CU1Ref1DieDG.find(DW_AT_type).getAsReference().getValueOr(-1ULL), CU1TypeDieDG.getOffset()); // Verify the sibling is our Ref2 DIE and that its DW_AT_type points to our // base type DIE in CU1. @@ -698,7 +689,7 @@ EXPECT_TRUE(CU1Ref2DieDG.isValid()); EXPECT_EQ(CU1Ref2DieDG.getTag(), DW_TAG_variable); EXPECT_EQ( - CU1Ref2DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL), + CU1Ref2DieDG.find(DW_AT_type).getAsReference().getValueOr(-1ULL), CU1TypeDieDG.getOffset()); // Verify the sibling is our Ref4 DIE and that its DW_AT_type points to our @@ -707,7 +698,7 @@ EXPECT_TRUE(CU1Ref4DieDG.isValid()); EXPECT_EQ(CU1Ref4DieDG.getTag(), DW_TAG_variable); EXPECT_EQ( - CU1Ref4DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL), + CU1Ref4DieDG.find(DW_AT_type).getAsReference().getValueOr(-1ULL), CU1TypeDieDG.getOffset()); // Verify the sibling is our Ref8 DIE and that its DW_AT_type points to our @@ -716,7 +707,7 @@ EXPECT_TRUE(CU1Ref8DieDG.isValid()); EXPECT_EQ(CU1Ref8DieDG.getTag(), DW_TAG_variable); EXPECT_EQ( - CU1Ref8DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL), + CU1Ref8DieDG.find(DW_AT_type).getAsReference().getValueOr(-1ULL), CU1TypeDieDG.getOffset()); // Verify the sibling is our RefAddr DIE and that its DW_AT_type points to our @@ -724,8 +715,7 @@ auto CU1RefAddrDieDG = CU1Ref8DieDG.getSibling(); EXPECT_TRUE(CU1RefAddrDieDG.isValid()); EXPECT_EQ(CU1RefAddrDieDG.getTag(), DW_TAG_variable); - EXPECT_EQ(CU1RefAddrDieDG.getAttributeValueAsReference(DW_AT_type) - .getValueOr(-1ULL), + EXPECT_EQ(CU1RefAddrDieDG.find(DW_AT_type).getAsReference().getValueOr(-1ULL), CU1TypeDieDG.getOffset()); // Verify the sibling of the Ref4 DIE is our RefAddr DIE and that its @@ -733,7 +723,7 @@ auto CU1ToCU2RefAddrDieDG = CU1RefAddrDieDG.getSibling(); EXPECT_TRUE(CU1ToCU2RefAddrDieDG.isValid()); EXPECT_EQ(CU1ToCU2RefAddrDieDG.getTag(), DW_TAG_variable); - EXPECT_EQ(CU1ToCU2RefAddrDieDG.getAttributeValueAsReference(DW_AT_type) + EXPECT_EQ(CU1ToCU2RefAddrDieDG.find(DW_AT_type).getAsReference() .getValueOr(-1ULL), CU2TypeDieDG.getOffset()); @@ -743,7 +733,7 @@ EXPECT_TRUE(CU2Ref1DieDG.isValid()); EXPECT_EQ(CU2Ref1DieDG.getTag(), DW_TAG_variable); EXPECT_EQ( - CU2Ref1DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL), + CU2Ref1DieDG.find(DW_AT_type).getAsReference().getValueOr(-1ULL), CU2TypeDieDG.getOffset()); // Verify the sibling is our Ref2 DIE and that its DW_AT_type points to our // base type DIE in CU2. @@ -751,7 +741,7 @@ EXPECT_TRUE(CU2Ref2DieDG.isValid()); EXPECT_EQ(CU2Ref2DieDG.getTag(), DW_TAG_variable); EXPECT_EQ( - CU2Ref2DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL), + CU2Ref2DieDG.find(DW_AT_type).getAsReference().getValueOr(-1ULL), CU2TypeDieDG.getOffset()); // Verify the sibling is our Ref4 DIE and that its DW_AT_type points to our @@ -760,7 +750,7 @@ EXPECT_TRUE(CU2Ref4DieDG.isValid()); EXPECT_EQ(CU2Ref4DieDG.getTag(), DW_TAG_variable); EXPECT_EQ( - CU2Ref4DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL), + CU2Ref4DieDG.find(DW_AT_type).getAsReference().getValueOr(-1ULL), CU2TypeDieDG.getOffset()); // Verify the sibling is our Ref8 DIE and that its DW_AT_type points to our @@ -769,7 +759,7 @@ EXPECT_TRUE(CU2Ref8DieDG.isValid()); EXPECT_EQ(CU2Ref8DieDG.getTag(), DW_TAG_variable); EXPECT_EQ( - CU2Ref8DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL), + CU2Ref8DieDG.find(DW_AT_type).getAsReference().getValueOr(-1ULL), CU2TypeDieDG.getOffset()); // Verify the sibling is our RefAddr DIE and that its DW_AT_type points to our @@ -777,8 +767,7 @@ auto CU2RefAddrDieDG = CU2Ref8DieDG.getSibling(); EXPECT_TRUE(CU2RefAddrDieDG.isValid()); EXPECT_EQ(CU2RefAddrDieDG.getTag(), DW_TAG_variable); - EXPECT_EQ(CU2RefAddrDieDG.getAttributeValueAsReference(DW_AT_type) - .getValueOr(-1ULL), + EXPECT_EQ(CU2RefAddrDieDG.find(DW_AT_type).getAsReference().getValueOr(-1ULL), CU2TypeDieDG.getOffset()); // Verify the sibling of the Ref4 DIE is our RefAddr DIE and that its @@ -786,7 +775,7 @@ auto CU2ToCU1RefAddrDieDG = CU2RefAddrDieDG.getSibling(); EXPECT_TRUE(CU2ToCU1RefAddrDieDG.isValid()); EXPECT_EQ(CU2ToCU1RefAddrDieDG.getTag(), DW_TAG_variable); - EXPECT_EQ(CU2ToCU1RefAddrDieDG.getAttributeValueAsReference(DW_AT_type) + EXPECT_EQ(CU2ToCU1RefAddrDieDG.find(DW_AT_type).getAsReference() .getValueOr(-1ULL), CU1TypeDieDG.getOffset()); } @@ -896,14 +885,14 @@ auto SubprogramDieNoPC = DieDG.getFirstChild(); EXPECT_TRUE(SubprogramDieNoPC.isValid()); EXPECT_EQ(SubprogramDieNoPC.getTag(), DW_TAG_subprogram); - OptU64 = SubprogramDieNoPC.getAttributeValueAsAddress(DW_AT_low_pc); + OptU64 = SubprogramDieNoPC.find(DW_AT_low_pc).getAsAddress(); EXPECT_FALSE((bool)OptU64); - OptU64 = SubprogramDieNoPC.getAttributeValueAsAddress(DW_AT_high_pc); + OptU64 = SubprogramDieNoPC.find(DW_AT_high_pc).getAsAddress(); EXPECT_FALSE((bool)OptU64); EXPECT_FALSE(SubprogramDieNoPC.getLowAndHighPC(LowPC, HighPC)); - OptU64 = SubprogramDieNoPC.getAttributeValueAsAddress(DW_AT_high_pc); + OptU64 = SubprogramDieNoPC.find(DW_AT_high_pc).getAsAddress(); EXPECT_FALSE((bool)OptU64); - OptU64 = SubprogramDieNoPC.getAttributeValueAsUnsignedConstant(DW_AT_high_pc); + OptU64 = SubprogramDieNoPC.find(DW_AT_high_pc).getAsUnsignedConstant(); EXPECT_FALSE((bool)OptU64); OptU64 = SubprogramDieNoPC.getHighPC(ActualLowPC); EXPECT_FALSE((bool)OptU64); @@ -916,12 +905,12 @@ auto SubprogramDieLowPC = SubprogramDieNoPC.getSibling(); EXPECT_TRUE(SubprogramDieLowPC.isValid()); EXPECT_EQ(SubprogramDieLowPC.getTag(), DW_TAG_subprogram); - OptU64 = SubprogramDieLowPC.getAttributeValueAsAddress(DW_AT_low_pc); + OptU64 = SubprogramDieLowPC.find(DW_AT_low_pc).getAsAddress(); EXPECT_TRUE((bool)OptU64); EXPECT_EQ(OptU64.getValue(), ActualLowPC); - OptU64 = SubprogramDieLowPC.getAttributeValueAsAddress(DW_AT_high_pc); + OptU64 = SubprogramDieLowPC.find(DW_AT_high_pc).getAsAddress(); EXPECT_FALSE((bool)OptU64); - OptU64 = SubprogramDieLowPC.getAttributeValueAsUnsignedConstant(DW_AT_high_pc); + OptU64 = SubprogramDieLowPC.find(DW_AT_high_pc).getAsUnsignedConstant(); EXPECT_FALSE((bool)OptU64); OptU64 = SubprogramDieLowPC.getHighPC(ActualLowPC); EXPECT_FALSE((bool)OptU64); @@ -934,12 +923,12 @@ auto SubprogramDieLowHighPC = SubprogramDieLowPC.getSibling(); EXPECT_TRUE(SubprogramDieLowHighPC.isValid()); EXPECT_EQ(SubprogramDieLowHighPC.getTag(), DW_TAG_subprogram); - OptU64 = SubprogramDieLowHighPC.getAttributeValueAsAddress(DW_AT_low_pc); + OptU64 = SubprogramDieLowHighPC.find(DW_AT_low_pc).getAsAddress(); EXPECT_TRUE((bool)OptU64); EXPECT_EQ(OptU64.getValue(), ActualLowPC); // Get the high PC as an address. This should succeed if the high PC was // encoded as an address and fail if the high PC was encoded as an offset. - OptU64 = SubprogramDieLowHighPC.getAttributeValueAsAddress(DW_AT_high_pc); + OptU64 = SubprogramDieLowHighPC.find(DW_AT_high_pc).getAsAddress(); if (SupportsHighPCAsOffset) { EXPECT_FALSE((bool)OptU64); } else { @@ -948,8 +937,7 @@ } // Get the high PC as an unsigned constant. This should succeed if the high PC // was encoded as an offset and fail if the high PC was encoded as an address. - OptU64 = SubprogramDieLowHighPC.getAttributeValueAsUnsignedConstant( - DW_AT_high_pc); + OptU64 = SubprogramDieLowHighPC.find(DW_AT_high_pc).getAsUnsignedConstant(); if (SupportsHighPCAsOffset) { EXPECT_TRUE((bool)OptU64); EXPECT_EQ(OptU64.getValue(), ActualHighPCOffset);