[3/7] Add call_function_later to DAP

Message ID 20241121-dap-launch-v3-v1-3-c1fa046b3285@adacore.com
State New
Headers
Series Rewrite DAP launch and attach implementations |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Tom Tromey Nov. 21, 2024, 8:35 p.m. UTC
  This adds a new call_function_later API to DAP.  This arranges to run
a function after the current request has completed.  This isn't used
yet, but will be at the end of this series.
---
 gdb/python/lib/gdb/dap/server.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)
  

Patch

diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py
index ceffefc81dc1c42d695008a0fe67454deab71ee5..09190452edff174cc913dc52d524739e1478ca86 100644
--- a/gdb/python/lib/gdb/dap/server.py
+++ b/gdb/python/lib/gdb/dap/server.py
@@ -281,6 +281,12 @@  class Server:
                         return
         self.send_event(event, body)
 
+    @in_dap_thread
+    def call_function_later(self, fn):
+        """Call FN later -- after the current request's response has been sent."""
+        with self.delayed_fns_lock:
+            self.delayed_fns.append(fn)
+
     # Note that this does not need to be run in any particular thread,
     # because it just creates an object and writes it to a thread-safe
     # queue.
@@ -321,6 +327,12 @@  def send_event_maybe_later(event, body=None):
     _server.send_event_maybe_later(event, body)
 
 
+def call_function_later(fn):
+    """Call FN later -- after the current request's response has been sent."""
+    global _server
+    _server.call_function_later(fn)
+
+
 # A helper decorator that checks whether the inferior is running.
 def _check_not_running(func):
     @functools.wraps(func)