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

b94e32
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
b94e32
From: Fedora GDB patches <invalid@email.com>
b94e32
Date: Fri, 27 Oct 2017 21:07:50 +0200
b94e32
Subject: gdb-simultaneous-step-resume-breakpoint-test.patch
b94e32
b94e32
;; New test for step-resume breakpoint placed in multiple threads at once.
b94e32
;;=fedoratest
b94e32
b94e32
diff --git a/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.c b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.c
b94e32
new file mode 100644
b94e32
--- /dev/null
b94e32
+++ b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.c
b94e32
@@ -0,0 +1,79 @@
b94e32
+/* Copyright 2009 Free Software Foundation, Inc.
b94e32
+
b94e32
+   Written by Fred Fish of Cygnus Support
b94e32
+   Contributed by Cygnus Support
b94e32
+
b94e32
+   This file is part of GDB.
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 multiple threads stepping into a .debug_line-less function with
b94e32
+   a breakpoint placed on its return-to-caller point.  */
b94e32
+
b94e32
+#include <pthread.h>
b94e32
+#include <assert.h>
b94e32
+#include <unistd.h>
b94e32
+#include <errno.h>
b94e32
+#include <stdio.h>
b94e32
+
b94e32
+#define THREADS 3
b94e32
+
b94e32
+static void *
b94e32
+func (void *unused)
b94e32
+{
b94e32
+  int i;
b94e32
+
b94e32
+  errno = 0;
b94e32
+  i = 0xdeadf00d;
b94e32
+  i = sleep (THREADS);	/* sleep-call */
b94e32
+  if (errno != 0)	/* sleep-after */
b94e32
+    perror ("sleep");
b94e32
+
b94e32
+  /* The GDB bug with forgotten step-resume breakpoint could leave stale
b94e32
+     breakpoint on the I assignment making it a nop.  */
b94e32
+  if (i == 0xdeadf00d)
b94e32
+    assert (0);
b94e32
+
b94e32
+  assert (i == 0);
b94e32
+
b94e32
+  pthread_exit (NULL);
b94e32
+}
b94e32
+
b94e32
+int
b94e32
+main (void)
b94e32
+{
b94e32
+  pthread_t threads[THREADS];
b94e32
+  int threadi;
b94e32
+
b94e32
+  for (threadi = 0; threadi < THREADS; threadi++)
b94e32
+    {
b94e32
+      int i;
b94e32
+
b94e32
+      i = pthread_create (&threads[threadi], NULL, func, NULL);
b94e32
+      assert (i == 0);
b94e32
+
b94e32
+      i = sleep (1);
b94e32
+      assert (i == 0);
b94e32
+    }
b94e32
+
b94e32
+  for (threadi = 0; threadi < THREADS; threadi++)
b94e32
+    {
b94e32
+      int i;
b94e32
+
b94e32
+      i = pthread_join (threads[threadi], NULL);
b94e32
+      assert (i == 0);
b94e32
+    }
b94e32
+
b94e32
+  return 0;	/* final-exit */
b94e32
+}
b94e32
diff --git a/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.exp b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.exp
b94e32
new file mode 100644
b94e32
--- /dev/null
b94e32
+++ b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.exp
b94e32
@@ -0,0 +1,65 @@
b94e32
+# Copyright (C) 2009 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 multiple threads stepping into a .debug_line-less function with
b94e32
+# a breakpoint placed on its return-to-caller point.
b94e32
+
b94e32
+set testfile simultaneous-step-resume-breakpoint
b94e32
+set srcfile ${testfile}.c
b94e32
+set binfile [standard_output_file ${testfile}]
b94e32
+
b94e32
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b94e32
+    return -1
b94e32
+}
b94e32
+
b94e32
+gdb_exit
b94e32
+gdb_start
b94e32
+gdb_reinitialize_dir $srcdir/$subdir
b94e32
+
b94e32
+# Ensure we have no debuginfo for the `sleep' call itself (=for libc).
b94e32
+gdb_test "set debug-file-directory /DoesNotExist"
b94e32
+
b94e32
+gdb_load ${binfile}
b94e32
+if ![runto_main] {
b94e32
+   return -1
b94e32
+}
b94e32
+
b94e32
+# Red Hat vendor patch does set it to "step" by default.
b94e32
+gdb_test "set scheduler-locking off"
b94e32
+
b94e32
+gdb_breakpoint [gdb_get_line_number "final-exit"]
b94e32
+
b94e32
+gdb_breakpoint [gdb_get_line_number "sleep-call"]
b94e32
+gdb_continue_to_breakpoint "sleep-call"
b94e32
+
b94e32
+gdb_test "step" "sleep-call.*" "step thread 1"
b94e32
+gdb_test "step" "sleep-call.*" "step thread 2"
b94e32
+gdb_test "step" "sleep-after.*" "step thread 3"
b94e32
+
b94e32
+set test "first continue"
b94e32
+gdb_test_multiple "continue" $test {
b94e32
+    -re "final-exit.*$gdb_prompt $" {
b94e32
+	# gdb-7.0.
b94e32
+	pass $test
b94e32
+	return
b94e32
+    }
b94e32
+    -re "sleep-after.*$gdb_prompt $" {
b94e32
+	# Fedora/RHEL branch.
b94e32
+	pass $test
b94e32
+    }
b94e32
+}
b94e32
+
b94e32
+gdb_test "continue" "sleep-after.*" "second continue"
b94e32
+gdb_test "continue" "final-exit.*" "third continue"