[llvm] 8d9070e - [Support] Add more context to DataExtractor getLEB128 errors
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 1 06:00:32 PDT 2020
Author: James Henderson
Date: 2020-06-01T14:00:01+01:00
New Revision: 8d9070e040d0aa916b3b63c319eabdf3e4a5f9df
URL: https://github.com/llvm/llvm-project/commit/8d9070e040d0aa916b3b63c319eabdf3e4a5f9df
DIFF: https://github.com/llvm/llvm-project/commit/8d9070e040d0aa916b3b63c319eabdf3e4a5f9df.diff
LOG: [Support] Add more context to DataExtractor getLEB128 errors
Reviewed by: clayborg, dblaikie, labath
Differential Revision: https://reviews.llvm.org/D80799
Added:
Modified:
llvm/lib/Support/DataExtractor.cpp
llvm/test/DebugInfo/X86/dwarfdump-debug-loclists-error-cases.s
llvm/test/tools/llvm-dwarfdump/X86/debug_line_short_prologue.s
llvm/unittests/Support/DataExtractorTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/DataExtractor.cpp b/llvm/lib/Support/DataExtractor.cpp
index aaf20ebf8425..99265c4c001b 100644
--- a/llvm/lib/Support/DataExtractor.cpp
+++ b/llvm/lib/Support/DataExtractor.cpp
@@ -206,7 +206,10 @@ static T getLEB128(StringRef Data, uint64_t *OffsetPtr, Error *Err,
Decoder(Bytes.data() + *OffsetPtr, &bytes_read, Bytes.end(), &error);
if (error) {
if (Err)
- *Err = createStringError(errc::illegal_byte_sequence, error);
+ *Err = createStringError(errc::illegal_byte_sequence,
+ "unable to decode LEB128 at offset 0x%8.8" PRIx64
+ ": %s",
+ *OffsetPtr, error);
return T();
}
*OffsetPtr += bytes_read;
diff --git a/llvm/test/DebugInfo/X86/dwarfdump-debug-loclists-error-cases.s b/llvm/test/DebugInfo/X86/dwarfdump-debug-loclists-error-cases.s
index 048104986fa4..ec92651a16ec 100644
--- a/llvm/test/DebugInfo/X86/dwarfdump-debug-loclists-error-cases.s
+++ b/llvm/test/DebugInfo/X86/dwarfdump-debug-loclists-error-cases.s
@@ -1,11 +1,11 @@
# RUN: llvm-mc %s -filetype obj -triple x86_64-pc-linux --defsym CASE1=0 -o %t1.o
-# RUN: not llvm-dwarfdump -debug-loclists %t1.o 2>&1 | FileCheck %s --check-prefix=ULEB
+# RUN: not llvm-dwarfdump -debug-loclists %t1.o 2>&1 | FileCheck %s --check-prefix=ULEB -DOFFSET=0x0000000d
# RUN: llvm-mc %s -filetype obj -triple x86_64-pc-linux --defsym CASE2=0 -o %t2.o
-# RUN: not llvm-dwarfdump -debug-loclists %t2.o 2>&1 | FileCheck %s --check-prefix=ULEB
+# RUN: not llvm-dwarfdump -debug-loclists %t2.o 2>&1 | FileCheck %s --check-prefix=ULEB -DOFFSET=0x0000000e
# RUN: llvm-mc %s -filetype obj -triple x86_64-pc-linux --defsym CASE3=0 -o %t3.o
-# RUN: not llvm-dwarfdump -debug-loclists %t3.o 2>&1 | FileCheck %s --check-prefix=ULEB
+# RUN: not llvm-dwarfdump -debug-loclists %t3.o 2>&1 | FileCheck %s --check-prefix=ULEB -DOFFSET=0x0000000f
# RUN: llvm-mc %s -filetype obj -triple x86_64-pc-linux --defsym CASE4=0 -o %t4.o
# RUN: not llvm-dwarfdump -debug-loclists %t4.o 2>&1 | FileCheck %s
@@ -20,7 +20,7 @@
# RUN: not llvm-dwarfdump -debug-loclists %t7.o 2>&1 | FileCheck %s --check-prefix=UNIMPL
# CHECK: error: unexpected end of data
-# ULEB: error: malformed uleb128, extends past end
+# ULEB: error: unable to decode LEB128 at offset [[OFFSET]]: malformed uleb128, extends past end
# UNIMPL: error: LLE of kind 47 not supported
.section .debug_loclists,"", at progbits
diff --git a/llvm/test/tools/llvm-dwarfdump/X86/debug_line_short_prologue.s b/llvm/test/tools/llvm-dwarfdump/X86/debug_line_short_prologue.s
index 0bf4bc90d85d..20391e7ea4d3 100644
--- a/llvm/test/tools/llvm-dwarfdump/X86/debug_line_short_prologue.s
+++ b/llvm/test/tools/llvm-dwarfdump/X86/debug_line_short_prologue.s
@@ -17,9 +17,9 @@
# C0-NEXT: warning: parsing line table prologue at 0x00000000 found an invalid directory or file table description at 0x00000027
# C0-NEXT: warning: failed to parse entry content descriptors: unexpected end of data at offset 0x27
# C1-NEXT: warning: parsing line table prologue at 0x00000000 found an invalid directory or file table description at 0x0000002a
-# C1-NEXT: warning: failed to parse entry content descriptors: malformed uleb128, extends past end
+# C1-NEXT: warning: failed to parse entry content descriptors: unable to decode LEB128 at offset 0x0000002a: malformed uleb128, extends past end
# C2-NEXT: warning: parsing line table prologue at 0x00000000 found an invalid directory or file table description at 0x0000002b
-# C2-NEXT: warning: failed to parse entry content descriptors: malformed uleb128, extends past end
+# C2-NEXT: warning: failed to parse entry content descriptors: unable to decode LEB128 at offset 0x0000002b: malformed uleb128, extends past end
# ALL: include_directories[ 0] = "/tmp"
# OK: file_names[ 0]:
# OK-NEXT: name: "foo"
diff --git a/llvm/unittests/Support/DataExtractorTest.cpp b/llvm/unittests/Support/DataExtractorTest.cpp
index 651961586071..cec08554e8f2 100644
--- a/llvm/unittests/Support/DataExtractorTest.cpp
+++ b/llvm/unittests/Support/DataExtractorTest.cpp
@@ -137,11 +137,25 @@ TEST(DataExtractorTest, LEB128_error) {
DataExtractor::Cursor C(0);
EXPECT_EQ(0U, DE.getULEB128(C));
- EXPECT_THAT_ERROR(C.takeError(), Failed());
+ EXPECT_THAT_ERROR(
+ C.takeError(),
+ FailedWithMessage("unable to decode LEB128 at offset 0x00000000: "
+ "malformed uleb128, extends past end"));
C = DataExtractor::Cursor(0);
EXPECT_EQ(0U, DE.getSLEB128(C));
- EXPECT_THAT_ERROR(C.takeError(), Failed());
+ EXPECT_THAT_ERROR(
+ C.takeError(),
+ FailedWithMessage("unable to decode LEB128 at offset 0x00000000: "
+ "malformed sleb128, extends past end"));
+
+ // Show non-zero offsets are reported appropriately.
+ C = DataExtractor::Cursor(1);
+ EXPECT_EQ(0U, DE.getULEB128(C));
+ EXPECT_THAT_ERROR(
+ C.takeError(),
+ FailedWithMessage("unable to decode LEB128 at offset 0x00000001: "
+ "malformed uleb128, extends past end"));
}
TEST(DataExtractorTest, Cursor_tell) {
More information about the llvm-commits
mailing list