From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id EBC063858D39; Thu, 22 Feb 2024 10:35:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EBC063858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1708598144; bh=1avJna6E1pon9tC+w9mRJkeFGAAHy5CqXsNolmOafvs=; h=From:To:Subject:Date:From; b=pgYn1Jf/3lElDZqYy9MEl5gET5FANpTmNDSSauH4LY9DgAspmQNqf3WO20YFjtqMf 7l6TmUNa1COmzvtYXBbw2hjeRYHuE0wDLq4w/7QD0+D8iw2xq2B9jYHl+kq8GJRhzA 84Ez8S6BCuH2Sg3LEsxYpNF7vYQnYnaoFXJsBECs= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/dap] Fix race between dap exit and gdb exit X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 05bf17f03b890424312163463754de63cee73074 X-Git-Newrev: 706c6624c26b2c954713c872021594bd3a156dd3 Message-Id: <20240222103544.EBC063858D39@sourceware.org> Date: Thu, 22 Feb 2024 10:35:44 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D706c6624c26b= 2c954713c872021594bd3a156dd3 commit 706c6624c26b2c954713c872021594bd3a156dd3 Author: Tom de Vries Date: Thu Feb 22 11:35:26 2024 +0100 [gdb/dap] Fix race between dap exit and gdb exit =20 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. =20 Fix this by waiting for DAP's main thread exit during the gdb_exiting e= vent. =20 Tested on aarch64-linux. =20 Approved-By: Tom Tromey =20 PR dap/31380 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31380 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/sta= rtup.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 =3D threading.current_thread() target() =20 - start_thread("DAP", really_start_dap) + # Note: unlike _dap_thread, dap_thread is a local variable. + dap_thread =3D 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) =20 =20 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 =20 # 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"