[PATCH] D72337: [DebugInfo][Support] Replace DWARFDataExtractor size function

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 7 08:21:10 PST 2020


jhenderson created this revision.
jhenderson added reviewers: JDevlieghere, MaskRay, ikudrin, vleschuk, labath, aprantl, dblaikie.
Herald added a project: LLVM.

This patch adds a new size function to the base DataExtractor class, which removes the need for the DWARFDataExtractor size function.

It is unclear why DWARFDataExtractor's size function returned zero in some circumstances (i.e. when it is constructed without a section, and with a different data source instead), so that behaviour has changed. The old behaviour could cause an assertion in the debug line parser, as the size did not reflect the actual data available, and could be lower than the current offset being parsed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72337

Files:
  llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h
  llvm/include/llvm/Support/DataExtractor.h
  llvm/unittests/Support/DataExtractorTest.cpp


Index: llvm/unittests/Support/DataExtractorTest.cpp
===================================================================
--- llvm/unittests/Support/DataExtractorTest.cpp
+++ llvm/unittests/Support/DataExtractorTest.cpp
@@ -269,4 +269,13 @@
   EXPECT_TRUE(DE.eof(C));
   EXPECT_THAT_ERROR(C.takeError(), Succeeded());
 }
+
+TEST(DataExtractorTest, size) {
+  uint8_t Data[] = {'A', 'B', 'C', 'D'};
+  DataExtractor DE1(StringRef(reinterpret_cast<char *>(Data), sizeof(Data)),
+                    false, 8);
+  EXPECT_EQ(DE1.size(), sizeof(Data));
+  DataExtractor DE2(ArrayRef<uint8_t>(Data), false, 8);
+  EXPECT_EQ(DE2.size(), sizeof(Data));
+}
 }
Index: llvm/include/llvm/Support/DataExtractor.h
===================================================================
--- llvm/include/llvm/Support/DataExtractor.h
+++ llvm/include/llvm/Support/DataExtractor.h
@@ -534,14 +534,14 @@
   /// error state of the cursor. The only way both eof and error states can be
   /// true is if one attempts a read while the cursor is at the very end of the
   /// data buffer.
-  bool eof(const Cursor &C) const { return Data.size() == C.Offset; }
+  bool eof(const Cursor &C) const { return size() == C.Offset; }
 
   /// Test the validity of \a offset.
   ///
   /// @return
   ///     \b true if \a offset is a valid offset into the data in this
   ///     object, \b false otherwise.
-  bool isValidOffset(uint64_t offset) const { return Data.size() > offset; }
+  bool isValidOffset(uint64_t offset) const { return size() > offset; }
 
   /// Test the availability of \a length bytes of data from \a offset.
   ///
@@ -563,6 +563,9 @@
     return isValidOffsetForDataOfSize(offset, AddressSize);
   }
 
+  /// Return the number of bytes in the underlying buffer.
+  size_t size() const { return Data.size(); }
+
 protected:
   // Make it possible for subclasses to access these fields without making them
   // public.
Index: llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h
===================================================================
--- llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h
+++ llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h
@@ -55,8 +55,6 @@
   /// reflect the absolute address of this pointer.
   Optional<uint64_t> getEncodedPointer(uint64_t *Offset, uint8_t Encoding,
                                        uint64_t AbsPosOffset = 0) const;
-
-  size_t size() const { return Section == nullptr ? 0 : Section->Data.size(); }
 };
 
 } // end namespace llvm


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72337.236595.patch
Type: text/x-patch
Size: 2491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200107/22daae40/attachment.bin>


More information about the llvm-commits mailing list