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