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

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