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

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