From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id P6x/LrVNp2Is3gEAWB0awg (envelope-from ) for ; Mon, 13 Jun 2022 10:46:13 -0400 Received: by simark.ca (Postfix, from userid 112) id B46321E224; Mon, 13 Jun 2022 10:46:13 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=gN85OpY8; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 3EC5A1E143 for ; Mon, 13 Jun 2022 10:46:13 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5D3E43852775 for ; Mon, 13 Jun 2022 14:46:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5D3E43852775 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1655131571; bh=OUUtGZLJTQZoGkhvLzYWX/N6Dgq837h0w9n4n5o+/MA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=gN85OpY81TJPcOuGTAt3PnrWf4rPnnJueCbjR2oyywhw4/tVoawBL61VFPpmktoZB UCnrUXslkuiNTWMlFZfcBmZ77nBm34NgFUGVx+q80QfDQR6QTLWXFRoK+lZGYLtfEx DoF5rNQZCi1tnubeLeEUny0Ip8x7l1GbzWCYa57Y= 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 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-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: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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")