[PATCH] D49379: lldbsuite: ignore decoding errors in _encoded_write

Konstantin Baladurin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 16 08:05:08 PDT 2018


kbaladurin created this revision.
kbaladurin added a reviewer: labath.
kbaladurin added a project: LLDB.
Herald added a subscriber: llvm-commits.

This patch fixes random test fails due to UnicodeDecodeError:

    ...
     File "lldb/packages/Python/lldbsuite/test/lldbtest.py", line 2070, in runCmd
      print(self.res.GetError(), file=sbuf)
    File "lldb/packages/Python/lldbsuite/test/lldbtest.py", line 293, in __exit__
      print(self.getvalue(), file=self.session)
    File "lldb/packages/Python/lldbsuite/support/encoded_file.py", line 34, in impl
      s = s.decode(encoding)
    File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
      return codecs.utf_8_decode(input, errors, True)
  UnicodeDecodeError: 'utf8' codec can't decode byte 0xfb in position 257: invalid start byte

This error occurs when we try to decode string that contains garbage, for example:

  runCmd: process continue
  output: Process 579 resuming
  Process 579 stopped
  * thread #2, name = 'test_hello_watc', stop reason = watchpoint 1
      frame #0: 0x000000000040150f func(char_ptr="\x01$\xad�, new_val='\x01') at main.cpp:40
     37           unsigned what = new_val;
     38           printf("new value written to location(%p) = %u\n", char_ptr, what);
     39           *char_ptr = new_val;
  -> 40       }
     41
     42       uint32_t
     43       access_pool (bool flag = false)

In such cases we should ignore decoding errors.


Repository:
  rL LLVM

https://reviews.llvm.org/D49379

Files:
  packages/Python/lldbsuite/support/encoded_file.py


Index: packages/Python/lldbsuite/support/encoded_file.py
===================================================================
--- packages/Python/lldbsuite/support/encoded_file.py
+++ packages/Python/lldbsuite/support/encoded_file.py
@@ -31,7 +31,7 @@
         # If we were asked to write a `str` (in Py2) or a `bytes` (in Py3) decode it
         # as unicode before attempting to write.
         if isinstance(s, six.binary_type):
-            s = s.decode(encoding)
+            s = s.decode(encoding, 'ignore')
         return old_write(s)
     return impl
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49379.155645.patch
Type: text/x-patch
Size: 561 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180716/19cc3336/attachment.bin>


More information about the llvm-commits mailing list