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

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