Blame SOURCES/gdb-rhbz2022177-dprintf-2.patch

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