]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/dap] Fix race between dap exit and gdb exit
authorTom de Vries <tdevries@suse.de>
Thu, 22 Feb 2024 10:35:26 +0000 (11:35 +0100)
committerTom de Vries <tdevries@suse.de>
Thu, 22 Feb 2024 10:35:26 +0000 (11:35 +0100)
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

gdb/python/lib/gdb/dap/startup.py
gdb/testsuite/gdb.dap/eof.exp

index 29fe78ecd537d6539b68428f98eb811d79df1ce9..a2b68996dbaef0f9f0141833b0b726bd14fcc5a8 100644 (file)
@@ -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):
index a84b1d21e0456c536c291a6b15049f6de8aae884..05048f2762a600e2e8013f2e220821d3ec52b0b8 100644 (file)
@@ -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"