From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id F26E3386F0EA; Mon, 27 Jun 2022 10:48:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F26E3386F0EA Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/testsuite] Handle older python in gdb.python/py-send-packet.py X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 772f8196d621a8009035ff4cb8aab2d7343269a9 X-Git-Newrev: 2135495484109f888167287cca249be9d84ed535 Message-Id: <20220627104802.F26E3386F0EA@sourceware.org> Date: Mon, 27 Jun 2022 10:48:02 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Jun 2022 10:48:03 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D213549548410= 9f888167287cca249be9d84ed535 commit 2135495484109f888167287cca249be9d84ed535 Author: Tom de Vries Date: Mon Jun 27 12:47:26 2022 +0200 [gdb/testsuite] Handle older python in gdb.python/py-send-packet.py =20 With python 3.4, I run into: ... Traceback (most recent call last):^M File "", line 1, in ^M File "outputs/gdb.python/py-send-packet/py-send-packet.py", line 128, in \ run_set_global_var_test^M res =3D conn.send_packet(b"X%x,4:\x02\x02\x02\x02" % addr)^M TypeError: Could not convert Python object: b'X%x,4:\x02\x02\x02\x02'.^M Error while executing Python code.^M ... while with python 3.6 this works fine. =20 The type of addr is , so the first thing to try is w= hether changing it into a string works: ... addr_str =3D "%x" % addr res =3D conn.send_packet(b"X%s,4:\x02\x02\x02\x02" % addr_str) ... which gets us the more detailed: ... TypeError: unsupported operand type(s) for %: 'bytes' and 'str' ... =20 Fix this by avoiding the '%' operator in the byte literal, and use inst= ead: ... def xpacket_header (addr): return ("X%x,4:" % addr).encode('ascii') ... res =3D conn.send_packet(xpacket_header(addr) + b"\x02\x02\x02\x02") ... =20 Tested on x86_64-linux, with python 3.4 and 3.6, and a backported versi= on was tested on the gdb-12-branch in combination with python 2.7. Diff: --- gdb/testsuite/gdb.python/py-send-packet.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/gdb.python/py-send-packet.py b/gdb/testsuite/gdb= .python/py-send-packet.py index a6adc8279cb..ae70b852538 100644 --- a/gdb/testsuite/gdb.python/py-send-packet.py +++ b/gdb/testsuite/gdb.python/py-send-packet.py @@ -114,6 +114,10 @@ def check_global_var(expected_val): if val !=3D expected_val: raise gdb.GdbError("global_var is 0x%x, expected 0x%x" % (val, exp= ected_val)) =20 +# Return a bytes object representing an 'X' packet header with +# address ADDR. +def xpacket_header (addr): + return ("X%x,4:" % addr).encode('ascii') =20 # Set the 'X' packet to the remote target to set a global variable. # Checks that we can send byte values. @@ -125,7 +129,7 @@ def run_set_global_var_test(): res =3D conn.send_packet("X%x,4:\x01\x01\x01\x01" % addr) assert isinstance(res, bytes) check_global_var(0x01010101) - res =3D conn.send_packet(b"X%x,4:\x02\x02\x02\x02" % addr) + res =3D conn.send_packet(xpacket_header(addr) + b"\x02\x02\x02\x02") assert isinstance(res, bytes) check_global_var(0x02020202) =20 @@ -142,7 +146,7 @@ def run_set_global_var_test(): assert saw_error check_global_var(0x02020202) # Now we pass a bytes object, which will work. - res =3D conn.send_packet(b"X%x,4:\xff\xff\xff\xff" % addr) + res =3D conn.send_packet(xpacket_header(addr) + b"\xff\xff\xff\xff") check_global_var(0xFFFFFFFF) =20 print("set global_var test passed")