|
|
7d6eda |
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
|
|
|
7d6eda |
From: Keith Seitz <keiths@redhat.com>
|
|
|
7d6eda |
Date: Thu, 16 Jul 2020 13:47:10 -0400
|
|
|
7d6eda |
Subject: gdb-rhbz1825311-src-cache-test.patch
|
|
|
7d6eda |
|
|
|
7d6eda |
;; Backport test for tui/25126
|
|
|
7d6eda |
;; Sergio Durigan Junior, RH BZ 1825311
|
|
|
7d6eda |
|
|
|
7d6eda |
commit f6be87130b5b327075a09c05e78532816f186995
|
|
|
7d6eda |
Author: Sergio Durigan Junior <sergiodj@redhat.com>
|
|
|
7d6eda |
Date: Thu Feb 6 17:52:54 2020 -0500
|
|
|
7d6eda |
|
|
|
7d6eda |
New testcase for PR tui/25126 (staled source cache)
|
|
|
7d6eda |
|
|
|
7d6eda |
I'm dealing with a Fedora GDB bug that is related to PR tui/25126, and
|
|
|
7d6eda |
I thought I'd write a specific testcase for it because I couldn't find
|
|
|
7d6eda |
one.
|
|
|
7d6eda |
|
|
|
7d6eda |
The idea is to get the simple reproducer from the bug and tweak the
|
|
|
7d6eda |
testcase around it. This one was a bit hard because, since we need to
|
|
|
7d6eda |
modify the source file and recompile it, it involved a bit of TCL-foo
|
|
|
7d6eda |
to do things. Also for this reason, I'm only enabling the test for
|
|
|
7d6eda |
native boards.
|
|
|
7d6eda |
|
|
|
7d6eda |
I tested this with an upstream GDB and made sure everything is
|
|
|
7d6eda |
passing. I also tested with a faulty GDB and made sure the test
|
|
|
7d6eda |
failed.
|
|
|
7d6eda |
|
|
|
7d6eda |
gdb/testsuite/ChangeLog:
|
|
|
7d6eda |
2020-02-11 Sergio Durigan Junior <sergiodj@redhat.com>
|
|
|
7d6eda |
2020-02-11 Sergio Durigan Junior <sergiodj@redhat.com>
|
|
|
7d6eda |
|
|
|
7d6eda |
PR tui/25126
|
|
|
7d6eda |
https://bugzilla.redhat.com/show_bug.cgi?id=1784210
|
|
|
7d6eda |
* gdb.base/cached-source-file.c: New file.
|
|
|
7d6eda |
* gdb.base/cached-source-file.exp: New file.
|
|
|
7d6eda |
|
|
|
7d6eda |
Change-Id: Ib1b074342ebe8613c6d1dfde631691ebdf6d81c6
|
|
|
7d6eda |
|
|
|
7d6eda |
diff --git a/gdb/testsuite/gdb.base/cached-source-file.c b/gdb/testsuite/gdb.base/cached-source-file.c
|
|
|
7d6eda |
new file mode 100644
|
|
|
7d6eda |
--- /dev/null
|
|
|
7d6eda |
+++ b/gdb/testsuite/gdb.base/cached-source-file.c
|
|
|
7d6eda |
@@ -0,0 +1,43 @@
|
|
|
7d6eda |
+/* This testcase is part of GDB, the GNU debugger.
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+ Copyright 2020 Free Software Foundation, Inc.
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+ This program is free software; you can redistribute it and/or modify
|
|
|
7d6eda |
+ it under the terms of the GNU General Public License as published by
|
|
|
7d6eda |
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
7d6eda |
+ (at your option) any later version.
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+ This program is distributed in the hope that it will be useful,
|
|
|
7d6eda |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
7d6eda |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
7d6eda |
+ GNU General Public License for more details.
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+ You should have received a copy of the GNU General Public License
|
|
|
7d6eda |
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+/* Test for PR tui/25126.
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+ The bug is about a regression that makes GDB not reload its source
|
|
|
7d6eda |
+ code cache when the inferior's symbols are reloaded, which leads to
|
|
|
7d6eda |
+ wrong backtraces/listings.
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+ This bug is reproducible even without using the TUI.
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+ The .exp testcase depends on the line numbers and contents from
|
|
|
7d6eda |
+ this file If you change this file, make sure to double-check the
|
|
|
7d6eda |
+ testcase. */
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+#include <stdio.h>
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+void
|
|
|
7d6eda |
+foo (void)
|
|
|
7d6eda |
+{
|
|
|
7d6eda |
+ printf ("hello\n"); /* break-here */
|
|
|
7d6eda |
+}
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+int
|
|
|
7d6eda |
+main ()
|
|
|
7d6eda |
+{
|
|
|
7d6eda |
+ foo ();
|
|
|
7d6eda |
+ return 0;
|
|
|
7d6eda |
+}
|
|
|
7d6eda |
diff --git a/gdb/testsuite/gdb.base/cached-source-file.exp b/gdb/testsuite/gdb.base/cached-source-file.exp
|
|
|
7d6eda |
new file mode 100644
|
|
|
7d6eda |
--- /dev/null
|
|
|
7d6eda |
+++ b/gdb/testsuite/gdb.base/cached-source-file.exp
|
|
|
7d6eda |
@@ -0,0 +1,98 @@
|
|
|
7d6eda |
+# Copyright (C) 2020 Free Software Foundation, Inc.
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+# This program is free software; you can redistribute it and/or modify
|
|
|
7d6eda |
+# it under the terms of the GNU General Public License as published by
|
|
|
7d6eda |
+# the Free Software Foundation; either version 3 of the License, or
|
|
|
7d6eda |
+# (at your option) any later version.
|
|
|
7d6eda |
+#
|
|
|
7d6eda |
+# This program is distributed in the hope that it will be useful,
|
|
|
7d6eda |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
7d6eda |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
7d6eda |
+# GNU General Public License for more details.
|
|
|
7d6eda |
+#
|
|
|
7d6eda |
+# You should have received a copy of the GNU General Public License
|
|
|
7d6eda |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+# Test for PR tui/25126.
|
|
|
7d6eda |
+#
|
|
|
7d6eda |
+# The bug is about a regression that makes GDB not reload its source
|
|
|
7d6eda |
+# code cache when the inferior's symbols are reloaded, which leads to
|
|
|
7d6eda |
+# wrong backtraces/listings.
|
|
|
7d6eda |
+#
|
|
|
7d6eda |
+# This bug is reproducible even without using the TUI.
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+standard_testfile
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+# Only run on native boards.
|
|
|
7d6eda |
+if { [use_gdb_stub] || [target_info gdb_protocol] == "extended-remote" } {
|
|
|
7d6eda |
+ return -1
|
|
|
7d6eda |
+}
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+# Because we need to modify the source file later, it's better if we
|
|
|
7d6eda |
+# just copy it to our output directory (instead of messing with the
|
|
|
7d6eda |
+# user's source directory).
|
|
|
7d6eda |
+set newsrc [standard_output_file $testfile].c
|
|
|
7d6eda |
+file copy -force -- $srcdir/$subdir/$srcfile $newsrc
|
|
|
7d6eda |
+set srcfile $newsrc
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
|
|
|
7d6eda |
+ return -1
|
|
|
7d6eda |
+}
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+# Get the line number for the line with the "break-here" marker.
|
|
|
7d6eda |
+set bp_line [gdb_get_line_number "break-here" $srcfile]
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+gdb_assert { [runto "$srcfile:$bp_line"] } \
|
|
|
7d6eda |
+ "run to $srcfile:$bp_line"
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+# Do a "list" and check that the printed line matches the line of the
|
|
|
7d6eda |
+# original source file.
|
|
|
7d6eda |
+gdb_test_no_output "set listsize 1"
|
|
|
7d6eda |
+gdb_test "list" "$bp_line\[ \t\]+printf \\(\"hello\\\\n\"\\); /\\* break-here \\*/" \
|
|
|
7d6eda |
+ "check the first version of the source file"
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+# Modify the original source file, and add an extra line into it.
|
|
|
7d6eda |
+# This only works locally because of the TCL commands.
|
|
|
7d6eda |
+set bkpsrc [standard_output_file $testfile].c.bkp
|
|
|
7d6eda |
+set bkpsrcfd [open $bkpsrc w]
|
|
|
7d6eda |
+set srcfd [open $srcfile r]
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+while { [gets $srcfd line] != -1 } {
|
|
|
7d6eda |
+ if { [string first "break-here" $line] != -1 } {
|
|
|
7d6eda |
+ # Put a "printf" line before the "break-here" line.
|
|
|
7d6eda |
+ puts $bkpsrcfd " printf (\"foo\\n\"); /* new-marker */"
|
|
|
7d6eda |
+ }
|
|
|
7d6eda |
+ puts $bkpsrcfd $line
|
|
|
7d6eda |
+}
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+close $bkpsrcfd
|
|
|
7d6eda |
+close $srcfd
|
|
|
7d6eda |
+file rename -force -- $bkpsrc $srcfile
|
|
|
7d6eda |
+# We have to wait 1 second because of the way GDB checks whether the
|
|
|
7d6eda |
+# binary has changed or not. GDB uses stat(2) and currently checks
|
|
|
7d6eda |
+# 'st_mtime', whose precision is measured in seconds. Since the copy,
|
|
|
7d6eda |
+# rename, and rebuild can take less than 1 second, GDB might mistakenly
|
|
|
7d6eda |
+# assume that the binary is unchanged.
|
|
|
7d6eda |
+sleep 1
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+# Recompile the modified source. We use "gdb_compile" here instead of
|
|
|
7d6eda |
+# "prepare_for_testing" because we don't want to call "clean_restart".
|
|
|
7d6eda |
+if { [gdb_compile "${srcfile}" "${binfile}" executable {debug}] != "" } {
|
|
|
7d6eda |
+ return -1
|
|
|
7d6eda |
+}
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+# Rerun the program. This should not only force GDB to reload the
|
|
|
7d6eda |
+# source cache, but also to break at BP_LINE again, which now has
|
|
|
7d6eda |
+# different contents.
|
|
|
7d6eda |
+gdb_test_multiple "run" "rerun program" {
|
|
|
7d6eda |
+ -re {The program being debugged has been started already\.\r\nStart it from the beginning\? \(y or n\) $} {
|
|
|
7d6eda |
+ set binregex [string_to_regexp $binfile]
|
|
|
7d6eda |
+ gdb_test "y" "\\`$binregex\\' has changed; re-reading symbols\.\r\nStarting program: ${binregex}.*" \
|
|
|
7d6eda |
+ "rerun program"
|
|
|
7d6eda |
+ }
|
|
|
7d6eda |
+}
|
|
|
7d6eda |
+
|
|
|
7d6eda |
+# Again, perform the listing and check that the line indeed has
|
|
|
7d6eda |
+# changed for GDB.
|
|
|
7d6eda |
+gdb_test "list" "${bp_line}\[ \t\]+printf \\(\"foo\\\\n\"\\); /\\\* new-marker \\\*/.*" \
|
|
|
7d6eda |
+ "verify that the source code is properly reloaded"
|