From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GGSkMgx+IGOTAjkAWB0awg (envelope-from ) for ; Tue, 13 Sep 2022 08:56:44 -0400 Received: by simark.ca (Postfix, from userid 112) id C2ECB1E112; Tue, 13 Sep 2022 08:56:44 -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=pm9gCQyX; 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=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.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 73B461E0D5 for ; Tue, 13 Sep 2022 08:56:44 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F052A385AE58 for ; Tue, 13 Sep 2022 12:56:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F052A385AE58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663073804; bh=owG+F8pI6suFy97XcChPzU0tAU2if+obz2pAXWjhWRk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pm9gCQyXlILWqz9FAIMb6q3lIc8pU8jjCfi+GhvbeAQXHg9hj+NPEknKK54C5VeAg a3kSqu4Kg+Xmxi384hRxYY9jQUeM3QMA93nibFiBdfSxWPEkcshi9aB25K4mle5gk+ lAj1DP60J7HUKwbH4HFlAtRb4l8/Fv1PeSSjtj1E= Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 8F4FD3858D39 for ; Tue, 13 Sep 2022 12:56:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8F4FD3858D39 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 78F6322475; Tue, 13 Sep 2022 12:56:22 +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 62B5D139B3; Tue, 13 Sep 2022 12:56:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id okYCF/Z9IGNpDwAAMHmgww (envelope-from ); Tue, 13 Sep 2022 12:56:22 +0000 Date: Tue, 13 Sep 2022 14:56:20 +0200 To: gdb-patches@sourceware.org Subject: [RFC][gdb] Handle pending ^C after rl_callback_read_char Message-ID: <20220913125619.GA15500@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 Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi, In completion tests in various test-cases, we've been running into these "clearing input line" timeouts: ... (gdb) $cmd^GPASS: gdb.gdb/unittest.exp: tab complete "$cmd" FAIL: gdb.gdb/unittest.exp: tab complete "$cmd" (clearing input line) (timeout) ... where $cmd == "maintenance selftest name_that_does_not_exist". AFAIU, the following scenario happens: - expect sends "$cmd\t" - gdb detects the stdin event, and calls rl_callback_read_char until it comes to handle \t - readline interprets the \t as completion, tries to complete, fails to do so, outputs a bell (^G) - expect sees the bell, and proceeds to send ^C - readline is still in the call to rl_callback_read_char, and stores the signal in _rl_caught_signal - readline returns from the call to rl_callback_read_char, without having handled _rl_caught_signal - gdb goes to wait for the next event - expect times out waiting for "Quit", the expected reaction for ^C Fix this by handling pending signals after each call to rl_callback_read_char. The fix is only available for readline 8.x, if --with-system-readline provides an older version, then the fix is disabled due to missing function rl_check_signals. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27813 Any comments? Thanks, - Tom [gdb] Handle pending ^C after rl_callback_read_char --- gdb/event-top.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gdb/event-top.c b/gdb/event-top.c index 290c3d87744..00adbe8fb4f 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -186,6 +186,22 @@ gdb_rl_callback_read_char_wrapper_noexcept () noexcept TRY_SJLJ { rl_callback_read_char (); +#if RL_VERSION_MAJOR >= 8 + /* It can happen that readline (while in rl_callback_read_char) + received a signal, but didn't handle it yet. Make sure it's handled + now. If we don't do that we run into two related problems: + - we have to wait for another event triggering + rl_callback_read_char before the signal is handled + - there's no guarantee that the signal will be processed before the + event. */ + while (rl_pending_signal () != 0) + /* Do this in a while loop, in case rl_check_signals also leaves a + pending signal. I'm not sure if that's possible, but it seems + better to handle the scenario than to assert. */ + rl_check_signals (); +#else + /* Unfortunately, rl_check_signals is not available. */ +#endif if (after_char_processing_hook) (*after_char_processing_hook) (); }