From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QbyOE4UiF2OUbTQAWB0awg (envelope-from ) for ; Tue, 06 Sep 2022 06:35:49 -0400 Received: by simark.ca (Postfix, from userid 112) id 44CFB1E4A7; Tue, 6 Sep 2022 06:35:49 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=gwmsy6Kl; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id F1E931E13B for ; Tue, 6 Sep 2022 06:35:48 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 97245385140B for ; Tue, 6 Sep 2022 10:35:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 97245385140B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1662460548; bh=XJAkDc9gn8pECKw3b5WVcxqEIJebyxqodg5lBQ33kEg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=gwmsy6Klg12zPGF3izm1k4xDUhIO4uBzBZNZZDEycaeOtesBI2Bb1hUJTTE8g9OE2 SSjHycNcvfl9XGticqeUuvuXRnUYqsUL7mh6xR5v2Q6+mcBy1VLTNE31a4V13a87GJ o5fzJd6udxQw0D4izKWg23zJCBe+QuVzSo49OEPo= Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 9F75738582AD for ; Tue, 6 Sep 2022 10:35:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9F75738582AD Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8CDD533AE6; Tue, 6 Sep 2022 10:35:27 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 75A4D13A7A; Tue, 6 Sep 2022 10:35:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id uu0UG28iF2NcDQAAMHmgww (envelope-from ); Tue, 06 Sep 2022 10:35:27 +0000 Date: Tue, 6 Sep 2022 12:35:26 +0200 To: gdb-patches@sourceware.org Subject: [PATCH][gdb] Fix abort in selftest run_on_main_thread with ^C Message-ID: <20220906103524.GA28357@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Cc: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi, When running selftest run_on_main_thread and pressing ^C, we can run into: ... Running selftest run_on_main_thread. terminate called without an active exception Fatal signal: Aborted ... The selftest function looks like this: ... static void run_tests () { std::thread thread; done = false; { gdb::block_signals blocker; thread = std::thread (set_done); } while (!done && gdb_do_one_event () >= 0) ; /* Actually the test will just hang, but we want to test something. */ SELF_CHECK (done); thread.join (); } ... The error message we see is due to the destructor of thread being called while thread is joinable. This is supposed to be taken care of by thread.join (), but the ^C prevents that one from being called, while the destructor is still called. Fix this by ensuring thread.join () is called (if indeed required) before the destructor using SCOPE_EXIT. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29549 Any comments? Thanks, - Tom [gdb] Fix abort in selftest run_on_main_thread with ^C --- gdb/unittests/main-thread-selftests.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gdb/unittests/main-thread-selftests.c b/gdb/unittests/main-thread-selftests.c index 7e1a30d7e80..8ab0c445d42 100644 --- a/gdb/unittests/main-thread-selftests.c +++ b/gdb/unittests/main-thread-selftests.c @@ -20,6 +20,7 @@ #include "defs.h" #include "gdbsupport/selftest.h" #include "gdbsupport/block-signals.h" +#include "gdbsupport/scope-exit.h" #include "run-on-main-thread.h" #include "gdbsupport/event-loop.h" #if CXX_STD_THREAD @@ -52,6 +53,11 @@ run_tests () { gdb::block_signals blocker; + SCOPE_EXIT + { + if (thread.joinable ()) + thread.join (); + }; thread = std::thread (set_done); } @@ -61,8 +67,6 @@ run_tests () /* Actually the test will just hang, but we want to test something. */ SELF_CHECK (done); - - thread.join (); } #endif