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

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