From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id A87533858C55; Sat, 7 May 2022 09:54:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A87533858C55 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/readline: fix extra 'quit' message problem X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 69464d2267c47e91f9ba77726c745d82b8864c88 X-Git-Newrev: 8f3babfaf8ea582bed93fd6abcde7bfc96d3a8dd Message-Id: <20220507095434.A87533858C55@sourceware.org> Date: Sat, 7 May 2022 09:54:34 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 May 2022 09:54:34 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D8f3babfaf8ea= 582bed93fd6abcde7bfc96d3a8dd commit 8f3babfaf8ea582bed93fd6abcde7bfc96d3a8dd Author: Andrew Burgess Date: Tue Apr 26 15:08:02 2022 +0100 gdb/readline: fix extra 'quit' message problem =20 After these two commits: =20 commit 4fb7bc4b147fd30b781ea2dad533956d0362295a Date: Mon Mar 7 13:49:21 2022 +0000 =20 readline: back-port changes needed to properly detect EOF =20 commit 91395d97d905c31ac38513e4aaedecb3b25e818f Date: Tue Feb 15 17:28:03 2022 +0000 =20 gdb: handle bracketed-paste-mode and EOF correctly =20 It was observed that, if a previous command is selected at the readline prompt using the up arrow key, then when the command is accepted (by pressing return) an unexpected 'quit' message will be printed by GDB. Here's an example session: =20 (gdb) p 123 $1 =3D 123 (gdb) p 123 quit $2 =3D 123 (gdb) =20 In this session the second 'p 123' was entered not by typing 'p 123', but by pressing the up arrow key to select the previous command. It is important that the up arrow key is used, typing Ctrl-p will not trigger the bug. =20 The problem here appears to be readline's EOF detection when handling multi-character input sequences. I have raised this issue on the readline mailing list here: =20 https://lists.gnu.org/archive/html/bug-readline/2022-04/msg00012.html =20 a solution has been proposed here: =20 https://lists.gnu.org/archive/html/bug-readline/2022-04/msg00016.html =20 This patch includes a test for this issue as well as a back-port of (the important bits of) readline commit: =20 commit 2ef9cec8c48ab1ae3a16b1874a49bd1f58eaaca1 Date: Wed May 4 11:18:04 2022 -0400 =20 fix for setting RL_STATE_EOF in callback mode =20 That commit also includes some updates to the readline documentation and tests that I have not included in this commit. =20 With this commit in place the unexpected 'quit' messages are resolved. Diff: --- gdb/testsuite/gdb.base/readline.exp | 10 ++++++++++ readline/readline/callback.c | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/gdb.base/readline.exp b/gdb/testsuite/gdb.base/r= eadline.exp index 4d770336eb6..caf3b4acb62 100644 --- a/gdb/testsuite/gdb.base/readline.exp +++ b/gdb/testsuite/gdb.base/readline.exp @@ -183,6 +183,16 @@ save_vars { env(TERM) } { } } =20 + # Use the up arrow to select a previous command. Check that + # no unexpected output is added between the previously + # selected command, and the output of that command. + gdb_test "print 123" "\\\$\[0-9\]* =3D 123" + gdb_test_multiple "\033\[A" "use up arrow" { + -re -wrap "print 123\r\n\\\$\[0-9\]* =3D 123" { + pass $gdb_test_name + } + } + # Now repeat the first test with a history file that fills the entire # history list. =20 diff --git a/readline/readline/callback.c b/readline/readline/callback.c index 58b84d2e2ad..93f23d97bc2 100644 --- a/readline/readline/callback.c +++ b/readline/readline/callback.c @@ -271,8 +271,11 @@ rl_callback_read_char (void) } =20 /* Make sure application hooks can see whether we saw EOF. */ - if (rl_eof_found =3D eof) - RL_SETSTATE(RL_STATE_EOF); + if (eof > 0) + { + rl_eof_found =3D eof; + RL_SETSTATE(RL_STATE_EOF); + } =20 if (rl_done) {