From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id B10F8384F024 for ; Mon, 19 Feb 2024 08:23:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B10F8384F024 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B10F8384F024 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708331037; cv=none; b=EtqI8IZaXj5FTzk+mDNSjXg5nEeSOHTOHskfJmetKuc2jYYnWvlcbTaOnmqCW+ZgrvSHS3I+pISU4RCqTxESkzfjQlWiNVyJtgeldF1dUmfoDGNdKBGMBJA1nvdPhtPUbYwOuRaOxMx7Sn/zppqdkDQElbB3w1DmNHURwYtcAPU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708331037; c=relaxed/simple; bh=ROZj7lQINH4i1leylivK7syyUVW/ptpPZ2Mai5zP3LA=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=dCCe56jMV2bc8+XM1krUK6y3tStgLcJiezoQhWWyPZqmGgmITA5tvjGFUTnLbLwWT7Hn59b4lDdvbotoqGBpuAeR5AYV8aSidZg3+MdUkeZQOh+GGEeN9l5Eg8s3BMyuBnrHwo+sxF7b+O4lj9WKyEumIoiy2d5hNt0lRO7G3E8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D2977222F3 for ; Mon, 19 Feb 2024 08:23:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708331033; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XabZPnMw8I4qPkH+buHVuA0anmtnD0pHDlwevevdHMA=; b=u7pa3D//oNhR89ybzFfEgWP8SZLkGOpSsmeM06yW2i3joX4CpSGYWtSDjkh5R5xxJM59aB Kz5qGsbf84VrVuvIlpGoOIRlUSXNufvyySMBrNr47rsgb//sZwp8yj/Bf1ro750RkJhWc1 WflPz+dnSj8N3GndKpE3R8yK5fpVhgY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708331033; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XabZPnMw8I4qPkH+buHVuA0anmtnD0pHDlwevevdHMA=; b=sZcFKBTJR8EnxT5YHvEKgMa6ZGLkC+aCnEtmeF6G+pbUfBOdav1HHQLua+h5Bt4mrc52Yb l/NGw7AhrZ0ie3AA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708331032; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XabZPnMw8I4qPkH+buHVuA0anmtnD0pHDlwevevdHMA=; b=MRUzMi9krtOsh6+3uyIG1C5Bp7Jn71Sv/WW1Iu7NmTXS4litxHWJhgQSB9d4rDjULU0evv xe5zsT1slAgmtvkzIX5GEf1rrQGUB2r8d5og8LbmHguPWygdxF0s1Ia3PhPQB/3i8Lnc8K JOeyIVS68+Cpsaz+lsvEvEmC5dDl89o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708331032; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XabZPnMw8I4qPkH+buHVuA0anmtnD0pHDlwevevdHMA=; b=baLOEUJa8ob508Rz8yRIb9s0V0xpewYmDvl3q53pZtf8Ztj2ZxQHeM+8u5CMwm8ygjERUH 93WjLi7mZ/WB1rCg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id AF39813AB0 for ; Mon, 19 Feb 2024 08:23:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id CLaaKRgQ02WaBAAAD6G6ig (envelope-from ) for ; Mon, 19 Feb 2024 08:23:52 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 7/8] [gdb/dap] Join JSON reader and writer threads with DAP thread Date: Mon, 19 Feb 2024 09:23:40 +0100 Message-Id: <20240219082341.21313-7-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240219082341.21313-1-tdevries@suse.de> References: <20240219082341.21313-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Level: X-Spamd-Bar: / Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=MRUzMi9k; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=baLOEUJa X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [0.49 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_NONE(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,sourceware.org:url]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: 0.49 X-Rspamd-Queue-Id: D2977222F3 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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. As part of the DAP shutdown, both the JSON reader thread and the JSON writer thread, as well as the DAP main thread run to exit, but these exits are not ordered in any way. Wait in the main DAP thread for the exit of the JSON writer thread. This makes sure that the responses are flushed to the DAP client before DAP shutdown. An earlier version of this patch used Queue.task_done() to accomplish the same, but that didn't guarantee writing the ": terminating" log entry from thread_wrapper before DAP shutdown. While we're at it, do the same for the JSON reader thread. Tested on aarch64-linux. PR dap/31380 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31380 --- gdb/python/lib/gdb/dap/io.py | 2 +- gdb/python/lib/gdb/dap/server.py | 6 ++++-- gdb/python/lib/gdb/dap/startup.py | 1 + 3 files changed, 6 insertions(+), 3 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() - 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/server.py index 7cc5a4681ee..f547fcc76bc 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -212,8 +212,8 @@ 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) - start_thread("JSON reader", self._reader_thread) + json_writer = start_json_writer(self.out_stream, self.write_queue) + json_reader = start_thread("JSON reader", self._reader_thread) while not self.done: cmd = self.read_queue.get() # A None value here means the reader hit EOF. @@ -229,6 +229,8 @@ 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() + json_reader.join() @in_dap_thread def send_event_later(self, event, body=None): diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py index 3b8df2fbf32..8dd89df2614 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=()): result = gdb.Thread(name=name, target=thread_wrapper, args=args, daemon=True) result.start() + return result def start_dap(target): -- 2.35.3