keiths / rpms / gdb

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