Blame SOURCES/gdb-6.5-BEA-testsuite.patch

0a406a
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
0a406a
From: Fedora GDB patches <invalid@email.com>
0a406a
Date: Fri, 27 Oct 2017 21:07:50 +0200
0a406a
Subject: gdb-6.5-BEA-testsuite.patch
0a406a
0a406a
;; Improved testsuite results by the testsuite provided by the courtesy of BEA.
0a406a
;;=fedoratest: For upstream it should be rewritten as a dejagnu test, the test of no "??" was useful.
0a406a
0a406a
diff --git a/gdb/testsuite/gdb.threads/threadcrash.c b/gdb/testsuite/gdb.threads/threadcrash.c
0a406a
new file mode 100644
0a406a
--- /dev/null
0a406a
+++ b/gdb/testsuite/gdb.threads/threadcrash.c
0a406a
@@ -0,0 +1,301 @@
0a406a
+/*
0a406a
+ * The point of this program is to crash in a multi-threaded app.
0a406a
+ * There are seven threads, doing the following things:
0a406a
+ * * Spinning
0a406a
+ * * Spinning inside a signal handler
0a406a
+ * * Spinning inside a signal handler executing on the altstack
0a406a
+ * * In a syscall
0a406a
+ * * In a syscall inside a signal handler
0a406a
+ * * In a syscall inside a signal handler executing on the altstack
0a406a
+ * * Finally, the main thread crashes in main, with no frills.
0a406a
+ *
0a406a
+ * These are the things threads in JRockit tend to be doing.  If gdb
0a406a
+ * can handle those things, both in core files and during live
0a406a
+ * debugging, that will help (at least) JRockit development.
0a406a
+ *
0a406a
+ * Let the program create a core file, then load the core file into
0a406a
+ * gdb.  Inside gdb, you should be able to do something like this:
0a406a
+ *
0a406a
+ * (gdb) t a a bt
0a406a
+ *
0a406a
+ * Thread 7 (process 4352):
0a406a
+ * #0  0x001ba7dc in __nanosleep_nocancel () from /lib/tls/libc.so.6
0a406a
+ * #1  0x001ba5ff in sleep () from /lib/tls/libc.so.6
0a406a
+ * #2  0x080488a2 in makeSyscall (ignored=0x0) at threadcrash.c:118
0a406a
+ * #3  0x006aadec in start_thread () from /lib/tls/libpthread.so.0
0a406a
+ * #4  0x001ed19a in clone () from /lib/tls/libc.so.6
0a406a
+ *
0a406a
+ * Thread 6 (process 4353):
0a406a
+ * #0  0x001ba7dc in __nanosleep_nocancel () from /lib/tls/libc.so.6
0a406a
+ * #1  0x001ba5ff in sleep () from /lib/tls/libc.so.6
0a406a
+ * #2  0x0804898f in syscallingSighandler (signo=10, info=0xb6be76f0, context=0xb6be7770)
0a406a
+ *     at threadcrash.c:168
0a406a
+ * #3  <signal handler called>
0a406a
+ * #4  0x006adf5e in pthread_kill () from /lib/tls/libpthread.so.0
0a406a
+ * #5  0x08048a51 in makeSyscallFromSighandler (ignored=0x0) at threadcrash.c:204
0a406a
+ * #6  0x006aadec in start_thread () from /lib/tls/libpthread.so.0
0a406a
+ * #7  0x001ed19a in clone () from /lib/tls/libc.so.6
0a406a
+ *
0a406a
+ * Thread 5 (process 4354):
0a406a
+ * #0  0x001ba7dc in __nanosleep_nocancel () from /lib/tls/libc.so.6
0a406a
+ * #1  0x001ba5ff in sleep () from /lib/tls/libc.so.6
0a406a
+ * #2  0x08048936 in syscallingAltSighandler (signo=3, info=0x959cd70, context=0x959cdf0)
0a406a
+ *     at threadcrash.c:144
0a406a
+ * #3  <signal handler called>
0a406a
+ * #4  0x006adf5e in pthread_kill () from /lib/tls/libpthread.so.0
0a406a
+ * #5  0x080489e2 in makeSyscallFromAltSighandler (ignored=0x0) at threadcrash.c:190
0a406a
+ * #6  0x006aadec in start_thread () from /lib/tls/libpthread.so.0
0a406a
+ * #7  0x001ed19a in clone () from /lib/tls/libc.so.6
0a406a
+ *
0a406a
+ * Thread 4 (process 4355):
0a406a
+ * #0  spin (ignored=0x0) at threadcrash.c:242
0a406a
+ * #1  0x006aadec in start_thread () from /lib/tls/libpthread.so.0
0a406a
+ * #2  0x001ed19a in clone () from /lib/tls/libc.so.6
0a406a
+ *
0a406a
+ * Thread 3 (process 4356):
0a406a
+ * #0  spinningSighandler (signo=12, info=0xb4de46f0, context=0xb4de4770) at threadcrash.c:180
0a406a
+ * #1  <signal handler called>
0a406a
+ * #2  0x006adf5e in pthread_kill () from /lib/tls/libpthread.so.0
0a406a
+ * #3  0x08048b2f in spinFromSighandler (ignored=0x0) at threadcrash.c:232
0a406a
+ * #4  0x006aadec in start_thread () from /lib/tls/libpthread.so.0
0a406a
+ * #5  0x001ed19a in clone () from /lib/tls/libc.so.6
0a406a
+ *
0a406a
+ * Thread 2 (process 4357):
0a406a
+ * #0  spinningAltSighandler (signo=14, info=0x959ee50, context=0x959eed0) at threadcrash.c:156
0a406a
+ * #1  <signal handler called>
0a406a
+ * #2  0x006adf5e in pthread_kill () from /lib/tls/libpthread.so.0
0a406a
+ * #3  0x08048ac0 in spinFromAltSighandler (ignored=0x0) at threadcrash.c:218
0a406a
+ * #4  0x006aadec in start_thread () from /lib/tls/libpthread.so.0
0a406a
+ * #5  0x001ed19a in clone () from /lib/tls/libc.so.6
0a406a
+ *
0a406a
+ * Thread 1 (process 4351):
0a406a
+ * #0  0x08048cf3 in main (argc=1, argv=0xbfff9d74) at threadcrash.c:273
0a406a
+ * (gdb)
0a406a
+ */
0a406a
+
0a406a
+#include <pthread.h>
0a406a
+#include <signal.h>
0a406a
+#include <assert.h>
0a406a
+#include <unistd.h>
0a406a
+#include <stdio.h>
0a406a
+#include <stdlib.h>
0a406a
+#include <string.h>
0a406a
+
0a406a
+#define SIGSYSCALL_ALT SIGQUIT
0a406a
+#define SIGSYSCALL SIGUSR1
0a406a
+#define SIGSPIN_ALT SIGALRM
0a406a
+#define SIGSPIN SIGUSR2
0a406a
+
0a406a
+typedef void (*sigaction_t)(int, siginfo_t *, void *);
0a406a
+
0a406a
+static void installHandler(int signo, sigaction_t handler, int onAltstack) {
0a406a
+   struct sigaction action;
0a406a
+   sigset_t sigset;
0a406a
+   int result;
0a406a
+   stack_t altstack;
0a406a
+   stack_t oldaltstack;
0a406a
+
0a406a
+   memset(&action, 0, sizeof(action));
0a406a
+   memset(&altstack, 0, sizeof(altstack));
0a406a
+   memset(&oldaltstack, 0, sizeof(oldaltstack));
0a406a
+
0a406a
+   if (onAltstack) {
0a406a
+      altstack.ss_sp = malloc(SIGSTKSZ);
0a406a
+      assert(altstack.ss_sp != NULL);
0a406a
+      altstack.ss_size = SIGSTKSZ;
0a406a
+      altstack.ss_flags = 0;
0a406a
+      result = sigaltstack(&altstack, &oldaltstack);
0a406a
+      assert(result == 0);
0a406a
+      assert(oldaltstack.ss_flags == SS_DISABLE);
0a406a
+   }
0a406a
+
0a406a
+   sigemptyset(&sigset);
0a406a
+
0a406a
+   action.sa_handler = NULL;
0a406a
+   action.sa_sigaction = handler;
0a406a
+   action.sa_mask = sigset;
0a406a
+   action.sa_flags = SA_SIGINFO;
0a406a
+   if (onAltstack) {
0a406a
+      action.sa_flags |= SA_ONSTACK;
0a406a
+   }
0a406a
+
0a406a
+   result = sigaction(signo, &action, NULL);
0a406a
+   assert(result == 0);
0a406a
+}
0a406a
+
0a406a
+static void installNormalHandler(int signo, sigaction_t handler) {
0a406a
+   installHandler(signo, handler, 0);
0a406a
+}
0a406a
+
0a406a
+static void installAlthandler(int signo, sigaction_t handler) {
0a406a
+   installHandler(signo, handler, 1);
0a406a
+}
0a406a
+
0a406a
+static void *makeSyscall(void *ignored) {
0a406a
+   (void)ignored;
0a406a
+
0a406a
+   sleep(42);
0a406a
+
0a406a
+   fprintf(stderr, "%s: returning\n", __FUNCTION__);
0a406a
+   return NULL;
0a406a
+}
0a406a
+
0a406a
+/* Return true if we're currently executing on the altstack */
0a406a
+static int onAltstack(void) {
0a406a
+   stack_t stack;
0a406a
+   int result;
0a406a
+
0a406a
+   result = sigaltstack(NULL, &stack);
0a406a
+   assert(result == 0);
0a406a
+
0a406a
+   return stack.ss_flags & SS_ONSTACK;
0a406a
+}
0a406a
+
0a406a
+static void syscallingAltSighandler(int signo, siginfo_t *info, void *context) {
0a406a
+   (void)signo;
0a406a
+   (void)info;
0a406a
+   (void)context;
0a406a
+
0a406a
+   if (!onAltstack()) {
0a406a
+      printf("%s() not running on altstack!\n", __FUNCTION__);
0a406a
+   }
0a406a
+
0a406a
+   sleep(42);
0a406a
+}
0a406a
+
0a406a
+static void spinningAltSighandler(int signo, siginfo_t *info, void *context) {
0a406a
+   (void)signo;
0a406a
+   (void)info;
0a406a
+   (void)context;
0a406a
+
0a406a
+   if (!onAltstack()) {
0a406a
+      printf("%s() not running on altstack!\n", __FUNCTION__);
0a406a
+   }
0a406a
+
0a406a
+   while (1);
0a406a
+}
0a406a
+
0a406a
+static void syscallingSighandler(int signo, siginfo_t *info, void *context) {
0a406a
+   (void)signo;
0a406a
+   (void)info;
0a406a
+   (void)context;
0a406a
+
0a406a
+   if (onAltstack()) {
0a406a
+      printf("%s() running on altstack!\n", __FUNCTION__);
0a406a
+   }
0a406a
+
0a406a
+   sleep(42);
0a406a
+}
0a406a
+
0a406a
+static void spinningSighandler(int signo, siginfo_t *info, void *context) {
0a406a
+   (void)signo;
0a406a
+   (void)info;
0a406a
+   (void)context;
0a406a
+
0a406a
+   if (onAltstack()) {
0a406a
+      printf("%s() running on altstack!\n", __FUNCTION__);
0a406a
+   }
0a406a
+
0a406a
+   while (1);
0a406a
+}
0a406a
+
0a406a
+static void *makeSyscallFromAltSighandler(void *ignored) {
0a406a
+   (void)ignored;
0a406a
+
0a406a
+   int result;
0a406a
+
0a406a
+   installAlthandler(SIGSYSCALL_ALT, syscallingAltSighandler);
0a406a
+
0a406a
+   result = pthread_kill(pthread_self(), SIGSYSCALL_ALT);
0a406a
+   assert(result == 0);
0a406a
+
0a406a
+   fprintf(stderr, "%s: returning\n", __FUNCTION__);
0a406a
+   return NULL;
0a406a
+}
0a406a
+
0a406a
+static void *makeSyscallFromSighandler(void *ignored) {
0a406a
+   (void)ignored;
0a406a
+
0a406a
+   int result;
0a406a
+
0a406a
+   installNormalHandler(SIGSYSCALL, syscallingSighandler);
0a406a
+
0a406a
+   result = pthread_kill(pthread_self(), SIGSYSCALL);
0a406a
+   assert(result == 0);
0a406a
+
0a406a
+   fprintf(stderr, "%s: returning\n", __FUNCTION__);
0a406a
+   return NULL;
0a406a
+}
0a406a
+
0a406a
+static void *spinFromAltSighandler(void *ignored) {
0a406a
+   (void)ignored;
0a406a
+
0a406a
+   int result;
0a406a
+
0a406a
+   installAlthandler(SIGSPIN_ALT, spinningAltSighandler);
0a406a
+
0a406a
+   result = pthread_kill(pthread_self(), SIGSPIN_ALT);
0a406a
+   assert(result == 0);
0a406a
+
0a406a
+   fprintf(stderr, "%s: returning\n", __FUNCTION__);
0a406a
+   return NULL;
0a406a
+}
0a406a
+
0a406a
+static void *spinFromSighandler(void *ignored) {
0a406a
+   (void)ignored;
0a406a
+
0a406a
+   int result;
0a406a
+
0a406a
+   installNormalHandler(SIGSPIN, spinningSighandler);
0a406a
+
0a406a
+   result = pthread_kill(pthread_self(), SIGSPIN);
0a406a
+   assert(result == 0);
0a406a
+
0a406a
+   fprintf(stderr, "%s: returning\n", __FUNCTION__);
0a406a
+   return NULL;
0a406a
+}
0a406a
+
0a406a
+static void *spin(void *ignored) {
0a406a
+   (void)ignored;
0a406a
+
0a406a
+   while (1);
0a406a
+
0a406a
+   fprintf(stderr, "%s: returning\n", __FUNCTION__);
0a406a
+   return NULL;
0a406a
+}
0a406a
+
0a406a
+int main(int argc, char *argv[]) {
0a406a
+   int result;
0a406a
+   pthread_t thread;
0a406a
+   volatile int bad;
0a406a
+
0a406a
+   result = pthread_create(&thread, NULL, makeSyscall, NULL);
0a406a
+   assert(result == 0);
0a406a
+   result = pthread_create(&thread, NULL, makeSyscallFromSighandler, NULL);
0a406a
+   assert(result == 0);
0a406a
+   result = pthread_create(&thread, NULL, makeSyscallFromAltSighandler, NULL);
0a406a
+   assert(result == 0);
0a406a
+   result = pthread_create(&thread, NULL, spin, NULL);
0a406a
+   assert(result == 0);
0a406a
+   result = pthread_create(&thread, NULL, spinFromSighandler, NULL);
0a406a
+   assert(result == 0);
0a406a
+   result = pthread_create(&thread, NULL, spinFromAltSighandler, NULL);
0a406a
+   assert(result == 0);
0a406a
+
0a406a
+   // Give threads some time to get going
0a406a
+   sleep(3);
0a406a
+
0a406a
+   // Crash
0a406a
+   bad = *(int*)7;
0a406a
+
0a406a
+   /* Workaround: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29628
0a406a
+      Simulate use to ensure `DW_AT_location' for them:
0a406a
+      readelf -a --debug threadcrash|grep -A5 -w argc
0a406a
+      --> DW_AT_location    : 2 byte block: 71 0     (DW_OP_breg1: 0)
0a406a
+      This case verified on: gcc-4.1.1-30.i386
0a406a
+      Keep it late to ensure persistency in the registers.  */
0a406a
+   bad = (int) argc;
0a406a
+   bad = (unsigned long) argv;
0a406a
+
0a406a
+   return 0;
0a406a
+}
0a406a
diff --git a/gdb/testsuite/gdb.threads/threadcrash.exp b/gdb/testsuite/gdb.threads/threadcrash.exp
0a406a
new file mode 100644
0a406a
--- /dev/null
0a406a
+++ b/gdb/testsuite/gdb.threads/threadcrash.exp
0a406a
@@ -0,0 +1,37 @@
0a406a
+# threadcrash.exp - The point of this program is to crash in a multi-threaded app.
0a406a
+
0a406a
+
0a406a
+set testfile threadcrash
0a406a
+set srcfile ${testfile}.c
0a406a
+set shellfile ${srcdir}/${subdir}/${testfile}.sh
0a406a
+set binfile [standard_output_file ${testfile}]
0a406a
+
0a406a
+set GDB_abs ${GDB}
0a406a
+if [regexp "^\[^/\]" ${GDB_abs}] {
0a406a
+    set GDB_abs $env(PWD)/${GDB_abs}
0a406a
+}
0a406a
+
0a406a
+if [istarget "*-*-linux"] then {
0a406a
+    set target_cflags "-D_MIT_POSIX_THREADS"
0a406a
+} else {
0a406a
+    set target_cflags ""
0a406a
+}
0a406a
+
0a406a
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
0a406a
+    return -1
0a406a
+}
0a406a
+
0a406a
+# ${shellfile} argument must not contain any directories.
0a406a
+set fd [open "|bash ${shellfile} ${binfile} $GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]" r]
0a406a
+while { [gets $fd line] >= 0 } {
0a406a
+    if [regexp " PASS: (.*)$" $line trash message] {
0a406a
+	pass $message
0a406a
+    } elseif [regexp " FAIL: (.*)$" $line trash message] {
0a406a
+	fail $message
0a406a
+    }
0a406a
+}
0a406a
+catch {
0a406a
+    close $fd
0a406a
+}
0a406a
+
0a406a
+return 0
0a406a
diff --git a/gdb/testsuite/gdb.threads/threadcrash.sh b/gdb/testsuite/gdb.threads/threadcrash.sh
0a406a
new file mode 100644
0a406a
--- /dev/null
0a406a
+++ b/gdb/testsuite/gdb.threads/threadcrash.sh
0a406a
@@ -0,0 +1,324 @@
0a406a
+#! /bin/bash
0a406a
+
0a406a
+# NOTE: threadcrash.c *must* be built with debugging symbols
0a406a
+#
0a406a
+# The point of this shell script is to crash treadcrash.c, load the
0a406a
+# resulting core file into gdb and verify that gdb can extract enough
0a406a
+# information from the core file.
0a406a
+#
0a406a
+# The return code from this script is the number of failed tests.
0a406a
+
0a406a
+LOG=gdbresult.log
0a406a
+
0a406a
+if [ $# = 0 ] ; then
0a406a
+    echo >&2 Syntax: $0 \<name of threadcrash binary\> [\<gdb binary\> \<args...\>]
0a406a
+    exit 1
0a406a
+fi
0a406a
+RUNME="$1"
0a406a
+shift
0a406a
+GDB="${*:-gdb}"
0a406a
+
0a406a
+
0a406a
+pf_prefix=""
0a406a
+function pf_prefix() {
0a406a
+	pf_prefix="$*"
0a406a
+}
0a406a
+
0a406a
+set_test=""
0a406a
+function set_test() {
0a406a
+	if [ -n "$set_test" ] ; then
0a406a
+		echo >&2 "DEJAGNU-BASH ERROR: set_test already set"
0a406a
+		exit 1
0a406a
+	fi
0a406a
+	set_test="$*"
0a406a
+	if [ -n "$pf_prefix" ] ; then
0a406a
+		set_test="$pf_prefix: $set_test"
0a406a
+	fi
0a406a
+}
0a406a
+
0a406a
+# INTERNAL
0a406a
+function record_test {
0a406a
+	if [ -z "$set_test" ] ; then
0a406a
+		echo >&2 "DEJAGNU-BASH ERROR: set_test not set"
0a406a
+		exit 1
0a406a
+	fi
0a406a
+	# Provide the leading whitespace delimiter:
0a406a
+	echo " $1: $set_test"
0a406a
+	set_test=""
0a406a
+}
0a406a
+
0a406a
+function pass() {
0a406a
+	record_test PASS
0a406a
+}
0a406a
+function fail() {
0a406a
+	record_test FAIL
0a406a
+}
0a406a
+
0a406a
+
0a406a
+# Verify that the gdb output doesn't contain $1.
0a406a
+function mustNotHave() {
0a406a
+    local BADWORD=$1
0a406a
+    set_test gdb output contains "$BADWORD"
0a406a
+    if grep -q "$BADWORD" $LOG ; then
0a406a
+        fail
0a406a
+        return 1
0a406a
+    fi
0a406a
+    pass
0a406a
+    return 0
0a406a
+}
0a406a
+
0a406a
+# Verify that the gdb output contains exactly $1 $2s.
0a406a
+function mustHaveCorrectAmount() {
0a406a
+    local WANTEDNUMBER=$1
0a406a
+    local GOODWORD=$2
0a406a
+    local ACTUALNUMBER=$(grep "$GOODWORD" $LOG | wc -l)
0a406a
+    set_test gdb output contained $ACTUALNUMBER \""$GOODWORD"\", not $WANTEDNUMBER as expected
0a406a
+    if [ $ACTUALNUMBER != $WANTEDNUMBER ] ; then
0a406a
+        fail
0a406a
+        return 1
0a406a
+    fi
0a406a
+    pass
0a406a
+    return 0
0a406a
+}
0a406a
+
0a406a
+# Verify that the gdb output contains seven threads
0a406a
+function mustHaveSevenThreads() {
0a406a
+    NTHREADS=$(egrep "^Thread [1-7] \(" $LOG | wc -l)
0a406a
+    set_test gdb output contains $NTHREADS threads, not 7 as expected
0a406a
+    if [ $NTHREADS != 7 ] ; then
0a406a
+        fail
0a406a
+        return 1
0a406a
+    fi
0a406a
+    pass
0a406a
+    return 0
0a406a
+}
0a406a
+
0a406a
+# Verify that the gdb output has all parameters on consecutive lines
0a406a
+function mustHaveSequence() {
0a406a
+    SEQUENCE="$*"
0a406a
+    NPARTS=$#
0a406a
+    grep "$1" -A$((NPARTS - 1)) $LOG > matches.log
0a406a
+
0a406a
+    while [ $# -gt 1 ] ; do
0a406a
+        shift
0a406a
+        ((NPARTS--))
0a406a
+        grep "$1" -A$((NPARTS - 1)) matches.log > temp.log
0a406a
+        mv temp.log matches.log
0a406a
+    done
0a406a
+    LASTPART=$1
0a406a
+
0a406a
+    set_test gdb output does not contain the sequence: $SEQUENCE
0a406a
+    if ! grep -q "$LASTPART" matches.log ; then
0a406a
+        fail
0a406a
+        return 1
0a406a
+    fi
0a406a
+    pass
0a406a
+    return 0
0a406a
+}
0a406a
+
0a406a
+# Verify that $LOG contains all information we want
0a406a
+function verifyLog() {
0a406a
+    local FAILURES=0
0a406a
+
0a406a
+    mustNotHave '??' || ((FAILURES++))
0a406a
+    mustHaveCorrectAmount 11 threadcrash.c: || ((FAILURES++))
0a406a
+
0a406a
+    mustHaveSevenThreads || ((FAILURES++))
0a406a
+    mustHaveSequence sleep "makeSyscall (ignored=" || ((FAILURES++))
0a406a
+
0a406a
+    mustHaveSequence sleep "syscallingSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
0a406a
+    mustHaveSequence pthread_kill "makeSyscallFromSighandler (ignored=" || ((FAILURES++))
0a406a
+
0a406a
+    mustHaveSequence sleep "syscallingAltSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
0a406a
+    mustHaveSequence pthread_kill "makeSyscallFromAltSighandler (ignored=" || ((FAILURES++))
0a406a
+
0a406a
+    mustHaveSequence Thread "spin (ignored=" || ((FAILURES++))
0a406a
+
0a406a
+    mustHaveSequence "spinningSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
0a406a
+    mustHaveSequence pthread_kill "spinFromSighandler (ignored=" || ((FAILURES++))
0a406a
+
0a406a
+    mustHaveSequence "spinningAltSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
0a406a
+    mustHaveSequence pthread_kill "spinFromAltSighandler (ignored=" || ((FAILURES++))
0a406a
+
0a406a
+    mustHaveSequence Thread "main (argc=1, argv=" || ((FAILURES++))
0a406a
+
0a406a
+    return $FAILURES
0a406a
+}
0a406a
+
0a406a
+# Put result of debugging a core file in $LOG
0a406a
+function getLogFromCore() {
0a406a
+    # Make sure we get a core file
0a406a
+    set_test Make sure we get a core file
0a406a
+    if ! ulimit -c unlimited ; then
0a406a
+        fail
0a406a
+        exit 1
0a406a
+    fi
0a406a
+    pass
0a406a
+
0a406a
+    # Run the crasher
0a406a
+    ./$(basename "$RUNME")
0a406a
+    EXITCODE=$?
0a406a
+
0a406a
+    # Verify that we actually crashed
0a406a
+    set_test $RUNME should have been killed by a signal, got non-signal exit code $EXITCODE
0a406a
+    if [ $EXITCODE -lt 128 ] ; then
0a406a
+        fail
0a406a
+        exit 1
0a406a
+    fi
0a406a
+    pass
0a406a
+
0a406a
+    # Verify that we got a core file
0a406a
+    set_test $RUNME did not create a core file
0a406a
+    if [ ! -r core* ] ; then
0a406a
+        fail
0a406a
+        exit 1
0a406a
+    fi
0a406a
+    pass
0a406a
+
0a406a
+    # Run gdb
0a406a
+    cat > gdbscript.gdb <
0a406a
+set width 0
0a406a
+t a a bt 100
0a406a
+quit
0a406a
+EOF
0a406a
+    cat gdbscript.gdb /dev/zero | $GDB -nx "./$(basename "$RUNME")" core* > $LOG
0a406a
+    EXITCODE=$?
0a406a
+
0a406a
+    set_test gdb exited with error code
0a406a
+    if [ $EXITCODE != 0 ] ; then
0a406a
+        ((FAILURES++))
0a406a
+        echo >&2 gdb exited with error code $EXITCODE
0a406a
+	fail
0a406a
+    fi
0a406a
+    pass
0a406a
+}
0a406a
+
0a406a
+# Put result of debugging a gcore file in $LOG
0a406a
+function getLogFromGcore() {
0a406a
+    # Create the core file
0a406a
+    rm -f core*
0a406a
+    cat > gdbscript.gdb <
0a406a
+handle SIGQUIT pass noprint nostop
0a406a
+handle SIGUSR1 pass noprint nostop
0a406a
+handle SIGUSR2 pass noprint nostop
0a406a
+handle SIGALRM pass noprint nostop
0a406a
+run
0a406a
+gcore
0a406a
+quit
0a406a
+EOF
0a406a
+    cat gdbscript.gdb /dev/zero | $GDB -nx "./$(basename "$RUNME")" > /dev/null
0a406a
+    EXITCODE=$?
0a406a
+
0a406a
+    set_test gdb exited with error code when creating gcore file
0a406a
+    if [ $EXITCODE != 0 ] ; then
0a406a
+        ((FAILURES++))
0a406a
+        echo >&2 gdb exited with error code $EXITCODE when creating gcore file
0a406a
+	fail
0a406a
+    fi
0a406a
+    pass
0a406a
+
0a406a
+    # Verify that we got a core file from gcore
0a406a
+    set_test gdb gcore did not create a core file
0a406a
+    if [ ! -r core* ] ; then
0a406a
+        fail
0a406a
+        exit 1
0a406a
+    fi
0a406a
+    pass
0a406a
+
0a406a
+    # Run gdb on the gcore file
0a406a
+    cat > gdbscript.gdb <
0a406a
+set width 0
0a406a
+t a a bt 100
0a406a
+quit
0a406a
+EOF
0a406a
+    cat gdbscript.gdb /dev/zero | $GDB -nx "./$(basename "$RUNME")" core* > $LOG
0a406a
+    EXITCODE=$?
0a406a
+
0a406a
+    set_test gdb exited with error code when examining gcore file
0a406a
+    if [ $EXITCODE != 0 ] ; then
0a406a
+        ((FAILURES++))
0a406a
+        echo >&2 gdb exited with error code $EXITCODE when examining gcore file
0a406a
+	fail
0a406a
+    fi
0a406a
+    pass
0a406a
+}
0a406a
+
0a406a
+# Put result of debugging a core file in $LOG
0a406a
+function getLogFromLiveProcess() {
0a406a
+    # Run gdb
0a406a
+    cat > gdbscript.gdb <
0a406a
+handle SIGQUIT pass noprint nostop
0a406a
+handle SIGUSR1 pass noprint nostop
0a406a
+handle SIGUSR2 pass noprint nostop
0a406a
+handle SIGALRM pass noprint nostop
0a406a
+set width 0
0a406a
+run
0a406a
+t a a bt 100
0a406a
+quit
0a406a
+EOF
0a406a
+    cat gdbscript.gdb /dev/zero | $GDB -nx "./$(basename "$RUNME")" > $LOG
0a406a
+    EXITCODE=$?
0a406a
+
0a406a
+    set_test gdb exited with error code
0a406a
+    if [ $EXITCODE != 0 ] ; then
0a406a
+        ((FAILURES++))
0a406a
+        echo >&2 gdb exited with error code $EXITCODE
0a406a
+	fail
0a406a
+    fi
0a406a
+    pass
0a406a
+}
0a406a
+
0a406a
+####### Main program follows #####################
0a406a
+
0a406a
+# Make sure we don't clobber anybody else's (core) file(s)
0a406a
+WORKDIR=/tmp/$PPID
0a406a
+mkdir -p $WORKDIR
0a406a
+cp "$RUNME" $WORKDIR
0a406a
+cd $WORKDIR
0a406a
+
0a406a
+# Count problems
0a406a
+FAILURES=0
0a406a
+
0a406a
+echo === Testing gdb vs core file...
0a406a
+pf_prefix core file
0a406a
+getLogFromCore
0a406a
+verifyLog
0a406a
+((FAILURES+=$?))
0a406a
+pf_prefix
0a406a
+echo === Core file tests done.
0a406a
+
0a406a
+echo
0a406a
+
0a406a
+echo === Testing gdb vs gcore file...
0a406a
+pf_prefix gcore file
0a406a
+getLogFromGcore
0a406a
+verifyLog
0a406a
+((FAILURES+=$?))
0a406a
+pf_prefix
0a406a
+echo === Gcore file tests done.
0a406a
+
0a406a
+echo
0a406a
+
0a406a
+echo === Testing gdb vs live process...
0a406a
+pf_prefix live process
0a406a
+getLogFromLiveProcess
0a406a
+verifyLog
0a406a
+((FAILURES+=$?))
0a406a
+pf_prefix
0a406a
+echo === Live process tests done.
0a406a
+
0a406a
+# Executive summary
0a406a
+echo
0a406a
+if [ $FAILURES == 0 ] ; then
0a406a
+    echo All tests passed!
0a406a
+else
0a406a
+    echo $FAILURES tests failed!
0a406a
+    echo
0a406a
+    echo Make sure the threadcrash binary contains debugging information \(build with \"gcc -g\"\).
0a406a
+fi
0a406a
+
0a406a
+# Clean up
0a406a
+cd /
0a406a
+rm -rf $WORKDIR
0a406a
+
0a406a
+exit $FAILURES
0a406a
diff --git a/gdb/testsuite/gdb.threads/threadcrash.sh-orig b/gdb/testsuite/gdb.threads/threadcrash.sh-orig
0a406a
new file mode 100644
0a406a
--- /dev/null
0a406a
+++ b/gdb/testsuite/gdb.threads/threadcrash.sh-orig
0a406a
@@ -0,0 +1,248 @@
0a406a
+#! /bin/bash
0a406a
+
0a406a
+# NOTE: threadcrash.c *must* be built with debugging symbols
0a406a
+#
0a406a
+# The point of this shell script is to crash treadcrash.c, load the
0a406a
+# resulting core file into gdb and verify that gdb can extract enough
0a406a
+# information from the core file.
0a406a
+#
0a406a
+# The return code from this script is the number of failed tests.
0a406a
+
0a406a
+LOG=gdbresult.log
0a406a
+
0a406a
+if [ $# != 1 ] ; then
0a406a
+    echo > /dev/stderr Syntax: $0 \<name of threadcrash binary\>
0a406a
+    exit 1
0a406a
+fi
0a406a
+RUNME="$1"
0a406a
+
0a406a
+# Verify that the gdb output doesn't contain $1.
0a406a
+function mustNotHave() {
0a406a
+    local BADWORD=$1
0a406a
+    if grep -q "$BADWORD" $LOG ; then
0a406a
+        echo >> /dev/stderr WARNING: gdb output contains "$BADWORD"
0a406a
+        return 1
0a406a
+    fi
0a406a
+    return 0
0a406a
+}
0a406a
+
0a406a
+# Verify that the gdb output contains exactly $1 $2s.
0a406a
+function mustHaveCorrectAmount() {
0a406a
+    local WANTEDNUMBER=$1
0a406a
+    local GOODWORD=$2
0a406a
+    local ACTUALNUMBER=$(grep "$GOODWORD" $LOG | wc -l)
0a406a
+    if [ $ACTUALNUMBER != $WANTEDNUMBER ] ; then
0a406a
+        echo >> /dev/stderr WARNING: gdb output contained $ACTUALNUMBER \""$GOODWORD"\", not $WANTEDNUMBER as expected
0a406a
+        return 1
0a406a
+    fi
0a406a
+    return 0
0a406a
+}
0a406a
+
0a406a
+# Verify that the gdb output contains seven threads
0a406a
+function mustHaveSevenThreads() {
0a406a
+    NTHREADS=$(egrep "^Thread [1-7] \(" $LOG | wc -l)
0a406a
+    if [ $NTHREADS != 7 ] ; then
0a406a
+        echo >> /dev/stderr WARNING: gdb output contains $NTHREADS threads, not 7 as expected
0a406a
+        return 1
0a406a
+    fi
0a406a
+    return 0
0a406a
+}
0a406a
+
0a406a
+# Verify that the gdb output has all parameters on consecutive lines
0a406a
+function mustHaveSequence() {
0a406a
+    SEQUENCE="$*"
0a406a
+    NPARTS=$#
0a406a
+    grep "$1" -A$((NPARTS - 1)) $LOG > matches.log
0a406a
+
0a406a
+    while [ $# -gt 1 ] ; do
0a406a
+        shift
0a406a
+        ((NPARTS--))
0a406a
+        grep "$1" -A$((NPARTS - 1)) matches.log > temp.log
0a406a
+        mv temp.log matches.log
0a406a
+    done
0a406a
+    LASTPART=$1
0a406a
+
0a406a
+    if ! grep -q "$LASTPART" matches.log ; then
0a406a
+        echo >> /dev/stderr WARNING: gdb output does not contain the sequence: $SEQUENCE
0a406a
+        return 1
0a406a
+    fi
0a406a
+    return 0
0a406a
+}
0a406a
+
0a406a
+# Verify that $LOG contains all information we want
0a406a
+function verifyLog() {
0a406a
+    local FAILURES=0
0a406a
+
0a406a
+    mustNotHave '??' || ((FAILURES++))
0a406a
+    mustHaveCorrectAmount 12 threadcrash.c: || ((FAILURES++))
0a406a
+
0a406a
+    mustHaveSevenThreads || ((FAILURES++))
0a406a
+    mustHaveSequence sleep "makeSyscall (ignored=" || ((FAILURES++))
0a406a
+
0a406a
+    mustHaveSequence sleep "syscallingSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
0a406a
+    mustHaveSequence pthread_kill "makeSyscallFromSighandler (ignored=" || ((FAILURES++))
0a406a
+
0a406a
+    mustHaveSequence sleep "syscallingAltSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
0a406a
+    mustHaveSequence pthread_kill "makeSyscallFromAltSighandler (ignored=" || ((FAILURES++))
0a406a
+
0a406a
+    mustHaveSequence Thread "spin (ignored=" || ((FAILURES++))
0a406a
+
0a406a
+    mustHaveSequence "spinningSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
0a406a
+    mustHaveSequence pthread_kill "spinFromSighandler (ignored=" || ((FAILURES++))
0a406a
+
0a406a
+    mustHaveSequence "spinningAltSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
0a406a
+    mustHaveSequence pthread_kill "spinFromAltSighandler (ignored=" || ((FAILURES++))
0a406a
+
0a406a
+    mustHaveSequence Thread "main (argc=1, argv=" || ((FAILURES++))
0a406a
+
0a406a
+    return $FAILURES
0a406a
+}
0a406a
+
0a406a
+# Put result of debugging a core file in $LOG
0a406a
+function getLogFromCore() {
0a406a
+    # Make sure we get a core file
0a406a
+    ulimit -c unlimited || exit 1
0a406a
+
0a406a
+    # Run the crasher
0a406a
+    ./$(basename "$RUNME")
0a406a
+    EXITCODE=$?
0a406a
+
0a406a
+    # Verify that we actually crashed
0a406a
+    if [ $EXITCODE -lt 128 ] ; then
0a406a
+        echo >> /dev/stderr ERROR: $RUNME should have been killed by a signal, got non-signal exit code $EXITCODE
0a406a
+        exit 1
0a406a
+    fi
0a406a
+
0a406a
+    # Verify that we got a core file
0a406a
+    if [ ! -r core* ] ; then
0a406a
+        echo >> /dev/stderr ERROR: $RUNME did not create a core file
0a406a
+        exit 1
0a406a
+    fi
0a406a
+
0a406a
+    # Run gdb
0a406a
+    cat > gdbscript.gdb <
0a406a
+set width 0
0a406a
+t a a bt 100
0a406a
+quit
0a406a
+EOF
0a406a
+    cat gdbscript.gdb /dev/zero | gdb -nx "./$(basename "$RUNME")" core* > $LOG
0a406a
+    EXITCODE=$?
0a406a
+
0a406a
+    if [ $EXITCODE != 0 ] ; then
0a406a
+        ((FAILURES++))
0a406a
+        echo >> /dev/stderr WARNING: gdb exited with error code $EXITCODE
0a406a
+    fi
0a406a
+}
0a406a
+
0a406a
+# Put result of debugging a gcore file in $LOG
0a406a
+function getLogFromGcore() {
0a406a
+    # Create the core file
0a406a
+    rm -f core*
0a406a
+    cat > gdbscript.gdb <
0a406a
+handle SIGQUIT pass noprint nostop
0a406a
+handle SIGUSR1 pass noprint nostop
0a406a
+handle SIGUSR2 pass noprint nostop
0a406a
+handle SIGALRM pass noprint nostop
0a406a
+run
0a406a
+gcore
0a406a
+quit
0a406a
+EOF
0a406a
+    cat gdbscript.gdb /dev/zero | gdb -nx "./$(basename "$RUNME")" > /dev/null
0a406a
+    EXITCODE=$?
0a406a
+
0a406a
+    if [ $EXITCODE != 0 ] ; then
0a406a
+        ((FAILURES++))
0a406a
+        echo >> /dev/stderr WARNING: gdb exited with error code $EXITCODE when creating gcore file
0a406a
+    fi
0a406a
+
0a406a
+    # Verify that we got a core file from gcore
0a406a
+    if [ ! -r core* ] ; then
0a406a
+        echo >> /dev/stderr ERROR: gdb gcore did not create a core file
0a406a
+        exit 1
0a406a
+    fi
0a406a
+
0a406a
+    # Run gdb on the gcore file
0a406a
+    cat > gdbscript.gdb <
0a406a
+set width 0
0a406a
+t a a bt 100
0a406a
+quit
0a406a
+EOF
0a406a
+    cat gdbscript.gdb /dev/zero | gdb -nx "./$(basename "$RUNME")" core* > $LOG
0a406a
+    EXITCODE=$?
0a406a
+
0a406a
+    if [ $EXITCODE != 0 ] ; then
0a406a
+        ((FAILURES++))
0a406a
+        echo >> /dev/stderr WARNING: gdb exited with error code $EXITCODE when examining gcore file
0a406a
+    fi
0a406a
+}
0a406a
+
0a406a
+# Put result of debugging a core file in $LOG
0a406a
+function getLogFromLiveProcess() {
0a406a
+    # Run gdb
0a406a
+    cat > gdbscript.gdb <
0a406a
+handle SIGQUIT pass noprint nostop
0a406a
+handle SIGUSR1 pass noprint nostop
0a406a
+handle SIGUSR2 pass noprint nostop
0a406a
+handle SIGALRM pass noprint nostop
0a406a
+set width 0
0a406a
+run
0a406a
+t a a bt 100
0a406a
+quit
0a406a
+EOF
0a406a
+    cat gdbscript.gdb /dev/zero | gdb -nx "./$(basename "$RUNME")" > $LOG
0a406a
+    EXITCODE=$?
0a406a
+
0a406a
+    if [ $EXITCODE != 0 ] ; then
0a406a
+        ((FAILURES++))
0a406a
+        echo >> /dev/stderr WARNING: gdb exited with error code $EXITCODE
0a406a
+    fi
0a406a
+}
0a406a
+
0a406a
+####### Main program follows #####################
0a406a
+
0a406a
+# Make sure we don't clobber anybody else's (core) file(s)
0a406a
+WORKDIR=/tmp/$PPID
0a406a
+mkdir -p $WORKDIR
0a406a
+cp "$RUNME" $WORKDIR
0a406a
+cd $WORKDIR
0a406a
+
0a406a
+# Count problems
0a406a
+FAILURES=0
0a406a
+
0a406a
+echo === Testing gdb vs core file...
0a406a
+getLogFromCore
0a406a
+verifyLog
0a406a
+((FAILURES+=$?))
0a406a
+echo === Core file tests done.
0a406a
+
0a406a
+echo
0a406a
+
0a406a
+echo === Testing gdb vs gcore file...
0a406a
+getLogFromGcore
0a406a
+verifyLog
0a406a
+((FAILURES+=$?))
0a406a
+echo === Gcore file tests done.
0a406a
+
0a406a
+echo
0a406a
+
0a406a
+echo === Testing gdb vs live process...
0a406a
+getLogFromLiveProcess
0a406a
+verifyLog
0a406a
+((FAILURES+=$?))
0a406a
+echo === Live process tests done.
0a406a
+
0a406a
+# Executive summary
0a406a
+echo
0a406a
+if [ $FAILURES == 0 ] ; then
0a406a
+    echo All tests passed!
0a406a
+else
0a406a
+    echo $FAILURES tests failed!
0a406a
+    echo
0a406a
+    echo Make sure the threadcrash binary contains debugging information \(build with \"gcc -g\"\).
0a406a
+fi
0a406a
+
0a406a
+# Clean up
0a406a
+cd /
0a406a
+rm -rf $WORKDIR
0a406a
+
0a406a
+exit $FAILURES