[llvm] r355255 - Revert "[DWARFFormValue] Cleanup DWARFFormValue interface. (2/2) (NFC)"

Vlad Tsyrklevich via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 1 17:10:00 PST 2019


Author: vlad.tsyrklevich
Date: Fri Mar  1 17:10:00 2019
New Revision: 355255

URL: http://llvm.org/viewvc/llvm-project?rev=355255&view=rev
Log:
Revert "[DWARFFormValue] Cleanup DWARFFormValue interface. (2/2) (NFC)"

This reverts commit r355233, it was causing UBSan failures.

Modified:
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h
    llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp
    llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
    llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp
    llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
    llvm/trunk/tools/dsymutil/DwarfLinker.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h?rev=355255&r1=355254&r2=355255&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h Fri Mar  1 17:10:00 2019
@@ -61,10 +61,6 @@ 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) {}
 
@@ -73,13 +69,8 @@ public:
   static DWARFFormValue createFromPValue(dwarf::Form F, const char *V);
   static DWARFFormValue createFromBlockValue(dwarf::Form F,
                                              ArrayRef<uint8_t> D);
-
-  /// 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);
+  static DWARFFormValue createFromUnit(dwarf::Form F, const DWARFUnit *Unit,
+                                       uint32_t *OffsetPtr);
 
   dwarf::Form getForm() const { return Form; }
   uint64_t getRawUValue() const { return Value.uval; }
@@ -92,10 +83,18 @@ public:
   static void dumpAddressSection(const DWARFObject &Obj, raw_ostream &OS,
                                  DIDumpOptions DumpOpts, uint64_t SectionIndex);
 
-  /// Legacy interface for initializing a DWARFFormValue from data.
+  /// 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).
+  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) {
-    return extractValue(Data, OffsetPtr, FormParams, nullptr, nullptr);
+                    dwarf::FormParams FormParams, const DWARFUnit *U) {
+    return extractValue(Data, OffsetPtr, FormParams, nullptr, U);
   }
 
   bool isInlinedCStr() const {
@@ -117,6 +116,20 @@ 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.
   ///

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp?rev=355255&r1=355254&r2=355255&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp Fri Mar  1 17:10:00 2019
@@ -166,8 +166,10 @@ Optional<DWARFFormValue> DWARFAbbreviati
       if (Spec.isImplicitConst())
         return DWARFFormValue::createFromSValue(Spec.Form,
                                                 Spec.getImplicitConstValue());
-      return DWARFFormValue::createFromData(Spec.Form, U.getFormParams(), U,
-                                            U.getDebugInfoExtractor(), &Offset);
+
+      DWARFFormValue FormValue(Spec.Form);
+      if (FormValue.extractValue(DebugInfoData, &Offset, U.getFormParams(), &U))
+        return FormValue;
     }
     // March Offset along until we get to the attribute we want.
     if (auto FixedSize = Spec.getByteSize(U))

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp?rev=355255&r1=355254&r2=355255&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp Fri Mar  1 17:10:00 2019
@@ -212,14 +212,15 @@ parseV5DirFileTables(const DWARFDataExtr
     if (*OffsetPtr >= EndPrologueOffset)
       return false;
     for (auto Descriptor : DirDescriptors) {
+      DWARFFormValue Value(Descriptor.Form);
       switch (Descriptor.Type) {
       case DW_LNCT_path:
-        IncludeDirectories.push_back(DWARFFormValue::createFromData(
-            Descriptor.Form, FormParams, *U, DebugLineData, OffsetPtr, &Ctx));
+        if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, &Ctx, U))
+          return false;
+        IncludeDirectories.push_back(Value);
         break;
       default:
-        if (!DWARFFormValue::skipValue(Descriptor.Form, DebugLineData,
-                                       OffsetPtr, FormParams))
+        if (!Value.skipValue(DebugLineData, OffsetPtr, FormParams))
           return false;
       }
     }
