public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Allow word wrapping even when paging is disabled
Date: Fri, 15 Apr 2022 17:53:54 +0000 (GMT)	[thread overview]
Message-ID: <20220415175354.6A6D03857363@sourceware.org> (raw)

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

commit 1f0f8b5d9d9053c4d164d01c6915c2e6b8c6ea48
Author: Tom Tromey <tom@tromey.com>
Date:   Sat Jan 8 18:26:35 2022 -0700

    Allow word wrapping even when paging is disabled
    
    PR cli/20741 points out that when pagination is disabled, this also
    disabled word wrapping.  However, the manual documents that these
    settings are separate -- if you intend to disable the wrapping, you
    must use "set width unlimited".
    
    This patch fixes the bug by letting the pagination-disabled case fall
    through to the code that also handles word-wrapping.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20741

Diff:
---
 gdb/utils.c | 52 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 44 insertions(+), 8 deletions(-)

diff --git a/gdb/utils.c b/gdb/utils.c
index 62a75d9e37f..b7d5859d6b3 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1582,10 +1582,8 @@ pager_file::puts (const char *linebuffer)
   if (linebuffer == 0)
     return;
 
-  /* Don't do any filtering if it is disabled.  */
-  if (!pagination_enabled
-      || pagination_disabled_for_command
-      || batch_flag
+  /* Don't do any filtering or wrapping if both are disabled.  */
+  if (batch_flag
       || (lines_per_page == UINT_MAX && chars_per_line == UINT_MAX)
       || top_level_interpreter () == NULL
       || top_level_interpreter ()->interp_ui_out ()->is_mi_like_p ())
@@ -1613,8 +1611,9 @@ pager_file::puts (const char *linebuffer)
       /* 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)
+      if (pagination_enabled
+	  && !pagination_disabled_for_command
+	  && lines_printed >= lines_per_page - 1)
 	prompt_for_continue ();
 
       while (*lineptr && *lineptr != '\n')
@@ -1689,8 +1688,9 @@ pager_file::puts (const char *linebuffer)
 	      /* 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)
+	      if (pagination_enabled
+		  && !pagination_disabled_for_command
+		  && lines_printed >= lines_per_page - 1)
 		{
 		  prompt_for_continue ();
 		  did_paginate = true;
@@ -1744,6 +1744,41 @@ pager_file::write (const char *buf, long length_buf)
   this->puts (str.c_str ());
 }
 
+#if GDB_SELF_TEST
+
+/* Test that disabling the pager does not also disable word
+   wrapping.  */
+
+static void
+test_pager ()
+{
+  string_file *strfile = new string_file ();
+  pager_file pager (strfile);
+
+  /* Make sure the pager is disabled.  */
+  scoped_restore save_enabled
+    = make_scoped_restore (&pagination_enabled, false);
+  scoped_restore save_disabled
+    = make_scoped_restore (&pagination_disabled_for_command, false);
+  scoped_restore save_batch
+    = make_scoped_restore (&batch_flag, false);
+  scoped_restore save_lines
+    = make_scoped_restore (&lines_per_page, 50);
+  /* Make it easy to word wrap.  */
+  scoped_restore save_chars
+    = make_scoped_restore (&chars_per_line, 15);
+  scoped_restore save_printed
+    = make_scoped_restore (&chars_printed, 0);
+
+  pager.puts ("aaaaaaaaaaaa");
+  pager.wrap_here (2);
+  pager.puts ("bbbbbbbbbbbb\n");
+
+  SELF_CHECK (strfile->string () == "aaaaaaaaaaaa\n  bbbbbbbbbbbb\n");
+}
+
+#endif /* GDB_SELF_TEST */
+
 void
 gdb_puts (const char *linebuffer, struct ui_file *stream)
 {
@@ -3696,5 +3731,6 @@ When set, debugging messages will be marked with seconds and microseconds."),
   selftests::register_test ("gdb_argv_array_view", gdb_argv_as_array_view_test);
   selftests::register_test ("strncmp_iw_with_mode",
 			    strncmp_iw_with_mode_tests);
+  selftests::register_test ("pager", test_pager);
 #endif
 }


                 reply	other threads:[~2022-04-15 17:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220415175354.6A6D03857363@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /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).