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

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