From: Joel Brobecker <brobecker@adacore.com>
To: Andrew Burgess <aburgess@redhat.com>
Cc: gdb-patches@sourceware.org, Eli Zaretskii <eliz@gnu.org>,
Joel Brobecker <brobecker@adacore.com>,
pedro@palves.net
Subject: Re: GDB 12.0.90 available for testing
Date: Sun, 24 Apr 2022 08:56:56 -0700 [thread overview]
Message-ID: <YmVzSDHQkGL9CQs1@adacore.com> (raw)
In-Reply-To: <874k2prr1c.fsf@redhat.com>
Hi everyone,
> Sorry for the slow reply, I've been off for the last week, so I'm only
> just catching up with my GDB emails.
>
> How does the patch below look? This moves the setbuf call into a new
> function, and includes the comment from gdb_readline_no_editing_callback.
Given the feedback received on this patch, and the fact that it was
tagged as important for the GDB 12 release, I performed one last round
of testing on Windows (using AdaCore's testsuite), and pushed Andrew's
patch below to both master and gdb-12-branch.
The one change I made was to the commit message, to add a reference
to the PR created by Eli.
Thanks everyone who contributed to finding, analyzing, fixing and
reviewing!
> commit 3ee791edccae840e11b9ebe70e5547dfbec04e00
> Author: Andrew Burgess <aburgess@redhat.com>
> Date: Tue Apr 19 17:00:04 2022 +0100
>
> gdb: move setbuf calls out of gdb_readline_no_editing_callback
>
> After this commit:
>
> commit d08cbc5d3203118da5583296e49273cf82378042
> Date: Wed Dec 22 12:57:44 2021 +0000
>
> gdb: unbuffer all input streams when not using readline
>
> Issues were reported with some MS-Windows hosts, see the thread
> starting here:
>
> https://sourceware.org/pipermail/gdb-patches/2022-March/187004.html
>
> The problem seems to be that calling setbuf on terminal file handles
> is not always acceptable, see this mail for more details:
>
> https://sourceware.org/pipermail/gdb-patches/2022-April/187310.html
>
> This commit does two things, first moving the setbuf calls out of
> gdb_readline_no_editing_callback so that we don't end up calling
> setbuf so often.
>
> Then, for MS-Windows hosts, we don't call setbuf for terminals, this
> appears to resolve the issues that have been reported.
>
> diff --git a/gdb/event-top.c b/gdb/event-top.c
> index b628f0397cb..a55338d78a2 100644
> --- a/gdb/event-top.c
> +++ b/gdb/event-top.c
> @@ -818,19 +818,6 @@ gdb_readline_no_editing_callback (gdb_client_data client_data)
> FILE *stream = ui->instream != nullptr ? ui->instream : ui->stdin_stream;
> gdb_assert (stream != nullptr);
>
> - /* Unbuffer the input stream, so that, later on, the calls to fgetc
> - fetch only one char at the time from the stream. The fgetc's will
> - get up to the first newline, but there may be more chars in the
> - stream after '\n'. If we buffer the input and fgetc drains the
> - stream, getting stuff beyond the newline as well, a select, done
> - afterwards will not trigger.
> -
> - This unbuffering was, at one point, not applied if the input stream
> - was a tty, however, the buffering can cause problems, even for a tty,
> - in some cases. Please ensure that any changes in this area run the MI
> - tests with the FORCE_SEPARATE_MI_TTY=1 flag being passed. */
> - setbuf (stream, NULL);
> -
> /* We still need the while loop here, even though it would seem
> obvious to invoke gdb_readline_no_editing_callback at every
> character entered. If not using the readline library, the
> diff --git a/gdb/top.c b/gdb/top.c
> index 1cfffbeee7e..263a2ce8f43 100644
> --- a/gdb/top.c
> +++ b/gdb/top.c
> @@ -257,6 +257,41 @@ void (*deprecated_context_hook) (int id);
> /* The highest UI number ever assigned. */
> static int highest_ui_num;
>
> +/* Unbuffer STREAM. This is a wrapper around setbuf(STREAM, nullptr)
> + which applies some special rules for MS-Windows hosts. */
> +
> +static void
> +unbuffer_stream (FILE *stream)
> +{
> + /* Unbuffer the input stream so that in gdb_readline_no_editing_callback,
> + the calls to fgetc fetch only one char at the time from STREAM.
> +
> + This is important because gdb_readline_no_editing_callback will read
> + from STREAM up to the first '\n' character, after this GDB returns to
> + the event loop and relies on a select on STREAM indicating that more
> + input is pending.
> +
> + If STREAM is buffered then the fgetc calls may have moved all the
> + pending input from the kernel into a local buffer, after which the
> + select will not indicate that more input is pending, and input after
> + the first '\n' will not be processed immediately.
> +
> + Please ensure that any changes in this area run the MI tests with the
> + FORCE_SEPARATE_MI_TTY=1 flag being passed. */
> +
> +#ifdef __MINGW32__
> + /* With MS-Windows runtime, making stdin unbuffered when it's
> + connected to the terminal causes it to misbehave. */
> + if (!ISATTY (stream))
> + setbuf (stream, nullptr);
> +#else
> + /* On GNU/Linux the issues described above can impact GDB even when
> + dealing with input from a terminal. For now we unbuffer the input
> + stream for everyone except MS-Windows. */
> + setbuf (stream, nullptr);
> +#endif
> +}
> +
> /* See top.h. */
>
> ui::ui (FILE *instream_, FILE *outstream_, FILE *errstream_)
> @@ -283,6 +318,8 @@ ui::ui (FILE *instream_, FILE *outstream_, FILE *errstream_)
> {
> buffer_init (&line_buffer);
>
> + unbuffer_stream (instream_);
> +
> if (ui_list == NULL)
> ui_list = this;
> else
> @@ -412,6 +449,8 @@ read_command_file (FILE *stream)
> {
> struct ui *ui = current_ui;
>
> + unbuffer_stream (stream);
> +
> scoped_restore save_instream
> = make_scoped_restore (&ui->instream, stream);
>
>
--
Joel
next prev parent reply other threads:[~2022-04-24 15:56 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-20 5:58 Joel Brobecker
2022-03-26 15:26 ` Eli Zaretskii
2022-03-26 15:53 ` Joel Brobecker
2022-03-26 16:15 ` Eli Zaretskii
2022-04-07 16:08 ` Tom Tromey
2022-04-07 16:12 ` Eli Zaretskii
2022-04-07 18:00 ` Joel Brobecker
2022-04-07 18:04 ` Simon Marchi
2022-04-07 19:02 ` Tom Tromey
2022-04-07 19:11 ` Joel Brobecker
2022-04-08 13:38 ` Tom Tromey
2022-04-08 14:33 ` Pedro Alves
2022-04-18 15:26 ` Tom Tromey
2022-04-18 16:13 ` Tom Tromey
2022-04-07 18:30 ` Tom Tromey
2022-04-08 6:58 ` Eli Zaretskii
2022-04-18 19:28 ` Tom Tromey
2022-03-26 17:59 ` Eli Zaretskii
2022-03-26 18:34 ` Eli Zaretskii
2022-03-26 18:51 ` Eli Zaretskii
2022-03-27 6:27 ` Eli Zaretskii
2022-03-31 6:23 ` Eli Zaretskii
2022-03-31 9:48 ` Pedro Alves
2022-03-31 11:55 ` Eli Zaretskii
2022-04-01 10:12 ` Andrew Burgess
2022-04-01 11:18 ` Eli Zaretskii
2022-04-01 11:25 ` Eli Zaretskii
2022-04-01 15:21 ` Andrew Burgess
2022-04-01 16:18 ` Eli Zaretskii
2022-04-03 13:02 ` Hannes Domani
2022-04-03 13:34 ` Eli Zaretskii
2022-04-03 14:03 ` Joel Brobecker
2022-04-03 15:26 ` Hannes Domani
2022-04-03 15:38 ` Eli Zaretskii
2022-04-07 11:09 ` Eli Zaretskii
2022-04-07 18:03 ` Joel Brobecker
2022-04-10 19:06 ` Joel Brobecker
2022-04-11 11:42 ` Eli Zaretskii
2022-04-17 17:28 ` Joel Brobecker
2022-04-19 16:12 ` Andrew Burgess
2022-04-19 16:16 ` Eli Zaretskii
2022-04-20 13:26 ` Andrew Burgess
2022-04-20 17:11 ` Joel Brobecker
2022-04-20 17:30 ` Eli Zaretskii
2022-04-24 15:56 ` Joel Brobecker [this message]
2022-04-25 8:48 ` Andrew Burgess
2022-04-07 18:28 ` Tom Tromey
2022-04-07 19:22 ` Pedro Alves
2022-04-08 4:04 ` Eli Zaretskii
2022-04-01 12:36 ` Joel Brobecker
2022-04-01 12:50 ` Eli Zaretskii
2022-04-01 14:12 ` Joel Brobecker
2022-04-01 14:27 ` Eli Zaretskii
2022-04-01 14:31 ` Joel Brobecker
2022-04-08 14:44 ` Pedro Alves
2022-04-08 20:05 ` Eli Zaretskii
2022-03-27 9:55 ` Eli Zaretskii
2022-03-27 1:55 ` Simon Marchi
2022-03-27 5:20 ` Eli Zaretskii
2022-04-07 16:13 ` Tom Tromey
2022-04-07 16:39 ` Eli Zaretskii
2022-03-31 6:21 ` Eli Zaretskii
2022-03-31 9:44 ` Pedro Alves
2022-03-31 11:58 ` Eli Zaretskii
2022-03-31 12:05 ` Pedro Alves
2022-03-31 14:00 ` Eli Zaretskii
2022-04-12 14:01 ` Luis Machado
2022-04-12 17:57 ` Joel Brobecker
2022-04-13 7:36 ` Luis Machado
2022-04-13 12:19 ` Luis Machado
2022-04-13 16:20 ` Jose E. Marchesi
2022-04-17 17:33 ` Joel Brobecker
2022-04-18 1:48 ` Alan Modra
2022-04-26 13:54 ` Luis Machado
2022-04-26 14:56 ` Joel Brobecker
2022-04-26 15:15 ` Luis Machado
2022-04-20 17:33 ` Pedro Alves
2022-04-20 17:52 ` Joel Brobecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YmVzSDHQkGL9CQs1@adacore.com \
--to=brobecker@adacore.com \
--cc=aburgess@redhat.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=pedro@palves.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).