[Lldb-commits] [PATCH] D58177: Fix lldb-server test suite for python3

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Feb 13 06:56:42 PST 2019


labath created this revision.
labath added reviewers: davide, zturner.
Herald added a reviewer: serge-sans-paille.

This patch finishes the python3-ification of the lldb-server test suite.
It reverts the partial attempt in r352709 to encode/decode the string
via utf8 before writing to the socket. This wasn't enough because the
gdb-remote protocol can sometimes (but not very often) carry binary
data, and the utf8 codec chokes on that. Instead I add utility functions
to the "seven" module for performing "identity" transformations on the
byte data. This basically drills back the hole in the python type system
that the string/bytes distinction was supposed to plug. That is not
ideal, but was the best solution of the alternatives I could come up
with. The options I considered were:

- make use of the type system to add type safety to the test suite: This required making a lot of changes to the test suite, since most of the strings would now become byte objects instead, and it was not even fully clear to me where to draw the line. One extreme solution would be to just use byte objects everywhere, as the protocol doesn't support non-ascii characters anyway. However, this appeared to be: a) weird, because most of the protocol actually deals with strings, but we would have to prefix everything with 'b' b) clunky, because the handling of the bytes objects is sufficiently different in PY2 and PY3 (e.g. b'a'[0] is a string in PY2, but an int in PY3).
- using the latin1 codec (which gives an identity transformation for the first 256 code points of unicode) instead of the custom bytes_to_string functions. This almost could work, but it was still slightly different between python 2 and 3, because in PY2 in would return a unicode object, which would then cause problems when combined with regular strings if it contained 8-bit chars.

With this in mind, I think the best solution for the time being is to
just coerce everything into the string type as early as possible, and
have things proceed indentically on both python versions. Once we stop
supporting python3, we can revisit the idea of using bytes objects more
prevasively.


https://reviews.llvm.org/D58177

Files:
  packages/Python/lldbsuite/support/seven.py
  packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteModuleInfo.py
  packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py
  packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
  packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
  packages/Python/lldbsuite/test/tools/lldb-server/socket_packet_pump.py

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58177.186646.patch
Type: text/x-patch
Size: 8059 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190213/4f2dfbed/attachment-0001.bin>


More information about the lldb-commits mailing list