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

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