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

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