From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id A5D213853829; Fri, 16 Sep 2022 13:53:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A5D213853829 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663336431; bh=pG4Aqcv9tUxyIWylrPnysZNV9b9fDv47qXfSHUmihD4=; h=From:To:Subject:Date:From; b=L4pjUqpvpmQvWgrBVENAqEEa6O6oTb+BMSul0bKgoBxk9q23+8dRnArrQumygX2gB UZMxP1kRhCIgIi0mu5u2nBwD9DuPBS2F356DQCB7lq+9d/bDLeqJmCdwYaURfdlOWL 6zQgSBYPJfpSb7oslOK6TNyP4k8pNW5bsocJYlGg= 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] Handle pending ^C after rl_callback_read_char X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 49c3ed081fed6b8e2b48fdc48f805f11e4589514 X-Git-Newrev: faf01aee1d03aef5b6f95fd0db358bf5e70578f9 Message-Id: <20220916135351.A5D213853829@sourceware.org> Date: Fri, 16 Sep 2022 13:53:51 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dfaf01aee1d03= aef5b6f95fd0db358bf5e70578f9 commit faf01aee1d03aef5b6f95fd0db358bf5e70578f9 Author: Tom de Vries Date: Fri Sep 16 15:53:47 2022 +0200 [gdb] Handle pending ^C after rl_callback_read_char =20 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 =3D=3D "maintenance selftest name_that_does_not_exist". =20 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 havi= ng handled _rl_caught_signal - gdb goes to wait for the next event - expect times out waiting for "Quit", the expected reaction for ^C =20 Fix this by handling pending signals after each call to rl_callback_rea= d_char. =20 The fix is only available for readline 8.x, if --with-system-readline p= rovides an older version, then the fix is disabled due to missing function rl_check_signals. =20 Tested on x86_64-linux. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D27813 Diff: --- 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 >=3D 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 () !=3D 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) (); }