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

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