From: Sergio Durigan Junior <sergiodj@redhat.com>
To: GDB Patches <gdb-patches@sourceware.org>
Cc: Luis Machado <luis.machado@linaro.org>,
Andrew Burgess <andrew.burgess@embecosm.com>,
Sergio Durigan Junior <sergiodj@redhat.com>
Subject: [PATCH v2] New testcase for PR tui/25126 (staled source cache)
Date: Mon, 10 Feb 2020 19:09:00 -0000 [thread overview]
Message-ID: <20200210190919.12692-1-sergiodj@redhat.com> (raw)
In-Reply-To: <20200206225943.26709-1-sergiodj@redhat.com>
Changes since v1:
- Fix typo.
- Improve testcase description.
- Use 'gdb_assert'.
- Improve description of "sleep 1" statement.
I'm dealing with a Fedora GDB bug that is related to PR tui/25126, and
I thought I'd write a specific testcase for it because I couldn't find
one.
The idea is to get the simple reproducer from the bug and tweak the
testcase around it. This one was a bit hard because, since we need to
modify the source file and recompile it, it involved a bit of TCL-foo
to do things. Also for this reason, I'm only enabling the test for
native boards.
I tested this with an upstream GDB and made sure everything is
passing. I also tested with a faulty GDB and made sure the test
failed.
gdb/testsuite/ChangeLog:
2020-02-10 Sergio Durigan Junior <sergiodj@redhat.com>
PR tui/25126
* gdb.base/cached-source-file.c: New file.
* gdb.base/cached-source-file.exp: New file.
Change-Id: Ib1b074342ebe8613c6d1dfde631691ebdf6d81c6
---
gdb/testsuite/gdb.base/cached-source-file.c | 37 ++++++++
gdb/testsuite/gdb.base/cached-source-file.exp | 94 +++++++++++++++++++
2 files changed, 131 insertions(+)
create mode 100644 gdb/testsuite/gdb.base/cached-source-file.c
create mode 100644 gdb/testsuite/gdb.base/cached-source-file.exp
diff --git a/gdb/testsuite/gdb.base/cached-source-file.c b/gdb/testsuite/gdb.base/cached-source-file.c
new file mode 100644
index 0000000000..9f698dcffe
--- /dev/null
+++ b/gdb/testsuite/gdb.base/cached-source-file.c
@@ -0,0 +1,37 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2020 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 for PR tui/25126.
+
+ The .exp testcase depends on the line numbers and contents from
+ this file If you change this file, make sure to double-check the
+ testcase. */
+
+#include <stdio.h>
+
+void
+foo (void)
+{
+ printf ("hello\n"); /* break-here */
+}
+
+int
+main ()
+{
+ foo ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/cached-source-file.exp b/gdb/testsuite/gdb.base/cached-source-file.exp
new file mode 100644
index 0000000000..f98bec09ca
--- /dev/null
+++ b/gdb/testsuite/gdb.base/cached-source-file.exp
@@ -0,0 +1,94 @@
+# Copyright (C) 2020 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 for PR tui/25126.
+# This bug is reproducible even without using the TUI.
+
+standard_testfile
+
+# Only run on native boards.
+if { [use_gdb_stub] || [target_info gdb_protocol] == "extended-remote" } {
+ return -1
+}
+
+# Because we need to modify the source file later, it's better if we
+# just copy if to our output directory (instead of messing with the
+# user's source directory).
+set newsrc [standard_output_file $testfile].c
+file copy -force -- $srcdir/$subdir/$srcfile $newsrc
+set srcfile $newsrc
+
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
+ return -1
+}
+
+# Get the line number for the line with the "break-here" marker.
+set bp_line [gdb_get_line_number "break-here" $srcfile]
+
+if { [runto "$srcfile:$bp_line"] } {
+ pass "run to $srcfile:$bp_line"
+} else {
+ fail "run to $srcfile:$bp_line"
+}
+
+# Do a "list" and check that the printed line matches the line of the
+# original source file.
+gdb_test_no_output "set listsize 1"
+gdb_test "list" "$bp_line\[ \t\]+printf \\(\"hello\\\\n\"\\); /\\* break-here \\*/" \
+ "check the first version of the source file"
+
+# Modify the original source file, and add an extra line into it.
+# This only works locally because of the TCL commands.
+set bkpsrc [standard_output_file $testfile].c.bkp
+set bkpsrcfd [open $bkpsrc w]
+set srcfd [open $srcfile r]
+
+while { [gets $srcfd line] != -1 } {
+ if { [string first "break-here" $line] != -1 } {
+ # Put a "printf" line before the "break-here" line.
+ puts $bkpsrcfd " printf (\"foo\\n\");"
+ }
+ puts $bkpsrcfd $line
+}
+
+close $bkpsrcfd
+close $srcfd
+file rename -force $bkpsrc $srcfile
+# Give it some time to perform the renaming. For some reason, TCL
+# needs some time after "file rename" in order to properly rename the
+# file.
+sleep 1
+
+# Recompile the modified source. We use "gdb_compile" here instead of
+# "prepare_for_testing" because we don't want to call "clean_restart".
+if { [gdb_compile "${srcfile}" "${binfile}" executable {debug}] != "" } {
+ return -1
+}
+
+# Rerun the program. This should not only force GDB to reload the
+# source cache, but also to break at line 6 again, which now has
+# different contents.
+gdb_test_multiple "run" "rerun program" {
+ -re {The program being debugged has been started already\.\r\nStart it from the beginning\? \(y or n\) $} {
+ set binregex [string_to_regexp $binfile]
+ gdb_test "y" "\\`$binregex\\' has changed; re-reading symbols\.\r\nStarting program: ${binregex}.*" \
+ "rerun program"
+ }
+}
+
+# Again, perform the listing and check that the line indeed has
+# changed for GDB.
+gdb_test "list" "${bp_line}\[ \t\]+printf \\(\"foo\\\\n\"\\);" \
+ "verify that the source code is properly reloaded"
--
2.21.0
next prev parent reply other threads:[~2020-02-10 19:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-06 23:00 [PATCH] " Sergio Durigan Junior
2020-02-07 9:41 ` Luis Machado
2020-02-07 11:47 ` Andrew Burgess
2020-02-07 17:09 ` Sergio Durigan Junior
2020-02-07 19:54 ` Sergio Durigan Junior
2020-02-07 20:11 ` Sergio Durigan Junior
2020-02-08 0:27 ` Andrew Burgess
2020-02-07 20:18 ` Luis Machado
2020-02-08 9:42 ` Luis Machado
2020-02-07 17:07 ` Sergio Durigan Junior
2020-02-10 19:09 ` Sergio Durigan Junior [this message]
2020-02-10 19:33 ` [PATCH v2] " Luis Machado
2020-02-10 20:03 ` Sergio Durigan Junior
2020-02-10 20:02 ` Sergio Durigan Junior
2020-02-10 21:55 ` Luis Machado
2020-02-11 11:10 ` Andrew Burgess
2020-02-11 16:38 ` Sergio Durigan Junior
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=20200210190919.12692-1-sergiodj@redhat.com \
--to=sergiodj@redhat.com \
--cc=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
--cc=luis.machado@linaro.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