aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2023-11-22 19:07:47 +0100
committerTom de Vries <tdevries@suse.de>2023-11-22 19:07:47 +0100
commit03893ce67b5d1af649d59f7e63b3959ce0ac0709 (patch)
tree09325fbd5c96caf9e0dada8a4beb8a8166d3ae9d /gdb
parent6697fa28bb6ee610323ea10cb815bac85c6d8184 (diff)
downloadgdb-03893ce67b5d1af649d59f7e63b3959ce0ac0709.zip
gdb-03893ce67b5d1af649d59f7e63b3959ce0ac0709.tar.gz
gdb-03893ce67b5d1af649d59f7e63b3959ce0ac0709.tar.bz2
[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
Diffstat (limited to 'gdb')
-rw-r--r--gdb/testsuite/gdb.tui/resize.exp9
-rw-r--r--gdb/tui/tui-layout.c22
-rw-r--r--gdb/tui/tui-layout.h6
3 files changed, 34 insertions, 3 deletions
diff --git a/gdb/testsuite/gdb.tui/resize.exp b/gdb/testsuite/gdb.tui/resize.exp
index 60d5116..e15f8a2 100644
--- a/gdb/testsuite/gdb.tui/resize.exp
+++ b/gdb/testsuite/gdb.tui/resize.exp
@@ -39,3 +39,12 @@ Term::check_contents "source at startup" "\\|.*21 *return 0"
Term::resize 40 90
Term::check_box "source box after resize" 0 0 90 26
+
+# Check that resizing to less than 3 lines doesn't cause problems.
+foreach lines { 2 1 } {
+ with_test_prefix lines=$lines {
+ Term::resize $lines 90 0
+ Term::wait_for ""
+ Term::check_region_contents "has prompt" 0 0 90 $lines "$gdb_prompt"
+ }
+}
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index b932649..85f4991 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -452,6 +452,13 @@ tui_layout_window::apply (int x_, int y_, int width_, int height_,
width = width_;
height = height_;
gdb_assert (m_window != nullptr);
+ if (width == 0 || height == 0)
+ {
+ /* The window was dropped, so it's going to be deleted, reset the
+ soon to be dangling pointer. */
+ m_window = nullptr;
+ return;
+ }
m_window->resize (height, width, x, y);
}
@@ -833,6 +840,7 @@ tui_layout_split::apply (int x_, int y_, int width_, int height_,
int available_size = m_vertical ? height : width;
int last_index = -1;
int total_weight = 0;
+ int prev = -1;
for (int i = 0; i < m_splits.size (); ++i)
{
bool cmd_win_already_exists = TUI_CMD_WIN != nullptr;
@@ -864,6 +872,14 @@ tui_layout_split::apply (int x_, int y_, int width_, int height_,
info[i].max_size = info[i].min_size;
}
+ if (info[i].min_size > info[i].max_size)
+ {
+ /* There is not enough room for this window, drop it. */
+ info[i].min_size = 0;
+ info[i].max_size = 0;
+ continue;
+ }
+
if (info[i].min_size == info[i].max_size)
available_size -= info[i].min_size;
else
@@ -874,10 +890,12 @@ tui_layout_split::apply (int x_, int y_, int width_, int height_,
/* Two adjacent boxed windows will share a border, making a bit
more size available. */
- if (i > 0
- && m_splits[i - 1].layout->last_edge_has_border_p ()
+ if (prev != -1
+ && m_splits[prev].layout->last_edge_has_border_p ()
&& m_splits[i].layout->first_edge_has_border_p ())
info[i].share_box = true;
+
+ prev = i;
}
/* If last_index is set then we have a window that is not of a fixed
diff --git a/gdb/tui/tui-layout.h b/gdb/tui/tui-layout.h
index a6d3485..4d29c05 100644
--- a/gdb/tui/tui-layout.h
+++ b/gdb/tui/tui-layout.h
@@ -189,7 +189,11 @@ public:
/* See tui_layout_base::get_windows. */
void get_windows (std::vector<tui_win_info *> *windows) override
{
- windows->push_back (m_window);
+ if (m_window != nullptr && m_window->is_visible ())
+ {
+ /* Only get visible windows. */
+ windows->push_back (m_window);
+ }
}
protected: