]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Handle "set height 1"
authorTom Tromey <tom@tromey.com>
Sun, 9 Jan 2022 02:37:38 +0000 (19:37 -0700)
committerTom Tromey <tom@tromey.com>
Fri, 15 Apr 2022 17:38:13 +0000 (11:38 -0600)
PR cli/17151 points out that "set height 1" has pathological behavior
in gdb.  What I see is that gdb will endlessly print the pagination
prompt.  This patch takes a simple and expedient approach to a fix:
pretend that the height is really 2.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17151

gdb/testsuite/gdb.base/page.exp
gdb/utils.c

index a38f1dd0c94d81db0a7c6da9f248d58d99426ca9..268777f8acbda1c48f0c2eecc00a8273765a5342 100644 (file)
@@ -121,6 +121,7 @@ foreach_with_prefix size {"0" "0x80000000" "unlimited"} {
 gdb_test "set width -1" "integer -1 out of range"
 gdb_test "set height -1" "integer -1 out of range"
 
-gdb_exit
-return 0
-
+# A height of 1 used to cause pathological behavior -- it would
+# endlessly prompt for paging without printing anything.
+gdb_test_no_output "set height 1"
+gdb_test "print 23" " = 23"
index b7d5859d6b3716fd02c0173f7454f4b0e36dd7c0..2465bf3a3edc12cb49ab61ce46b1583950b5920a 100644 (file)
@@ -1601,6 +1601,12 @@ pager_file::puts (const char *linebuffer)
                         m_wrap_indent = 0;
                       });
 
+  /* If the user does "set height 1" then the pager will exhibit weird
+     behavior.  This is pathological, though, so don't allow it.  */
+  const unsigned int lines_allowed = (lines_per_page > 1
+                                     ? lines_per_page - 1
+                                     : 1);
+
   /* Go through and output each character.  Show line extension
      when this is necessary; prompt user for new page when this is
      necessary.  */
@@ -1613,7 +1619,7 @@ pager_file::puts (const char *linebuffer)
         it here.  */
       if (pagination_enabled
          && !pagination_disabled_for_command
-         && lines_printed >= lines_per_page - 1)
+         && lines_printed >= lines_allowed)
        prompt_for_continue ();
 
       while (*lineptr && *lineptr != '\n')
@@ -1690,7 +1696,7 @@ pager_file::puts (const char *linebuffer)
                 this loop, so we must continue to check it here.  */
              if (pagination_enabled
                  && !pagination_disabled_for_command
-                 && lines_printed >= lines_per_page - 1)
+                 && lines_printed >= lines_allowed)
                {
                  prompt_for_continue ();
                  did_paginate = true;