From a9a480efd13e62975bd68f637e406c089ad3f0b4 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Wed, 11 Jan 2017 17:43:37 +0000 Subject: [PATCH] Remove all variants of DWARFDie::getAttributeValueAs...() that had parameters that specified default values. Now we only support returning Optional<> values and have changed all clients over to use Optional::getValueOr(). Differential Revision: https://reviews.llvm.org/D28569 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291686 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/DebugInfo/DWARF/DWARFDie.h | 74 -------- lib/DebugInfo/DWARF/DWARFDie.cpp | 45 +---- lib/DebugInfo/DWARF/DWARFUnit.cpp | 10 +- tools/dsymutil/DwarfLinker.cpp | 41 +++-- .../DebugInfo/DWARF/DWARFDebugInfoTest.cpp | 165 ++++++++++-------- 5 files changed, 125 insertions(+), 210 deletions(-) diff --git a/include/llvm/DebugInfo/DWARF/DWARFDie.h b/include/llvm/DebugInfo/DWARF/DWARFDie.h index 5a24b7c8729..e335e28b39d 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFDie.h +++ b/include/llvm/DebugInfo/DWARF/DWARFDie.h @@ -140,21 +140,6 @@ public: 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. - /// \param FailValue the value to return if this DIE doesn't have this - /// attribute. - /// \returns the address value of the attribute or FailValue if the - /// attribute doesn't exist or if the attribute's form isn't a form that - /// describes an address. - uint64_t getAttributeValueAsAddress(dwarf::Attribute Attr, - uint64_t 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 @@ -165,21 +150,6 @@ public: /// \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. - /// \param FailValue the value to return if this DIE doesn't have this - /// attribute. - /// \returns the signed integer constant value of the attribute or FailValue - /// if the attribute doesn't exist or if the attribute's form isn't a form - /// that describes a signed integer. - int64_t getAttributeValueAsSignedConstant(dwarf::Attribute Attr, - int64_t FailValue) 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 @@ -191,21 +161,6 @@ public: 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. - /// \param FailValue the value to return if this DIE doesn't have this - /// attribute. - /// \returns the unsigned integer constant value of the attribute or FailValue - /// if the attribute doesn't exist or if the attribute's form isn't a form - /// that describes an unsigned integer. - uint64_t getAttributeValueAsUnsignedConstant(dwarf::Attribute Attr, - uint64_t FailValue) 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 @@ -217,21 +172,6 @@ public: Optional getAttributeValueAsUnsignedConstant(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. - /// \param FailValue the value to return if this DIE doesn't have this - /// attribute. - /// \returns the unsigned integer constant value of the attribute or FailValue - /// if the attribute doesn't exist or if the attribute's form isn't a form - /// that describes a reference. - uint64_t getAttributeValueAsReference(dwarf::Attribute Attr, - uint64_t FailValue) 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 @@ -242,20 +182,6 @@ public: /// \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. - /// \param FailValue the value to return if this DIE doesn't have this - /// attribute. - /// \returns the unsigned integer constant value of the attribute or FailValue - /// if the attribute doesn't exist or if the attribute's form isn't a form - /// that describes a section offset. - uint64_t getAttributeValueAsSectionOffset(dwarf::Attribute Attr, - uint64_t FailValue) 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 diff --git a/lib/DebugInfo/DWARF/DWARFDie.cpp b/lib/DebugInfo/DWARF/DWARFDie.cpp index 2aac3474654..89b83b11ab6 100644 --- a/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -152,13 +152,6 @@ const char *DWARFDie::getAttributeValueAsString(dwarf::Attribute Attr, return Result.hasValue() ? Result.getValue() : FailValue; } -uint64_t DWARFDie::getAttributeValueAsAddress(dwarf::Attribute Attr, - uint64_t FailValue) const { - if (auto Value = getAttributeValueAsAddress(Attr)) - return *Value; - return FailValue; -} - Optional DWARFDie::getAttributeValueAsAddress(dwarf::Attribute Attr) const { if (auto FormValue = getAttributeValue(Attr)) @@ -166,13 +159,6 @@ DWARFDie::getAttributeValueAsAddress(dwarf::Attribute Attr) const { return None; } -int64_t DWARFDie::getAttributeValueAsSignedConstant(dwarf::Attribute Attr, - int64_t FailValue) const { - if (auto Value = getAttributeValueAsSignedConstant(Attr)) - return *Value; - return FailValue; -} - Optional DWARFDie::getAttributeValueAsSignedConstant(dwarf::Attribute Attr) const { if (auto FormValue = getAttributeValue(Attr)) @@ -180,15 +166,6 @@ DWARFDie::getAttributeValueAsSignedConstant(dwarf::Attribute Attr) const { return None; } -uint64_t -DWARFDie::getAttributeValueAsUnsignedConstant(dwarf::Attribute Attr, - uint64_t FailValue) const { - if (auto Value = getAttributeValueAsUnsignedConstant(Attr)) - return *Value; - return FailValue; -} - - Optional DWARFDie::getAttributeValueAsUnsignedConstant(dwarf::Attribute Attr) const { if (auto FormValue = getAttributeValue(Attr)) @@ -196,14 +173,6 @@ DWARFDie::getAttributeValueAsUnsignedConstant(dwarf::Attribute Attr) const { return None; } -uint64_t DWARFDie::getAttributeValueAsReference(dwarf::Attribute Attr, - uint64_t FailValue) const { - if (auto Value = getAttributeValueAsReference(Attr)) - return *Value; - return FailValue; -} - - Optional DWARFDie::getAttributeValueAsReference(dwarf::Attribute Attr) const { if (auto FormValue = getAttributeValue(Attr)) @@ -211,13 +180,6 @@ DWARFDie::getAttributeValueAsReference(dwarf::Attribute Attr) const { return None; } -uint64_t DWARFDie::getAttributeValueAsSectionOffset(dwarf::Attribute Attr, - uint64_t FailValue) const { - if (auto Value = getAttributeValueAsSectionOffset(Attr)) - return *Value; - return FailValue; -} - Optional DWARFDie::getAttributeValueAsSectionOffset(dwarf::Attribute Attr) const { if (auto FormValue = getAttributeValue(Attr)) @@ -345,9 +307,10 @@ DWARFDie::getName(DINameKind Kind) const { void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine, uint32_t &CallColumn) const { - CallFile = getAttributeValueAsUnsignedConstant(DW_AT_call_file, 0); - CallLine = getAttributeValueAsUnsignedConstant(DW_AT_call_line, 0); - CallColumn = getAttributeValueAsUnsignedConstant(DW_AT_call_column, 0); + CallFile = getAttributeValueAsUnsignedConstant(DW_AT_call_file).getValueOr(0); + CallLine = getAttributeValueAsUnsignedConstant(DW_AT_call_line).getValueOr(0); + CallColumn = + getAttributeValueAsUnsignedConstant(DW_AT_call_column).getValueOr(0); } void DWARFDie::dump(raw_ostream &OS, unsigned RecurseDepth, diff --git a/lib/DebugInfo/DWARF/DWARFUnit.cpp b/lib/DebugInfo/DWARF/DWARFUnit.cpp index 63fb0d3bc36..ee2c569b0bc 100644 --- a/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -230,10 +230,12 @@ size_t DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly) { BaseAddr = UnitDie.getAttributeValueAsAddress(DW_AT_entry_pc); if (BaseAddr) setBaseAddress(*BaseAddr); - AddrOffsetSectionBase = UnitDie.getAttributeValueAsSectionOffset( - DW_AT_GNU_addr_base, 0); - RangeSectionBase = UnitDie.getAttributeValueAsSectionOffset( - DW_AT_rnglists_base, 0); + AddrOffsetSectionBase = + UnitDie.getAttributeValueAsSectionOffset(DW_AT_GNU_addr_base) + .getValueOr(0); + RangeSectionBase = + UnitDie.getAttributeValueAsSectionOffset(DW_AT_rnglists_base) + .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. } diff --git a/tools/dsymutil/DwarfLinker.cpp b/tools/dsymutil/DwarfLinker.cpp index ecd631c1039..f1ec8a62267 100644 --- a/tools/dsymutil/DwarfLinker.cpp +++ b/tools/dsymutil/DwarfLinker.cpp @@ -205,7 +205,9 @@ public: Info.resize(OrigUnit.getNumDIEs()); auto CUDie = OrigUnit.getUnitDIE(false); - unsigned Lang = CUDie.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_language, 0); + unsigned Lang = + CUDie.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_language) + .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 || @@ -1556,7 +1558,8 @@ PointerIntPair DeclContextTree::getChildDeclContext( // 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, 0)) + !DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_external) + .getValueOr(0)) return PointerIntPair(nullptr); LLVM_FALLTHROUGH; case dwarf::DW_TAG_member: @@ -1570,7 +1573,8 @@ PointerIntPair DeclContextTree::getChildDeclContext( // 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, 0)) + if (DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_artificial) + .getValueOr(0)) return PointerIntPair(nullptr); break; } @@ -1610,11 +1614,12 @@ PointerIntPair DeclContextTree::getChildDeclContext( // 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, UINT64_MAX); + ByteSize = DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_byte_size) + .getValueOr(UINT64_MAX); if (Tag != dwarf::DW_TAG_namespace || !Name) { - if (unsigned FileNum = DIE.getAttributeValueAsUnsignedConstant( - dwarf::DW_AT_decl_file, 0)) { + if (unsigned FileNum = + DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_decl_file) + .getValueOr(0)) { if (const auto *LT = U.getOrigUnit().getContext().getLineTableForUnit( &U.getOrigUnit())) { // FIXME: dsymutil-classic compatibility. I'd rather not @@ -1627,8 +1632,9 @@ PointerIntPair DeclContextTree::getChildDeclContext( // instead of "" would allow more uniquing, but for now, do // it this way to match dsymutil-classic. if (LT->hasFileAtIndex(FileNum)) { - Line = DIE.getAttributeValueAsUnsignedConstant( - dwarf::DW_AT_decl_line, 0); + Line = + DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_decl_line) + .getValueOr(0); // Cache the resolved paths, because calling realpath is expansive. StringRef ResolvedPath = U.getResolvedPath(FileNum); if (!ResolvedPath.empty()) { @@ -1803,9 +1809,10 @@ static bool analyzeContextInfo(const DWARFDie &DIE, // Prune this DIE if it is either a forward declaration inside a // DW_TAG_module or a DW_TAG_module that contains nothing but // forward declarations. - Info.Prune &= (DIE.getTag() == dwarf::DW_TAG_module) || - DIE.getAttributeValueAsUnsignedConstant( - dwarf::DW_AT_declaration, 0); + Info.Prune &= + (DIE.getTag() == dwarf::DW_TAG_module) || + DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_declaration) + .getValueOr(0); // Don't prune it if there is no definition for the DIE. Info.Prune &= Info.Ctxt && Info.Ctxt->getCanonicalDIEOffset(); @@ -2740,12 +2747,13 @@ DIE *DwarfLinker::DIECloner::cloneDIE( // 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, 0); + InputDIE.getAttributeValueAsAddress(dwarf::DW_AT_high_pc).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, UINT64_MAX); + InputDIE.getAttributeValueAsAddress(dwarf::DW_AT_low_pc) + .getValueOr(UINT64_MAX); } // Reset the Offset to 0 as we will be working on the local copy of @@ -2864,8 +2872,9 @@ void DwarfLinker::patchRangesForUnit(const CompileUnit &Unit, auto InvalidRange = FunctionRanges.end(), CurrRange = InvalidRange; DWARFUnit &OrigUnit = Unit.getOrigUnit(); auto OrigUnitDie = OrigUnit.getUnitDIE(false); - uint64_t OrigLowPc = OrigUnitDie.getAttributeValueAsAddress( - dwarf::DW_AT_low_pc, -1ULL); + uint64_t OrigLowPc = + OrigUnitDie.getAttributeValueAsAddress(dwarf::DW_AT_low_pc) + .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; diff --git a/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp b/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp index 4ad9e22dba1..a4109a34097 100644 --- a/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp +++ b/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp @@ -228,7 +228,7 @@ void TestAllForms() { //---------------------------------------------------------------------- // Test address forms //---------------------------------------------------------------------- - EXPECT_EQ(DieDG.getAttributeValueAsAddress(Attr_DW_FORM_addr, 0), + EXPECT_EQ(DieDG.getAttributeValueAsAddress(Attr_DW_FORM_addr).getValueOr(0), AddrValue); //---------------------------------------------------------------------- @@ -273,18 +273,18 @@ void TestAllForms() { //---------------------------------------------------------------------- // Test data forms //---------------------------------------------------------------------- - EXPECT_EQ( - DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data1, 0), - Data1); - EXPECT_EQ( - DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data2, 0), - Data2); - EXPECT_EQ( - DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data4, 0), - Data4); - EXPECT_EQ( - DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data8, 0), - Data8); + EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data1) + .getValueOr(0), + Data1); + EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data2) + .getValueOr(0), + Data2); + EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data4) + .getValueOr(0), + Data4); + EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_data8) + .getValueOr(0), + Data8); //---------------------------------------------------------------------- // Test string forms @@ -302,64 +302,71 @@ void TestAllForms() { //---------------------------------------------------------------------- // Test reference forms //---------------------------------------------------------------------- - EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref_addr, 0), - RefAddr); - EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref1, 0), + EXPECT_EQ( + DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref_addr).getValueOr(0), + RefAddr); + EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref1).getValueOr(0), Data1); - EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref2, 0), + EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref2).getValueOr(0), Data2); - EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref4, 0), + EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref4).getValueOr(0), Data4); - EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref8, 0), + EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref8).getValueOr(0), Data8); - EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref_sig8, 0), - Data8_2); - EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref_udata, 0), - UData[0]); + EXPECT_EQ( + DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref_sig8).getValueOr(0), + Data8_2); + EXPECT_EQ( + DieDG.getAttributeValueAsReference(Attr_DW_FORM_ref_udata).getValueOr(0), + UData[0]); //---------------------------------------------------------------------- // Test flag forms //---------------------------------------------------------------------- - EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant( - Attr_DW_FORM_flag_true, 0ULL), + EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_flag_true) + .getValueOr(0), 1ULL); - EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant( - Attr_DW_FORM_flag_false, 1ULL), + EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_flag_false) + .getValueOr(1), 0ULL); - EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant( - Attr_DW_FORM_flag_present, 0ULL), + EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_flag_present) + .getValueOr(0ULL), 1ULL); //---------------------------------------------------------------------- // Test SLEB128 based forms //---------------------------------------------------------------------- - EXPECT_EQ(DieDG.getAttributeValueAsSignedConstant(Attr_DW_FORM_sdata, 0), - SData); + EXPECT_EQ( + DieDG.getAttributeValueAsSignedConstant(Attr_DW_FORM_sdata).getValueOr(0), + SData); if (Version >= 5) - EXPECT_EQ(DieDG.getAttributeValueAsSignedConstant( - Attr_DW_FORM_implicit_const, 0), ICSData); + EXPECT_EQ( + DieDG.getAttributeValueAsSignedConstant(Attr_DW_FORM_implicit_const) + .getValueOr(0), + ICSData); //---------------------------------------------------------------------- // Test ULEB128 based forms //---------------------------------------------------------------------- - EXPECT_EQ( - DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_udata, 0), - UData[0]); + EXPECT_EQ(DieDG.getAttributeValueAsUnsignedConstant(Attr_DW_FORM_udata) + .getValueOr(0), + UData[0]); //---------------------------------------------------------------------- // Test DWARF32/DWARF64 forms //---------------------------------------------------------------------- - EXPECT_EQ( - DieDG.getAttributeValueAsReference(Attr_DW_FORM_GNU_ref_alt, 0), - Dwarf32Values[0]); - EXPECT_EQ( - DieDG.getAttributeValueAsSectionOffset(Attr_DW_FORM_sec_offset, 0), - Dwarf32Values[1]); + EXPECT_EQ(DieDG.getAttributeValueAsReference(Attr_DW_FORM_GNU_ref_alt) + .getValueOr(0), + Dwarf32Values[0]); + EXPECT_EQ(DieDG.getAttributeValueAsSectionOffset(Attr_DW_FORM_sec_offset) + .getValueOr(0), + Dwarf32Values[1]); //---------------------------------------------------------------------- // Add an address at the end to make sure we can decode this value //---------------------------------------------------------------------- - EXPECT_EQ(DieDG.getAttributeValueAsAddress(Attr_Last, 0), AddrValue); + EXPECT_EQ(DieDG.getAttributeValueAsAddress(Attr_Last).getValueOr(0), + AddrValue); } TEST(DWARFDebugInfo, TestDWARF32Version2Addr4AllForms) { @@ -665,65 +672,69 @@ template void TestReferences() { auto CU1TypeDieDG = Unit1DieDG.getFirstChild(); EXPECT_TRUE(CU1TypeDieDG.isValid()); EXPECT_EQ(CU1TypeDieDG.getTag(), DW_TAG_base_type); - EXPECT_EQ( - CU1TypeDieDG.getAttributeValueAsUnsignedConstant(DW_AT_encoding, 0), - DW_ATE_signed); + EXPECT_EQ(CU1TypeDieDG.getAttributeValueAsUnsignedConstant(DW_AT_encoding) + .getValueOr(0), + DW_ATE_signed); // Verify the first child of the compile unit 2 DIE is our float base type. auto CU2TypeDieDG = Unit2DieDG.getFirstChild(); EXPECT_TRUE(CU2TypeDieDG.isValid()); EXPECT_EQ(CU2TypeDieDG.getTag(), DW_TAG_base_type); - EXPECT_EQ( - CU2TypeDieDG.getAttributeValueAsUnsignedConstant(DW_AT_encoding, 0), - DW_ATE_float); + EXPECT_EQ(CU2TypeDieDG.getAttributeValueAsUnsignedConstant(DW_AT_encoding) + .getValueOr(0), + DW_ATE_float); // Verify the sibling of the base type DIE is our Ref1 DIE and that its // DW_AT_type points to our base type DIE. auto CU1Ref1DieDG = CU1TypeDieDG.getSibling(); EXPECT_TRUE(CU1Ref1DieDG.isValid()); EXPECT_EQ(CU1Ref1DieDG.getTag(), DW_TAG_variable); - EXPECT_EQ(CU1Ref1DieDG.getAttributeValueAsReference(DW_AT_type, -1ULL), - CU1TypeDieDG.getOffset()); + EXPECT_EQ( + CU1Ref1DieDG.getAttributeValueAsReference(DW_AT_type).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. auto CU1Ref2DieDG = CU1Ref1DieDG.getSibling(); EXPECT_TRUE(CU1Ref2DieDG.isValid()); EXPECT_EQ(CU1Ref2DieDG.getTag(), DW_TAG_variable); - EXPECT_EQ(CU1Ref2DieDG.getAttributeValueAsReference(DW_AT_type, -1ULL), - CU1TypeDieDG.getOffset()); + EXPECT_EQ( + CU1Ref2DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL), + CU1TypeDieDG.getOffset()); // Verify the sibling is our Ref4 DIE and that its DW_AT_type points to our // base type DIE in CU1. auto CU1Ref4DieDG = CU1Ref2DieDG.getSibling(); EXPECT_TRUE(CU1Ref4DieDG.isValid()); EXPECT_EQ(CU1Ref4DieDG.getTag(), DW_TAG_variable); - EXPECT_EQ(CU1Ref4DieDG.getAttributeValueAsReference(DW_AT_type, -1ULL), - CU1TypeDieDG.getOffset()); + EXPECT_EQ( + CU1Ref4DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL), + CU1TypeDieDG.getOffset()); // Verify the sibling is our Ref8 DIE and that its DW_AT_type points to our // base type DIE in CU1. auto CU1Ref8DieDG = CU1Ref4DieDG.getSibling(); EXPECT_TRUE(CU1Ref8DieDG.isValid()); EXPECT_EQ(CU1Ref8DieDG.getTag(), DW_TAG_variable); - EXPECT_EQ(CU1Ref8DieDG.getAttributeValueAsReference(DW_AT_type, -1ULL), - CU1TypeDieDG.getOffset()); + EXPECT_EQ( + CU1Ref8DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL), + CU1TypeDieDG.getOffset()); // Verify the sibling is our RefAddr DIE and that its DW_AT_type points to our // base type DIE in CU1. auto CU1RefAddrDieDG = CU1Ref8DieDG.getSibling(); EXPECT_TRUE(CU1RefAddrDieDG.isValid()); EXPECT_EQ(CU1RefAddrDieDG.getTag(), DW_TAG_variable); - EXPECT_EQ( - CU1RefAddrDieDG.getAttributeValueAsReference(DW_AT_type, -1ULL), - CU1TypeDieDG.getOffset()); + EXPECT_EQ(CU1RefAddrDieDG.getAttributeValueAsReference(DW_AT_type) + .getValueOr(-1ULL), + CU1TypeDieDG.getOffset()); // Verify the sibling of the Ref4 DIE is our RefAddr DIE and that its // DW_AT_type points to our base type DIE. auto CU1ToCU2RefAddrDieDG = CU1RefAddrDieDG.getSibling(); EXPECT_TRUE(CU1ToCU2RefAddrDieDG.isValid()); EXPECT_EQ(CU1ToCU2RefAddrDieDG.getTag(), DW_TAG_variable); - EXPECT_EQ(CU1ToCU2RefAddrDieDG.getAttributeValueAsReference(DW_AT_type, - -1ULL), + EXPECT_EQ(CU1ToCU2RefAddrDieDG.getAttributeValueAsReference(DW_AT_type) + .getValueOr(-1ULL), CU2TypeDieDG.getOffset()); // Verify the sibling of the base type DIE is our Ref1 DIE and that its @@ -731,48 +742,52 @@ template void TestReferences() { auto CU2Ref1DieDG = CU2TypeDieDG.getSibling(); EXPECT_TRUE(CU2Ref1DieDG.isValid()); EXPECT_EQ(CU2Ref1DieDG.getTag(), DW_TAG_variable); - EXPECT_EQ(CU2Ref1DieDG.getAttributeValueAsReference(DW_AT_type, -1ULL), - CU2TypeDieDG.getOffset()); + EXPECT_EQ( + CU2Ref1DieDG.getAttributeValueAsReference(DW_AT_type).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. auto CU2Ref2DieDG = CU2Ref1DieDG.getSibling(); EXPECT_TRUE(CU2Ref2DieDG.isValid()); EXPECT_EQ(CU2Ref2DieDG.getTag(), DW_TAG_variable); - EXPECT_EQ(CU2Ref2DieDG.getAttributeValueAsReference(DW_AT_type, -1ULL), - CU2TypeDieDG.getOffset()); + EXPECT_EQ( + CU2Ref2DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL), + CU2TypeDieDG.getOffset()); // Verify the sibling is our Ref4 DIE and that its DW_AT_type points to our // base type DIE in CU2. auto CU2Ref4DieDG = CU2Ref2DieDG.getSibling(); EXPECT_TRUE(CU2Ref4DieDG.isValid()); EXPECT_EQ(CU2Ref4DieDG.getTag(), DW_TAG_variable); - EXPECT_EQ(CU2Ref4DieDG.getAttributeValueAsReference(DW_AT_type, -1ULL), - CU2TypeDieDG.getOffset()); + EXPECT_EQ( + CU2Ref4DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL), + CU2TypeDieDG.getOffset()); // Verify the sibling is our Ref8 DIE and that its DW_AT_type points to our // base type DIE in CU2. auto CU2Ref8DieDG = CU2Ref4DieDG.getSibling(); EXPECT_TRUE(CU2Ref8DieDG.isValid()); EXPECT_EQ(CU2Ref8DieDG.getTag(), DW_TAG_variable); - EXPECT_EQ(CU2Ref8DieDG.getAttributeValueAsReference(DW_AT_type, -1ULL), - CU2TypeDieDG.getOffset()); + EXPECT_EQ( + CU2Ref8DieDG.getAttributeValueAsReference(DW_AT_type).getValueOr(-1ULL), + CU2TypeDieDG.getOffset()); // Verify the sibling is our RefAddr DIE and that its DW_AT_type points to our // base type DIE in CU2. auto CU2RefAddrDieDG = CU2Ref8DieDG.getSibling(); EXPECT_TRUE(CU2RefAddrDieDG.isValid()); EXPECT_EQ(CU2RefAddrDieDG.getTag(), DW_TAG_variable); - EXPECT_EQ( - CU2RefAddrDieDG.getAttributeValueAsReference(DW_AT_type, -1ULL), - CU2TypeDieDG.getOffset()); + EXPECT_EQ(CU2RefAddrDieDG.getAttributeValueAsReference(DW_AT_type) + .getValueOr(-1ULL), + CU2TypeDieDG.getOffset()); // Verify the sibling of the Ref4 DIE is our RefAddr DIE and that its // DW_AT_type points to our base type DIE. auto CU2ToCU1RefAddrDieDG = CU2RefAddrDieDG.getSibling(); EXPECT_TRUE(CU2ToCU1RefAddrDieDG.isValid()); EXPECT_EQ(CU2ToCU1RefAddrDieDG.getTag(), DW_TAG_variable); - EXPECT_EQ(CU2ToCU1RefAddrDieDG.getAttributeValueAsReference(DW_AT_type, - -1ULL), + EXPECT_EQ(CU2ToCU1RefAddrDieDG.getAttributeValueAsReference(DW_AT_type) + .getValueOr(-1ULL), CU1TypeDieDG.getOffset()); }