keiths / rpms / gdb

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