binutils-gdb/gdb/tui
Tom de Vries 03893ce67b [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
2023-11-22 19:07:47 +01:00
..
ChangeLog-1998-2003
tui-command.c
tui-command.h [gdb/tui] Allow command window of 1 or 2 lines 2023-11-22 19:07:47 +01:00
tui-data.c gdb/tui: make tui_win_info::title private 2023-07-15 11:40:45 +01:00
tui-data.h [gdb/tui] Factor out tui_noscroll_window et al 2023-11-14 15:45:18 +01:00
tui-disasm.c gdb: Replace gdb::optional with std::optional 2023-11-21 11:52:35 +00:00
tui-disasm.h
tui-file.c
tui-file.h
tui-hooks.c gdb: add all_objfiles_removed observer 2023-10-05 13:20:50 -04:00
tui-hooks.h
tui-interp.c gdb: move struct ui and related things to ui.{c,h} 2023-05-01 15:40:54 -04:00
tui-io.c gdb: Use std::string_view instead of gdb::string_view 2023-11-21 11:52:36 +00:00
tui-io.h
tui-layout.c [gdb/tui] Fix resizing of terminal to 1 or 2 lines 2023-11-22 19:07:47 +01:00
tui-layout.h [gdb/tui] Fix resizing of terminal to 1 or 2 lines 2023-11-22 19:07:47 +01:00
tui-location.c
tui-location.h Remove explanatory comments from includes 2023-09-20 11:45:16 -06:00
tui-out.c
tui-out.h
tui-regs.c [gdb/tui] Add tui_win_info::{box_width,box_size} 2023-11-13 21:22:50 +01:00
tui-regs.h
tui-source.c [gdb/tui] Add tui_win_info::{box_width,box_size} 2023-11-13 21:22:50 +01:00
tui-source.h
tui-stack.c [gdb/tui] Fix length of status line string 2023-04-26 18:15:56 +02:00
tui-stack.h [gdb/tui] Factor out tui_noscroll_window et al 2023-11-14 15:45:18 +01:00
tui-win.c gdb: Use std::string_view instead of gdb::string_view 2023-11-21 11:52:36 +00:00
tui-win.h gdb/tui: add 'set tui mouse-events off' to restore mouse selection 2023-09-20 16:35:36 +01:00
tui-wingeneral.c [gdb/tui] Add tui_win_info::{box_width,box_size} 2023-11-13 21:22:50 +01:00
tui-wingeneral.h
tui-winsource.c [gdb/tui] Don't include border_width in left_margin 2023-11-13 21:22:50 +01:00
tui-winsource.h [gdb/tui] Don't include border_width in left_margin 2023-11-13 21:22:50 +01:00
tui.c [gdb/tui] Fix superfluous newline for long prompt 2023-07-21 08:17:51 +02:00
tui.h