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

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