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

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