From: Tom Tromey Date: Wed, 3 Sep 2025 15:08:01 +0000 (-0600) Subject: Remove Invoker class from DAP X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e14efc5bf7c1af686976cae532acf3d6ad31b2a1;p=thirdparty%2Fbinutils-gdb.git Remove Invoker class from DAP 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. --- diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index 7dab582d0c3..98a80842633 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -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))