From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 13A78385AE75 for ; Mon, 13 Jun 2022 14:45:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 13A78385AE75 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 325D31F37C for ; Mon, 13 Jun 2022 14:45:48 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1F6C613443 for ; Mon, 13 Jun 2022 14:45:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yYOMBpxNp2LnSwAAMHmgww (envelope-from ) for ; Mon, 13 Jun 2022 14:45:48 +0000 Date: Mon, 13 Jun 2022 16:45:46 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdb/testsuite] Handle older python in gdb.python/py-send-packet.py Message-ID: <20220613144545.GA20118@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jun 2022 14:45:52 -0000 Hi, 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 = 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. The type of addr is , so the first thing to try is whether changing it into a string works: ... addr_str = "%x" % addr res = 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' ... Fix this by avoiding the '%' operator in the byte literal, and use instead: ... def xpacket_header (addr): return ("X%x,4:" % addr).encode('ascii') ... res = conn.send_packet(xpacket_header(addr) + b"\x02\x02\x02\x02") ... Tested on x86_64-linux, with python 3.4 and 3.6, and a backported version was tested on the gdb-12-branch in combination with python 2.7. Any comments? Thanks, - Tom [gdb/testsuite] Handle older python in gdb.python/py-send-packet.py --- 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 != expected_val: raise gdb.GdbError("global_var is 0x%x, expected 0x%x" % (val, expected_val)) +# Return a bytes object representing an 'X' packet header with +# address ADDR. +def xpacket_header (addr): + return ("X%x,4:" % addr).encode('ascii') # 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 = conn.send_packet("X%x,4:\x01\x01\x01\x01" % addr) assert isinstance(res, bytes) check_global_var(0x01010101) - res = conn.send_packet(b"X%x,4:\x02\x02\x02\x02" % addr) + res = conn.send_packet(xpacket_header(addr) + b"\x02\x02\x02\x02") assert isinstance(res, bytes) check_global_var(0x02020202) @@ -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 = conn.send_packet(b"X%x,4:\xff\xff\xff\xff" % addr) + res = conn.send_packet(xpacket_header(addr) + b"\xff\xff\xff\xff") check_global_var(0xFFFFFFFF) print("set global_var test passed")