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

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