[PATCH] D80799: [Support] Add more context to DataExtractor getLEB128 errors

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 1 06:23:52 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG8d9070e040d0: [Support] Add more context to DataExtractor getLEB128 errors (authored by jhenderson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80799/new/

https://reviews.llvm.org/D80799

Files:
  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


Index: llvm/unittests/Support/DataExtractorTest.cpp
===================================================================
--- llvm/unittests/Support/DataExtractorTest.cpp
+++ 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) {
Index: llvm/test/tools/llvm-dwarfdump/X86/debug_line_short_prologue.s
===================================================================
--- llvm/test/tools/llvm-dwarfdump/X86/debug_line_short_prologue.s
+++ 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"
Index: llvm/test/DebugInfo/X86/dwarfdump-debug-loclists-error-cases.s
===================================================================
--- llvm/test/DebugInfo/X86/dwarfdump-debug-loclists-error-cases.s
+++ 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
Index: llvm/lib/Support/DataExtractor.cpp
===================================================================
--- llvm/lib/Support/DataExtractor.cpp
+++ 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80799.267600.patch
Type: text/x-patch
Size: 4945 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200601/e6024a39/attachment.bin>


More information about the llvm-commits mailing list