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

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