aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-10-26 16:56:27 -0600
committerTom Tromey <tom@tromey.com>2019-11-19 13:27:25 -0700
commit9f6ad286efc0edf7d0cdb8a4126a23d38a267f8d (patch)
treeffc49d645384be569e25d409d9abfd659eb74d00 /gdb/tui
parent435d3d88360d1ad9aac798f6bff7d7b5363efe3e (diff)
downloadgdb-9f6ad286efc0edf7d0cdb8a4126a23d38a267f8d.zip
gdb-9f6ad286efc0edf7d0cdb8a4126a23d38a267f8d.tar.gz
gdb-9f6ad286efc0edf7d0cdb8a4126a23d38a267f8d.tar.bz2
Fix the "winheight" command
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
Diffstat (limited to 'gdb/tui')
-rw-r--r--gdb/tui/tui-data.c19
-rw-r--r--gdb/tui/tui-data.h1
-rw-r--r--gdb/tui/tui-win.c29
3 files changed, 22 insertions, 27 deletions
diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c
index 522bb9a..8f79658 100644
--- a/gdb/tui/tui-data.c
+++ b/gdb/tui/tui-data.c
@@ -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
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 0e45da5..282b49e 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -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);
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index feeee34..c8d36c7 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -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)