Blame SOURCES/gdb-simultaneous-step-resume-breakpoint-test.patch

ed07ac
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
ed07ac
From: Fedora GDB patches <invalid@email.com>
ed07ac
Date: Fri, 27 Oct 2017 21:07:50 +0200
ed07ac
Subject: gdb-simultaneous-step-resume-breakpoint-test.patch
ed07ac
ed07ac
;; New test for step-resume breakpoint placed in multiple threads at once.
ed07ac
;;=fedoratest
ed07ac
ed07ac
diff --git a/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.c b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.c
ed07ac
new file mode 100644
ed07ac
--- /dev/null
ed07ac
+++ b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.c
ed07ac
@@ -0,0 +1,79 @@
ed07ac
+/* Copyright 2009 Free Software Foundation, Inc.
ed07ac
+
ed07ac
+   Written by Fred Fish of Cygnus Support
ed07ac
+   Contributed by Cygnus Support
ed07ac
+
ed07ac
+   This file is part of GDB.
ed07ac
+
ed07ac
+   This program is free software; you can redistribute it and/or modify
ed07ac
+   it under the terms of the GNU General Public License as published by
ed07ac
+   the Free Software Foundation; either version 3 of the License, or
ed07ac
+   (at your option) any later version.
ed07ac
+
ed07ac
+   This program is distributed in the hope that it will be useful,
ed07ac
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ed07ac
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ed07ac
+   GNU General Public License for more details.
ed07ac
+
ed07ac
+   You should have received a copy of the GNU General Public License
ed07ac
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
ed07ac
+
ed07ac
+/* Test multiple threads stepping into a .debug_line-less function with
ed07ac
+   a breakpoint placed on its return-to-caller point.  */
ed07ac
+
ed07ac
+#include <pthread.h>
ed07ac
+#include <assert.h>
ed07ac
+#include <unistd.h>
ed07ac
+#include <errno.h>
ed07ac
+#include <stdio.h>
ed07ac
+
ed07ac
+#define THREADS 3
ed07ac
+
ed07ac
+static void *
ed07ac
+func (void *unused)
ed07ac
+{
ed07ac
+  int i;
ed07ac
+
ed07ac
+  errno = 0;
ed07ac
+  i = 0xdeadf00d;
ed07ac
+  i = sleep (THREADS);	/* sleep-call */
ed07ac
+  if (errno != 0)	/* sleep-after */
ed07ac
+    perror ("sleep");
ed07ac
+
ed07ac
+  /* The GDB bug with forgotten step-resume breakpoint could leave stale
ed07ac
+     breakpoint on the I assignment making it a nop.  */
ed07ac
+  if (i == 0xdeadf00d)
ed07ac
+    assert (0);
ed07ac
+
ed07ac
+  assert (i == 0);
ed07ac
+
ed07ac
+  pthread_exit (NULL);
ed07ac
+}
ed07ac
+
ed07ac
+int
ed07ac
+main (void)
ed07ac
+{
ed07ac
+  pthread_t threads[THREADS];
ed07ac
+  int threadi;
ed07ac
+
ed07ac
+  for (threadi = 0; threadi < THREADS; threadi++)
ed07ac
+    {
ed07ac
+      int i;
ed07ac
+
ed07ac
+      i = pthread_create (&threads[threadi], NULL, func, NULL);
ed07ac
+      assert (i == 0);
ed07ac
+
ed07ac
+      i = sleep (1);
ed07ac
+      assert (i == 0);
ed07ac
+    }
ed07ac
+
ed07ac
+  for (threadi = 0; threadi < THREADS; threadi++)
ed07ac
+    {
ed07ac
+      int i;
ed07ac
+
ed07ac
+      i = pthread_join (threads[threadi], NULL);
ed07ac
+      assert (i == 0);
ed07ac
+    }
ed07ac
+
ed07ac
+  return 0;	/* final-exit */
ed07ac
+}
ed07ac
diff --git a/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.exp b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.exp
ed07ac
new file mode 100644
ed07ac
--- /dev/null
ed07ac
+++ b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.exp
ed07ac
@@ -0,0 +1,65 @@
ed07ac
+# Copyright (C) 2009 Free Software Foundation, Inc.
ed07ac
+
ed07ac
+# This program is free software; you can redistribute it and/or modify
ed07ac
+# it under the terms of the GNU General Public License as published by
ed07ac
+# the Free Software Foundation; either version 3 of the License, or
ed07ac
+# (at your option) any later version.
ed07ac
+#
ed07ac
+# This program is distributed in the hope that it will be useful,
ed07ac
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
ed07ac
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ed07ac
+# GNU General Public License for more details.
ed07ac
+#
ed07ac
+# You should have received a copy of the GNU General Public License
ed07ac
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
ed07ac
+
ed07ac
+# Test multiple threads stepping into a .debug_line-less function with
ed07ac
+# a breakpoint placed on its return-to-caller point.
ed07ac
+
ed07ac
+set testfile simultaneous-step-resume-breakpoint
ed07ac
+set srcfile ${testfile}.c
ed07ac
+set binfile [standard_output_file ${testfile}]
ed07ac
+
ed07ac
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
ed07ac
+    return -1
ed07ac
+}
ed07ac
+
ed07ac
+gdb_exit
ed07ac
+gdb_start
ed07ac
+gdb_reinitialize_dir $srcdir/$subdir
ed07ac
+
ed07ac
+# Ensure we have no debuginfo for the `sleep' call itself (=for libc).
ed07ac
+gdb_test "set debug-file-directory /DoesNotExist"
ed07ac
+
ed07ac
+gdb_load ${binfile}
ed07ac
+if ![runto_main] {
ed07ac
+   return -1
ed07ac
+}
ed07ac
+
ed07ac
+# Red Hat vendor patch does set it to "step" by default.
ed07ac
+gdb_test "set scheduler-locking off"
ed07ac
+
ed07ac
+gdb_breakpoint [gdb_get_line_number "final-exit"]
ed07ac
+
ed07ac
+gdb_breakpoint [gdb_get_line_number "sleep-call"]
ed07ac
+gdb_continue_to_breakpoint "sleep-call"
ed07ac
+
ed07ac
+gdb_test "step" "sleep-call.*" "step thread 1"
ed07ac
+gdb_test "step" "sleep-call.*" "step thread 2"
ed07ac
+gdb_test "step" "sleep-after.*" "step thread 3"
ed07ac
+
ed07ac
+set test "first continue"
ed07ac
+gdb_test_multiple "continue" $test {
ed07ac
+    -re "final-exit.*$gdb_prompt $" {
ed07ac
+	# gdb-7.0.
ed07ac
+	pass $test
ed07ac
+	return
ed07ac
+    }
ed07ac
+    -re "sleep-after.*$gdb_prompt $" {
ed07ac
+	# Fedora/RHEL branch.
ed07ac
+	pass $test
ed07ac
+    }
ed07ac
+}
ed07ac
+
ed07ac
+gdb_test "continue" "sleep-after.*" "second continue"
ed07ac
+gdb_test "continue" "final-exit.*" "third continue"