[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 03893ce67b ("[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>
This commit is contained in:
Tom de Vries
2023-12-08 17:36:35 +01:00
parent 44671f3f7f
commit ee1e9bbb51
5 changed files with 76 additions and 31 deletions

View File

@@ -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"
}

View File

@@ -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_)

View File

@@ -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. */

View File

@@ -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. */

View File

@@ -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. */