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

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