From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 1052A3858437 for ; Mon, 7 Mar 2022 15:13:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1052A3858437 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-587-aoig-BFEOjKVUzD0BxlOyQ-1; Mon, 07 Mar 2022 10:13:22 -0500 X-MC-Unique: aoig-BFEOjKVUzD0BxlOyQ-1 Received: by mail-wr1-f69.google.com with SMTP id t15-20020adfdc0f000000b001ef93643476so4645244wri.2 for ; Mon, 07 Mar 2022 07:13:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=If2hjBXFnUFEVIq8MaBmZsVzdIqPNL2H9ym52CrQuoQ=; b=aTr7Xs4c7LM9P8GBlIWK0f85YOubbuuBjH7Gb1B8t8Havq0DVvPn8n3WRBDTRuCAw+ UIeZavUr2K3L48VjovNmBgx8tlyiB7HjizWvX9U13OjUO3i0k7rf/MAG/fM3ttnWxU0r XlMplK0jM+wkvuDxSq6sYH77XS8abMgt/vxRn/iNTVlL9tIWdbyAEceHV1OpKDz0GCuO W3gqB5Y2J07rPpm8nrNXpVeElITvLwureGf/TsM1IblkQVa5Bes0Y6Z9KNeVMKRfFO+h uqcKSHTWecMkVHkJp36QzOCMpDIjmz4hlN5VVgZusuoKtyaxBXlCq1xvKBT+hsHg/kn7 B93A== X-Gm-Message-State: AOAM531wcCMbeVGtJe2yAsuiuui1RbIaZXiprUcKYb/LxJJWdgLdFv6s FElEEdTTdjVnYbyq/Wqv9ZQJrqpa7plBGLvBoPCDamiXOZEezPX+w2XhyLn5i6d1J1ZEdF4d4pv HG/vucwf3JPhrKS06CN8wqALrSgGDYPUuCKZDqKK2pVmCNsAgD37A/K9VaJg10fpoj3toE3+V6g == X-Received: by 2002:a1c:f018:0:b0:37b:c13c:3128 with SMTP id a24-20020a1cf018000000b0037bc13c3128mr18665379wmb.157.1646666001242; Mon, 07 Mar 2022 07:13:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJx31DV+a9BuJCPmvaALQFystKxDBPWoKOpt+GDaSMwHCJIc6IgUCzI3kCKyW+Sglza74lgcwg== X-Received: by 2002:a1c:f018:0:b0:37b:c13c:3128 with SMTP id a24-20020a1cf018000000b0037bc13c3128mr18665355wmb.157.1646666000896; Mon, 07 Mar 2022 07:13:20 -0800 (PST) Received: from localhost (host86-134-151-205.range86-134.btcentralplus.com. [86.134.151.205]) by smtp.gmail.com with ESMTPSA id i15-20020a05600011cf00b001edc2966dd4sm11424436wrx.47.2022.03.07.07.13.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 07:13:20 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/2] readline: back-port changes needed to properly detect EOF Date: Mon, 7 Mar 2022 15:13:14 +0000 Message-Id: <452f0981e2ae041ec22b46da254e742b9d62730d.1646665813.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-List-Received-Date: Mon, 07 Mar 2022 15:13:29 -0000 This commit is a partial back-port of this upstream readline commit: commit 002d31aa5f5929eb32d0e0e2e8b8d35d99e59961 Author: Chet Ramey Date: Thu Mar 3 11:11:47 2022 -0500 add rl_eof_found to public API; fix pointer aliasing problems \ with history-search-backward; fix a display problem with \ runs of invisible characters at the end of a physical \ screen line I have only pulled in the parts of this commit that relate to the new rl_eof_found global, and the RL_STATE_EOF state flag. These changes are needed in order to fix PR cli/28833, and are discussed in this thread to the bug-readline mailing list: https://lists.gnu.org/archive/html/bug-readline/2022-02/msg00021.html The above commit is not yet in any official readline release, but my hope is that now it has been merged into the readline tree it should be safe enough to back port this fix to GDB's tree. At some point in the future we will inevitably want to roll forward the version of readline that we maintain in the binutils-gdb repository. When that day comes the changes in this commit can be replaced with the latest upstream readline code, as I have not changed the meaning of this code at all from what is in upstream readline. This commit alone does not fix the PR cli/28833 issue, for that the next commit, which changes GDB itself, is needed. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28833 --- readline/readline/callback.c | 8 +++++++- readline/readline/doc/rltech.texi | 11 +++++++++++ readline/readline/readline.c | 19 ++++++++++++------- readline/readline/readline.h | 8 +++++++- readline/readline/rlprivate.h | 1 - readline/readline/rltty.c | 4 ++-- 6 files changed, 39 insertions(+), 12 deletions(-) diff --git a/readline/readline/callback.c b/readline/readline/callback.c index a466cf9b6ef..58b84d2e2ad 100644 --- a/readline/readline/callback.c +++ b/readline/readline/callback.c @@ -1,6 +1,6 @@ /* callback.c -- functions to use readline as an X `callback' mechanism. */ -/* Copyright (C) 1987-2017 Free Software Foundation, Inc. +/* Copyright (C) 1987-2022 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -136,6 +136,8 @@ rl_callback_read_char (void) abort (); } + eof = 0; + memcpy ((void *)olevel, (void *)_rl_top_level, sizeof (procenv_t)); #if defined (HAVE_POSIX_SIGSETJMP) jcode = sigsetjmp (_rl_top_level, 0); @@ -268,6 +270,10 @@ rl_callback_read_char (void) _rl_want_redisplay = 0; } + /* Make sure application hooks can see whether we saw EOF. */ + if (rl_eof_found = eof) + RL_SETSTATE(RL_STATE_EOF); + if (rl_done) { line = readline_internal_teardown (eof); diff --git a/readline/readline/doc/rltech.texi b/readline/readline/doc/rltech.texi index bbf57c239c9..797e34d95e0 100644 --- a/readline/readline/doc/rltech.texi +++ b/readline/readline/doc/rltech.texi @@ -323,6 +323,14 @@ @deftypevar int rl_done Setting this to a non-zero value causes Readline to return the current line immediately. +Readline will set this variable when it has read a key sequence bound +to @code{accept-line} and is about to return the line to the caller. +@end deftypevar + +@deftypevar int rl_eof_found +Readline will set this variable when it has read an EOF character (e.g., the +stty @samp{EOF} character) on an empty line or encountered a read error and +is about to return a NULL line to the caller. @end deftypevar @deftypevar int rl_num_chars_to_read @@ -588,6 +596,9 @@ @item RL_STATE_DONE Readline has read a key sequence bound to @code{accept-line} and is about to return the line to the caller. +@item RL_STATE_EOF +Readline has read an EOF character (e.g., the stty @samp{EOF} character) +or encountered a read error and is about to return a NULL line to the caller. @end table @end deftypevar diff --git a/readline/readline/readline.c b/readline/readline/readline.c index e61d188bbe9..0e33587f234 100644 --- a/readline/readline/readline.c +++ b/readline/readline/readline.c @@ -1,7 +1,7 @@ /* readline.c -- a general facility for reading lines of input with emacs style editing and completion. */ -/* Copyright (C) 1987-2020 Free Software Foundation, Inc. +/* Copyright (C) 1987-2022 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -165,6 +165,9 @@ int rl_end; /* Make this non-zero to return the current input_line. */ int rl_done; +/* If non-zero when readline_internal returns, it means we found EOF */ +int rl_eof_found = 0; + /* The last function executed by readline. */ rl_command_func_t *rl_last_func = (rl_command_func_t *)NULL; @@ -218,9 +221,6 @@ int _rl_eof_char = CTRL ('D'); /* Non-zero makes this the next keystroke to read. */ int rl_pending_input = 0; -/* If non-zero when readline_internal returns, it means we found EOF */ -int _rl_eof_found = 0; - /* Pointer to a useful terminal name. */ const char *rl_terminal_name = (const char *)NULL; @@ -474,6 +474,9 @@ readline_internal_teardown (int eof) RL_CHECK_SIGNALS (); + if (eof) + RL_SETSTATE (RL_STATE_EOF); /* XXX */ + /* Restore the original of this history line, iff the line that we are editing was originally in the history, AND the line has changed. */ entry = current_history (); @@ -596,6 +599,7 @@ readline_internal_charloop (void) RL_SETSTATE(RL_STATE_DONE); return (rl_done = 1); #else + RL_SETSTATE(RL_STATE_EOF); eof_found = 1; break; #endif @@ -636,6 +640,7 @@ readline_internal_charloop (void) RL_SETSTATE(RL_STATE_DONE); return (rl_done = 1); #else + RL_SETSTATE(RL_STATE_EOF); eof_found = 1; break; #endif @@ -703,8 +708,8 @@ static char * readline_internal (void) { readline_internal_setup (); - _rl_eof_found = readline_internal_charloop (); - return (readline_internal_teardown (_rl_eof_found)); + rl_eof_found = readline_internal_charloop (); + return (readline_internal_teardown (rl_eof_found)); } void @@ -1161,7 +1166,7 @@ rl_initialize (void) /* We aren't done yet. We haven't even gotten started yet! */ rl_done = 0; - RL_UNSETSTATE(RL_STATE_DONE); + RL_UNSETSTATE(RL_STATE_DONE|RL_STATE_EOF); /* Tell the history routines what is going on. */ _rl_start_using_history (); diff --git a/readline/readline/readline.h b/readline/readline/readline.h index 78fa39d02a1..9f79810f290 100644 --- a/readline/readline/readline.h +++ b/readline/readline/readline.h @@ -1,6 +1,6 @@ /* Readline.h -- the names of functions callable from within readline. */ -/* Copyright (C) 1987-2020 Free Software Foundation, Inc. +/* Copyright (C) 1987-2022 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -553,6 +553,10 @@ extern int rl_mark; line and should return it. */ extern int rl_done; +/* Flag to indicate that readline has read an EOF character or read has + returned 0 or error, and is returning a NULL line as a result. */ +extern int rl_eof_found; + /* If set to a character value, that will be the next keystroke read. */ extern int rl_pending_input; @@ -906,6 +910,8 @@ extern int rl_persistent_signal_handlers; #define RL_STATE_REDISPLAYING 0x1000000 /* updating terminal display */ #define RL_STATE_DONE 0x2000000 /* done; accepted line */ +#define RL_STATE_EOF 0x8000000 /* done; got eof on read */ + #define RL_SETSTATE(x) (rl_readline_state |= (x)) #define RL_UNSETSTATE(x) (rl_readline_state &= ~(x)) diff --git a/readline/readline/rlprivate.h b/readline/readline/rlprivate.h index 23ab2d8cec0..02838ae21ae 100644 --- a/readline/readline/rlprivate.h +++ b/readline/readline/rlprivate.h @@ -544,7 +544,6 @@ extern FILE *_rl_in_stream; extern FILE *_rl_out_stream; extern int _rl_last_command_was_kill; extern int _rl_eof_char; -extern int _rl_eof_found; extern procenv_t _rl_top_level; extern _rl_keyseq_cxt *_rl_kscxt; extern int _rl_keyseq_timeout; diff --git a/readline/readline/rltty.c b/readline/readline/rltty.c index d0cd572713a..11997b7c9d8 100644 --- a/readline/readline/rltty.c +++ b/readline/readline/rltty.c @@ -1,7 +1,7 @@ /* rltty.c -- functions to prepare and restore the terminal for readline's use. */ -/* Copyright (C) 1992-2017 Free Software Foundation, Inc. +/* Copyright (C) 1992-2022 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -692,7 +692,7 @@ rl_deprep_terminal (void) if (terminal_prepped & TPX_BRACKPASTE) { fprintf (rl_outstream, BRACK_PASTE_FINI); - if (_rl_eof_found) + if (rl_eof_found) fprintf (rl_outstream, "\n"); } -- 2.25.4