[llvm] 5754a61 - [DataExtractor] Improve error message when we run off the end of the buffer
Pavel Labath via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 28 00:32:36 PST 2020
Author: Pavel Labath
Date: 2020-02-28T09:02:33+01:00
New Revision: 5754a61e57efaa9bec8ad8ea8589a73b27edb0a8
URL: https://github.com/llvm/llvm-project/commit/5754a61e57efaa9bec8ad8ea8589a73b27edb0a8
DIFF: https://github.com/llvm/llvm-project/commit/5754a61e57efaa9bec8ad8ea8589a73b27edb0a8.diff
LOG: [DataExtractor] Improve error message when we run off the end of the buffer
Summary: Include the offset at which this happened.
Reviewers: dblaikie, jhenderson
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75265
Added:
Modified:
llvm/lib/Support/DataExtractor.cpp
llvm/test/DebugInfo/X86/dwarfdump-debug-loc-error-cases2.s
llvm/test/DebugInfo/X86/dwarfdump-debug-loclists-error-cases2.s
llvm/unittests/DebugInfo/DWARF/DWARFDataExtractorTest.cpp
llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/DataExtractor.cpp b/llvm/lib/Support/DataExtractor.cpp
index 3d19b4d481bb..d6fd9a5e09a0 100644
--- a/llvm/lib/Support/DataExtractor.cpp
+++ b/llvm/lib/Support/DataExtractor.cpp
@@ -15,10 +15,11 @@
using namespace llvm;
-static void unexpectedEndReached(Error *E) {
+static void unexpectedEndReached(Error *E, uint64_t Offset) {
if (E)
*E = createStringError(errc::illegal_byte_sequence,
- "unexpected end of data");
+ "unexpected end of data at offset 0x%" PRIx64,
+ Offset);
}
static bool isError(Error *E) { return E && *E; }
@@ -33,7 +34,7 @@ static T getU(uint64_t *offset_ptr, const DataExtractor *de,
uint64_t offset = *offset_ptr;
if (!de->isValidOffsetForDataOfSize(offset, sizeof(T))) {
- unexpectedEndReached(Err);
+ unexpectedEndReached(Err, offset);
return val;
}
std::memcpy(&val, &Data[offset], sizeof(val));
@@ -56,7 +57,7 @@ static T *getUs(uint64_t *offset_ptr, T *dst, uint32_t count,
uint64_t offset = *offset_ptr;
if (!de->isValidOffsetForDataOfSize(offset, sizeof(*dst) * count)) {
- unexpectedEndReached(Err);
+ unexpectedEndReached(Err, offset);
return nullptr;
}
for (T *value_ptr = dst, *end = dst + count; value_ptr != end;
@@ -229,5 +230,5 @@ void DataExtractor::skip(Cursor &C, uint64_t Length) const {
if (isValidOffsetForDataOfSize(C.Offset, Length))
C.Offset += Length;
else
- unexpectedEndReached(&C.Err);
+ unexpectedEndReached(&C.Err, C.Offset);
}
diff --git a/llvm/test/DebugInfo/X86/dwarfdump-debug-loc-error-cases2.s b/llvm/test/DebugInfo/X86/dwarfdump-debug-loc-error-cases2.s
index f15deb546ed0..7e951e58d2c7 100644
--- a/llvm/test/DebugInfo/X86/dwarfdump-debug-loc-error-cases2.s
+++ b/llvm/test/DebugInfo/X86/dwarfdump-debug-loc-error-cases2.s
@@ -8,11 +8,11 @@
# CHECK: DW_AT_name ("x1")
# CHECK-NEXT: DW_AT_location (0xdeadbeef
-# CHECK-NEXT: error: unexpected end of data)
+# CHECK-NEXT: error: unexpected end of data at offset 0xdeadbeef)
# CHECK: DW_AT_name ("x2")
# CHECK-NEXT: DW_AT_location (0x00000036
-# CHECK-NEXT: error: unexpected end of data)
+# CHECK-NEXT: error: unexpected end of data at offset 0x48)
.type f, at function
diff --git a/llvm/test/DebugInfo/X86/dwarfdump-debug-loclists-error-cases2.s b/llvm/test/DebugInfo/X86/dwarfdump-debug-loclists-error-cases2.s
index 48ae8d4db755..7a0c42c64f97 100644
--- a/llvm/test/DebugInfo/X86/dwarfdump-debug-loclists-error-cases2.s
+++ b/llvm/test/DebugInfo/X86/dwarfdump-debug-loclists-error-cases2.s
@@ -8,11 +8,11 @@
# CHECK: DW_AT_name ("x1")
# CHECK-NEXT: DW_AT_location (0xdeadbeef
-# CHECK-NEXT: error: unexpected end of data)
+# CHECK-NEXT: error: unexpected end of data at offset 0xdeadbeef)
# CHECK: DW_AT_name ("x2")
# CHECK-NEXT: DW_AT_location (0x00000025
-# CHECK-NEXT: error: unexpected end of data)
+# CHECK-NEXT: error: unexpected end of data at offset 0x34)
.type f, at function
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDataExtractorTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDataExtractorTest.cpp
index 589ae3ff12b1..6528cd074c86 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFDataExtractorTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFDataExtractorTest.cpp
@@ -41,13 +41,15 @@ TEST(DWARFDataExtractorTest, getInitialLength) {
auto ErrorResult = std::make_tuple(0, dwarf::DWARF32, 0);
// Empty data.
- EXPECT_THAT_EXPECTED(GetWithError({}),
- FailedWithMessage("unexpected end of data"));
+ EXPECT_THAT_EXPECTED(
+ GetWithError({}),
+ FailedWithMessage("unexpected end of data at offset 0x0"));
EXPECT_EQ(GetWithoutError({}), ErrorResult);
// Not long enough for the U32 field.
- EXPECT_THAT_EXPECTED(GetWithError({0x00, 0x01, 0x02}),
- FailedWithMessage("unexpected end of data"));
+ EXPECT_THAT_EXPECTED(
+ GetWithError({0x00, 0x01, 0x02}),
+ FailedWithMessage("unexpected end of data at offset 0x0"));
EXPECT_EQ(GetWithoutError({0x00, 0x01, 0x02}), ErrorResult);
EXPECT_THAT_EXPECTED(
@@ -72,14 +74,15 @@ TEST(DWARFDataExtractorTest, getInitialLength) {
EXPECT_EQ(GetWithoutError({0xff, 0xff, 0xff, 0xf0}), ErrorResult);
// DWARF64 marker without the subsequent length field.
- EXPECT_THAT_EXPECTED(GetWithError({0xff, 0xff, 0xff, 0xff}),
- FailedWithMessage("unexpected end of data"));
+ EXPECT_THAT_EXPECTED(
+ GetWithError({0xff, 0xff, 0xff, 0xff}),
+ FailedWithMessage("unexpected end of data at offset 0x4"));
EXPECT_EQ(GetWithoutError({0xff, 0xff, 0xff, 0xff}), ErrorResult);
// Not enough data for the U64 length.
EXPECT_THAT_EXPECTED(
GetWithError({0xff, 0xff, 0xff, 0xff, 0x00, 0x01, 0x02, 0x03}),
- FailedWithMessage("unexpected end of data"));
+ FailedWithMessage("unexpected end of data at offset 0x4"));
EXPECT_EQ(GetWithoutError({0xff, 0xff, 0xff, 0xff, 0x00, 0x01, 0x02, 0x03}),
ErrorResult);
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp
index 53124925a895..b662965a482e 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFDieTest.cpp
@@ -105,9 +105,9 @@ TEST(DWARFDie, getLocations) {
&ErrorInfoBase::message,
"Unable to resolve indirect address 1 for: DW_LLE_startx_length")));
- EXPECT_THAT_EXPECTED(Die.getLocations(DW_AT_call_data_location),
- Failed<ErrorInfoBase>(testing::Property(
- &ErrorInfoBase::message, "unexpected end of data")));
+ EXPECT_THAT_EXPECTED(
+ Die.getLocations(DW_AT_call_data_location),
+ FailedWithMessage("unexpected end of data at offset 0x20"));
EXPECT_THAT_EXPECTED(
Die.getLocations(DW_AT_call_data_value),
More information about the llvm-commits
mailing list