[v2,1/2,gdb/dap] Move send_gdb and send_gdb_with_response to server module

Message ID 20240226115825.29705-1-tdevries@suse.de
State Superseded
Headers
Series [v2,1/2,gdb/dap] Move send_gdb and send_gdb_with_response to server module |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Tom de Vries Feb. 26, 2024, 11:58 a.m. UTC
  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
  

Comments

Tom Tromey Feb. 28, 2024, 8:09 p.m. UTC | #1
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> Move functions send_gdb and send_gdb_with_response, as well as class Invoker
Tom> to server module.

Tom> Separated out to make the following patch easier to read.

Tom> Tested on aarch64-linux.

Ok.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

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