From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 3FF9D3858C27 for ; Tue, 24 Oct 2023 09:48:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3FF9D3858C27 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 3FF9D3858C27 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2178:6::1c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698140934; cv=none; b=UotUKqjl0UpEcUBrFEmArarjWdUOQrxha/IV2k5ga5yV9c5mDmDKDx3JgE2kDfVFBQpZoEE4aqZbINw5FyNwjry1AUhOfp84DO5AlHxHpLXMhSQvjWE8dsX8bFXRKYkSffFJ+sNgiFFT0yyJ2YQpp43gfUiV9Fl93yqwzp8AFlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698140934; c=relaxed/simple; bh=mwPHAZ+fez6X4Igo7SiGY55TBXgfpZnhK0yHnIK8dnQ=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=L7UQOlY55h0uu0K6WpJkNJtq6CvOkiYn/MLxTVxHA3i92i8HuJtbcpeRjTPDsWP1DmXO+EFOlm2QYgjop4D/vkZFwxkobTSoSvMPTuv9P/JzgOvNJU8OAWXd+pqg5X3hciUPw7uV6xJekskndcZ+zy1iO5vgLArlv31toq5s6dQ= ARC-Authentication-Results: i=1; server2.sourceware.org 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 A4AF821B9B for ; Tue, 24 Oct 2023 09:48:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1698140926; 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=KIayz907l45HqPrO1oxon8yO1sF/uPwey6Cz9cMyLhA=; b=YyX15Ea3rXfPcrlk5Y7Y3F0fpw0us+6pwOCn8CfOKVPyvF3zyCteKlgeqkDuHRA2f/ltwt XzPtWaVcjobiMw+s86pxbfjaxBgrh7QDLnMQdCizH9OVtqIHDyKc8DWGgrXvPuEna0ZNkX 6BNSRjstPoIFyFrC2EOn16m3YjMELN0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1698140926; 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=KIayz907l45HqPrO1oxon8yO1sF/uPwey6Cz9cMyLhA=; b=QpqWp5kzlZZf/BkKizT961fTCH2KS1ozr3bhxq0kGb6sgwvYuRpyQrYQdnbLM6F/32bkEB K5tt+u3wuK8SLlDw== 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 913EA134F5 for ; Tue, 24 Oct 2023 09:48:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id AKw7Iv6SN2UhEQAAMHmgww (envelope-from ) for ; Tue, 24 Oct 2023 09:48:46 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v5 6/6] [gdb/cli] Simplify gdb_highlight_event_listener::notify Date: Tue, 24 Oct 2023 11:49:33 +0200 Message-Id: <20231024094933.12009-7-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231024094933.12009-1-tdevries@suse.de> References: <20231024094933.12009-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -2.10 X-Spamd-Result: default: False [-2.10 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCPT_COUNT_ONE(0.00)[1]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_LONG(-3.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Status: No, score=-11.9 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 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: Currently gdb_highlight_event_listener::notify does things more complicated than necessary because of the unittest. In more detail, the unit test cannot handle it if force_quit is called. Fix this by making signal_handler_selftest capture force_quit. This causes the question also to be asked for the SIGTERM case, so it leaves a less attractive command line after terminating: ... $ gdb -q a.out -ex "list" Reading symbols from a.out... $ ncel source styling using GNU source highlight of test.cpp? ([y] or n) ... This patch currently makes gdb.gdb/unittest.exp fail: ... FAIL: gdb.gdb/unittest.exp: no executable loaded: \ maintenance selftest (got interactive prompt) FAIL: gdb.gdb/unittest.exp: reversed initialization: \ selftest not dependent on initialization order FAIL: gdb.gdb/unittest.exp: executable loaded: \ maintenance selftest (got interactive prompt) ... because the testsuite triggers on the highlighting question. Since this patch is an RFC at this point, I haven't invested time in addressing this yet. Tested on x86_64-linux. --- gdb/event-top.c | 4 ++++ gdb/source-cache.c | 29 +++++++++++------------------ gdb/top.c | 7 +++++++ gdb/top.h | 7 +++++++ 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index 8c01c0902ea..b4b3fec5cdc 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -1235,6 +1235,8 @@ signal_handler_selftest::signal_handler_selftest () m_saved_sigint_handler = signal (SIGINT, SIG_IGN); m_saved_sigterm_handler = signal (SIGTERM, SIG_IGN); + capture_quit_force = true; + /* Only code from the selftest itself can cause the SIGINT or SIGTERM signal handlers to run. */ m_valid = true; @@ -1242,6 +1244,8 @@ signal_handler_selftest::signal_handler_selftest () signal_handler_selftest::~signal_handler_selftest () { + capture_quit_force = false; + /* Make sure that no pending SIGINT or SIGTERM escapes from the selftest. */ clear_pending_sigint (); diff --git a/gdb/source-cache.c b/gdb/source-cache.c index 6f514cbba3e..032a5d5b234 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -221,25 +221,18 @@ class gdb_highlight_event_listener : public srchilite::HighlightEventListener return; } - /* If we got a SIGTERM, skip querying. This isn't strictly - necessary as yquery runs a nested event loop for the secondary - prompt, which runs pending async signal handlers. However, - this helps with the unit test, which makes sure that the quit - call at the bottom throws a gdb_exception_forced_quit exception - and that our caller doesn't swallow it. Note we may receive a - SIGTERM in between the query and the quit call. */ - if (!sync_quit_force_run) + /* Ask the user what to do. If we got a SIGTERM, don't skip querying. + Skipping isn't necessary as yquery runs a nested event loop for the + secondary prompt, which runs pending async signal handlers. Note we + may receive a SIGTERM in between the query and the quit call. */ + int resp + = (yquery + (_("Cancel source styling using GNU source highlight of %s? "), + m_fullname.c_str ())); + if (!sync_quit_force_run && !resp) { - /* Ask the user what to do. */ - int resp - = (yquery - (_("Cancel source styling using GNU source highlight of %s? "), - m_fullname.c_str ())); - if (!resp) - { - /* Continue highlighting. */ - return; - } + /* Continue highlighting. */ + return; } /* Interrupt highlighting. Note we don't abort via the QUIT macro diff --git a/gdb/top.c b/gdb/top.c index 5028440b671..03b9ec5e1ae 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1725,12 +1725,19 @@ undo_terminal_modifications_before_exit (void) current_ui = saved_top_level; } +#if GDB_SELF_TEST +bool capture_quit_force; +#endif /* Quit without asking for confirmation. */ void quit_force (int *exit_arg, int from_tty) { +#if GDB_SELF_TEST + if (capture_quit_force) + throw_forced_quit ("capture_quit_force"); +#endif int exit_code = 0; /* Clear the quit flag and sync_quit_force_run so that a diff --git a/gdb/top.h b/gdb/top.h index 47e16ca104e..d63396e6598 100644 --- a/gdb/top.h +++ b/gdb/top.h @@ -109,4 +109,11 @@ extern bool check_quiet_mode (); extern void unbuffer_stream (FILE *stream); +#if GDB_SELF_TEST +/* Rather than forcibly quitting when quit_force is called, note that it was + called by throwing a forced_quit. This allows selftests to handle this + situation. */ +extern bool capture_quit_force; +#endif + #endif -- 2.35.3