From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id D5E88385828B; Wed, 21 Feb 2024 09:46:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D5E88385828B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1708508796; bh=0H14+7d43g9/54TBm7knyAcPF0Rus2GY/8LiCCnJbfU=; h=From:To:Subject:Date:From; b=T28APQkRkB2RixAj8kqcGpyLZGd8UQTAGOEy46LYOauYM2QGr7SOioUTeV2J3p7Lw k3TAa1i+DzXMuErH4YnyVHyRHVuuESkDa8HQplyMjRnY8GLKcxn6IX/F0iBu8cGGHo PDP7HUO9JdIL2cn52kcy1GrENYNbFBfU7SepFZ/4= 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] Join JSON writer thread with DAP thread X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: d61933410868ff2dd52a896520a2b620d35f3615 X-Git-Newrev: 7c34de9efdb13fff482ed0c4de0dffee1e1880f3 Message-Id: <20240221094636.D5E88385828B@sourceware.org> Date: Wed, 21 Feb 2024 09:46:36 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D7c34de9efdb1= 3fff482ed0c4de0dffee1e1880f3 commit 7c34de9efdb13fff482ed0c4de0dffee1e1880f3 Author: Tom de Vries Date: Wed Feb 21 10:46:08 2024 +0100 [gdb/dap] Join JSON writer thread with DAP thread =20 The DAP interpreter runs in its own thread, and starts a few threads: - the JSON reader thread, - the JSON writer thread, and - the inferior output reader thread. =20 As part of the DAP shutdown, both the JSON reader thread and the JSON w= riter thread, as well as the DAP main thread run to exit, but these exits are= not ordered in any way. =20 Wait in the main DAP thread for the exit of the JSON writer thread. =20 This makes sure that the responses are flushed to the DAP client before= DAP shutdown. =20 An earlier version of this patch used Queue.task_done() to accomplish t= he same, but that didn't guarantee writing the ": terminating" log entry from thread_wrapper before DAP shutdown. =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/io.py | 2 +- gdb/python/lib/gdb/dap/server.py | 3 ++- gdb/python/lib/gdb/dap/startup.py | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gdb/python/lib/gdb/dap/io.py b/gdb/python/lib/gdb/dap/io.py index 4edd504c727..81e835c7527 100644 --- a/gdb/python/lib/gdb/dap/io.py +++ b/gdb/python/lib/gdb/dap/io.py @@ -79,4 +79,4 @@ def start_json_writer(stream, queue): stream.write(body_bytes) stream.flush() =20 - start_thread("JSON writer", _json_writer) + return start_thread("JSON writer", _json_writer) diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/serv= er.py index 7cc5a4681ee..e7110660741 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -212,7 +212,7 @@ class Server: # Before looping, start the thread that writes JSON to the # client, and the thread that reads output from the inferior. start_thread("output reader", self._read_inferior_output) - start_json_writer(self.out_stream, self.write_queue) + json_writer =3D start_json_writer(self.out_stream, self.write_queu= e) start_thread("JSON reader", self._reader_thread) while not self.done: cmd =3D self.read_queue.get() @@ -229,6 +229,7 @@ class Server: # JSON-writing thread, so that we can ensure that all # responses are flushed to the client before exiting. self.write_queue.put(None) + json_writer.join() =20 @in_dap_thread def send_event_later(self, event, body=3DNone): diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/sta= rtup.py index 60491212c67..0a42c91e8f4 100644 --- a/gdb/python/lib/gdb/dap/startup.py +++ b/gdb/python/lib/gdb/dap/startup.py @@ -80,6 +80,7 @@ def start_thread(name, target, args=3D()): =20 result =3D gdb.Thread(name=3Dname, target=3Dthread_wrapper, args=3Darg= s, daemon=3DTrue) result.start() + return result =20 =20 def start_dap(target):