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

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