]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/dap] Move send_gdb and send_gdb_with_response to server module
authorTom de Vries <tdevries@suse.de>
Thu, 29 Feb 2024 20:29:34 +0000 (21:29 +0100)
committerTom de Vries <tdevries@suse.de>
Thu, 29 Feb 2024 20:29:34 +0000 (21:29 +0100)
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 <tom@tromey.com>
gdb/python/lib/gdb/dap/next.py
gdb/python/lib/gdb/dap/server.py
gdb/python/lib/gdb/dap/startup.py

index 17bf57d178838d01b1db134fe91595d2cc9edea0..1dc1d6dd74d192b45b65077750c06e1bd3977cb2 100644 (file)
@@ -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
 
 
index 19840f4028d3b2a4bc5194a8c9a3118ac9707852..fe1f8bbd4281fe75b43415eef63b77ae546d739d 100644 (file)
@@ -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
index a2b68996dbaef0f9f0141833b0b726bd14fcc5a8..aaf1e8cd65751a01190010c81e7960edc750544f 100644 (file)
@@ -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