Skip to content

Commit b6ffa2f

Browse files
committed
[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
1 parent add04b9 commit b6ffa2f

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h

-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ class DWARFDataExtractor : public DataExtractor {
5555
/// reflect the absolute address of this pointer.
5656
Optional<uint64_t> getEncodedPointer(uint64_t *Offset, uint8_t Encoding,
5757
uint64_t AbsPosOffset = 0) const;
58-
59-
size_t size() const { return Section == nullptr ? 0 : Section->Data.size(); }
6058
};
6159

6260
} // end namespace llvm

llvm/include/llvm/Support/DataExtractor.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -534,14 +534,14 @@ class DataExtractor {
534534
/// error state of the cursor. The only way both eof and error states can be
535535
/// true is if one attempts a read while the cursor is at the very end of the
536536
/// data buffer.
537-
bool eof(const Cursor &C) const { return Data.size() == C.Offset; }
537+
bool eof(const Cursor &C) const { return size() == C.Offset; }
538538

539539
/// Test the validity of \a offset.
540540
///
541541
/// @return
542542
/// \b true if \a offset is a valid offset into the data in this
543543
/// object, \b false otherwise.
544-
bool isValidOffset(uint64_t offset) const { return Data.size() > offset; }
544+
bool isValidOffset(uint64_t offset) const { return size() > offset; }
545545

546546
/// Test the availability of \a length bytes of data from \a offset.
547547
///
@@ -563,6 +563,9 @@ class DataExtractor {
563563
return isValidOffsetForDataOfSize(offset, AddressSize);
564564
}
565565

566+
/// Return the number of bytes in the underlying buffer.
567+
size_t size() const { return Data.size(); }
568+
566569
protected:
567570
// Make it possible for subclasses to access these fields without making them
568571
// public.

llvm/unittests/Support/DataExtractorTest.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,13 @@ TEST(DataExtractorTest, eof) {
269269
EXPECT_TRUE(DE.eof(C));
270270
EXPECT_THAT_ERROR(C.takeError(), Succeeded());
271271
}
272+
273+
TEST(DataExtractorTest, size) {
274+
uint8_t Data[] = {'A', 'B', 'C', 'D'};
275+
DataExtractor DE1(StringRef(reinterpret_cast<char *>(Data), sizeof(Data)),
276+
false, 8);
277+
EXPECT_EQ(DE1.size(), sizeof(Data));
278+
DataExtractor DE2(ArrayRef<uint8_t>(Data), false, 8);
279+
EXPECT_EQ(DE2.size(), sizeof(Data));
280+
}
272281
}

0 commit comments

Comments
 (0)