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

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