Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb: Don't flush line wrap buffer before adding newline
Date: Tue, 05 Feb 2019 15:55:00 -0000	[thread overview]
Message-ID: <20190205155545.GC2829@embecosm.com> (raw)
In-Reply-To: <87womentlq.fsf@tromey.com>

* Tom Tromey <tom@tromey.com> [2019-02-05 08:27:29 -0700]:

> >>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:
> 
> Andrew> 	* utils.c (fputs_maybe_filtered): Don't flush the line wrap buffer
> Andrew> 	before inserting a newline for line-wrapping.
> 
> Thanks, this is ok.

Really, I was just teasing - this patch is rubbish :-/

(Not really, I spotted my mistake immediately after hitting send.)

The code used to look like this:

    if (wrap_column)
    {
      emit_style_escape (ui_file_style ());
      flush_wrap_buffer (stream);
      fputc_unfiltered ('\n', stream);
    }

The problem is that 'emit_style_escape' sends the escape string to the
wrap_buffer, while the newline is sent directly to the console.

This means that GDB is still styled when the newline is sent, which I
think means that if we hit a pager prompt this could be styled.

I did consider having a second version of 'emit_style_escape' that
by-passed the wrap_buffer, but I worried that this might be too open
to incorrect use.  Instead I thought a better approach would be backup
and clear the wrap_buffer before calling 'emit_style_escape' in the
above code, the 'flush_wrap_buffer' can then be used safely.

The patch below shows a new proposal for utils.c.

Do you agree with the issues I see above?

What do you think of the new approach?

Thanks,
Andrew


---

diff --git a/gdb/utils.c b/gdb/utils.c
index 6fb5736abb5..153de6cd0f8 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1787,9 +1787,12 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
 	         anyway; if it's wrong, let us keep going.  */
 	      if (wrap_column)
 		{
+		  std::string tmp = wrap_buffer;
+		  wrap_buffer.clear ();
 		  emit_style_escape (ui_file_style ());
 		  flush_wrap_buffer (stream);
 		  fputc_unfiltered ('\n', stream);
+		  wrap_buffer = tmp;
 		}
 
 	      /* Possible new page.  Note that


  reply	other threads:[~2019-02-05 15:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-05 15:10 Andrew Burgess
2019-02-05 15:27 ` Tom Tromey
2019-02-05 15:55   ` Andrew Burgess [this message]
2019-02-05 20:44     ` Tom Tromey
2019-02-05 17:15       ` Andrew Burgess

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=20190205155545.GC2829@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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