public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] [gdb/dap] Fix race between dap exit and gdb exit
@ 2024-02-22 10:35 Tom de Vries
0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2024-02-22 10:35 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=706c6624c26b2c954713c872021594bd3a156dd3
commit 706c6624c26b2c954713c872021594bd3a156dd3
Author: Tom de Vries <tdevries@suse.de>
Date: Thu Feb 22 11:35:26 2024 +0100
[gdb/dap] Fix race between dap exit and gdb exit
When DAP shuts down due to an EOF event, there's a race between:
- gdb's main thread handling a SIGHUP, and
- the DAP main thread exiting.
Fix this by waiting for DAP's main thread exit during the gdb_exiting event.
Tested on aarch64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
PR dap/31380
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31380
Diff:
---
gdb/python/lib/gdb/dap/startup.py | 10 +++++++++-
gdb/testsuite/gdb.dap/eof.exp | 9 +++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py
index 29fe78ecd53..a2b68996dba 100644
--- a/gdb/python/lib/gdb/dap/startup.py
+++ b/gdb/python/lib/gdb/dap/startup.py
@@ -93,7 +93,15 @@ def start_dap(target):
_dap_thread = threading.current_thread()
target()
- start_thread("DAP", really_start_dap)
+ # Note: unlike _dap_thread, dap_thread is a local variable.
+ dap_thread = start_thread("DAP", really_start_dap)
+
+ def _on_gdb_exiting(event):
+ thread_log("joining DAP thread ...")
+ dap_thread.join()
+ thread_log("joining DAP thread done")
+
+ gdb.events.gdb_exiting.connect(_on_gdb_exiting)
def in_gdb_thread(func):
diff --git a/gdb/testsuite/gdb.dap/eof.exp b/gdb/testsuite/gdb.dap/eof.exp
index a84b1d21e04..05048f2762a 100644
--- a/gdb/testsuite/gdb.dap/eof.exp
+++ b/gdb/testsuite/gdb.dap/eof.exp
@@ -38,3 +38,12 @@ dap_check_log_file
# Check that first log message is present.
dap_check_log_file_re [string_to_regexp "starting DAP server"]
+
+# There should be one "READ:" for the initialize request, and at least one
+# "WROTE:" for the initialize response.
+dap_check_log_file_re "READ:"
+dap_check_log_file_re "WROTE:"
+
+# Check that all thread termination messages are there.
+dap_check_log_file_re "JSON writer: terminating"
+dap_check_log_file_re "DAP: terminating"
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-02-22 10:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-22 10:35 [binutils-gdb] [gdb/dap] Fix race between dap exit and gdb exit Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).