aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2025-02-06 15:02:37 +0000
committerAndrew Burgess <aburgess@redhat.com>2025-02-14 21:06:30 +0000
commitf589ead3af31d50513428d930290443a59aed425 (patch)
tree0453133a58f5f93ede757678497620456936df3c /gdb/testsuite
parent6ea89e2ddb2af33f1778faeeeb8149a2f575fbd3 (diff)
downloadbinutils-f589ead3af31d50513428d930290443a59aed425.zip
binutils-f589ead3af31d50513428d930290443a59aed425.tar.gz
binutils-f589ead3af31d50513428d930290443a59aed425.tar.bz2
gdb/tui: use maybe_update for source centring in an extra case
I noticed that, with recent versions of GDB, when the TUI is enabled before the inferior is started, the source code display is not as helpful as it used to be. Here's a simple test program being displayed using GDB 15.2, at this point the inferior has not started, all I've done is 'tui enable': ┌─hello.c────────────────────────────────────────────────┐ │ 10 return 0; │ │ 11 } │ │ 12 │ │ 13 /* The main function. */ │ │ 14 │ │ 15 int │ │ 16 main () │ │ 17 { │ │ 18 printf ("Hello World\n"); │ │ 19 call_me ( 0, 1, 2, 3, 4, 5, 6, 7 ); │ │ 20 return 0; │ │ 21 } │ │ │ │ │ └────────────────────────────────────────────────────────┘ Compare this to GDB 16.2: ┌─hello.c────────────────────────────────────────────────┐ │ 17 { │ │ 18 printf ("Hello World\n"); │ │ 19 call_me ( 0, 1, 2, 3, 4, 5, 6, 7 ); │ │ 20 return 0; │ │ 21 } │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ └────────────────────────────────────────────────────────┘ I think the new layout is not as good because it is missing the context of the function name. The new behaviour started with the commit: commit 49e607f511c1fab82a0116990a72d1915c74bb4a Author: Stephan Rohr <stephan.rohr@intel.com> Date: Sat Aug 3 02:07:42 2024 -0700 gdb: adjust the default place of 'list' to main's prologue I don't think the new behaviour is really a problem with that commit, rather, when using 'tui enable' before the inferior has started GDB ends up calling tui_source_window_base::rerender(), and then passes through the code path which calls update_source_window_with_addr(). When using 'tui enable' after the inferior has started, GDB again calls tui_source_window_base::rerender(), but this time has a frame, and so takes the second code path, which centres the selected source line, and then calls update_source_window. The point is that the update_source_window_with_addr() path doesn't include the logic to centre the source line. Before the above commit this was fine as GDB's default location would be prior to main, and so we got the "good" TUI output. After the above commit the default location is now main's prologue, and without the centring logic, the first line shown is main's prologue. I propose fixing this by having update_source_window_with_addr() call maybe_update(). This will first check if the requested line is already visible, and if not, show the requested line with centring applied. After this commit, the 'tui enable' state is now: ┌─hello.c─────────────────────────────────────────────────────┐ │ 11 } │ │ 12 │ │ 13 /* The main function. */ │ │ 14 │ │ 15 int │ │ 16 main () │ │ 17 { │ │ 18 printf ("Hello World\n"); │ │ 19 call_me ( 0, 1, 2, 3, 4, 5, 6, 7 ); │ │ 20 return 0; │ │ 21 } │ │ │ │ │ │ │ └─────────────────────────────────────────────────────────────┘ It's not identical to the old behaviour, but that was never the objective, we do however, see the context around main's prologue, which will usually be enough to see the function name and return type, which I think is useful. Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/gdb.tui/tui-init-source.c47
-rw-r--r--gdb/testsuite/gdb.tui/tui-init-source.exp41
2 files changed, 88 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.tui/tui-init-source.c b/gdb/testsuite/gdb.tui/tui-init-source.c
new file mode 100644
index 0000000..43f56b3
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/tui-init-source.c
@@ -0,0 +1,47 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2025 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/>. */
+
+/* These numbered comments are to ensure the TUI source window will be
+ filled with content, and give us something to match against. */
+
+/* 01 */
+/* 02 */
+/* 03 */
+/* 04 */
+/* 05 */
+/* 06 */
+/* 07 */
+/* 08 */
+/* 09 */
+/* 10 */
+
+int
+main (void)
+{
+ return 0;
+}
+
+/* 11 */
+/* 12 */
+/* 13 */
+/* 14 */
+/* 15 */
+/* 16 */
+/* 17 */
+/* 18 */
+/* 19 */
+/* 20 */
diff --git a/gdb/testsuite/gdb.tui/tui-init-source.exp b/gdb/testsuite/gdb.tui/tui-init-source.exp
new file mode 100644
index 0000000..274b334
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/tui-init-source.exp
@@ -0,0 +1,41 @@
+# Copyright 2025 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/>.
+
+# When enabling TUI prior to starting the inferior, check that the
+# default source code location is centred within the window.
+
+require allow_tui_tests
+
+tuiterm_env
+
+standard_testfile
+
+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 the source code box displays at least one line before main,
+# the type and name of the main function, and one line after main.
+Term::check_region_contents \
+ "check source is reasonably centred" \
+ 1 1 78 13 \
+ "/\\* 10 \\*/.*int.*main \\(void\\).*/\\* 11 \\*/"