summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-01-25 23:21:18 +0000
committerZachary Turner <zturner@google.com>2016-01-25 23:21:18 +0000
commit4407396fb94dc3a1da5b51f9512381f9bb46ca64 (patch)
tree1117e1b13e0b664b9808a077d443c9d4f626f5ee /lldb/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py
parentbea3a85151ef5154f0c99722b5bad5bb56b2ac55 (diff)
downloadbcm5719-llvm-4407396fb94dc3a1da5b51f9512381f9bb46ca64.tar.gz
bcm5719-llvm-4407396fb94dc3a1da5b51f9512381f9bb46ca64.zip
Fix some issues with bytes and strings in Python 3.
SBProcess::ReadMemory and other related functions such as WriteMemory are returning Python string() objects. This means that in Python 3 that are returning Unicode objects. In reality they should be returning bytes objects which is the same as a string in Python 2, but different in Python 3. This patch updates the generated SWIG code to return Python bytes objects for all memory related functions. One quirk of this patch is that the C++ signature of ReadCStringFromMemory has it writing c-string data into a void*. This confuses our swig typemaps which expect that a void* means byte data. So I hacked up a custom typemap which maps this specific function to treat the void* as string data instead of byte data. llvm-svn: 258743
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py')
-rw-r--r--lldb/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py12
1 files changed, 4 insertions, 8 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py b/lldb/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py
index f312bc8a924..31d129b67ee 100644
--- a/lldb/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py
+++ b/lldb/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py
@@ -56,7 +56,7 @@ class ProcessAPITestCase(TestBase):
self.expect(content, "Result from SBProcess.ReadMemory() matches our expected output: 'x'",
exe=False,
- startstr = 'x')
+ startstr = b'x')
# Read (char *)my_char_ptr.
val = frame.FindValue("my_char_ptr", lldb.eValueTypeVariableGlobal)
@@ -154,7 +154,7 @@ class ProcessAPITestCase(TestBase):
self.expect(content, "Result from SBProcess.ReadMemory() matches our expected output: 'a'",
exe=False,
- startstr = 'a')
+ startstr = b'a')
@add_test_categories(['pyapi'])
def test_access_my_int(self):
@@ -206,9 +206,8 @@ class ProcessAPITestCase(TestBase):
# But we want to use the WriteMemory() API to assign 256 to the variable.
# Now use WriteMemory() API to write 256 into the global variable.
- new_value = str(bytes)
error = lldb.SBError()
- result = process.WriteMemory(location, new_value, error)
+ result = process.WriteMemory(location, bytes, error)
if not error.Success() or result != byteSize:
self.fail("SBProcess.WriteMemory() failed")
@@ -230,14 +229,11 @@ class ProcessAPITestCase(TestBase):
if not error.Success():
self.fail("SBProcess.ReadMemory() failed")
- # Use "ascii" as the encoding because each element of 'content' is in the range [0..255].
- new_bytes = bytearray(content, "ascii")
-
# The bytearray_to_int utility function expects a little endian bytearray.
if byteOrder == lldb.eByteOrderBig:
new_bytes.reverse()
- new_value = bytearray_to_int(new_bytes, byteSize)
+ new_value = bytearray_to_int(content, byteSize)
if new_value != 256:
self.fail("Memory content read from 'my_int' does not match (int)256")
OpenPOWER on IntegriCloud