diff --git a/llvm/lib/Support/DataExtractor.cpp b/llvm/lib/Support/DataExtractor.cpp --- a/llvm/lib/Support/DataExtractor.cpp +++ b/llvm/lib/Support/DataExtractor.cpp @@ -206,7 +206,10 @@ 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 --- 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,"",@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 --- 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 --- a/llvm/unittests/Support/DataExtractorTest.cpp +++ b/llvm/unittests/Support/DataExtractorTest.cpp @@ -137,11 +137,25 @@ 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) {