From: Jonas Devlieghere Date: Fri, 1 Mar 2019 22:14:24 +0000 (+0000) Subject: [DWARFFormValue] Cleanup DWARFFormValue interface. (2/2) (NFC) X-Git-Tag: android-x86-9.0-r1~6388 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=ca58bd27df5df9742dcdc3f45864879f6327aaa0;p=android-x86%2Fexternal-llvm.git [DWARFFormValue] Cleanup DWARFFormValue interface. (2/2) (NFC) Continues the work started in r354941. Changes (all but one) uses of the extractValue to static createFromData. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355233 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/DebugInfo/DWARF/DWARFFormValue.h b/include/llvm/DebugInfo/DWARF/DWARFFormValue.h index 8107624f8a8..f6d907e1881 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFFormValue.h +++ b/include/llvm/DebugInfo/DWARF/DWARFFormValue.h @@ -61,6 +61,10 @@ private: DWARFFormValue(dwarf::Form F, ValueType V) : Form(F), Value(V) {} + bool extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr, + dwarf::FormParams FormParams, const DWARFUnit *Unit, + const DWARFContext *Ctx); + public: DWARFFormValue(dwarf::Form F = dwarf::Form(0)) : Form(F) {} @@ -69,8 +73,13 @@ public: static DWARFFormValue createFromPValue(dwarf::Form F, const char *V); static DWARFFormValue createFromBlockValue(dwarf::Form F, ArrayRef D); - static DWARFFormValue createFromUnit(dwarf::Form F, const DWARFUnit *Unit, - uint32_t *OffsetPtr); + + /// Creates a from value from the given data. The DWARF context form the unit + /// is used, unless one is provided explicitly. + static DWARFFormValue + createFromData(dwarf::Form F, dwarf::FormParams FormParams, + const DWARFUnit &U, const DWARFDataExtractor &Data, + uint32_t *OffsetPtr, const DWARFContext *Ctx = nullptr); dwarf::Form getForm() const { return Form; } uint64_t getRawUValue() const { return Value.uval; } @@ -83,18 +92,10 @@ public: static void dumpAddressSection(const DWARFObject &Obj, raw_ostream &OS, DIDumpOptions DumpOpts, uint64_t SectionIndex); - /// Extracts a value in \p Data at offset \p *OffsetPtr. The information - /// in \p FormParams is needed to interpret some forms. The optional - /// \p Context and \p Unit allows extracting information if the form refers - /// to other sections (e.g., .debug_str). + /// Legacy interface for initializing a DWARFFormValue from data. bool extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr, - dwarf::FormParams FormParams, - const DWARFContext *Context = nullptr, - const DWARFUnit *Unit = nullptr); - - bool extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr, - dwarf::FormParams FormParams, const DWARFUnit *U) { - return extractValue(Data, OffsetPtr, FormParams, nullptr, U); + dwarf::FormParams FormParams) { + return extractValue(Data, OffsetPtr, FormParams, nullptr, nullptr); } bool isInlinedCStr() const { @@ -117,20 +118,6 @@ public: /// Skip a form's value in \p DebugInfoData at the offset specified by /// \p OffsetPtr. /// - /// Skips the bytes for the current form and updates the offset. - /// - /// \param DebugInfoData The data where we want to skip the value. - /// \param OffsetPtr A reference to the offset that will be updated. - /// \param Params DWARF parameters to help interpret forms. - /// \returns true on success, false if the form was not skipped. - bool skipValue(DataExtractor DebugInfoData, uint32_t *OffsetPtr, - const dwarf::FormParams Params) const { - return DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr, Params); - } - - /// Skip a form's value in \p DebugInfoData at the offset specified by - /// \p OffsetPtr. - /// /// Skips the bytes for the specified form and updates the offset. /// /// \param Form The DW_FORM enumeration that indicates the form to skip. diff --git a/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp b/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp index f4dd7993760..f607dfe37cb 100644 --- a/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp +++ b/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp @@ -166,10 +166,8 @@ Optional DWARFAbbreviationDeclaration::getAttributeValue( if (Spec.isImplicitConst()) return DWARFFormValue::createFromSValue(Spec.Form, Spec.getImplicitConstValue()); - - DWARFFormValue FormValue(Spec.Form); - if (FormValue.extractValue(DebugInfoData, &Offset, U.getFormParams(), &U)) - return FormValue; + return DWARFFormValue::createFromData(Spec.Form, U.getFormParams(), U, + U.getDebugInfoExtractor(), &Offset); } // March Offset along until we get to the attribute we want. if (auto FixedSize = Spec.getByteSize(U)) diff --git a/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/lib/DebugInfo/DWARF/DWARFDebugLine.cpp index a2c25248618..8dbca510d15 100644 --- a/lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ b/lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -212,15 +212,14 @@ parseV5DirFileTables(const DWARFDataExtractor &DebugLineData, if (*OffsetPtr >= EndPrologueOffset) return false; for (auto Descriptor : DirDescriptors) { - DWARFFormValue Value(Descriptor.Form); switch (Descriptor.Type) { case DW_LNCT_path: - if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, &Ctx, U)) - return false; - IncludeDirectories.push_back(Value); + IncludeDirectories.push_back(DWARFFormValue::createFromData( + Descriptor.Form, FormParams, *U, DebugLineData, OffsetPtr, &Ctx)); break; default: - if (!Value.skipValue(DebugLineData, OffsetPtr, FormParams)) + if (!DWARFFormValue::skipValue(Descriptor.Form, DebugLineData, + OffsetPtr, FormParams)) return false; } } @@ -240,9 +239,8 @@ parseV5DirFileTables(const DWARFDataExtractor &DebugLineData, return false; DWARFDebugLine::FileNameEntry FileEntry; for (auto Descriptor : FileDescriptors) { - DWARFFormValue Value(Descriptor.Form); - if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, &Ctx, U)) - return false; + DWARFFormValue Value = DWARFFormValue::createFromData( + Descriptor.Form, FormParams, *U, DebugLineData, OffsetPtr, &Ctx); switch (Descriptor.Type) { case DW_LNCT_path: FileEntry.Name = Value; diff --git a/lib/DebugInfo/DWARF/DWARFDie.cpp b/lib/DebugInfo/DWARF/DWARFDie.cpp index 4cd69bc8017..4b9cff73751 100644 --- a/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -278,7 +278,8 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, OS << formatv(" [{0}]", Form); DWARFUnit *U = Die.getDwarfUnit(); - DWARFFormValue FormValue = DWARFFormValue::createFromUnit(Form, U, OffsetPtr); + DWARFFormValue FormValue = DWARFFormValue::createFromData( + Form, U->getFormParams(), *U, U->getDebugInfoExtractor(), OffsetPtr); OS << "\t("; @@ -686,8 +687,9 @@ void DWARFDie::attribute_iterator::updateForIndex( uint32_t ParseOffset = AttrValue.Offset; auto U = Die.getDwarfUnit(); assert(U && "Die must have valid DWARF unit"); - AttrValue.Value = DWARFFormValue::createFromUnit( - AbbrDecl.getFormByIndex(Index), U, &ParseOffset); + AttrValue.Value = DWARFFormValue::createFromData( + AbbrDecl.getFormByIndex(Index), U->getFormParams(), *U, + U->getDebugInfoExtractor(), &ParseOffset); AttrValue.ByteSize = ParseOffset - AttrValue.Offset; } else { assert(Index == NumAttrs && "Indexes should be [0, NumAttrs) only"); diff --git a/lib/DebugInfo/DWARF/DWARFFormValue.cpp b/lib/DebugInfo/DWARF/DWARFFormValue.cpp index 7ddc8820fc6..0d96614ccae 100644 --- a/lib/DebugInfo/DWARF/DWARFFormValue.cpp +++ b/lib/DebugInfo/DWARF/DWARFFormValue.cpp @@ -97,11 +97,14 @@ DWARFFormValue DWARFFormValue::createFromBlockValue(dwarf::Form F, return DWARFFormValue(F, V); } -DWARFFormValue DWARFFormValue::createFromUnit(dwarf::Form F, const DWARFUnit *U, - uint32_t *OffsetPtr) { +DWARFFormValue DWARFFormValue::createFromData(dwarf::Form F, + dwarf::FormParams FormParams, + const DWARFUnit &U, + const DWARFDataExtractor &Data, + uint32_t *OffsetPtr, + const DWARFContext *Ctx) { DWARFFormValue FormValue(F); - FormValue.extractValue(U->getDebugInfoExtractor(), OffsetPtr, - U->getFormParams(), U); + FormValue.extractValue(Data, OffsetPtr, FormParams, &U, Ctx); return FormValue; } @@ -231,8 +234,8 @@ bool DWARFFormValue::isFormClass(DWARFFormValue::FormClass FC) const { bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr, dwarf::FormParams FP, - const DWARFContext *Ctx, - const DWARFUnit *CU) { + const DWARFUnit *CU, + const DWARFContext *Ctx) { if (!Ctx && CU) Ctx = &CU->getContext(); C = Ctx; diff --git a/tools/dsymutil/DwarfLinker.cpp b/tools/dsymutil/DwarfLinker.cpp index e3749a32a16..6ada03fd6a9 100644 --- a/tools/dsymutil/DwarfLinker.cpp +++ b/tools/dsymutil/DwarfLinker.cpp @@ -584,7 +584,7 @@ unsigned DwarfLinker::shouldKeepVariableDIE(RelocationManager &RelocMgr, MyInfo.InDebugMap = true; return Flags | TF_Keep; } - + Optional LocationIdx = Abbrev->findAttributeIndex(dwarf::DW_AT_location); if (!LocationIdx) @@ -754,7 +754,9 @@ void DwarfLinker::keepDIEAndDependencies( continue; } - Val.extractValue(Data, &Offset, Unit.getFormParams(), &Unit); + Val = DWARFFormValue::createFromData(AttrSpec.Form, Unit.getFormParams(), + Unit, Unit.getDebugInfoExtractor(), + &Offset); CompileUnit *ReferencedCU; if (auto RefDie = resolveDIEReference(*this, DMO, Units, Val, Unit, Die, ReferencedCU)) { @@ -1552,9 +1554,9 @@ DIE *DwarfLinker::DIECloner::cloneDIE( continue; } - DWARFFormValue Val(AttrSpec.Form); uint32_t AttrSize = Offset; - Val.extractValue(Data, &Offset, U.getFormParams(), &U); + DWARFFormValue Val = DWARFFormValue::createFromData( + AttrSpec.Form, U.getFormParams(), U, Data, &Offset); AttrSize = Offset - AttrSize; OutOffset += cloneAttribute(*Die, InputDIE, DMO, Unit, StringPool, Val,