@@ -239,8 +240,9 @@ parseV5DirFileTables(const DWARFDataExtr
       return false;
     DWARFDebugLine::FileNameEntry FileEntry;
     for (auto Descriptor : FileDescriptors) {
-      DWARFFormValue Value = DWARFFormValue::createFromData(
-          Descriptor.Form, FormParams, *U, DebugLineData, OffsetPtr, &Ctx);
+      DWARFFormValue Value(Descriptor.Form);
+      if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, &Ctx, U))
+        return false;
       switch (Descriptor.Type) {
       case DW_LNCT_path:
         FileEntry.Name = Value;

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp?rev=355255&r1=355254&r2=355255&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp Fri Mar  1 17:10:00 2019
@@ -278,8 +278,7 @@ static void dumpAttribute(raw_ostream &O
     OS << formatv(" [{0}]", Form);
 
   DWARFUnit *U = Die.getDwarfUnit();
-  DWARFFormValue FormValue = DWARFFormValue::createFromData(
-      Form, U->getFormParams(), *U, U->getDebugInfoExtractor(), OffsetPtr);
+  DWARFFormValue FormValue = DWARFFormValue::createFromUnit(Form, U, OffsetPtr);
 
   OS << "\t(";
 
@@ -687,9 +686,8 @@ void DWARFDie::attribute_iterator::updat
     uint32_t ParseOffset = AttrValue.Offset;
     auto U = Die.getDwarfUnit();
     assert(U && "Die must have valid DWARF unit");
-    AttrValue.Value = DWARFFormValue::createFromData(
-        AbbrDecl.getFormByIndex(Index), U->getFormParams(), *U,
-        U->getDebugInfoExtractor(), &ParseOffset);
+    AttrValue.Value = DWARFFormValue::createFromUnit(
+        AbbrDecl.getFormByIndex(Index), U, &ParseOffset);
     AttrValue.ByteSize = ParseOffset - AttrValue.Offset;
   } else {
     assert(Index == NumAttrs && "Indexes should be [0, NumAttrs) only");

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp?rev=355255&r1=355254&r2=355255&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp Fri Mar  1 17:10:00 2019
@@ -97,14 +97,11 @@ DWARFFormValue DWARFFormValue::createFro
   return DWARFFormValue(F, V);
 }
 
-DWARFFormValue DWARFFormValue::createFromData(dwarf::Form F,
-                                              dwarf::FormParams FormParams,
-                                              const DWARFUnit &U,
-                                              const DWARFDataExtractor &Data,
-                                              uint32_t *OffsetPtr,
-                                              const DWARFContext *Ctx) {
+DWARFFormValue DWARFFormValue::createFromUnit(dwarf::Form F, const DWARFUnit *U,
+                                              uint32_t *OffsetPtr) {
   DWARFFormValue FormValue(F);
-  FormValue.extractValue(Data, OffsetPtr, FormParams, &U, Ctx);
+  FormValue.extractValue(U->getDebugInfoExtractor(), OffsetPtr,
+                         U->getFormParams(), U);
   return FormValue;
 }
 
@@ -234,8 +231,8 @@ bool DWARFFormValue::isFormClass(DWARFFo
 
 bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data,
                                   uint32_t *OffsetPtr, dwarf::FormParams FP,
-                                  const DWARFUnit *CU,
-                                  const DWARFContext *Ctx) {
+                                  const DWARFContext *Ctx,
+                                  const DWARFUnit *CU) {
   if (!Ctx && CU)
     Ctx = &CU->getContext();
   C = Ctx;

Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=355255&r1=355254&r2=355255&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Fri Mar  1 17:10:00 2019
@@ -584,7 +584,7 @@ unsigned DwarfLinker::shouldKeepVariable
     MyInfo.InDebugMap = true;
     return Flags | TF_Keep;
   }
-
+  
   Optional<uint32_t> LocationIdx =
       Abbrev->findAttributeIndex(dwarf::DW_AT_location);
   if (!LocationIdx)
@@ -754,9 +754,7 @@ void DwarfLinker::keepDIEAndDependencies
       continue;
     }
 
-    Val = DWARFFormValue::createFromData(AttrSpec.Form, Unit.getFormParams(),
-                                         Unit, Unit.getDebugInfoExtractor(),
-                                         &Offset);
+    Val.extractValue(Data, &Offset, Unit.getFormParams(), &Unit);
     CompileUnit *ReferencedCU;
     if (auto RefDie = resolveDIEReference(*this, DMO, Units, Val, Unit, Die,
                                           ReferencedCU)) {
@@ -1554,9 +1552,9 @@ DIE *DwarfLinker::DIECloner::cloneDIE(
       continue;
     }
 
+    DWARFFormValue Val(AttrSpec.Form);
     uint32_t AttrSize = Offset;
-    DWARFFormValue Val = DWARFFormValue::createFromData(
-        AttrSpec.Form, U.getFormParams(), U, Data, &Offset);
+    Val.extractValue(Data, &Offset, U.getFormParams(), &U);
     AttrSize = Offset - AttrSize;
 
     OutOffset += cloneAttribute(*Die, InputDIE, DMO, Unit, StringPool, Val,




More information about the llvm-commits mailing list