Fix the "winheight" command
authorTom Tromey <tom@tromey.com>
Sat, 26 Oct 2019 22:56:27 +0000 (16:56 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 19 Nov 2019 20:27:25 +0000 (13:27 -0700)
The "winheight" command is broken.  I probably broke it in one of my
TUI refactoring patches, though I didn't track down exactly which one.

The bug is that the code does:

  *buf_ptr = '\0';

... but then never advances buf_ptr past this point, so no window name
is seen.

This patch refactors the code a bit so that a copy of the argument
string is not needed, also fixing the bug.

A new test case is included.

gdb/ChangeLog
2019-11-19  Tom Tromey  <tom@tromey.com>

* tui/tui-win.c (tui_partial_win_by_name): Move from tui-data.c.
Now static.  Change type of "name".
(tui_set_win_height_command): Don't copy "arg".
* tui/tui-data.h (tui_partial_win_by_name): Don't declare.
* tui/tui-data.c (tui_partial_win_by_name): Move to tui-win.c.

gdb/testsuite/ChangeLog
2019-11-19  Tom Tromey  <tom@tromey.com>

* gdb.tui/winheight.exp: New file.

Change-Id: I0871e93777a70036dbec9c9543f862f42e3a81e5

gdb/ChangeLog
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.tui/winheight.exp [new file with mode: 0644]
gdb/tui/tui-data.c
gdb/tui/tui-data.h
gdb/tui/tui-win.c

index 11ec2e3d85c621e8f113df2f5aa6273db5f02a88..cf65de2e21134eeb8d3ceedc6a60a088d07b003b 100644 (file)
@@ -1,3 +1,11 @@
+2019-11-19  Tom Tromey  <tom@tromey.com>
+
+       * tui/tui-win.c (tui_partial_win_by_name): Move from tui-data.c.
+       Now static.  Change type of "name".
+       (tui_set_win_height_command): Don't copy "arg".
+       * tui/tui-data.h (tui_partial_win_by_name): Don't declare.
+       * tui/tui-data.c (tui_partial_win_by_name): Move to tui-win.c.
+
 2019-11-19  Ali Tamur <tamur@google.com>
 
        * dwarf2read.c (dw2_get_file_names_reader): Replace "if (attr)" with
index 806389c956c580664cc56111f19fd63f672024c9..32dc3083328a99a2e6fbc2cf8a5250c8091b975d 100644 (file)
@@ -1,3 +1,7 @@
+2019-11-19  Tom Tromey  <tom@tromey.com>
+
+       * gdb.tui/winheight.exp: New file.
+
 2019-11-19  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb.base/ctf-whatis.c: Delete.
diff --git a/gdb/testsuite/gdb.tui/winheight.exp b/gdb/testsuite/gdb.tui/winheight.exp
new file mode 100644 (file)
index 0000000..cf65c75
--- /dev/null
@@ -0,0 +1,37 @@
+# Copyright 2019 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test the "winheight" command.
+
+load_lib "tuiterm.exp"
+
+standard_testfile tui-layout.c
+
+if {[build_executable "failed to prepare" ${testfile} ${srcfile}] == -1} {
+    return -1
+}
+
+Term::clean_restart 24 80 $testfile
+if {![Term::enter_tui]} {
+    unsupported "TUI not supported"
+}
+
+Term::check_box "source box" 0 0 80 15
+
+Term::command "winheight cmd +5"
+Term::check_box "smaller source box" 0 0 80 10
+
+Term::command "winheight cmd -5"
+Term::check_box "larger source box" 0 0 80 15
index 522bb9acebd173f4d35769e77f9f95440b07350b..8f79658d6b7be6bbbed8fec71877221ee4e3f8ba 100644 (file)
@@ -158,25 +158,6 @@ tui_prev_win (struct tui_win_info *cur_win)
 }
 
 
-/* Answer the window represented by name.  */
-struct tui_win_info *
-tui_partial_win_by_name (const char *name)
-{
-  if (name != NULL)
-    {
-      for (tui_win_info *item : all_tui_windows ())
-       {
-         const char *cur_name = item->name ();
-
-         if (strlen (name) <= strlen (cur_name)
-             && startswith (cur_name, name))
-           return item;
-       }
-    }
-
-  return NULL;
-}
-
 /* See tui-data.h.  */
 
 void
index 0e45da5934ffd149ab0efbb79744598f3df4937a..282b49ee6f9f3b093cda2aec63a426720ab2c8ae 100644 (file)
@@ -294,7 +294,6 @@ struct all_tui_windows
 
 
 /* Data Manipulation Functions.  */
-extern struct tui_win_info *tui_partial_win_by_name (const char *);
 extern enum tui_layout_type tui_current_layout (void);
 extern int tui_term_height (void);
 extern void tui_set_term_height_to (int);
index feeee34c0831d76c82a216d0da1251b200124692..c8d36c7e63719c6f9131963dd5e605dc204a7f66 100644 (file)
@@ -51,6 +51,7 @@
 #include "gdb_curses.h"
 #include <ctype.h>
 #include "readline/readline.h"
+#include "gdbsupport/gdb_string_view.h"
 
 #include <signal.h>
 
@@ -792,6 +793,24 @@ tui_scroll_right_command (const char *arg, int from_tty)
 }
 
 
+/* Answer the window represented by name.  */
+static struct tui_win_info *
+tui_partial_win_by_name (gdb::string_view name)
+{
+  if (name != NULL)
+    {
+      for (tui_win_info *item : all_tui_windows ())
+       {
+         const char *cur_name = item->name ();
+
+         if (startswith (cur_name, name))
+           return item;
+       }
+    }
+
+  return NULL;
+}
+
 /* Set focus to the window named by 'arg'.  */
 static void
 tui_set_focus_command (const char *arg, int from_tty)
@@ -939,20 +958,16 @@ tui_set_win_height_command (const char *arg, int from_tty)
   tui_enable ();
   if (arg != NULL)
     {
-      std::string copy = arg;
-      char *buf = &copy[0];
-      char *buf_ptr = buf;
-      char *wname = NULL;
+      const char *buf = arg;
+      const char *buf_ptr = buf;
       int new_height;
       struct tui_win_info *win_info;
 
-      wname = buf_ptr;
       buf_ptr = strchr (buf_ptr, ' ');
       if (buf_ptr != NULL)
        {
-         *buf_ptr = '\0';
-
          /* Validate the window name.  */
+         gdb::string_view wname (buf, buf_ptr - buf);
          win_info = tui_partial_win_by_name (wname);
 
          if (win_info == NULL)
This page took 0.037854 seconds and 4 git commands to generate.