From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 1/2] [gdb/dap] Move send_gdb_with_response to server module
Date: Fri, 23 Feb 2024 17:51:27 +0100 [thread overview]
Message-ID: <20240223165128.32211-1-tdevries@suse.de> (raw)
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(-)
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
base-commit: e433bca4847acd34b6178a392335ed10060639ec
--
2.35.3
next reply other threads:[~2024-02-23 16:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-23 16:51 Tom de Vries [this message]
2024-02-23 16:51 ` [PATCH 2/2] [gdb/dap] Fix stray KeyboardInterrupt after cancel Tom de Vries
2024-02-23 17:27 ` Tom Tromey
2024-02-26 12:24 ` Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240223165128.32211-1-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).