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

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