+import binascii
import six
if six.PY2:
return get_command_status_output(command)[1]
cmp_ = lambda x, y: (x > y) - (x < y)
+
+def bitcast_to_string(b):
+ """
+ Take a string(PY2) or a bytes(PY3) object and return a string. The returned
+ string contains the exact same bytes as the input object (latin1 <-> unicode
+ transformation is an identity operation for the first 256 code points).
+ """
+ return b if six.PY2 else b.decode("latin1")
+
+def bitcast_to_bytes(s):
+ """
+ Take a string and return a string(PY2) or a bytes(PY3) object. The returned
+ object contains the exact same bytes as the input string. (latin1 <->
+ unicode transformation is an identity operation for the first 256 code
+ points).
+ """
+ return s if six.PY2 else s.encode("latin1")
+
+def unhexlify(hexstr):
+ """Hex-decode a string. The result is always a string."""
+ return bitcast_to_string(binascii.unhexlify(hexstr))
+
+def hexlify(data):
+ """Hex-encode string data. The result if always a string."""
+ return bitcast_to_string(binascii.hexlify(bitcast_to_bytes(data)))
import gdbremote_testcase
import lldbgdbserverutils
+from lldbsuite.support import seven
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
self.test_sequence.add_log_lines([
'read packet: $jModulesInfo:[{"file":"%s","triple":"%s"}]]#00' % (
lldbutil.append_to_process_working_directory(self, "a.out"),
- info["triple"].decode('hex')),
+ seven.unhexlify(info["triple"])),
{"direction": "send",
"regex": r'^\$\[{(.*)}\]\]#[0-9A-Fa-f]{2}',
"capture": {1: "spec"}},
the initial set of tests implemented.
"""
-from __future__ import print_function
+from __future__ import division, print_function
import unittest2
import lldbgdbserverutils
import platform
import signal
+from lldbsuite.support import seven
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test.lldbdwarf import *
# Ensure what we read from inferior memory is what we wrote.
self.assertIsNotNone(context.get("read_contents"))
- read_contents = context.get("read_contents").decode("hex")
+ read_contents = seven.unhexlify(context.get("read_contents"))
self.assertEqual(read_contents, MEMORY_CONTENTS)
@debugserver_test
message_address = int(context.get("message_address"), 16)
# Hex-encode the test message, adding null termination.
- hex_encoded_message = TEST_MESSAGE.encode("hex")
+ hex_encoded_message = seven.hexlify(TEST_MESSAGE)
# Write the message to the inferior. Verify that we can read it with the hex-encoded (m)
# and binary (x) memory read packets.
reg_index = self.select_modifiable_register(reg_infos)
self.assertIsNotNone(reg_index)
- reg_byte_size = int(reg_infos[reg_index]["bitsize"]) / 8
+ reg_byte_size = int(reg_infos[reg_index]["bitsize"]) // 8
self.assertTrue(reg_byte_size > 0)
# Run the process a bit so threads can start up, and collect register
Base class for gdb-remote test cases.
"""
-from __future__ import print_function
+from __future__ import division, print_function
import errno
import time
from lldbsuite.test import configuration
from lldbsuite.test.lldbtest import *
+from lldbsuite.support import seven
from lldbgdbserverutils import *
import logging
if can_read and sock in can_read:
recv_bytes = sock.recv(4096)
if recv_bytes:
- response += recv_bytes.decode("utf-8")
+ response += seven.bitcast_to_string(recv_bytes)
self.assertTrue(expected_content_regex.match(response))
reg_index = reg_info["lldb_register_index"]
self.assertIsNotNone(reg_index)
- reg_byte_size = int(reg_info["bitsize"]) / 8
+ reg_byte_size = int(reg_info["bitsize"]) // 8
self.assertTrue(reg_byte_size > 0)
# Handle thread suffix.
endian, p_response)
# Flip the value by xoring with all 1s
- all_one_bits_raw = "ff" * (int(reg_info["bitsize"]) / 8)
+ all_one_bits_raw = "ff" * (int(reg_info["bitsize"]) // 8)
flipped_bits_int = initial_reg_value ^ int(all_one_bits_raw, 16)
# print("reg (index={}, name={}): val={}, flipped bits (int={}, hex={:x})".format(reg_index, reg_info["name"], initial_reg_value, flipped_bits_int, flipped_bits_int))
self.assertIsNotNone(context.get("g_c1_contents"))
self.assertIsNotNone(context.get("g_c2_contents"))
- return (context.get("g_c1_contents").decode("hex") == expected_g_c1) and (
- context.get("g_c2_contents").decode("hex") == expected_g_c2)
+ return (seven.unhexlify(context.get("g_c1_contents")) == expected_g_c1) and (
+ seven.unhexlify(context.get("g_c2_contents")) == expected_g_c2)
def single_step_only_steps_one_instruction(
self, use_Hc_packet=True, step_instruction="s"):
"""Module for supporting unit testing of the lldb-server debug monitor exe.
"""
-from __future__ import print_function
+from __future__ import division, print_function
import os
value = value >> 8
if byte_size:
# Add zero-fill to the right/end (MSB side) of the value.
- retval += "00" * (byte_size - len(retval) / 2)
+ retval += "00" * (byte_size - len(retval) // 2)
return retval
elif endian == 'big':
value = value >> 8
if byte_size:
# Add zero-fill to the left/front (MSB side) of the value.
- retval = ("00" * (byte_size - len(retval) / 2)) + retval
+ retval = ("00" * (byte_size - len(retval) // 2)) + retval
return retval
else:
import codecs
from six.moves import queue
+from lldbsuite.support import seven
def _handle_output_packet_string(packet_contents):
elif packet_contents == "OK":
return None
else:
- return packet_contents[1:].decode("hex")
+ return seven.unhexlify(packet_contents[1:])
def _dump_queue(the_queue):
can_read, _, _ = select.select([self._socket], [], [], 0)
if can_read and self._socket in can_read:
try:
- new_bytes = self._socket.recv(4096)
+ new_bytes = seven.bitcast_to_string(self._socket.recv(4096))
if self._logger and new_bytes and len(new_bytes) > 0:
self._logger.debug(
"pump received bytes: {}".format(new_bytes))