aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2025-12-16 08:43:43 -0700
committerTom Tromey <tromey@adacore.com>2026-01-05 06:30:49 -0700
commit5d33cb5d4bfefd5458b4268fe3fbc0eaa9dfc6b6 (patch)
tree7a0d9dc58d2287623d90b68553f8b402dbcbe95e /gdb/python
parentbe970c68891fcfd0cf4008a515f87becc9dd3100 (diff)
downloadbinutils-5d33cb5d4bfefd5458b4268fe3fbc0eaa9dfc6b6.zip
binutils-5d33cb5d4bfefd5458b4268fe3fbc0eaa9dfc6b6.tar.gz
binutils-5d33cb5d4bfefd5458b4268fe3fbc0eaa9dfc6b6.tar.bz2
Fix DAP 'disconnect' implementation
gdb's implementation of the DAP 'disconnect' request was incorrect in a few ways. First, the 'terminateDebuggee' field is optional, and has a special meaning when not supplied: it should do whatever the default is. Second, if the inferior was attached, it should detach rather than terminate by default. Finally, if the inferior was not started at all, it seems reasonable for this request to simply succeed silently -- currently it returns "success: false" with the reason being that the inferior isn't running. Approved-By: Andrew Burgess <aburgess@redhat.com>
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/lib/gdb/dap/server.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py
index bc56a72..64ad247 100644
--- a/gdb/python/lib/gdb/dap/server.py
+++ b/gdb/python/lib/gdb/dap/server.py
@@ -19,6 +19,7 @@ import inspect
import json
import threading
from contextlib import contextmanager
+from typing import Optional
import gdb
@@ -618,11 +619,26 @@ def terminate(**args):
exec_and_log("kill")
+@in_gdb_thread
+def _disconnect_or_kill(terminate: Optional[bool]):
+ inf = gdb.selected_inferior()
+ if inf.connection is None:
+ # Nothing to do here.
+ return
+ if terminate is None:
+ # The default depends on whether the inferior was attached or
+ # launched.
+ terminate = not inf.was_attached
+ if terminate:
+ exec_and_log("kill")
+ elif inf.was_attached:
+ exec_and_log("detach")
+
+
@request("disconnect", on_dap_thread=True, expect_stopped=False)
@capability("supportTerminateDebuggee")
-def disconnect(*, terminateDebuggee: bool = False, **args):
- if terminateDebuggee:
- send_gdb_with_response(lambda: exec_and_log("kill"))
+def disconnect(*, terminateDebuggee: Optional[bool] = None, **args):
+ send_gdb_with_response(lambda: _disconnect_or_kill(terminateDebuggee))
_server.shutdown()