diff options
author | James Henderson <james.henderson@sony.com> | 2020-01-13 09:30:52 +0000 |
---|---|---|
committer | James Henderson <james.henderson@sony.com> | 2020-01-13 10:53:00 +0000 |
commit | b6ffa2fe1250a8f506cc66044275b0bced56059e (patch) | |
tree | 4e90d3b012779005afa50bad6fd76bbaeec52bd1 | |
parent | add04b9653848de583c542e0596737f7d7c21553 (diff) | |
download | bcm5719-llvm-b6ffa2fe1250a8f506cc66044275b0bced56059e.tar.gz bcm5719-llvm-b6ffa2fe1250a8f506cc66044275b0bced56059e.zip |
[DebugInfo][Support] Replace DWARFDataExtractor size function
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.
Reviewed by: dblaikie
Differential Revision: https://reviews.llvm.org/D72337
-rw-r--r-- | llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/Support/DataExtractor.h | 7 | ||||
-rw-r--r-- | llvm/unittests/Support/DataExtractorTest.cpp | 9 |
3 files changed, 14 insertions, 4 deletions
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h index 980724c525d..6f7ddb2ef42 100644 --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h @@ -55,8 +55,6 @@ public: /// 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 diff --git a/llvm/include/llvm/Support/DataExtractor.h b/llvm/include/llvm/Support/DataExtractor.h index f590a1e104f..0be478811b2 100644 --- a/llvm/include/llvm/Support/DataExtractor.h +++ b/llvm/include/llvm/Support/DataExtractor.h @@ -534,14 +534,14 @@ public: /// 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 @@ public: 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. diff --git a/llvm/unittests/Support/DataExtractorTest.cpp b/llvm/unittests/Support/DataExtractorTest.cpp index d182715d199..cdb8bfdcb8b 100644 --- a/llvm/unittests/Support/DataExtractorTest.cpp +++ b/llvm/unittests/Support/DataExtractorTest.cpp @@ -269,4 +269,13 @@ TEST(DataExtractorTest, eof) { 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)); +} } |