From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH] [gdb/tui] Fix displaying main after resizing
Date: Fri, 24 Nov 2023 09:59:02 +0100 [thread overview]
Message-ID: <20231124085902.24318-1-tdevries@suse.de> (raw)
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 a call to tui_display_main from tui_enable to
tui_apply_current_layout.
Tested on x86_64-linux.
---
gdb/testsuite/gdb.tui/resize-one-line.exp | 50 +++++++++++++++++++++++
gdb/tui/tui-layout.c | 5 ++-
gdb/tui/tui.c | 2 -
3 files changed, 54 insertions(+), 3 deletions(-)
create mode 100644 gdb/testsuite/gdb.tui/resize-one-line.exp
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 00000000000..5f8847cb94b
--- /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 85f4991c769..e1507fa25c2 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -111,7 +111,10 @@ tui_apply_current_layout (bool preserve_cmd_win_size_p)
if (gdbarch == nullptr && TUI_DISASM_WIN != nullptr)
tui_get_begin_asm_address (&gdbarch, &addr);
- tui_update_source_windows_with_addr (gdbarch, addr);
+ if (addr == 0)
+ tui_display_main ();
+ else
+ tui_update_source_windows_with_addr (gdbarch, addr);
}
/* See tui-layout. */
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index 941c65c970f..83fe343bd3d 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -495,8 +495,6 @@ tui_enable (void)
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
base-commit: ad785961c9ee2dbe80f233cf7f6f408e678d2197
--
2.35.3
next reply other threads:[~2023-11-24 8:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-24 8:59 Tom de Vries [this message]
2023-11-25 3:43 ` Tom Tromey
2023-11-25 9:44 ` Tom de Vries
2023-12-08 15:20 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231124085902.24318-1-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).