Blame SOURCES/gdb-6.6-bz237572-ppc-atomic-sequence-test.patch

b94e32
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
b94e32
From: Jan Kratochvil <jan.kratochvil@redhat.com>
b94e32
Date: Fri, 27 Oct 2017 21:07:50 +0200
b94e32
Subject: gdb-6.6-bz237572-ppc-atomic-sequence-test.patch
b94e32
b94e32
;; Support for stepping over PPC atomic instruction sequences (BZ 237572).
b94e32
;;=fedoratest
b94e32
b94e32
2007-06-25  Jan Kratochvil  <jan.kratochvil@redhat.com>
b94e32
b94e32
	* gdb.threads/atomic-seq-threaded.c,
b94e32
	gdb.threads/atomic-seq-threaded.exp: New files.
b94e32
b94e32
diff --git a/gdb/testsuite/gdb.threads/atomic-seq-threaded.c b/gdb/testsuite/gdb.threads/atomic-seq-threaded.c
b94e32
new file mode 100644
b94e32
--- /dev/null
b94e32
+++ b/gdb/testsuite/gdb.threads/atomic-seq-threaded.c
b94e32
@@ -0,0 +1,171 @@
b94e32
+/* This testcase is part of GDB, the GNU debugger.
b94e32
+
b94e32
+   Copyright 2007 Free Software Foundation, Inc.
b94e32
+
b94e32
+   This program is free software; you can redistribute it and/or modify
b94e32
+   it under the terms of the GNU General Public License as published by
b94e32
+   the Free Software Foundation; either version 2 of the License, or
b94e32
+   (at your option) any later version.
b94e32
+
b94e32
+   This program is distributed in the hope that it will be useful,
b94e32
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
b94e32
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b94e32
+   GNU General Public License for more details.
b94e32
+
b94e32
+   You should have received a copy of the GNU General Public License
b94e32
+   along with this program; if not, write to the Free Software
b94e32
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
b94e32
+   MA 02110-1301, USA.  */
b94e32
+
b94e32
+/* Test stepping over RISC atomic sequences.
b94e32
+   This variant testcases the code for stepping another thread while skipping
b94e32
+   over the atomic sequence in the former thread
b94e32
+   (STEPPING_PAST_SINGLESTEP_BREAKPOINT).
b94e32
+   Code comes from gcc/testsuite/gcc.dg/sync-2.c  */
b94e32
+
b94e32
+/* { dg-options "-march=i486" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
b94e32
+/* { dg-options "-mcpu=v9" { target sparc*-*-* } } */
b94e32
+
b94e32
+/* Test functionality of the intrinsics for 'short' and 'char'.  */
b94e32
+
b94e32
+#include <stdlib.h>
b94e32
+#include <string.h>
b94e32
+#include <pthread.h>
b94e32
+#include <assert.h>
b94e32
+#include <unistd.h>
b94e32
+
b94e32
+#define LOOPS 2
b94e32
+
b94e32
+static int unused;
b94e32
+
b94e32
+static char AI[18];
b94e32
+static char init_qi[18] = { 3,5,7,9,0,0,0,0,-1,0,0,0,0,0,-1,0,0,0 };
b94e32
+static char test_qi[18] = { 3,5,7,9,1,4,22,-12,7,8,9,7,1,-12,7,8,9,7 };
b94e32
+
b94e32
+static void
b94e32
+do_qi (void)
b94e32
+{
b94e32
+  if (__sync_fetch_and_add(AI+4, 1) != 0)
b94e32
+    abort ();
b94e32
+  if (__sync_fetch_and_add(AI+5, 4) != 0)
b94e32
+    abort ();
b94e32
+  if (__sync_fetch_and_add(AI+6, 22) != 0)
b94e32
+    abort ();
b94e32
+  if (__sync_fetch_and_sub(AI+7, 12) != 0)
b94e32
+    abort ();
b94e32
+  if (__sync_fetch_and_and(AI+8, 7) != (char)-1)
b94e32
+    abort ();
b94e32
+  if (__sync_fetch_and_or(AI+9, 8) != 0)
b94e32
+    abort ();
b94e32
+  if (__sync_fetch_and_xor(AI+10, 9) != 0)
b94e32
+    abort ();
b94e32
+  if (__sync_fetch_and_nand(AI+11, 7) != 0)
b94e32
+    abort ();
b94e32
+
b94e32
+  if (__sync_add_and_fetch(AI+12, 1) != 1)
b94e32
+    abort ();
b94e32
+  if (__sync_sub_and_fetch(AI+13, 12) != (char)-12)
b94e32
+    abort ();
b94e32
+  if (__sync_and_and_fetch(AI+14, 7) != 7)
b94e32
+    abort ();
b94e32
+  if (__sync_or_and_fetch(AI+15, 8) != 8)
b94e32
+    abort ();
b94e32
+  if (__sync_xor_and_fetch(AI+16, 9) != 9)
b94e32
+    abort ();
b94e32
+  if (__sync_nand_and_fetch(AI+17, 7) != 7)
b94e32
+    abort ();
b94e32
+}
b94e32
+
b94e32
+static short AL[18];
b94e32
+static short init_hi[18] = { 3,5,7,9,0,0,0,0,-1,0,0,0,0,0,-1,0,0,0 };
b94e32
+static short test_hi[18] = { 3,5,7,9,1,4,22,-12,7,8,9,7,1,-12,7,8,9,7 };
b94e32
+
b94e32
+static void
b94e32
+do_hi (void)
b94e32
+{
b94e32
+  if (__sync_fetch_and_add(AL+4, 1) != 0)
b94e32
+    abort ();
b94e32
+  if (__sync_fetch_and_add(AL+5, 4) != 0)
b94e32
+    abort ();
b94e32
+  if (__sync_fetch_and_add(AL+6, 22) != 0)
b94e32
+    abort ();
b94e32
+  if (__sync_fetch_and_sub(AL+7, 12) != 0)
b94e32
+    abort ();
b94e32
+  if (__sync_fetch_and_and(AL+8, 7) != -1)
b94e32
+    abort ();
b94e32
+  if (__sync_fetch_and_or(AL+9, 8) != 0)
b94e32
+    abort ();
b94e32
+  if (__sync_fetch_and_xor(AL+10, 9) != 0)
b94e32
+    abort ();
b94e32
+  if (__sync_fetch_and_nand(AL+11, 7) != 0)
b94e32
+    abort ();
b94e32
+
b94e32
+  if (__sync_add_and_fetch(AL+12, 1) != 1)
b94e32
+    abort ();
b94e32
+  if (__sync_sub_and_fetch(AL+13, 12) != -12)
b94e32
+    abort ();
b94e32
+  if (__sync_and_and_fetch(AL+14, 7) != 7)
b94e32
+    abort ();
b94e32
+  if (__sync_or_and_fetch(AL+15, 8) != 8)
b94e32
+    abort ();
b94e32
+  if (__sync_xor_and_fetch(AL+16, 9) != 9)
b94e32
+    abort ();
b94e32
+  if (__sync_nand_and_fetch(AL+17, 7) != 7)
b94e32
+    abort ();
b94e32
+}
b94e32
+
b94e32
+static void *
b94e32
+start1 (void *arg)
b94e32
+{
b94e32
+  unsigned loop;
b94e32
+  sleep(1);
b94e32
+
b94e32
+  for (loop = 0; loop < LOOPS; loop++)
b94e32
+    {
b94e32
+      memcpy(AI, init_qi, sizeof(init_qi));
b94e32
+
b94e32
+      do_qi ();
b94e32
+
b94e32
+      if (memcmp (AI, test_qi, sizeof(test_qi)))
b94e32
+	abort ();
b94e32
+    }
b94e32
+
b94e32
+  return arg;						/* _delete1_ */
b94e32
+}
b94e32
+
b94e32
+static void *
b94e32
+start2 (void *arg)
b94e32
+{
b94e32
+  unsigned loop;
b94e32
+
b94e32
+  for (loop = 0; loop < LOOPS; loop++)
b94e32
+    {
b94e32
+      memcpy(AL, init_hi, sizeof(init_hi));
b94e32
+
b94e32
+      do_hi ();
b94e32
+
b94e32
+      if (memcmp (AL, test_hi, sizeof(test_hi)))
b94e32
+	abort ();
b94e32
+    }
b94e32
+
b94e32
+  return arg;						/* _delete2_ */
b94e32
+}
b94e32
+
b94e32
+int
b94e32
+main (int argc, char **argv)
b94e32
+{
b94e32
+  pthread_t thread;
b94e32
+  int i;
b94e32
+
b94e32
+  i = pthread_create (&thread, NULL, start1, NULL);	/* _create_ */
b94e32
+  assert (i == 0);					/* _create_after_ */
b94e32
+
b94e32
+  sleep (1);
b94e32
+
b94e32
+  start2 (NULL);
b94e32
+
b94e32
+  i = pthread_join (thread, NULL);			/* _delete_ */
b94e32
+  assert (i == 0);
b94e32
+
b94e32
+  return 0;						/* _exit_ */
b94e32
+}
b94e32
diff --git a/gdb/testsuite/gdb.threads/atomic-seq-threaded.exp b/gdb/testsuite/gdb.threads/atomic-seq-threaded.exp
b94e32
new file mode 100644
b94e32
--- /dev/null
b94e32
+++ b/gdb/testsuite/gdb.threads/atomic-seq-threaded.exp
b94e32
@@ -0,0 +1,84 @@
b94e32
+# atomic-seq-threaded.exp -- Test case for stepping over RISC atomic code seqs.
b94e32
+# This variant testcases the code for stepping another thread while skipping
b94e32
+# over the atomic sequence in the former thread
b94e32
+# (STEPPING_PAST_SINGLESTEP_BREAKPOINT).
b94e32
+# Copyright (C) 2007 Free Software Foundation, Inc.
b94e32
+
b94e32
+# This program is free software; you can redistribute it and/or modify
b94e32
+# it under the terms of the GNU General Public License as published by
b94e32
+# the Free Software Foundation; either version 2 of the License, or
b94e32
+# (at your option) any later version.
b94e32
+#
b94e32
+# This program is distributed in the hope that it will be useful,
b94e32
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b94e32
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b94e32
+# GNU General Public License for more details.
b94e32
+#
b94e32
+# You should have received a copy of the GNU General Public License
b94e32
+# along with this program; if not, write to the Free Software
b94e32
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
b94e32
+
b94e32
+# Please email any bugs, comments, and/or additions to this file to:
b94e32
+# bug-gdb@prep.ai.mit.edu
b94e32
+
b94e32
+set testfile atomic-seq-threaded
b94e32
+set srcfile ${testfile}.c
b94e32
+set binfile [standard_output_file ${testfile}]
b94e32
+
b94e32
+foreach opts {{} {compiler=gcc4} {FAIL}} {
b94e32
+    if {$opts eq "FAIL"} {
b94e32
+	return -1
b94e32
+    }
b94e32
+    if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug $opts]] eq "" } {
b94e32
+	break
b94e32
+    }
b94e32
+}
b94e32
+
b94e32
+gdb_exit
b94e32
+gdb_start
b94e32
+gdb_reinitialize_dir $srcdir/$subdir
b94e32
+
b94e32
+gdb_load ${binfile}
b94e32
+if ![runto_main] then {
b94e32
+   fail "Can't run to main"
b94e32
+   return 0
b94e32
+}
b94e32
+
b94e32
+# pthread_create () will not pass even on x86_64 with software watchpoint.
b94e32
+# Pass after pthread_create () without any watchpoint active.
b94e32
+set line [gdb_get_line_number "_create_after_"]
b94e32
+gdb_test "tbreak $line" \
b94e32
+	 "reakpoint (\[0-9\]+) at .*$srcfile, line $line\..*" \
b94e32
+	 "set breakpoint after pthread_create ()"
b94e32
+gdb_test "c" \
b94e32
+	 ".*/\\* _create_after_ \\*/.*" \
b94e32
+	 "run till after pthread_create ()"
b94e32
+
b94e32
+# Without a watchpoint being software no single-stepping would be used.
b94e32
+set test "Start (software) watchpoint"
b94e32
+gdb_test_multiple "watch unused" $test {
b94e32
+    -re "Watchpoint \[0-9\]+: unused.*$gdb_prompt $" {
b94e32
+	pass $test
b94e32
+    }
b94e32
+    -re "Hardware watchpoint \[0-9\]+: unused.*$gdb_prompt $" {
b94e32
+	# We do not test the goal but still the whole testcase should pass.
b94e32
+	unsupported $test
b94e32
+    }
b94e32
+}
b94e32
+
b94e32
+# More thorough testing of the scheduling logic.
b94e32
+gdb_test "set scheduler-locking step" ""
b94e32
+
b94e32
+# Critical code path is stepped through at this point.
b94e32
+set line [gdb_get_line_number "_exit_"]
b94e32
+gdb_test "tbreak $line" \
b94e32
+	 "reakpoint \[0-9\]+ at .*$srcfile, line $line\..*" \
b94e32
+	 "set breakpoint at _exit_"
b94e32
+gdb_test "c" \
b94e32
+	 ".*/\\* _exit_ \\*/.*" \
b94e32
+	 "run till _exit_"
b94e32
+
b94e32
+# Just a nonproblematic program exit.
b94e32
+gdb_test "c" \
b94e32
+	 ".*Program exited normally\\..*" \
b94e32
+	 "run till program exit"