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

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