]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-6.5-BEA-testsuite.patch
- updated (performance fixes).
[packages/gdb.git] / gdb-6.5-BEA-testsuite.patch
CommitLineData
3a58abaf
AM
1Index: ./gdb/testsuite/gdb.threads/threadcrash.c
2===================================================================
3RCS file: gdb/testsuite/gdb.threads/threadcrash.c
4diff -N gdb/testsuite/gdb.threads/threadcrash.c
5--- /dev/null 1 Jan 1970 00:00:00 -0000
6+++ ./gdb/testsuite/gdb.threads/threadcrash.c 31 Oct 2006 17:54:38 -0000
7@@ -0,0 +1,301 @@
8+/*
9+ * The point of this program is to crash in a multi-threaded app.
10+ * There are seven threads, doing the following things:
11+ * * Spinning
12+ * * Spinning inside a signal handler
13+ * * Spinning inside a signal handler executing on the altstack
14+ * * In a syscall
15+ * * In a syscall inside a signal handler
16+ * * In a syscall inside a signal handler executing on the altstack
17+ * * Finally, the main thread crashes in main, with no frills.
18+ *
19+ * These are the things threads in JRockit tend to be doing. If gdb
20+ * can handle those things, both in core files and during live
21+ * debugging, that will help (at least) JRockit development.
22+ *
23+ * Let the program create a core file, then load the core file into
24+ * gdb. Inside gdb, you should be able to do something like this:
25+ *
26+ * (gdb) t a a bt
27+ *
28+ * Thread 7 (process 4352):
29+ * #0 0x001ba7dc in __nanosleep_nocancel () from /lib/tls/libc.so.6
30+ * #1 0x001ba5ff in sleep () from /lib/tls/libc.so.6
31+ * #2 0x080488a2 in makeSyscall (ignored=0x0) at threadcrash.c:118
32+ * #3 0x006aadec in start_thread () from /lib/tls/libpthread.so.0
33+ * #4 0x001ed19a in clone () from /lib/tls/libc.so.6
34+ *
35+ * Thread 6 (process 4353):
36+ * #0 0x001ba7dc in __nanosleep_nocancel () from /lib/tls/libc.so.6
37+ * #1 0x001ba5ff in sleep () from /lib/tls/libc.so.6
38+ * #2 0x0804898f in syscallingSighandler (signo=10, info=0xb6be76f0, context=0xb6be7770)
39+ * at threadcrash.c:168
40+ * #3 <signal handler called>
41+ * #4 0x006adf5e in pthread_kill () from /lib/tls/libpthread.so.0
42+ * #5 0x08048a51 in makeSyscallFromSighandler (ignored=0x0) at threadcrash.c:204
43+ * #6 0x006aadec in start_thread () from /lib/tls/libpthread.so.0
44+ * #7 0x001ed19a in clone () from /lib/tls/libc.so.6
45+ *
46+ * Thread 5 (process 4354):
47+ * #0 0x001ba7dc in __nanosleep_nocancel () from /lib/tls/libc.so.6
48+ * #1 0x001ba5ff in sleep () from /lib/tls/libc.so.6
49+ * #2 0x08048936 in syscallingAltSighandler (signo=3, info=0x959cd70, context=0x959cdf0)
50+ * at threadcrash.c:144
51+ * #3 <signal handler called>
52+ * #4 0x006adf5e in pthread_kill () from /lib/tls/libpthread.so.0
53+ * #5 0x080489e2 in makeSyscallFromAltSighandler (ignored=0x0) at threadcrash.c:190
54+ * #6 0x006aadec in start_thread () from /lib/tls/libpthread.so.0
55+ * #7 0x001ed19a in clone () from /lib/tls/libc.so.6
56+ *
57+ * Thread 4 (process 4355):
58+ * #0 spin (ignored=0x0) at threadcrash.c:242
59+ * #1 0x006aadec in start_thread () from /lib/tls/libpthread.so.0
60+ * #2 0x001ed19a in clone () from /lib/tls/libc.so.6
61+ *
62+ * Thread 3 (process 4356):
63+ * #0 spinningSighandler (signo=12, info=0xb4de46f0, context=0xb4de4770) at threadcrash.c:180
64+ * #1 <signal handler called>
65+ * #2 0x006adf5e in pthread_kill () from /lib/tls/libpthread.so.0
66+ * #3 0x08048b2f in spinFromSighandler (ignored=0x0) at threadcrash.c:232
67+ * #4 0x006aadec in start_thread () from /lib/tls/libpthread.so.0
68+ * #5 0x001ed19a in clone () from /lib/tls/libc.so.6
69+ *
70+ * Thread 2 (process 4357):
71+ * #0 spinningAltSighandler (signo=14, info=0x959ee50, context=0x959eed0) at threadcrash.c:156
72+ * #1 <signal handler called>
73+ * #2 0x006adf5e in pthread_kill () from /lib/tls/libpthread.so.0
74+ * #3 0x08048ac0 in spinFromAltSighandler (ignored=0x0) at threadcrash.c:218
75+ * #4 0x006aadec in start_thread () from /lib/tls/libpthread.so.0
76+ * #5 0x001ed19a in clone () from /lib/tls/libc.so.6
77+ *
78+ * Thread 1 (process 4351):
79+ * #0 0x08048cf3 in main (argc=1, argv=0xbfff9d74) at threadcrash.c:273
80+ * (gdb)
81+ */
82+
83+#include <pthread.h>
84+#include <signal.h>
85+#include <assert.h>
86+#include <unistd.h>
87+#include <stdio.h>
88+#include <stdlib.h>
89+#include <string.h>
90+
91+#define SIGSYSCALL_ALT SIGQUIT
92+#define SIGSYSCALL SIGUSR1
93+#define SIGSPIN_ALT SIGALRM
94+#define SIGSPIN SIGUSR2
95+
96+typedef void (*sigaction_t)(int, siginfo_t *, void *);
97+
98+static void installHandler(int signo, sigaction_t handler, int onAltstack) {
99+ struct sigaction action;
100+ sigset_t sigset;
101+ int result;
102+ stack_t altstack;
103+ stack_t oldaltstack;
104+
105+ memset(&action, 0, sizeof(action));
106+ memset(&altstack, 0, sizeof(altstack));
107+ memset(&oldaltstack, 0, sizeof(oldaltstack));
108+
109+ if (onAltstack) {
110+ altstack.ss_sp = malloc(SIGSTKSZ);
111+ assert(altstack.ss_sp != NULL);
112+ altstack.ss_size = SIGSTKSZ;
113+ altstack.ss_flags = 0;
114+ result = sigaltstack(&altstack, &oldaltstack);
115+ assert(result == 0);
116+ assert(oldaltstack.ss_flags == SS_DISABLE);
117+ }
118+
119+ sigemptyset(&sigset);
120+
121+ action.sa_handler = NULL;
122+ action.sa_sigaction = handler;
123+ action.sa_mask = sigset;
124+ action.sa_flags = SA_SIGINFO;
125+ if (onAltstack) {
126+ action.sa_flags |= SA_ONSTACK;
127+ }
128+
129+ result = sigaction(signo, &action, NULL);
130+ assert(result == 0);
131+}
132+
133+static void installNormalHandler(int signo, sigaction_t handler) {
134+ installHandler(signo, handler, 0);
135+}
136+
137+static void installAlthandler(int signo, sigaction_t handler) {
138+ installHandler(signo, handler, 1);
139+}
140+
141+static void *makeSyscall(void *ignored) {
142+ (void)ignored;
143+
144+ sleep(42);
145+
146+ fprintf(stderr, "%s: returning\n", __FUNCTION__);
147+ return NULL;
148+}
149+
150+/* Return true if we're currently executing on the altstack */
151+static int onAltstack(void) {
152+ stack_t stack;
153+ int result;
154+
155+ result = sigaltstack(NULL, &stack);
156+ assert(result == 0);
157+
158+ return stack.ss_flags & SS_ONSTACK;
159+}
160+
161+static void syscallingAltSighandler(int signo, siginfo_t *info, void *context) {
162+ (void)signo;
163+ (void)info;
164+ (void)context;
165+
166+ if (!onAltstack()) {
167+ printf("%s() not running on altstack!\n", __FUNCTION__);
168+ }
169+
170+ sleep(42);
171+}
172+
173+static void spinningAltSighandler(int signo, siginfo_t *info, void *context) {
174+ (void)signo;
175+ (void)info;
176+ (void)context;
177+
178+ if (!onAltstack()) {
179+ printf("%s() not running on altstack!\n", __FUNCTION__);
180+ }
181+
182+ while (1);
183+}
184+
185+static void syscallingSighandler(int signo, siginfo_t *info, void *context) {
186+ (void)signo;
187+ (void)info;
188+ (void)context;
189+
190+ if (onAltstack()) {
191+ printf("%s() running on altstack!\n", __FUNCTION__);
192+ }
193+
194+ sleep(42);
195+}
196+
197+static void spinningSighandler(int signo, siginfo_t *info, void *context) {
198+ (void)signo;
199+ (void)info;
200+ (void)context;
201+
202+ if (onAltstack()) {
203+ printf("%s() running on altstack!\n", __FUNCTION__);
204+ }
205+
206+ while (1);
207+}
208+
209+static void *makeSyscallFromAltSighandler(void *ignored) {
210+ (void)ignored;
211+
212+ int result;
213+
214+ installAlthandler(SIGSYSCALL_ALT, syscallingAltSighandler);
215+
216+ result = pthread_kill(pthread_self(), SIGSYSCALL_ALT);
217+ assert(result == 0);
218+
219+ fprintf(stderr, "%s: returning\n", __FUNCTION__);
220+ return NULL;
221+}
222+
223+static void *makeSyscallFromSighandler(void *ignored) {
224+ (void)ignored;
225+
226+ int result;
227+
228+ installNormalHandler(SIGSYSCALL, syscallingSighandler);
229+
230+ result = pthread_kill(pthread_self(), SIGSYSCALL);
231+ assert(result == 0);
232+
233+ fprintf(stderr, "%s: returning\n", __FUNCTION__);
234+ return NULL;
235+}
236+
237+static void *spinFromAltSighandler(void *ignored) {
238+ (void)ignored;
239+
240+ int result;
241+
242+ installAlthandler(SIGSPIN_ALT, spinningAltSighandler);
243+
244+ result = pthread_kill(pthread_self(), SIGSPIN_ALT);
245+ assert(result == 0);
246+
247+ fprintf(stderr, "%s: returning\n", __FUNCTION__);
248+ return NULL;
249+}
250+
251+static void *spinFromSighandler(void *ignored) {
252+ (void)ignored;
253+
254+ int result;
255+
256+ installNormalHandler(SIGSPIN, spinningSighandler);
257+
258+ result = pthread_kill(pthread_self(), SIGSPIN);
259+ assert(result == 0);
260+
261+ fprintf(stderr, "%s: returning\n", __FUNCTION__);
262+ return NULL;
263+}
264+
265+static void *spin(void *ignored) {
266+ (void)ignored;
267+
268+ while (1);
269+
270+ fprintf(stderr, "%s: returning\n", __FUNCTION__);
271+ return NULL;
272+}
273+
274+int main(int argc, char *argv[]) {
275+ int result;
276+ pthread_t thread;
277+ volatile int bad;
278+
279+ result = pthread_create(&thread, NULL, makeSyscall, NULL);
280+ assert(result == 0);
281+ result = pthread_create(&thread, NULL, makeSyscallFromSighandler, NULL);
282+ assert(result == 0);
283+ result = pthread_create(&thread, NULL, makeSyscallFromAltSighandler, NULL);
284+ assert(result == 0);
285+ result = pthread_create(&thread, NULL, spin, NULL);
286+ assert(result == 0);
287+ result = pthread_create(&thread, NULL, spinFromSighandler, NULL);
288+ assert(result == 0);
289+ result = pthread_create(&thread, NULL, spinFromAltSighandler, NULL);
290+ assert(result == 0);
291+
292+ // Give threads some time to get going
293+ sleep(3);
294+
295+ // Crash
296+ bad = *(int*)7;
297+
298+ /* Workaround: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29628
299+ Simulate use to ensure `DW_AT_location' for them:
300+ readelf -a --debug threadcrash|grep -A5 -w argc
301+ --> DW_AT_location : 2 byte block: 71 0 (DW_OP_breg1: 0)
302+ This case verified on: gcc-4.1.1-30.i386
303+ Keep it late to ensure persistency in the registers. */
304+ bad = (int) argc;
305+ bad = (unsigned long) argv;
306+
307+ return 0;
308+}
309Index: ./gdb/testsuite/gdb.threads/threadcrash.exp
310===================================================================
311RCS file: gdb/testsuite/gdb.threads/threadcrash.exp
312diff -N gdb/testsuite/gdb.threads/threadcrash.exp
313--- /dev/null 1 Jan 1970 00:00:00 -0000
314+++ ./gdb/testsuite/gdb.threads/threadcrash.exp 31 Oct 2006 17:54:38 -0000
315@@ -0,0 +1,37 @@
316+# threadcrash.exp - The point of this program is to crash in a multi-threaded app.
317+
318+
319+set testfile threadcrash
320+set srcfile ${testfile}.c
321+set shellfile ${srcdir}/${subdir}/${testfile}.sh
322+set binfile ${objdir}/${subdir}/${testfile}
323+
324+set GDB_abs ${GDB}
325+if [regexp "^\[^/\]" ${GDB_abs}] {
326+ set GDB_abs $env(PWD)/${GDB_abs}
327+}
328+
329+if [istarget "*-*-linux"] then {
330+ set target_cflags "-D_MIT_POSIX_THREADS"
331+} else {
332+ set target_cflags ""
333+}
334+
335+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
336+ return -1
337+}
338+
339+# ${shellfile} argument must not contain any directories.
340+set fd [open "|bash ${shellfile} ${binfile} $GDB -nw $GDBFLAGS" r]
341+while { [gets $fd line] >= 0 } {
342+ if [regexp " PASS: (.*)$" $line trash message] {
343+ pass $message
344+ } elseif [regexp " FAIL: (.*)$" $line trash message] {
345+ fail $message
346+ }
347+}
348+catch {
349+ close $fd
350+}
351+
352+return 0
353Index: ./gdb/testsuite/gdb.threads/threadcrash.sh
354===================================================================
355RCS file: gdb/testsuite/gdb.threads/threadcrash.sh
356diff -N gdb/testsuite/gdb.threads/threadcrash.sh
357--- /dev/null 1 Jan 1970 00:00:00 -0000
358+++ ./gdb/testsuite/gdb.threads/threadcrash.sh 31 Oct 2006 17:54:38 -0000
359@@ -0,0 +1,324 @@
360+#! /bin/bash
361+
362+# NOTE: threadcrash.c *must* be built with debugging symbols
363+#
364+# The point of this shell script is to crash treadcrash.c, load the
365+# resulting core file into gdb and verify that gdb can extract enough
366+# information from the core file.
367+#
368+# The return code from this script is the number of failed tests.
369+
370+LOG=gdbresult.log
371+
372+if [ $# = 0 ] ; then
373+ echo >&2 Syntax: $0 \<name of threadcrash binary\> [\<gdb binary\> \<args...\>]
374+ exit 1
375+fi
376+RUNME="$1"
377+shift
378+GDB="${*:-gdb}"
379+
380+
381+pf_prefix=""
382+function pf_prefix() {
383+ pf_prefix="$*"
384+}
385+
386+set_test=""
387+function set_test() {
388+ if [ -n "$set_test" ] ; then
389+ echo >&2 "DEJAGNU-BASH ERROR: set_test already set"
390+ exit 1
391+ fi
392+ set_test="$*"
393+ if [ -n "$pf_prefix" ] ; then
394+ set_test="$pf_prefix: $set_test"
395+ fi
396+}
397+
398+# INTERNAL
399+function record_test {
400+ if [ -z "$set_test" ] ; then
401+ echo >&2 "DEJAGNU-BASH ERROR: set_test not set"
402+ exit 1
403+ fi
404+ # Provide the leading whitespace delimiter:
405+ echo " $1: $set_test"
406+ set_test=""
407+}
408+
409+function pass() {
410+ record_test PASS
411+}
412+function fail() {
413+ record_test FAIL
414+}
415+
416+
417+# Verify that the gdb output doesn't contain $1.
418+function mustNotHave() {
419+ local BADWORD=$1
420+ set_test gdb output contains "$BADWORD"
421+ if grep -q "$BADWORD" $LOG ; then
422+ fail
423+ return 1
424+ fi
425+ pass
426+ return 0
427+}
428+
429+# Verify that the gdb output contains exactly $1 $2s.
430+function mustHaveCorrectAmount() {
431+ local WANTEDNUMBER=$1
432+ local GOODWORD=$2
433+ local ACTUALNUMBER=$(grep "$GOODWORD" $LOG | wc -l)
434+ set_test gdb output contained $ACTUALNUMBER \""$GOODWORD"\", not $WANTEDNUMBER as expected
435+ if [ $ACTUALNUMBER != $WANTEDNUMBER ] ; then
436+ fail
437+ return 1
438+ fi
439+ pass
440+ return 0
441+}
442+
443+# Verify that the gdb output contains seven threads
444+function mustHaveSevenThreads() {
445+ NTHREADS=$(egrep "^Thread [1-7] \(" $LOG | wc -l)
446+ set_test gdb output contains $NTHREADS threads, not 7 as expected
447+ if [ $NTHREADS != 7 ] ; then
448+ fail
449+ return 1
450+ fi
451+ pass
452+ return 0
453+}
454+
455+# Verify that the gdb output has all parameters on consecutive lines
456+function mustHaveSequence() {
457+ SEQUENCE="$*"
458+ NPARTS=$#
459+ grep "$1" -A$((NPARTS - 1)) $LOG > matches.log
460+
461+ while [ $# -gt 1 ] ; do
462+ shift
463+ ((NPARTS--))
464+ grep "$1" -A$((NPARTS - 1)) matches.log > temp.log
465+ mv temp.log matches.log
466+ done
467+ LASTPART=$1
468+
469+ set_test gdb output does not contain the sequence: $SEQUENCE
470+ if ! grep -q "$LASTPART" matches.log ; then
471+ fail
472+ return 1
473+ fi
474+ pass
475+ return 0
476+}
477+
478+# Verify that $LOG contains all information we want
479+function verifyLog() {
480+ local FAILURES=0
481+
482+ mustNotHave '??' || ((FAILURES++))
483+ mustHaveCorrectAmount 12 threadcrash.c: || ((FAILURES++))
484+
485+ mustHaveSevenThreads || ((FAILURES++))
486+ mustHaveSequence sleep "makeSyscall (ignored=" || ((FAILURES++))
487+
488+ mustHaveSequence sleep "syscallingSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
489+ mustHaveSequence pthread_kill "makeSyscallFromSighandler (ignored=" || ((FAILURES++))
490+
491+ mustHaveSequence sleep "syscallingAltSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
492+ mustHaveSequence pthread_kill "makeSyscallFromAltSighandler (ignored=" || ((FAILURES++))
493+
494+ mustHaveSequence Thread "spin (ignored=" || ((FAILURES++))
495+
496+ mustHaveSequence "spinningSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
497+ mustHaveSequence pthread_kill "spinFromSighandler (ignored=" || ((FAILURES++))
498+
499+ mustHaveSequence "spinningAltSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
500+ mustHaveSequence pthread_kill "spinFromAltSighandler (ignored=" || ((FAILURES++))
501+
502+ mustHaveSequence Thread "main (argc=1, argv=" || ((FAILURES++))
503+
504+ return $FAILURES
505+}
506+
507+# Put result of debugging a core file in $LOG
508+function getLogFromCore() {
509+ # Make sure we get a core file
510+ set_test Make sure we get a core file
511+ if ! ulimit -c unlimited ; then
512+ fail
513+ exit 1
514+ fi
515+ pass
516+
517+ # Run the crasher
518+ ./$(basename "$RUNME")
519+ EXITCODE=$?
520+
521+ # Verify that we actually crashed
522+ set_test $RUNME should have been killed by a signal, got non-signal exit code $EXITCODE
523+ if [ $EXITCODE -lt 128 ] ; then
524+ fail
525+ exit 1
526+ fi
527+ pass
528+
529+ # Verify that we got a core file
530+ set_test $RUNME did not create a core file
531+ if [ ! -r core* ] ; then
532+ fail
533+ exit 1
534+ fi
535+ pass
536+
537+ # Run gdb
538+ cat > gdbscript.gdb <<EOF
539+set width 0
540+t a a bt 100
541+quit
542+EOF
543+ cat gdbscript.gdb /dev/zero | $GDB -nx "./$(basename "$RUNME")" core* > $LOG
544+ EXITCODE=$?
545+
546+ set_test gdb exited with error code
547+ if [ $EXITCODE != 0 ] ; then
548+ ((FAILURES++))
549+ echo >&2 gdb exited with error code $EXITCODE
550+ fail
551+ fi
552+ pass
553+}
554+
555+# Put result of debugging a gcore file in $LOG
556+function getLogFromGcore() {
557+ # Create the core file
558+ rm -f core*
559+ cat > gdbscript.gdb <<EOF
560+handle SIGQUIT pass noprint nostop
561+handle SIGUSR1 pass noprint nostop
562+handle SIGUSR2 pass noprint nostop
563+handle SIGALRM pass noprint nostop
564+run
565+gcore
566+quit
567+EOF
568+ cat gdbscript.gdb /dev/zero | $GDB -nx "./$(basename "$RUNME")" > /dev/null
569+ EXITCODE=$?
570+
571+ set_test gdb exited with error code when creating gcore file
572+ if [ $EXITCODE != 0 ] ; then
573+ ((FAILURES++))
574+ echo >&2 gdb exited with error code $EXITCODE when creating gcore file
575+ fail
576+ fi
577+ pass
578+
579+ # Verify that we got a core file from gcore
580+ set_test gdb gcore did not create a core file
581+ if [ ! -r core* ] ; then
582+ fail
583+ exit 1
584+ fi
585+ pass
586+
587+ # Run gdb on the gcore file
588+ cat > gdbscript.gdb <<EOF
589+set width 0
590+t a a bt 100
591+quit
592+EOF
593+ cat gdbscript.gdb /dev/zero | $GDB -nx "./$(basename "$RUNME")" core* > $LOG
594+ EXITCODE=$?
595+
596+ set_test gdb exited with error code when examining gcore file
597+ if [ $EXITCODE != 0 ] ; then
598+ ((FAILURES++))
599+ echo >&2 gdb exited with error code $EXITCODE when examining gcore file
600+ fail
601+ fi
602+ pass
603+}
604+
605+# Put result of debugging a core file in $LOG
606+function getLogFromLiveProcess() {
607+ # Run gdb
608+ cat > gdbscript.gdb <<EOF
609+handle SIGQUIT pass noprint nostop
610+handle SIGUSR1 pass noprint nostop
611+handle SIGUSR2 pass noprint nostop
612+handle SIGALRM pass noprint nostop
613+set width 0
614+run
615+t a a bt 100
616+quit
617+EOF
618+ cat gdbscript.gdb /dev/zero | $GDB -nx "./$(basename "$RUNME")" > $LOG
619+ EXITCODE=$?
620+
621+ set_test gdb exited with error code
622+ if [ $EXITCODE != 0 ] ; then
623+ ((FAILURES++))
624+ echo >&2 gdb exited with error code $EXITCODE
625+ fail
626+ fi
627+ pass
628+}
629+
630+####### Main program follows #####################
631+
632+# Make sure we don't clobber anybody else's (core) file(s)
633+WORKDIR=/tmp/$PPID
634+mkdir -p $WORKDIR
635+cp "$RUNME" $WORKDIR
636+cd $WORKDIR
637+
638+# Count problems
639+FAILURES=0
640+
641+echo === Testing gdb vs core file...
642+pf_prefix core file
643+getLogFromCore
644+verifyLog
645+((FAILURES+=$?))
646+pf_prefix
647+echo === Core file tests done.
648+
649+echo
650+
651+echo === Testing gdb vs gcore file...
652+pf_prefix gcore file
653+getLogFromGcore
654+verifyLog
655+((FAILURES+=$?))
656+pf_prefix
657+echo === Gcore file tests done.
658+
659+echo
660+
661+echo === Testing gdb vs live process...
662+pf_prefix live process
663+getLogFromLiveProcess
664+verifyLog
665+((FAILURES+=$?))
666+pf_prefix
667+echo === Live process tests done.
668+
669+# Executive summary
670+echo
671+if [ $FAILURES == 0 ] ; then
672+ echo All tests passed!
673+else
674+ echo $FAILURES tests failed!
675+ echo
676+ echo Make sure the threadcrash binary contains debugging information \(build with \"gcc -g\"\).
677+fi
678+
679+# Clean up
680+cd /
681+rm -rf $WORKDIR
682+
683+exit $FAILURES
684Index: ./gdb/testsuite/gdb.threads/threadcrash.sh-orig
685===================================================================
686RCS file: gdb/testsuite/gdb.threads/threadcrash.sh-orig
687diff -N gdb/testsuite/gdb.threads/threadcrash.sh-orig
688--- /dev/null 1 Jan 1970 00:00:00 -0000
689+++ ./gdb/testsuite/gdb.threads/threadcrash.sh-orig 31 Oct 2006 17:54:38 -0000
690@@ -0,0 +1,248 @@
691+#! /bin/bash
692+
693+# NOTE: threadcrash.c *must* be built with debugging symbols
694+#
695+# The point of this shell script is to crash treadcrash.c, load the
696+# resulting core file into gdb and verify that gdb can extract enough
697+# information from the core file.
698+#
699+# The return code from this script is the number of failed tests.
700+
701+LOG=gdbresult.log
702+
703+if [ $# != 1 ] ; then
704+ echo > /dev/stderr Syntax: $0 \<name of threadcrash binary\>
705+ exit 1
706+fi
707+RUNME="$1"
708+
709+# Verify that the gdb output doesn't contain $1.
710+function mustNotHave() {
711+ local BADWORD=$1
712+ if grep -q "$BADWORD" $LOG ; then
713+ echo >> /dev/stderr WARNING: gdb output contains "$BADWORD"
714+ return 1
715+ fi
716+ return 0
717+}
718+
719+# Verify that the gdb output contains exactly $1 $2s.
720+function mustHaveCorrectAmount() {
721+ local WANTEDNUMBER=$1
722+ local GOODWORD=$2
723+ local ACTUALNUMBER=$(grep "$GOODWORD" $LOG | wc -l)
724+ if [ $ACTUALNUMBER != $WANTEDNUMBER ] ; then
725+ echo >> /dev/stderr WARNING: gdb output contained $ACTUALNUMBER \""$GOODWORD"\", not $WANTEDNUMBER as expected
726+ return 1
727+ fi
728+ return 0
729+}
730+
731+# Verify that the gdb output contains seven threads
732+function mustHaveSevenThreads() {
733+ NTHREADS=$(egrep "^Thread [1-7] \(" $LOG | wc -l)
734+ if [ $NTHREADS != 7 ] ; then
735+ echo >> /dev/stderr WARNING: gdb output contains $NTHREADS threads, not 7 as expected
736+ return 1
737+ fi
738+ return 0
739+}
740+
741+# Verify that the gdb output has all parameters on consecutive lines
742+function mustHaveSequence() {
743+ SEQUENCE="$*"
744+ NPARTS=$#
745+ grep "$1" -A$((NPARTS - 1)) $LOG > matches.log
746+
747+ while [ $# -gt 1 ] ; do
748+ shift
749+ ((NPARTS--))
750+ grep "$1" -A$((NPARTS - 1)) matches.log > temp.log
751+ mv temp.log matches.log
752+ done
753+ LASTPART=$1
754+
755+ if ! grep -q "$LASTPART" matches.log ; then
756+ echo >> /dev/stderr WARNING: gdb output does not contain the sequence: $SEQUENCE
757+ return 1
758+ fi
759+ return 0
760+}
761+
762+# Verify that $LOG contains all information we want
763+function verifyLog() {
764+ local FAILURES=0
765+
766+ mustNotHave '??' || ((FAILURES++))
767+ mustHaveCorrectAmount 12 threadcrash.c: || ((FAILURES++))
768+
769+ mustHaveSevenThreads || ((FAILURES++))
770+ mustHaveSequence sleep "makeSyscall (ignored=" || ((FAILURES++))
771+
772+ mustHaveSequence sleep "syscallingSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
773+ mustHaveSequence pthread_kill "makeSyscallFromSighandler (ignored=" || ((FAILURES++))
774+
775+ mustHaveSequence sleep "syscallingAltSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
776+ mustHaveSequence pthread_kill "makeSyscallFromAltSighandler (ignored=" || ((FAILURES++))
777+
778+ mustHaveSequence Thread "spin (ignored=" || ((FAILURES++))
779+
780+ mustHaveSequence "spinningSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
781+ mustHaveSequence pthread_kill "spinFromSighandler (ignored=" || ((FAILURES++))
782+
783+ mustHaveSequence "spinningAltSighandler (signo=" "signal handler called" 0x || ((FAILURES++))
784+ mustHaveSequence pthread_kill "spinFromAltSighandler (ignored=" || ((FAILURES++))
785+
786+ mustHaveSequence Thread "main (argc=1, argv=" || ((FAILURES++))
787+
788+ return $FAILURES
789+}
790+
791+# Put result of debugging a core file in $LOG
792+function getLogFromCore() {
793+ # Make sure we get a core file
794+ ulimit -c unlimited || exit 1
795+
796+ # Run the crasher
797+ ./$(basename "$RUNME")
798+ EXITCODE=$?
799+
800+ # Verify that we actually crashed
801+ if [ $EXITCODE -lt 128 ] ; then
802+ echo >> /dev/stderr ERROR: $RUNME should have been killed by a signal, got non-signal exit code $EXITCODE
803+ exit 1
804+ fi
805+
806+ # Verify that we got a core file
807+ if [ ! -r core* ] ; then
808+ echo >> /dev/stderr ERROR: $RUNME did not create a core file
809+ exit 1
810+ fi
811+
812+ # Run gdb
813+ cat > gdbscript.gdb <<EOF
814+set width 0
815+t a a bt 100
816+quit
817+EOF
818+ cat gdbscript.gdb /dev/zero | gdb -nx "./$(basename "$RUNME")" core* > $LOG
819+ EXITCODE=$?
820+
821+ if [ $EXITCODE != 0 ] ; then
822+ ((FAILURES++))
823+ echo >> /dev/stderr WARNING: gdb exited with error code $EXITCODE
824+ fi
825+}
826+
827+# Put result of debugging a gcore file in $LOG
828+function getLogFromGcore() {
829+ # Create the core file
830+ rm -f core*
831+ cat > gdbscript.gdb <<EOF
832+handle SIGQUIT pass noprint nostop
833+handle SIGUSR1 pass noprint nostop
834+handle SIGUSR2 pass noprint nostop
835+handle SIGALRM pass noprint nostop
836+run
837+gcore
838+quit
839+EOF
840+ cat gdbscript.gdb /dev/zero | gdb -nx "./$(basename "$RUNME")" > /dev/null
841+ EXITCODE=$?
842+
843+ if [ $EXITCODE != 0 ] ; then
844+ ((FAILURES++))
845+ echo >> /dev/stderr WARNING: gdb exited with error code $EXITCODE when creating gcore file
846+ fi
847+
848+ # Verify that we got a core file from gcore
849+ if [ ! -r core* ] ; then
850+ echo >> /dev/stderr ERROR: gdb gcore did not create a core file
851+ exit 1
852+ fi
853+
854+ # Run gdb on the gcore file
855+ cat > gdbscript.gdb <<EOF
856+set width 0
857+t a a bt 100
858+quit
859+EOF
860+ cat gdbscript.gdb /dev/zero | gdb -nx "./$(basename "$RUNME")" core* > $LOG
861+ EXITCODE=$?
862+
863+ if [ $EXITCODE != 0 ] ; then
864+ ((FAILURES++))
865+ echo >> /dev/stderr WARNING: gdb exited with error code $EXITCODE when examining gcore file
866+ fi
867+}
868+
869+# Put result of debugging a core file in $LOG
870+function getLogFromLiveProcess() {
871+ # Run gdb
872+ cat > gdbscript.gdb <<EOF
873+handle SIGQUIT pass noprint nostop
874+handle SIGUSR1 pass noprint nostop
875+handle SIGUSR2 pass noprint nostop
876+handle SIGALRM pass noprint nostop
877+set width 0
878+run
879+t a a bt 100
880+quit
881+EOF
882+ cat gdbscript.gdb /dev/zero | gdb -nx "./$(basename "$RUNME")" > $LOG
883+ EXITCODE=$?
884+
885+ if [ $EXITCODE != 0 ] ; then
886+ ((FAILURES++))
887+ echo >> /dev/stderr WARNING: gdb exited with error code $EXITCODE
888+ fi
889+}
890+
891+####### Main program follows #####################
892+
893+# Make sure we don't clobber anybody else's (core) file(s)
894+WORKDIR=/tmp/$PPID
895+mkdir -p $WORKDIR
896+cp "$RUNME" $WORKDIR
897+cd $WORKDIR
898+
899+# Count problems
900+FAILURES=0
901+
902+echo === Testing gdb vs core file...
903+getLogFromCore
904+verifyLog
905+((FAILURES+=$?))
906+echo === Core file tests done.
907+
908+echo
909+
910+echo === Testing gdb vs gcore file...
911+getLogFromGcore
912+verifyLog
913+((FAILURES+=$?))
914+echo === Gcore file tests done.
915+
916+echo
917+
918+echo === Testing gdb vs live process...
919+getLogFromLiveProcess
920+verifyLog
921+((FAILURES+=$?))
922+echo === Live process tests done.
923+
924+# Executive summary
925+echo
926+if [ $FAILURES == 0 ] ; then
927+ echo All tests passed!
928+else
929+ echo $FAILURES tests failed!
930+ echo
931+ echo Make sure the threadcrash binary contains debugging information \(build with \"gcc -g\"\).
932+fi
933+
934+# Clean up
935+cd /
936+rm -rf $WORKDIR
937+
938+exit $FAILURES
This page took 0.709453 seconds and 4 git commands to generate.