]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[gdb/tui] Fix resizing of terminal to 1 or 2 lines
authorTom de Vries <tdevries@suse.de>
Wed, 22 Nov 2023 18:07:47 +0000 (19:07 +0100)
committerTom de Vries <tdevries@suse.de>
Wed, 22 Nov 2023 18:07:47 +0000 (19:07 +0100)
commit03893ce67b5d1af649d59f7e63b3959ce0ac0709
tree09325fbd5c96caf9e0dada8a4beb8a8166d3ae9d
parent6697fa28bb6ee610323ea10cb815bac85c6d8184
[gdb/tui] Fix resizing of terminal to 1 or 2 lines

When starting TUI in a terminal with 3 lines:
...
$ echo $LINES
3
$ gdb -q -tui
...
and resizing the terminal to 2 lines we run into a segfault.

The problem is that for the source 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 = 56
(gdb) p y
$3 = -1
(gdb) p x
$4 = 0
...
which results in a nullptr.

This violates the assumption here in tui_apply_current_layout:
....
  /* Get the new list of currently visible windows.  */
  std::vector<tui_win_info *> new_tui_windows;
  applied_layout->get_windows (&new_tui_windows);
...
that get_windows only returns visible windows, which leads to tui_windows
holding a dangling pointer, which results in the segfault.

Fix this by:
- making sure get_windows only returns visible windows, and
- detecting the situation and dropping windows from the layout if
  there's no room for them.

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
gdb/testsuite/gdb.tui/resize.exp
gdb/tui/tui-layout.c
gdb/tui/tui-layout.h