diff options
author | Tom de Vries <tdevries@suse.de> | 2023-11-22 19:07:47 +0100 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2023-11-22 19:07:47 +0100 |
commit | 6697fa28bb6ee610323ea10cb815bac85c6d8184 (patch) | |
tree | 5a5eb72dcfd2adb6e4802b1f81bbc67890ec2260 | |
parent | e8c3dafa5f529e85d7179441be7d039ee9e062bc (diff) | |
download | gdb-6697fa28bb6ee610323ea10cb815bac85c6d8184.zip gdb-6697fa28bb6ee610323ea10cb815bac85c6d8184.tar.gz gdb-6697fa28bb6ee610323ea10cb815bac85c6d8184.tar.bz2 |
[gdb/tui] Allow command window of 1 or 2 lines
When starting TUI in a terminal with 2 lines (likewise with 1 line):
...
$ echo $LINES
2
$ gdb -q -tui
...
we run into this assert in tui_apply_current_layout:
...
/* This should always be made visible by a layout. */
gdb_assert (TUI_CMD_WIN != nullptr);
...
The problem is that for the command window:
- the minimum height is 3 (the default), but
- the maximum height is only 2 because there are only 2 lines.
This discrepancy eventually leads to a call to newwin in make_window with:
...
(gdb) p height
$1 = 3
(gdb) p width
$2 = 66
(gdb) p y
$3 = -1
(gdb) p x
$4 = 0
(gdb)
...
which results in a nullptr, which eventually triggers the assert.
The easiest way to fix this is to change the minimum height of the command
window to 1. However, that would also change behaviour for the case that the
screen size is 3 lines or more. For instance, in gdb.tui/winheight.exp the
number of lines in the terminal is 24, and the test-case checks that the user
cannot increase the source window height to the point that the command window
height would be less than 3.
Fix this by calculating the minimum height of the command window as follows:
- the default (3) if max_height () allows it, and
- max_height () otherwise.
Tested on x86_64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
PR tui/31044
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31044
-rw-r--r-- | gdb/testsuite/gdb.tui/small-term.exp | 29 | ||||
-rw-r--r-- | gdb/tui/tui-command.h | 12 |
2 files changed, 41 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.tui/small-term.exp b/gdb/testsuite/gdb.tui/small-term.exp new file mode 100644 index 0000000..c67c5ca --- /dev/null +++ b/gdb/testsuite/gdb.tui/small-term.exp @@ -0,0 +1,29 @@ +# Copyright 2023 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 running TUI in a tuiterm with few lines. + +tuiterm_env + +foreach_with_prefix lines { 1 2 3 4 5 6 7 } { + Term::clean_restart $lines 80 + + if {![Term::enter_tui]} { + unsupported "TUI not supported" + return + } + + Term::check_region_contents "has prompt" 0 0 80 $lines "$gdb_prompt" +} diff --git a/gdb/tui/tui-command.h b/gdb/tui/tui-command.h index d743dd8..e4d04ef 100644 --- a/gdb/tui/tui-command.h +++ b/gdb/tui/tui-command.h @@ -40,6 +40,18 @@ struct tui_cmd_window void resize (int height, int width, int origin_x, int origin_y) override; + /* Compute the minimum height of this window. */ + virtual int min_height () const override + { + int preferred_min = tui_win_info::min_height (); + int max = max_height (); + /* If there is enough space to accommodate the preferred minimum height, + use it. Otherwise, use as much as possible. */ + return (preferred_min <= max + ? preferred_min + : max); + } + int start_line = 0; }; |