From patchwork Thu Jan 5 09:49:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 62720 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E38133858C3A for ; Thu, 5 Jan 2023 09:49:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E38133858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1672912171; bh=6NC+C/qmZZQ8lHak2hQzMBov+Qu1ogjt4a8jQpqq5C4=; h=Date:Subject:To:Cc:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=hiH7B04bILYrD0uCx0MTCd7Sm/Ej8QnZchEoqWRSybZWA0dF0FfpiFYcPoa3mBcHI xcnmYeuzdWba+egyzUhjM8NwRsGw+JICbkZ797TLRyGS0FOoenkw/j9dLMo4oV24ZE BdyRt+iDQ1y+7JHlg2NVpJhMEAiYBCDV+ZfEA7zk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 17D503858D35 for ; Thu, 5 Jan 2023 09:49:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17D503858D35 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 C202A6BCFE; Thu, 5 Jan 2023 09:49:05 +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 A99C313338; Thu, 5 Jan 2023 09:49:05 +0000 (UTC) Received: from dovecot-director1.suse.de ([192.168.254.64]) by imap2.suse-dmz.suse.de with ESMTPSA id cM4SKBGdtmN0QwAAMHmgww (envelope-from ); Thu, 05 Jan 2023 09:49:05 +0000 Message-ID: Date: Thu, 5 Jan 2023 10:49:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: [PATCH] [gdb/python] Avoid queue.SimpleQueue for python 3.6 Content-Language: en-US To: Tom Tromey Cc: Tom Tromey via Gdb-patches References: <20220901163059.3678708-1-tromey@adacore.com> <87bkrk8j21.fsf@tromey.com> <877d1duivp.fsf@tromey.com> <87k024khch.fsf@tromey.com> <5cd9edba-b1b2-060e-d8d2-98ff6d28a5e7@suse.de> <87tu17iu2j.fsf@tromey.com> <7f2d41d6-ba52-a7da-4144-a252aabd10ea@suse.de> <0b6635ea-ee55-1edd-6f4b-149a3ab200f5@suse.de> In-Reply-To: <0b6635ea-ee55-1edd-6f4b-149a3ab200f5@suse.de> X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" [ was: Re: [PATCH] Initial implementation of Debugger Adapter Protocol ] On 1/4/23 13:27, Tom de Vries wrote: > On 1/4/23 12:59, Tom de Vries via Gdb-patches wrote: >> On 1/3/23 15:14, Tom Tromey wrote: >>> Tom> /home/vries/gdb_versions/devel/src/gdb/python/py-dap.c: In member >>> Tom> function ‘virtual void dap_interp::init(bool)’: >>> Tom> /home/vries/gdb_versions/devel/src/gdb/python/py-dap.c:83:27: >>> error: >>> Tom> ‘PyObject_CallNoArgs’ was not declared in this scope >>> Tom>    gdbpy_ref<> result_obj (PyObject_CallNoArgs (func.get ())); >>> Tom>                            ^~~~~~~~~~~~~~~~~~~ >>> Tom> /home/vries/gdb_versions/devel/src/gdb/python/py-dap.c:83:27: note: >>> Tom> suggested alternative: ‘_PyObject_CallNoArg’ >>> Tom>    gdbpy_ref<> result_obj (PyObject_CallNoArgs (func.get ())); >>> Tom>                            ^~~~~~~~~~~~~~~~~~~ >>> Tom>                            _PyObject_CallNoArg >>> Tom> ... >>> >>> Sorry about that.  I'm going to apply the appended, which should fix the >>> problem. >> >> That fixed the build problem, thanks for that. >> >> Now I'm running into an error in the testsuite: >> ... >> ERROR: eof reading json header >>      while executing >> "error "eof reading json header"" >>      invoked from within >> "expect { >> -i exp19 -timeout 10 >>          -re "^Content-Length: (\[0-9\]+)\r\n" { >>              set length $expect_out(1,string) >>              exp_continue >>          } >>          -re "^(\[^\r\n\]+)..." >>      ("uplevel" body line 1) >>      invoked from within >> "uplevel $body" NONE eof reading json header >> UNRESOLVED: gdb.dap/basic-dap.exp: startup - initialize >> ... > > Hmm, that seems to be because: > ... > (gdb) > #5  0x0000000000a59a7c in gdbpy_handle_exception () >     at /home/vries/gdb_versions/devel/src/gdb/python/py-utils.c:396 > 396             error (_("Error occurred in Python: %s"), msg.get ()); > (gdb) p msg.get () > $1 = 0x2b91d10 "module 'queue' has no attribute 'SimpleQueue'" > ... > > That's new in python 3.7, and I have: > ... > $ ldd ./gdb | grep python >         libpython3.6m.so.1.0 => /usr/lib64/libpython3.6m.so.1.0 > (0x00007f93ed624000) > ... Fixed by attached commit, any comments? Thanks, - Tom From 2704ba927c369d834d8b88adb136e323f3c2036d Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Thu, 5 Jan 2023 10:34:58 +0100 Subject: [PATCH] [gdb/python] Avoid queue.SimpleQueue for python 3.6 On openSUSE Leap 15.4 with python 3.6, the gdb.dap/basic-dap.exp test-case fails as follows: ... ERROR: eof reading json header while executing "error "eof reading json header"" invoked from within "expect { -i exp19 -timeout 10 -re "^Content-Length: (\[0-9\]+)\r\n" { set length $expect_out(1,string) exp_continue } -re "^(\[^\r\n\]+)..." ("uplevel" body line 1) invoked from within "uplevel $body" NONE eof reading json header UNRESOLVED: gdb.dap/basic-dap.exp: startup - initialize ... Investigation using a "catch throw" shows that: ... (gdb) at gdb/python/py-utils.c:396 396 error (_("Error occurred in Python: %s"), msg.get ()); (gdb) p msg.get () $1 = 0x2b91d10 "module 'queue' has no attribute 'SimpleQueue'" ... The python class queue.SimpleQueue was introduced in python 3.7. Fix this by falling back to queue.Queue for python <= 3.6. Tested on x86_64-linux, by successfully running the test-case: ... # of expected passes 47 ... --- gdb/python/lib/gdb/dap/server.py | 6 +++++- gdb/python/lib/gdb/dap/startup.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index d6fc0bd5754..f8cb6170a96 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -15,6 +15,7 @@ import json import queue +import sys from .io import start_json_writer, read_json from .startup import ( @@ -47,7 +48,10 @@ class Server: # This queue accepts JSON objects that are then sent to the # DAP client. Writing is done in a separate thread to avoid # blocking the read loop. - self.write_queue = queue.SimpleQueue() + if sys.version_info[0] == 3 and sys.version_info[1] <= 6: + self.write_queue = queue.Queue() + else: + self.write_queue = queue.SimpleQueue() self.done = False global _server _server = self diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py index acfdcb4d81b..523705a5933 100644 --- a/gdb/python/lib/gdb/dap/startup.py +++ b/gdb/python/lib/gdb/dap/startup.py @@ -22,6 +22,7 @@ import signal import threading import traceback from contextlib import contextmanager +import sys # The GDB thread, aka the main thread. @@ -173,7 +174,10 @@ def send_gdb_with_response(fn): """ if isinstance(fn, str): fn = Invoker(fn) - result_q = queue.SimpleQueue() + if sys.version_info[0] == 3 and sys.version_info[1] <= 6: + result_q = queue.Queue() + else: + result_q = queue.SimpleQueue() def message(): try: base-commit: b26c8438c71d44427fc9c7ef6fa2ab1742d220a9 -- 2.35.3