From patchwork Thu Nov 14 22:51:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 35903 Received: (qmail 110395 invoked by alias); 14 Nov 2019 22:56:36 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 110378 invoked by uid 89); 14 Nov 2019 22:56:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT autolearn=ham version=3.3.1 spammy=Answer, winheight, refactoring X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Nov 2019 22:56:34 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 66F90204A7; Thu, 14 Nov 2019 17:51:31 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id DDD6121080 for ; Thu, 14 Nov 2019 17:51:21 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id D0DE428171 for ; Thu, 14 Nov 2019 17:51:21 -0500 (EST) X-Gerrit-PatchSet: 3 Date: Thu, 14 Nov 2019 17:51:20 -0500 From: "Tom Tromey (Code Review)" To: gdb-patches@sourceware.org Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [review v3] Fix the "winheight" command X-Gerrit-Change-Id: I0871e93777a70036dbec9c9543f862f42e3a81e5 X-Gerrit-Change-Number: 371 X-Gerrit-ChangeURL: X-Gerrit-Commit: 7a37a847f584fea16dcc2e65bf00ce4364a81612 In-Reply-To: References: Reply-To: tromey@sourceware.org, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-76-gf8b6da0ab5 Message-Id: <20191114225121.D0DE428171@gnutoolchain-gerrit.osci.io> Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/371 ...................................................................... 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. 2019-11-12 Tom Tromey * 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-12 Tom Tromey * gdb.tui/winheight.exp: New file. Change-Id: I0871e93777a70036dbec9c9543f862f42e3a81e5 --- M gdb/ChangeLog M gdb/testsuite/ChangeLog A gdb/testsuite/gdb.tui/winheight.exp M gdb/tui/tui-data.c M gdb/tui/tui-data.h M gdb/tui/tui-win.c 6 files changed, 71 insertions(+), 27 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c4d591b..5a928d0 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 2019-11-12 Tom Tromey + * 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-12 Tom Tromey + * tui/tui-win.c (tui_set_win_height_command): Call tui_adjust_window_height. (tui_adjust_win_heights, new_height_ok): Remove. diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index dd638ba..ed16999 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2019-11-12 Tom Tromey + * gdb.tui/winheight.exp: New file. + +2019-11-12 Tom Tromey + * gdb.tui/resize.exp: Update. * gdb.tui/empty.exp (layouts): Update. diff --git a/gdb/testsuite/gdb.tui/winheight.exp b/gdb/testsuite/gdb.tui/winheight.exp new file mode 100644 index 0000000..cf65c75 --- /dev/null +++ b/gdb/testsuite/gdb.tui/winheight.exp @@ -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 . + +# 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 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 @@ } -/* 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 58fe821..a0e296f 100644 --- a/gdb/tui/tui-data.h +++ b/gdb/tui/tui-data.h @@ -305,7 +305,6 @@ /* 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 44631af..4a4c59b 100644 --- a/gdb/tui/tui-win.c +++ b/gdb/tui/tui-win.c @@ -51,6 +51,7 @@ #include "gdb_curses.h" #include #include "readline/readline.h" +#include "gdbsupport/gdb_string_view.h" #include @@ -687,6 +688,24 @@ } +/* 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) @@ -834,20 +853,16 @@ tui_enable (); if (arg != NULL) { - std::string copy = arg; - char *buf = ©[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)