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

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