From patchwork Thu Feb 29 13:59:35 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: 86594 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 6FFA03858413 for ; Thu, 29 Feb 2024 14:00:18 +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 80830385841F for ; Thu, 29 Feb 2024 13:59:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80830385841F 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 80830385841F 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=1709215163; cv=none; b=dZMQJ6PYgL7PW3xcVm2K4r2c+p9zjbQGQB2VylQR4hUXykz+j9eB9JwdXF6BP4ke0FI/veJKgKMVLtjIsBy0A9iRK8loNNECELNhk+agR0FojaC9110cYxf1Bz41ECGiRZE9IICnfK3kUqQlZd9CwslH54IbTrFceIIGXHSIPSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709215163; c=relaxed/simple; bh=L8MktvBiecF7vm625uux1BTpxbuRg36JOcX85bdOTPk=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=Ql2qH87uM/kc3yorZmD9s3JpOdiE3p/5VN3nRtr6d+CZ5Pn38o4kcPX+XNC3kO+uJQfw2Rq8fjN10T2DyTNszu9piXTJWd+enErESzcF7C6O+1M+aZo4cV2mIusEHmSy3QFuhtLoCqsyDKvDYTVA2fc9oHPK/y40Eq7tdTPJYo0= 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 7D1D11F7F1; Thu, 29 Feb 2024 13:59:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709215159; 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=zX0yejoKr5VAu5MRTIsjGHCS+CDgN3ScNzUArlAfCtc=; b=YGNjLRX5LVbGxj4ImWSCrFz0CiFVWLLVu9EEF3clQ44M3YtbXSI5tjmPAl5upS6G8Z2iE6 mG7GB9IMQrupmMQxEJ8Fu0ZQMhvM4Ynk4sGU7xxMkF6cXar/FbmnGky+uUgzd5m22LZZlB oUf22t+GZ5q2Q5zigZDsX5F+4y8RPg8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709215159; 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=zX0yejoKr5VAu5MRTIsjGHCS+CDgN3ScNzUArlAfCtc=; b=puQ0XSXEWyOaxEXot/DYgvvifwXY0J+7q4K9o4HJm2Umxo8y7sAZAQR+XqlHU5qA36g7K0 mHXuFOrQKYZ0enCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709215159; 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=zX0yejoKr5VAu5MRTIsjGHCS+CDgN3ScNzUArlAfCtc=; b=YGNjLRX5LVbGxj4ImWSCrFz0CiFVWLLVu9EEF3clQ44M3YtbXSI5tjmPAl5upS6G8Z2iE6 mG7GB9IMQrupmMQxEJ8Fu0ZQMhvM4Ynk4sGU7xxMkF6cXar/FbmnGky+uUgzd5m22LZZlB oUf22t+GZ5q2Q5zigZDsX5F+4y8RPg8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709215159; 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=zX0yejoKr5VAu5MRTIsjGHCS+CDgN3ScNzUArlAfCtc=; b=puQ0XSXEWyOaxEXot/DYgvvifwXY0J+7q4K9o4HJm2Umxo8y7sAZAQR+XqlHU5qA36g7K0 mHXuFOrQKYZ0enCA== 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 6258013503; Thu, 29 Feb 2024 13:59:19 +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 q8+0FreN4GVnGQAAD6G6ig (envelope-from ); Thu, 29 Feb 2024 13:59:19 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v3 1/2] [gdb/dap] Move send_gdb and send_gdb_with_response to server module Date: Thu, 29 Feb 2024 14:59:35 +0100 Message-Id: <20240229135936.10140-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [1.90 / 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)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; 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-Score: 1.90 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. Approved-By: Tom Tromey --- 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: 801977ce47911ecb88b7b2ffc502aafe807535b5 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 19840f4028d..fe1f8bbd428 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, @@ -422,3 +420,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