aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2024-11-20 12:46:53 -0700
committerTom Tromey <tromey@adacore.com>2024-12-09 13:52:54 -0700
commitd8e96210c0c214626cb33221bf39108c626cc2ba (patch)
treecbc2d1af8f3bbc4d4e3e7ed9880b9c639cbd7da4 /gdb/python
parent278b1d211ddbe0136168bc4a7346a0eb67adf1ab (diff)
downloadgdb-d8e96210c0c214626cb33221bf39108c626cc2ba.zip
gdb-d8e96210c0c214626cb33221bf39108c626cc2ba.tar.gz
gdb-d8e96210c0c214626cb33221bf39108c626cc2ba.tar.bz2
Refactor CancellationHandler in DAP
This refactors the DAP CancellationHandler to be a context manager, and reorganizes the caller to use this. This is a bit more robust and also simplifies a subsequent patch in this series. Reviewed-by: Kévin Le Gouguec <legouguec@adacore.com>
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/lib/gdb/dap/server.py33
1 files changed, 15 insertions, 18 deletions
diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py
index 0919045..0f3991d 100644
--- a/gdb/python/lib/gdb/dap/server.py
+++ b/gdb/python/lib/gdb/dap/server.py
@@ -65,15 +65,17 @@ class CancellationHandler:
self.in_flight_gdb_thread = None
self.reqs = []
- def starting(self, req):
- """Call at the start of the given request."""
- with self.lock:
- self.in_flight_dap_thread = req
-
- def done(self, req):
- """Indicate that the request is done."""
- with self.lock:
- self.in_flight_dap_thread = None
+ @contextmanager
+ def current_request(self, req):
+ """Return a new context manager that registers that request
+ REQ has started."""
+ try:
+ with self.lock:
+ self.in_flight_dap_thread = req
+ yield
+ finally:
+ with self.lock:
+ self.in_flight_dap_thread = None
def cancel(self, req):
"""Call to cancel a request.
@@ -150,7 +152,6 @@ class Server:
"command": params["command"],
}
try:
- self.canceller.starting(req)
if "arguments" in params:
args = params["arguments"]
else:
@@ -181,11 +182,6 @@ class Server:
result["message"] = str(e)
return result
- @in_dap_thread
- def _handle_command_finish(self, params):
- req = params["seq"]
- self.canceller.done(req)
-
# Read inferior output and sends OutputEvents to the client. It
# is run in its own thread.
def _read_inferior_output(self):
@@ -243,9 +239,10 @@ class Server:
# A None value here means the reader hit EOF.
if cmd is None:
break
- result = self._handle_command(cmd)
- self._send_json(result)
- self._handle_command_finish(cmd)
+ req = cmd["seq"]
+ with self.canceller.current_request(req):
+ result = self._handle_command(cmd)
+ self._send_json(result)
fns = None
with self.delayed_fns_lock:
fns = self.delayed_fns