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

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