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

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