From patchwork Mon Feb 26 11:58:24 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: 86373 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 E1B773858408 for ; Mon, 26 Feb 2024 11:58:43 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 837B93858CDB for ; Mon, 26 Feb 2024 11:58:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 837B93858CDB 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 837B93858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708948700; cv=none; b=GHC6NeB9tl3n/aN/3rShzWHK+oAVZL2tGN+VVI72dhMk+Pv5VDS4ho12eLh/e41HYL+JBvAIgx3Z2ZJN2m4RfPdK1tvVH2iuOBNUb5qHne7BgCWtxJLTlBTq+29maoSC+W+XBsdXothzJCf04j06BrdbCSUrSqO23pDTXLUIEes= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708948700; c=relaxed/simple; bh=MszjSNPYCG8TKr95nyvV7xd5MG84tFOn8PHd2I3KTc0=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=vY/yT5t6hgQS6ssNG9Qz0EfpVvVZ+NGk+6F8DFUzvqiJjfttQmFxCs2zWwmakGh6VdrpGjCvi9TPgvFb+F10Tx79yfbc0MGfDnBjD/6V9aDlvK3Kh6hE91sSwfN8/LhC6wJJ7F2cTC1m5pgOzvfHGzH8L/iCaQXkSL70vEXa5EQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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-out1.suse.de (Postfix) with ESMTPS id 7181D2257C for ; Mon, 26 Feb 2024 11:58:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708948697; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=7TRLbhQ5lfddohM4LZ+utvVsyGaEsg26oNIj2yFYzfU=; b=aUQcdB09i381nTETjf3DDc1s4gKfo/FoszAbmTqQ+Kx3ZEgH9mZDHMZl8EeCOj0BD06Ow4 kCSAAoQeKJE9XRKnSgOnFzq9OH7+hgYzz6QY3cjmBDjZtOnzMwqdQyiSxIMxuUJbe4/nwc jwQnotzf7oEB+J94z8d/G4O1Uy3SRbM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708948697; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=7TRLbhQ5lfddohM4LZ+utvVsyGaEsg26oNIj2yFYzfU=; b=ylB+ybZ1hLhJw4tsi6899ogGvd/g0jeNybQrKwqyz0kOEt6CfL3Ouxhfk2zNcLWIPAv1aO hilQJnxFgDNwsZBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708948697; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=7TRLbhQ5lfddohM4LZ+utvVsyGaEsg26oNIj2yFYzfU=; b=aUQcdB09i381nTETjf3DDc1s4gKfo/FoszAbmTqQ+Kx3ZEgH9mZDHMZl8EeCOj0BD06Ow4 kCSAAoQeKJE9XRKnSgOnFzq9OH7+hgYzz6QY3cjmBDjZtOnzMwqdQyiSxIMxuUJbe4/nwc jwQnotzf7oEB+J94z8d/G4O1Uy3SRbM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708948697; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=7TRLbhQ5lfddohM4LZ+utvVsyGaEsg26oNIj2yFYzfU=; b=ylB+ybZ1hLhJw4tsi6899ogGvd/g0jeNybQrKwqyz0kOEt6CfL3Ouxhfk2zNcLWIPAv1aO hilQJnxFgDNwsZBA== 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 59EE313A3A for ; Mon, 26 Feb 2024 11:58:17 +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 7DF+FNl83GU+RwAAD6G6ig (envelope-from ) for ; Mon, 26 Feb 2024 11:58:17 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 1/2] [gdb/dap] Move send_gdb and send_gdb_with_response to server module Date: Mon, 26 Feb 2024 12:58:24 +0100 Message-Id: <20240226115825.29705-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=aUQcdB09; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=ylB+ybZ1 X-Spamd-Result: default: False [-2.31 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; R_MISSING_CHARSET(2.50)[]; TO_DN_NONE(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_DKIM_ARC_DNSWL_HI(-1.00)[]; FROM_HAS_DN(0.00)[]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCPT_COUNT_ONE(0.00)[1]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_IN_DNSWL_HI(-1.00)[2a07:de40:b281:106:10:150:64:167:received,2a07:de40:b281:104:10:150:64:97:from]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 7181D2257C X-Spam-Level: X-Spam-Score: -2.31 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 Move functions send_gdb and send_gdb_with_response, as well as class Invoker to server module. 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 | 48 +++++++++++++++++++++++++++++-- gdb/python/lib/gdb/dap/startup.py | 46 ----------------------------- 3 files changed, 48 insertions(+), 50 deletions(-) base-commit: 4a4fd10d1707424b9b13aa4af0cec7590c086ea0 diff --git a/gdb/python/lib/gdb/dap/next.py b/gdb/python/lib/gdb/dap/next.py index 17bf57d1788..1dc1d6dd74d 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, send_gdb_with_response +from .startup import in_gdb_thread 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..e957b886fb8 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -27,8 +27,6 @@ from .startup import ( DAPQueue, in_dap_thread, in_gdb_thread, - send_gdb, - send_gdb_with_response, start_thread, log, log_stack, @@ -421,3 +419,49 @@ def cancel(**args): # ... which gdb takes to mean that it is fine for all cancel # requests to report success. return None + + +class Invoker(object): + """A simple class that can invoke a gdb command.""" + + def __init__(self, cmd): + self.cmd = cmd + + # This is invoked in the gdb thread to run the command. + @in_gdb_thread + def __call__(self): + exec_and_log(self.cmd) + + +def send_gdb(cmd): + """Send CMD to the gdb thread. + CMD can be either a function or a string. + If it is a string, it is passed to gdb.execute.""" + 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 diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py index a2b68996dba..aaf1e8cd657 100644 --- a/gdb/python/lib/gdb/dap/startup.py +++ b/gdb/python/lib/gdb/dap/startup.py @@ -214,49 +214,3 @@ def exec_and_log(cmd): log(">>> " + output) except gdb.error: log_stack() - - -class Invoker(object): - """A simple class that can invoke a gdb command.""" - - def __init__(self, cmd): - self.cmd = cmd - - # This is invoked in the gdb thread to run the command. - @in_gdb_thread - def __call__(self): - exec_and_log(self.cmd) - - -def send_gdb(cmd): - """Send CMD to the gdb thread. - CMD can be either a function or a string. - If it is a string, it is passed to gdb.execute.""" - 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