]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Remove Invoker class from DAP
authorTom Tromey <tromey@adacore.com>
Wed, 3 Sep 2025 15:08:01 +0000 (09:08 -0600)
committerTom Tromey <tromey@adacore.com>
Fri, 26 Sep 2025 15:29:13 +0000 (09:29 -0600)
The Invoker used to be more convenient, before DAP requests were run
on the gdb thread by default.  Now it is barely used and easily
replaced by a couple of lambdas.

gdb/python/lib/gdb/dap/server.py

index 7dab582d0c37452e072fddf2e6d58e4754769e06..98a808426333d91ab705e6f7d8c8353e97461d54 100644 (file)
@@ -398,7 +398,7 @@ class Server:
         # responses are flushed to the client before exiting.
         self._write_queue.put(None)
         json_writer.join()
-        send_gdb("quit")
+        send_gdb(lambda: exec_and_log("quit"))
 
     @in_dap_thread
     def set_defer_events(self):
@@ -614,7 +614,7 @@ def terminate(**args):
 @capability("supportTerminateDebuggee")
 def disconnect(*, terminateDebuggee: bool = False, **args):
     if terminateDebuggee:
-        send_gdb_with_response("kill")
+        send_gdb_with_response(lambda: exec_and_log("kill"))
     _server.shutdown()
 
 
@@ -633,18 +633,6 @@ def cancel(**args):
     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)
-
-
 class Cancellable(object):
 
     def __init__(self, fn, result_q=None):
@@ -677,25 +665,16 @@ class Cancellable(object):
 
 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)
-
+    CMD is a function."""
     # Post the event and don't wait for the result.
     gdb.post_event(Cancellable(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)
-
     # Post the event and wait for the result in result_q.
     result_q = DAPQueue()
     gdb.post_event(Cancellable(fn, result_q))