public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb/gdb-8.3-branch] Fix style bug when paging
@ 2019-05-08 16:30 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2019-05-08 16:30 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d0e1efa6ae35091a76023bc4e32b6b1e745fa393

commit d0e1efa6ae35091a76023bc4e32b6b1e745fa393
Author: Tom Tromey <tromey@adacore.com>
Date:   Wed May 1 11:13:31 2019 -0600

    Fix style bug when paging
    
    Philippe pointed out a styling bug that would occur in some conditions
    when paging:
    
        https://sourceware.org/ml/gdb-patches/2019-04/msg00101.html
    
    I was finally able to reproduce this, and this patch fixes the bug.
    
    The problem occurred when text overflowed the line, causing a
    pagination prompt, but when no wrap column had been set.  In this
    case, the current style was reset to show the prompt, but then not
    reset back to the previously applied style before emitting the rest of
    the line.
    
    The fix is to record the applied style in this case, and re-apply it
    afterward -- but only if the pager prompt was emitted, something that
    the existing style.exp pointed out on the first, more naive, version
    of the patch.
    
    Tested on x86-64 Fedora 29.
    
    gdb/ChangeLog
    2019-05-08  Tom Tromey  <tromey@adacore.com>
    
    	* utils.c (fputs_maybe_filtered): Reset style after paging, even
    	when no wrap column is set.

Diff:
---
 gdb/ChangeLog |  5 +++++
 gdb/utils.c   | 24 +++++++++++++++++++++---
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ebd6a52..40fc452 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-05-08  Tom Tromey  <tromey@adacore.com>
+
+	* utils.c (fputs_maybe_filtered): Reset style after paging, even
+	when no wrap column is set.
+
 2019-05-04  Tom Tromey  <tom@tromey.com>
 
 	* psymtab.c (psymbol_name_matches, match_partial_symbol)
diff --git a/gdb/utils.c b/gdb/utils.c
index dd686fa..83ddc23 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1808,10 +1808,20 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
 	    {
 	      unsigned int save_chars = chars_printed;
 
+	      /* If we change the style, below, we'll want to reset it
+		 before continuing to print.  If there is no wrap
+		 column, then we'll only reset the style if the pager
+		 prompt is given; and to avoid emitting style
+		 sequences in the middle of a run of text, we track
+		 this as well.  */
+	      ui_file_style save_style;
+	      bool did_paginate = false;
+
 	      chars_printed = 0;
 	      lines_printed++;
 	      if (wrap_column)
 		{
+		  save_style = wrap_style;
 		  if (can_emit_style_escape (stream))
 		    emit_style_escape (ui_file_style (), stream);
 		  /* If we aren't actually wrapping, don't output
@@ -1821,21 +1831,27 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
 		  fputc_unfiltered ('\n', stream);
 		}
 	      else
-		flush_wrap_buffer (stream);
+		{
+		  save_style = applied_style;
+		  flush_wrap_buffer (stream);
+		}
 
 	      /* Possible new page.  Note that
 		 PAGINATION_DISABLED_FOR_COMMAND might be set during
 		 this loop, so we must continue to check it here.  */
 	      if (lines_printed >= lines_per_page - 1
 		  && !pagination_disabled_for_command)
-		prompt_for_continue ();
+		{
+		  prompt_for_continue ();
+		  did_paginate = true;
+		}
 
 	      /* Now output indentation and wrapped string.  */
 	      if (wrap_column)
 		{
 		  fputs_unfiltered (wrap_indent, stream);
 		  if (can_emit_style_escape (stream))
-		    emit_style_escape (wrap_style, stream);
+		    emit_style_escape (save_style, stream);
 		  /* FIXME, this strlen is what prevents wrap_indent from
 		     containing tabs.  However, if we recurse to print it
 		     and count its chars, we risk trouble if wrap_indent is
@@ -1846,6 +1862,8 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
 		    + (save_chars - wrap_column);
 		  wrap_column = 0;	/* And disable fancy wrap */
 		}
+	      else if (did_paginate && can_emit_style_escape (stream))
+		emit_style_escape (save_style, stream);
 	    }
 	}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-05-08 16:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-08 16:30 [binutils-gdb/gdb-8.3-branch] Fix style bug when paging Tom Tromey

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).