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

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