aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2023-12-08 17:36:35 +0100
committerTom de Vries <tdevries@suse.de>2023-12-08 17:36:35 +0100
commitee1e9bbb5139d766d70cfa036979cec73a1223b7 (patch)
tree1ece1cc9745f4b7c440581531d8a4d61dc514d95
parent44671f3f7f4c6435e7a639ad2215629f4e1ea8a7 (diff)
downloadgdb-ee1e9bbb5139d766d70cfa036979cec73a1223b7.zip
gdb-ee1e9bbb5139d766d70cfa036979cec73a1223b7.tar.gz
gdb-ee1e9bbb5139d766d70cfa036979cec73a1223b7.tar.bz2
[gdb/tui] Fix displaying main after resizing
A TUI src window is displaying either: - the source for the current frame, - the source for main, or - the string "[ No Source Available ]". Since commit 03893ce67b5 ("[gdb/tui] Fix resizing of terminal to 1 or 2 lines") we're able to resize the TUI to 1 line without crashing. I noticed that if TUI is displaying main, and we resize to 1 line (destroying the src window) and then back to a larger terminal (reconstructing the src window), the TUI displays "[ No Source Available ]" instead of main. Fix this by moving the responsibility for showing main from tui_enable to tui_source_window_base::rerender. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
-rw-r--r--gdb/testsuite/gdb.tui/resize-one-line.exp50
-rw-r--r--gdb/tui/tui-layout.c25
-rw-r--r--gdb/tui/tui-winsource.c22
-rw-r--r--gdb/tui/tui-winsource.h5
-rw-r--r--gdb/tui/tui.c5
5 files changed, 76 insertions, 31 deletions
diff --git a/gdb/testsuite/gdb.tui/resize-one-line.exp b/gdb/testsuite/gdb.tui/resize-one-line.exp
new file mode 100644
index 0000000..5f8847c
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/resize-one-line.exp
@@ -0,0 +1,50 @@
+# 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/>.
+
+# Check that when showing main (because of lack of current frame) in the src
+# window, resizing to 1 line and back doesn't change the contents of the src
+# window.
+
+tuiterm_env
+
+standard_testfile main-one-line.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"
+ return
+}
+
+# Check that we have a source box containing main.
+Term::check_box "source box" 0 0 80 15
+Term::check_region_contents "src window shows main" 0 0 80 15 "main"
+
+# Resize to a single line.
+Term::resize 1 80 0
+Term::wait_for ""
+
+# Resize back to the previous size.
+Term::resize 24 80 0
+
+# Check that we still have a source box containing main.
+with_test_prefix "after resizing" {
+ gdb_assert { [Term::wait_for_region_contents 0 0 80 15 "main"] } \
+ "src window shows main"
+}
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index 85f4991..a4cb5a8 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -45,8 +45,6 @@
#include "gdb_curses.h"
#include "gdbsupport/gdb-safe-ctype.h"
-static void extract_display_start_addr (struct gdbarch **, CORE_ADDR *);
-
/* The layouts. */
static std::vector<std::unique_ptr<tui_layout_split>> layouts;
@@ -69,11 +67,6 @@ std::vector<tui_win_info *> tui_windows;
void
tui_apply_current_layout (bool preserve_cmd_win_size_p)
{
- struct gdbarch *gdbarch;
- CORE_ADDR addr;
-
- extract_display_start_addr (&gdbarch, &addr);
-
for (tui_win_info *win_info : tui_windows)
win_info->make_visible (false);
@@ -108,10 +101,6 @@ tui_apply_current_layout (bool preserve_cmd_win_size_p)
/* Replace the global list of active windows. */
tui_windows = std::move (new_tui_windows);
-
- if (gdbarch == nullptr && TUI_DISASM_WIN != nullptr)
- tui_get_begin_asm_address (&gdbarch, &addr);
- tui_update_source_windows_with_addr (gdbarch, addr);
}
/* See tui-layout. */
@@ -284,20 +273,6 @@ tui_remove_some_windows ()
tui_apply_current_layout (true);
}
-static void
-extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
-{
- if (TUI_SRC_WIN != nullptr)
- TUI_SRC_WIN->display_start_addr (gdbarch_p, addr_p);
- else if (TUI_DISASM_WIN != nullptr)
- TUI_DISASM_WIN->display_start_addr (gdbarch_p, addr_p);
- else
- {
- *gdbarch_p = nullptr;
- *addr_p = 0;
- }
-}
-
void
tui_win_info::resize (int height_, int width_,
int origin_x_, int origin_y_)
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index acbaef9..52c0b5b 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -178,6 +178,18 @@ tui_source_window_base::update_source_window_as_is
}
+/* See tui-winsource.h. */
+void
+tui_source_window_base::update_source_window_with_addr (struct gdbarch *gdbarch,
+ CORE_ADDR addr)
+{
+ struct symtab_and_line sal {};
+ if (addr != 0)
+ sal = find_pc_line (addr, 0);
+
+ update_source_window (gdbarch, sal);
+}
+
/* Function to ensure that the source and/or disassembly windows
reflect the input address. */
void
@@ -473,7 +485,15 @@ tui_source_window_base::rerender ()
update_source_window (gdbarch, cursal);
}
else
- erase_source_content ();
+ {
+ CORE_ADDR addr;
+ struct gdbarch *gdbarch;
+ tui_get_begin_asm_address (&gdbarch, &addr);
+ if (addr == 0)
+ erase_source_content ();
+ else
+ update_source_window_with_addr (gdbarch, addr);
+ }
}
/* See tui-data.h. */
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index c282616..523d0ea 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -183,6 +183,11 @@ public:
virtual void display_start_addr (struct gdbarch **gdbarch_p,
CORE_ADDR *addr_p) = 0;
+ /* Function to ensure that the source or disassembly window
+ reflects the input address. Single window variant of
+ update_source_windows_with_addr. */
+ void update_source_window_with_addr (struct gdbarch *, CORE_ADDR);
+
private:
/* Used for horizontal scroll. */
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index 941c65c..33aced2 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -493,11 +493,6 @@ tui_enable (void)
tui_resize_all ();
}
- if (deprecated_safe_get_selected_frame ())
- tui_show_frame_info (deprecated_safe_get_selected_frame ());
- else
- tui_display_main ();
-
/* Install the TUI specific hooks. This must be done after the call to
tui_display_main so that we don't detect the symtab changed event it
can cause. */