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

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