|
|
93189d |
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
|
|
|
93189d |
From: Kevin Buettner <kevinb@redhat.com>
|
|
|
93189d |
Date: Wed, 10 Nov 2021 18:55:43 -0700
|
|
|
93189d |
Subject: gdb-rhbz2022177-dprintf-2.patch
|
|
|
93189d |
|
|
|
93189d |
;; Backport test case for dprintf bug (RH BZ 2022177).
|
|
|
93189d |
|
|
|
93189d |
Test case for Bug 28308
|
|
|
93189d |
|
|
|
93189d |
The purpose of this test is described in the comments in
|
|
|
93189d |
dprintf-execution-x-script.exp.
|
|
|
93189d |
|
|
|
93189d |
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28308
|
|
|
93189d |
|
|
|
93189d |
The name of this new test was based on that of an existing test,
|
|
|
93189d |
bp-cmds-execution-x-script.exp. I started off by copying that test,
|
|
|
93189d |
adding to it, and then rewriting almost all of it. It's different
|
|
|
93189d |
enough that I decided that listing the copyright year as 2021
|
|
|
93189d |
was sufficient.
|
|
|
93189d |
|
|
|
93189d |
diff --git a/gdb/testsuite/gdb.base/dprintf-execution-x-script.c b/gdb/testsuite/gdb.base/dprintf-execution-x-script.c
|
|
|
93189d |
new file mode 100644
|
|
|
93189d |
--- /dev/null
|
|
|
93189d |
+++ b/gdb/testsuite/gdb.base/dprintf-execution-x-script.c
|
|
|
93189d |
@@ -0,0 +1,53 @@
|
|
|
93189d |
+/* This testcase is part of GDB, the GNU debugger.
|
|
|
93189d |
+
|
|
|
93189d |
+ Copyright 2021 Free Software Foundation, Inc.
|
|
|
93189d |
+
|
|
|
93189d |
+ This program is free software; you can redistribute it and/or modify
|
|
|
93189d |
+ it under the terms of the GNU General Public License as published by
|
|
|
93189d |
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
93189d |
+ (at your option) any later version.
|
|
|
93189d |
+
|
|
|
93189d |
+ This program is distributed in the hope that it will be useful,
|
|
|
93189d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
93189d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
93189d |
+ GNU General Public License for more details.
|
|
|
93189d |
+
|
|
|
93189d |
+ You should have received a copy of the GNU General Public License
|
|
|
93189d |
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
93189d |
+
|
|
|
93189d |
+#include <stdlib.h>
|
|
|
93189d |
+#include <stdio.h>
|
|
|
93189d |
+
|
|
|
93189d |
+volatile int vi = 0;
|
|
|
93189d |
+
|
|
|
93189d |
+void
|
|
|
93189d |
+inc_vi ()
|
|
|
93189d |
+{
|
|
|
93189d |
+ vi++;
|
|
|
93189d |
+}
|
|
|
93189d |
+
|
|
|
93189d |
+void
|
|
|
93189d |
+print_vi ()
|
|
|
93189d |
+{
|
|
|
93189d |
+ printf ("vi=%d\n", vi);
|
|
|
93189d |
+}
|
|
|
93189d |
+
|
|
|
93189d |
+void
|
|
|
93189d |
+increment ()
|
|
|
93189d |
+{
|
|
|
93189d |
+ inc_vi ();
|
|
|
93189d |
+}
|
|
|
93189d |
+
|
|
|
93189d |
+int
|
|
|
93189d |
+main (int argc, char **argv)
|
|
|
93189d |
+{
|
|
|
93189d |
+ print_vi ();
|
|
|
93189d |
+ increment ();
|
|
|
93189d |
+ print_vi ();
|
|
|
93189d |
+ increment ();
|
|
|
93189d |
+ print_vi ();
|
|
|
93189d |
+ increment ();
|
|
|
93189d |
+ print_vi ();
|
|
|
93189d |
+
|
|
|
93189d |
+ exit (0);
|
|
|
93189d |
+}
|
|
|
93189d |
diff --git a/gdb/testsuite/gdb.base/dprintf-execution-x-script.exp b/gdb/testsuite/gdb.base/dprintf-execution-x-script.exp
|
|
|
93189d |
new file mode 100644
|
|
|
93189d |
--- /dev/null
|
|
|
93189d |
+++ b/gdb/testsuite/gdb.base/dprintf-execution-x-script.exp
|
|
|
93189d |
@@ -0,0 +1,85 @@
|
|
|
93189d |
+# Copyright 2021 Free Software Foundation, Inc.
|
|
|
93189d |
+
|
|
|
93189d |
+# This program is free software; you can redistribute it and/or modify
|
|
|
93189d |
+# it under the terms of the GNU General Public License as published by
|
|
|
93189d |
+# the Free Software Foundation; either version 3 of the License, or
|
|
|
93189d |
+# (at your option) any later version.
|
|
|
93189d |
+#
|
|
|
93189d |
+# This program is distributed in the hope that it will be useful,
|
|
|
93189d |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
93189d |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
93189d |
+# GNU General Public License for more details.
|
|
|
93189d |
+#
|
|
|
93189d |
+# You should have received a copy of the GNU General Public License
|
|
|
93189d |
+# along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
93189d |
+
|
|
|
93189d |
+# Test that commands in a GDB script file run via GDB's -x flag work
|
|
|
93189d |
+# as expected. Specifically, the script creates a dprintf breakpoint
|
|
|
93189d |
+# as well as a normal breakpoint that has "continue" in its command
|
|
|
93189d |
+# list, and then does "run". Correct output from GDB is checked as
|
|
|
93189d |
+# part of this test.
|
|
|
93189d |
+
|
|
|
93189d |
+# Bail out if the target can't use the 'run' command.
|
|
|
93189d |
+if ![target_can_use_run_cmd] {
|
|
|
93189d |
+ return 0
|
|
|
93189d |
+}
|
|
|
93189d |
+
|
|
|
93189d |
+standard_testfile
|
|
|
93189d |
+
|
|
|
93189d |
+if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
|
|
|
93189d |
+ return -1
|
|
|
93189d |
+}
|
|
|
93189d |
+
|
|
|
93189d |
+# This is the name of the GDB script to load.
|
|
|
93189d |
+set x_file ${srcdir}/${subdir}/$testfile.gdb
|
|
|
93189d |
+
|
|
|
93189d |
+# Create context in which the global, GDBFLAGS, will be restored at
|
|
|
93189d |
+# the end of the block. All commands run within the block are
|
|
|
93189d |
+# actually run in the outer context. (This is why 'res' is available
|
|
|
93189d |
+# outside of the save_vars block.)
|
|
|
93189d |
+save_vars { GDBFLAGS } {
|
|
|
93189d |
+ # Set flags with which to start GDB.
|
|
|
93189d |
+ append GDBFLAGS " -ex \"set height unlimited\""
|
|
|
93189d |
+ append GDBFLAGS " -x \"$x_file\""
|
|
|
93189d |
+ append GDBFLAGS " --args \"$binfile\""
|
|
|
93189d |
+
|
|
|
93189d |
+ # Start GDB with above flags.
|
|
|
93189d |
+ set res [gdb_spawn]
|
|
|
93189d |
+}
|
|
|
93189d |
+
|
|
|
93189d |
+set test "load and run script with -x"
|
|
|
93189d |
+if { $res != 0} {
|
|
|
93189d |
+ fail $test
|
|
|
93189d |
+ return -1
|
|
|
93189d |
+}
|
|
|
93189d |
+
|
|
|
93189d |
+# The script loaded via -x contains a run command; while running, GDB
|
|
|
93189d |
+# is expected to print three messages from dprintf breakpoints along
|
|
|
93189d |
+# with three interspersed messages from an ordinary breakpoint (which
|
|
|
93189d |
+# was set up with a continue command). Set up pattern D to match
|
|
|
93189d |
+# output from hitting the dprintf breakpoint and B for the ordinary
|
|
|
93189d |
+# breakpoint. Then set PAT to contain the entire pattern of expected
|
|
|
93189d |
+# output from the interspersed dprintf and ordinary breakpoints along
|
|
|
93189d |
+# with some (additional) expected output from the dprintf breakpoints,
|
|
|
93189d |
+# i.e. 0, 1, and 2.
|
|
|
93189d |
+set d "dprintf in increment.., vi="
|
|
|
93189d |
+set b "Breakpoint ., inc_vi"
|
|
|
93189d |
+set pat "${d}0.*?$b.*?${d}1.*?$b.*?${d}2.*?$b.*?"
|
|
|
93189d |
+
|
|
|
93189d |
+proc do_test {cmd test} {
|
|
|
93189d |
+ gdb_test $cmd "$::pat$::inferior_exited_re normally.*" $test
|
|
|
93189d |
+}
|
|
|
93189d |
+
|
|
|
93189d |
+# Check output from running script with -x
|
|
|
93189d |
+do_test "" $test
|
|
|
93189d |
+
|
|
|
93189d |
+# Restart GDB and 'source' the script; this will (still) run the program
|
|
|
93189d |
+# due to the 'run' command in the script.
|
|
|
93189d |
+clean_restart $binfile
|
|
|
93189d |
+do_test "source $x_file" "load and run script using source command"
|
|
|
93189d |
+
|
|
|
93189d |
+# This should leave us at the gdb prompt; Run program again using
|
|
|
93189d |
+# already established breakpoints, i.e. those loaded from the
|
|
|
93189d |
+# script. Prior to fixing PR 28308, this was the only test that
|
|
|
93189d |
+# would pass.
|
|
|
93189d |
+do_test "run" "run again"
|
|
|
93189d |
diff --git a/gdb/testsuite/gdb.base/dprintf-execution-x-script.gdb b/gdb/testsuite/gdb.base/dprintf-execution-x-script.gdb
|
|
|
93189d |
new file mode 100644
|
|
|
93189d |
--- /dev/null
|
|
|
93189d |
+++ b/gdb/testsuite/gdb.base/dprintf-execution-x-script.gdb
|
|
|
93189d |
@@ -0,0 +1,21 @@
|
|
|
93189d |
+# Copyright 2021 Free Software Foundation, Inc.
|
|
|
93189d |
+
|
|
|
93189d |
+# This program is free software; you can redistribute it and/or modify
|
|
|
93189d |
+# it under the terms of the GNU General Public License as published by
|
|
|
93189d |
+# the Free Software Foundation; either version 3 of the License, or
|
|
|
93189d |
+# (at your option) any later version.
|
|
|
93189d |
+#
|
|
|
93189d |
+# This program is distributed in the hope that it will be useful,
|
|
|
93189d |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
93189d |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
93189d |
+# GNU General Public License for more details.
|
|
|
93189d |
+#
|
|
|
93189d |
+# You should have received a copy of the GNU General Public License
|
|
|
93189d |
+# along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
93189d |
+
|
|
|
93189d |
+dprintf increment, "dprintf in increment(), vi=%d\n", vi
|
|
|
93189d |
+break inc_vi
|
|
|
93189d |
+commands
|
|
|
93189d |
+ continue
|
|
|
93189d |
+end
|
|
|
93189d |
+run
|