From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH] [gdb/tui] Don't show incorrect source file in source window
Date: Wed, 29 Jan 2025 11:21:02 +0100 [thread overview]
Message-ID: <20250129102102.28617-1-tdevries@suse.de> (raw)
Consider the test-case sources main.c and foo.c:
...
$ cat main.c
extern int foo (void);
int
main (void)
{
return foo ();
}
$ cat foo.c
extern int foo (void);
int
foo (void)
{
return 0;
}
...
and main.c compiled with debug info, and foo.c without:
...
$ gcc -g main.c -c
$ gcc foo.c -c
$ gcc -g main.o foo.o
...
In TUI mode, if we run to foo:
...
$ gdb -q a.out -tui -ex "b foo" -ex run
...
it gets us "[ No Source Available ]":
...
┌─main.c─────────────────────────────────────────┐
│ │
│ │
│ │
│ [ No Source Available ] │
│ │
│ │
└────────────────────────────────────────────────┘
(src) In: foo L?? PC: 0x400566
db.so.1".
Breakpoint 1, 0x0000000000400566 in foo ()
(gdb)
...
But after resizing (pressing ctrl-<minus> in the gnome-terminal), we get
instead the source for main.c:
...
┌─main.c───────────────────────────────────────────────────┐
│ 3 int │
│ 4 main (void) │
│ 5 { │
│ 6 return foo (); │
│ 7 } │
│ │
│ │
└──────────────────────────────────────────────────────────┘
(src) In: foo L?? PC: 0x400566
db.so.1".
Breakpoint 1, 0x0000000000400566 in foo ()
(gdb)
...
which is inappropriate because we're stopped in function foo, which is not in
main.c.
Fix this in tui_source_window_base::rerender.
Tested on x86_64-linux.
Reported-By: Andrew Burgess <aburgess@redhat.com>
PR tui/32614
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32614
---
gdb/testsuite/gdb.tui/resize-3-foo.c | 24 ++++++++++
gdb/testsuite/gdb.tui/resize-3-main.c | 24 ++++++++++
gdb/testsuite/gdb.tui/resize-3.exp | 63 +++++++++++++++++++++++++++
gdb/tui/tui-winsource.c | 6 +++
4 files changed, 117 insertions(+)
create mode 100644 gdb/testsuite/gdb.tui/resize-3-foo.c
create mode 100644 gdb/testsuite/gdb.tui/resize-3-main.c
create mode 100644 gdb/testsuite/gdb.tui/resize-3.exp
diff --git a/gdb/testsuite/gdb.tui/resize-3-foo.c b/gdb/testsuite/gdb.tui/resize-3-foo.c
new file mode 100644
index 00000000000..653b24ba92b
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/resize-3-foo.c
@@ -0,0 +1,24 @@
+/* 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/>. */
+
+extern int foo (void);
+
+int
+foo (void)
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.tui/resize-3-main.c b/gdb/testsuite/gdb.tui/resize-3-main.c
new file mode 100644
index 00000000000..95fdd3b6ba0
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/resize-3-main.c
@@ -0,0 +1,24 @@
+/* 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/>. */
+
+extern int foo (void);
+
+int
+main (void)
+{
+ return foo ();
+}
diff --git a/gdb/testsuite/gdb.tui/resize-3.exp b/gdb/testsuite/gdb.tui/resize-3.exp
new file mode 100644
index 00000000000..ec022b4a177
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/resize-3.exp
@@ -0,0 +1,63 @@
+# 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/>.
+
+# Test TUI resizing while showing "No Source Available".
+
+require allow_tui_tests
+
+standard_testfile -main.c -foo.c
+
+if { [build_executable_from_specs "failed to prepare" \
+ $testfile {debug} \
+ $srcfile {debug} \
+ $srcfile2 {nodebug}] == -1 } {
+ return -1
+}
+
+tuiterm_env
+
+Term::clean_restart 24 80 $testfile
+
+# It would be simpler to run directly to foo and then enter TUI, but that
+# fails to trigger PR32614. So instead, we first run to main, enter TUI and
+# then run to foo.
+if {![runto_main]} {
+ perror "test suppressed"
+ return
+}
+
+# Set a breakpoint on foo, easier to do before entering TUI.
+gdb_breakpoint foo
+
+if {![Term::enter_tui]} {
+ unsupported "TUI not supported"
+ return
+}
+
+# Continue to foo.
+Term::command continue
+
+with_test_prefix "before resize" {
+ Term::check_contents "Source window empty" \
+ "No Source Available"
+}
+
+Term::resize 40 90
+
+with_test_prefix "after resize" {
+ # Regression test for PR32614.
+ Term::check_contents "Source window empty" \
+ "No Source Available"
+}
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index a5d0c594545..bf4052755df 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -460,6 +460,12 @@ tui_source_window_base::rerender ()
struct gdbarch *gdbarch = get_frame_arch (frame);
struct symtab *s = find_pc_line_symtab (get_frame_pc (frame));
+ if (s == nullptr)
+ {
+ erase_source_content ();
+ return;
+ }
+
if (this != tui_src_win ())
find_line_pc (s, cursal.line, &cursal.pc);
base-commit: d1b55b91df48f26a8541646bb88231ad5b9a0832
--
2.43.0
next reply other threads:[~2025-01-29 10:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-29 10:21 Tom de Vries [this message]
2025-01-29 11:25 ` Andrew Burgess
2025-01-29 12:27 ` Tom de Vries
2025-01-29 12:44 ` Tom de Vries
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=20250129102102.28617-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