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

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