From patchwork Fri Feb 23 16:51:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 86290 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 D79FE385842A for ; Fri, 23 Feb 2024 16:51:58 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 2C9F13858D1E for ; Fri, 23 Feb 2024 16:51:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C9F13858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2C9F13858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708707089; cv=none; b=wny3hLyloBn0iIjhMY2hmRD8iVU+LI1qp3Sn0CCYSh0snk5H843cFPi8KGjy8v4yCXqF3ZjaudIbr34g0ZYeTTNWRQE9kHH+oV8gnQ5ZTgxb54wr7g39UU5EGc6VGY8IBc4X2R8sBlQif4qsuS27Ih3z24R/dXMpD0/T7+HRtJg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708707089; c=relaxed/simple; bh=XGAnNAFuddzt5EGsJkWxXSHaO7nQmowr7BrdVYsqo4w=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=n7pAgXk3sEv7vDyOkl1J45sFxhZ7kEli15wgSL+8VsjZVUK/hNJeVDjEpbGpUf3ApvU67Db6dOHLZTlcj+RDTOGkhRglnAKWX+2PKJqScuiXSG3qOLdyVdqhvsChpA3fmsyrBkJRIoFlj9XI26LgWHp1a+gCXaLQkywrW7WF3ic= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3B4281FC2A; Fri, 23 Feb 2024 16:51:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708707087; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=l8BfHqVXMYeXh6uknYRpyK/ca1TQgEyes/82qVpzSew=; b=PYFSCx4/7hlbrslpeMG44iAI3x9go8tBnlBwura95UTXkAYbeCl162WRnJReZCHFL+4PHi 6c2rJL2uutdr8MKhqPiHdanAwabd4JNp/4x70MBuHxwBV0eYr2qK45iaEJ/920dkl6uAzU mdj2foOqqPxIC5zRXkJZ8FhnhNPjEKY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708707087; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=l8BfHqVXMYeXh6uknYRpyK/ca1TQgEyes/82qVpzSew=; b=0Hn9svN9sLgDVMqwCOLketFwx55jxm0mvOmgQTzMLHgu/aD+GF+4+zSltIKpFWTnvA6Mez pqLtJOq/MmuqMhCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708707087; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=l8BfHqVXMYeXh6uknYRpyK/ca1TQgEyes/82qVpzSew=; b=PYFSCx4/7hlbrslpeMG44iAI3x9go8tBnlBwura95UTXkAYbeCl162WRnJReZCHFL+4PHi 6c2rJL2uutdr8MKhqPiHdanAwabd4JNp/4x70MBuHxwBV0eYr2qK45iaEJ/920dkl6uAzU mdj2foOqqPxIC5zRXkJZ8FhnhNPjEKY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708707087; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=l8BfHqVXMYeXh6uknYRpyK/ca1TQgEyes/82qVpzSew=; b=0Hn9svN9sLgDVMqwCOLketFwx55jxm0mvOmgQTzMLHgu/aD+GF+4+zSltIKpFWTnvA6Mez pqLtJOq/MmuqMhCA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1E49C133DC; Fri, 23 Feb 2024 16:51:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id lIruBQ/N2GUINwAAD6G6ig (envelope-from ); Fri, 23 Feb 2024 16:51:27 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/2] [gdb/dap] Move send_gdb_with_response to server module Date: Fri, 23 Feb 2024 17:51:27 +0100 Message-Id: <20240223165128.32211-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: 0.71 X-Spamd-Result: default: False [0.71 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.19)[-0.961]; RCPT_COUNT_TWO(0.00)[2]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Status: No, score=-12.3 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Separated out to make the following patch easier to read. Tested on aarch64-linux. --- gdb/python/lib/gdb/dap/next.py | 4 ++-- gdb/python/lib/gdb/dap/server.py | 26 +++++++++++++++++++++++++- gdb/python/lib/gdb/dap/startup.py | 25 ------------------------- 3 files changed, 27 insertions(+), 28 deletions(-) base-commit: e433bca4847acd34b6178a392335ed10060639ec diff --git a/gdb/python/lib/gdb/dap/next.py b/gdb/python/lib/gdb/dap/next.py index 17bf57d1788..f81f2e40461 100644 --- a/gdb/python/lib/gdb/dap/next.py +++ b/gdb/python/lib/gdb/dap/next.py @@ -16,8 +16,8 @@ import gdb from .events import exec_and_expect_stop -from .server import capability, request -from .startup import in_gdb_thread, send_gdb, send_gdb_with_response +from .server import capability, request, send_gdb_with_response +from .startup import in_gdb_thread, send_gdb from .state import set_thread diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index 6757f2921bf..ecec41cc321 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -28,7 +28,6 @@ from .startup import ( in_dap_thread, in_gdb_thread, send_gdb, - send_gdb_with_response, start_thread, log, log_stack, @@ -421,3 +420,28 @@ def cancel(**args): # ... which gdb takes to mean that it is fine for all cancel # requests to report success. return None + + +def send_gdb_with_response(fn): + """Send FN to the gdb thread and return its result. + If FN is a string, it is passed to gdb.execute and None is + returned as the result. + If FN throws an exception, this function will throw the + same exception in the calling thread. + """ + if isinstance(fn, str): + fn = Invoker(fn) + result_q = DAPQueue() + + def message(): + try: + val = fn() + result_q.put(val) + except (Exception, KeyboardInterrupt) as e: + result_q.put(e) + + send_gdb(message) + val = result_q.get() + if isinstance(val, (Exception, KeyboardInterrupt)): + raise val + return val diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py index a2b68996dba..2893886cc00 100644 --- a/gdb/python/lib/gdb/dap/startup.py +++ b/gdb/python/lib/gdb/dap/startup.py @@ -235,28 +235,3 @@ def send_gdb(cmd): if isinstance(cmd, str): cmd = Invoker(cmd) gdb.post_event(cmd) - - -def send_gdb_with_response(fn): - """Send FN to the gdb thread and return its result. - If FN is a string, it is passed to gdb.execute and None is - returned as the result. - If FN throws an exception, this function will throw the - same exception in the calling thread. - """ - if isinstance(fn, str): - fn = Invoker(fn) - result_q = DAPQueue() - - def message(): - try: - val = fn() - result_q.put(val) - except (Exception, KeyboardInterrupt) as e: - result_q.put(e) - - send_gdb(message) - val = result_q.get() - if isinstance(val, (Exception, KeyboardInterrupt)): - raise val - return val