From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 29D3A392AC2A for ; Tue, 28 Jun 2022 15:09:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 29D3A392AC2A 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-out1.suse.de (Postfix) with ESMTPS id 5A57721F87 for ; Tue, 28 Jun 2022 15:09:16 +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 46E3713ACA for ; Tue, 28 Jun 2022 15:09:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EkeGD5wZu2LBbQAAMHmgww (envelope-from ) for ; Tue, 28 Jun 2022 15:09:16 +0000 Message-ID: <8c086e54-80de-1848-3085-cb07e2d4407f@suse.de> Date: Tue, 28 Jun 2022 17:09:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: [committed][gdb/testsuite] Handle older python in gdb.python/py-send-packet.py Content-Language: en-US From: Tom de Vries To: gdb-patches@sourceware.org References: <20220613144545.GA20118@delia.home> In-Reply-To: <20220613144545.GA20118@delia.home> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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: Tue, 28 Jun 2022 15:09:18 -0000 On 6/13/22 16:45, Tom de Vries wrote: > 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? Committed. 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")