1 # quicksort.exp -- Expect script to test gdb with quicksort.c
2 # Copyright (C) 1992 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
29 if { ![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"] } {
30 verbose "HPUX thread test ignored for non-hppa or pre-HP/UX-10.30 targets."
34 set testfile quicksort
35 set srcfile ${srcdir}/${subdir}/${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
38 if [get_compiler_info ${binfile}] {
42 # To build the executable we need to link against the thread library.
44 # cc -Ae -g -o quicksort -lpthread quicksort.c
46 #compile "${srcfile} -Ae -g -lpthread -o ${binfile}"
48 if {$gcc_compiled == 0} {
49 set additional_flags "additional_flags=-Ae"
51 set additional_flags ""
54 if { [gdb_compile "${srcdir}/${subdir}/${testfile}.c" "${binfile}.o" object [list debug $additional_flags]] != "" } {
55 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
57 remote_exec build "ld /usr/ccs/lib/crt0.o ${binfile}.o -lcl -lpthread -lc /opt/langtools/lib/end.o -o ${binfile}"
60 # Thread stuff is _slow_; prepare for long waits.
62 set oldtimeout $timeout
63 set timeout [expr "$timeout + 300"]
64 set oldverbose $verbose
67 # Further, this test has some "null" lines designed
68 # to consume output from gdb that was too late to be
69 # matched (sequence is "gdb_test" sends; timeout and
70 # on to next send; result finally comes in; mismatch).
72 # The null command is 'gdb_test "p \$pc" ".*" ""'
74 # NOTE: to pass a literal "$", "/" or "*" (etc.) to gdb_test,
75 # remember that the pattern will be escaped once and
82 gdb_test "p \$pc" ".*" ""
85 #=========================
87 # Simple sanity test first.
91 gdb_reinitialize_dir $srcdir/$subdir
94 gdb_test "tb 122" ".*Breakpoint.*" ""
95 gdb_test "r" ".*122.*" ""
96 gdb_test "thr 99" ".*Thread ID 99 not known.*" "Check too-big thread number"
97 gdb_test "tb 145 thr 3" ".*Breakpoint.*" "set thread-specific bp 145"
98 gdb_test "tb 146 thr 4" ".*Breakpoint.*" "set thread-specific bp 146"
99 gdb_test "c" ".*Switched to thread.*145.*" "auto switch"
100 gdb_test "c" ".*Switched to thread.*146.*" "auto switch 2"
101 gdb_test "c" ".*Program exited normally.*" ""
103 #=========================
105 # Test that you can't do a thread select after a program runs.
107 gdb_test "thread" ".*No stack.*" "No live thread after run"
108 gdb_test "thr 2" ".*No stack.*" "Can't set thread after run"
110 #=========================
112 # Test thread command changes, look for frame level reset bug.
116 gdb_reinitialize_dir $srcdir/$subdir
118 gdb_test "b 122" ".*" ""
119 gdb_test "r" ".*122.*" ""
121 # Prep for frame level test--go up/info thread/check frame
123 gdb_test "up" ".*quick_sort.*" ""
124 gdb_test "up" ".*main.*" ""
128 -re ".*7 thread.* in .* from .* in .* from .* 6 thread.*$gdb_prompt $" {
129 fail "old thread command, says things twice"
131 -re ".*7 system thread.*6 system th.*5 sys.*4.*3.*2.*1.*work_init.*$gdb_prompt $" {
134 -re ".*$gdb_prompt $" { fail "no info thread command" }
135 timeout { fail "timeout" }
138 # We should have been restored two frames up--check.
142 -re ".*Initial frame selected.*$gdb_prompt $" {
143 pass "Frame correctly reset after 'info threads'"
145 -re ".*quick_sort.*$gdb_prompt $" {
146 fail "Old gdb bug; should be fixed someday"
148 -re ".*$gdb_prompt $" {
149 fail "real bug--FIX!"
151 timeout { fail "timeout" }
154 # Do it again, only just go to a middle frame, and use another thread.
156 gdb_test "thr 5" ".*" ""
157 gdb_test "bt" ".* ___ksleep.*_lwp_cond_timedwait.*pthread_cond_wait.*worker.*__pthread_create_system.*" ""
158 gdb_test "up" ".*1.*_lwp_cond_timedwait.*" ""
159 gdb_test "up" ".*2.*pthread_cond_wait.*" ""
160 gdb_test "up" ".*3.*worker.*" ""
161 gdb_test "i th" ".*7.*6.*work_init.*" ""
162 gdb_test "f" ".*3.*worker.*" "Frame restored"
163 gdb_test "p wp->max_pile" ".*= 128.*" "can see vars in frame"
165 # Thread command changes
167 gdb_test "thr" ".*Current thread is 5.*" "threads-no-num"
168 gdb_test "thr 6" ".*Switching to thread 6.*" "new switch"
169 gdb_test "thr" ".*Current thread is 6.*" "check switch"
170 #gdb_test "thr 6" ".*Current thread is already 6.*" "dup, no switch"
171 gdb_test "thr app all p x" ".*No symbol.*" ""
172 gdb_test "thr" ".*Current thread is 6.*" "restore current thread"
174 #=========================
190 -re ".*Breakpoint.*145.*$gdb_prompt $" {
193 -re ".*is 7.*$gdb_prompt $" {
194 set hit7 [expr "$hit7 + 1"]
196 -re ".*is 6.*$gdb_prompt $" {
197 set hit6 [expr "$hit6 + 1"]
199 -re ".*is 5.*$gdb_prompt $" {
200 set hit5 [expr "$hit5 + 1"]
202 -re ".*is 4.*$gdb_prompt $" {
203 set hit4 [expr "$hit4 + 1"]
205 -re ".*is 3.*$gdb_prompt $" {
206 set hit3 [expr "$hit3 + 1"]
208 -re ".*is 2.*$gdb_prompt $" {
209 set hit2 [expr "$hit2 + 1"]
211 -re ".*$gdb_prompt $" {
212 fail "can't see which thread"
214 timeout { fail "timeout" }
217 -re ".*$gdb_prompt $" {
218 fail "thread command"
220 timeout { fail "timeout" }
226 gdb_reinitialize_dir $srcdir/$subdir
228 gdb_test "break 122" ".*" ""
229 gdb_test "run" ".*122.*" ""
231 # Make sure we hit a bp on every thread.
233 # Try one, via thread-specific bps
235 gdb_test "break 145 thr 2" ".*" "set thread-specific bp thr 2"
236 gdb_test "break 145 thr 3" ".*" "set thread-specific bp thr 3"
237 gdb_test "break 145 thr 4" ".*" "set thread-specific bp thr 4"
238 gdb_test "break 145 thr 5" ".*" "set thread-specific bp thr 5"
239 gdb_test "break 145 thr 6" ".*" "set thread-specific bp thr 6"
240 gdb_test "break 145 thr 7" ".*" "set thread-specific bp thr 7"
256 if { [expr "$hit2 == 1"]
257 && [expr "$hit3 == 1"]
258 && [expr "$hit4 == 1"]
259 && [expr "$hit5 == 1"]
260 && [expr "$hit6 == 1"]
261 && [expr "$hit7 == 1"] } {
262 pass "thread-specific bps 1"
264 fail "thread-specific bps 1"
267 #====================
269 # Now use generic bps
273 gdb_reinitialize_dir $srcdir/$subdir
275 gdb_test "b 122" ".*" ""
276 gdb_test "r" ".*122.*" ""
278 # Make sure we hit a bp on every thread.
280 # Try two, via non-thread-specific bp
282 gdb_test "b 145" ".*" "b 145"
298 if { [expr "$hit2 == 1"]
299 && [expr "$hit3 == 1"]
300 && [expr "$hit4 == 1"]
301 && [expr "$hit5 == 1"]
302 && [expr "$hit6 == 1"]
303 && [expr "$hit7 == 1"] } {
304 pass "thread-specific bps 2"
306 fail "thread-specific bps 2"
309 #====================
311 # Complicated (original) test next.
315 gdb_reinitialize_dir $srcdir/$subdir
318 if ![runto_main] then {
319 fail "Can't run to main"
323 # OK, we're at "main", there should be one thread.
325 gdb_test "info thread" ".*\\\* 1 system thread .*main.*" "initial thread"
327 # Try to see the threads being created: set a breakpoint
328 # after the creation and go around the loop a few times.
330 gdb_test "break 109" "Breakpoint.*109.*" "set bpt"
332 gdb_test "c" ".*New thread.*Breakpoint.*109.*" "first continue"
335 # Make sure we don't wait (waiting is for attach test)
337 gdb_test "set wait_here = 0" ".*" ""
339 send_gdb "info thr\n"
341 -re ".*2 system th.*1 sy.*109.*$gdb_prompt $" { pass "saw thread create" }
342 -re ".*1 system thread.*87.*$gdb_prompt $" { fail "didn't see thread create" }
343 -re ".*$gdb_prompt $" { fail "no info thread command" }
344 timeout { fail "timeout" }
347 gdb_test "c" ".*New thread.*Breakpoint.*109.*" "continue"
350 send_gdb "info thr\n"
352 -re ".*3 system thread.*2 sys.*\\\* 1 system thread.*109.*$gdb_prompt $" {
353 pass "saw thread create" }
354 -re ".*2 system thread.*1 sys.*109.*$gdb_prompt $" {
355 fail "didn't see thread create"
357 -re ".*1 system thread.*109.*$gdb_prompt $" {
358 fail "didn't see thread create"
360 -re ".*$gdb_prompt $" {
361 fail "no info thread command"
363 timeout { fail "timeout" }
367 gdb_test "clear" ".*Deleted breakpoint.*" ""
369 # Now go on to the end of thread creation.
371 gdb_test "b 122" ".*" "set bpt 122"
372 gdb_test "c" ".*New thread.*New thread.*New thread.*122.*" ""
373 gdb_test "p \$pc" ".*" ""
374 gdb_test "clear" ".*Deleted breakpoint.*" ""
376 send_gdb "info thr\n"
378 -re ".*7 system thread.*6 sys.*5.*1 system thread.*122.*$gdb_prompt $"
379 { pass "saw thread creates" }
380 -re ".*$gdb_prompt $"
381 { fail "no info thread command" }
382 timeout { fail "timeout" }
385 # Try a thread-specific breakpoint; we expect the other threads to
386 # be waiting at this point.
388 gdb_test "thr 3" ".*Switching to thread.*ksleep.*" "thread switch"
389 gdb_test "i th" ".*\\\* 3 system thread.*" "show new current thread"
391 gdb_test "up" ".*lwp_cond_timedwait.*" ""
392 gdb_test "up" ".*pthread_cond_wait.*" ""
393 gdb_test "up" ".*worker.*144.*" ""
395 gdb_test "b 145 th 3" ".*Breakpoint.*145.*" "set thread-specific bp"
396 gdb_test "i b" ".*breakpoint.*breakpoint.*145 thread 3.*" "show thread-specific bp"
398 gdb_test "c" ".*Breakpoint.*145.*145.*" "hit thread-specific bp"
399 gdb_test "p \$pc" ".*" ""
401 # Test thread apply command on thread specific data.
403 gdb_test "thre app all p \$pc" ".*Thread 7.*Thread 6.*Thread 5.*Thread 4.*Thread 3.*Thread 2.*Thread 1.*" "thread apply all"
404 gdb_test "thr ap 1 3 5 p \$pc" ".*Thread 1.*Thread 3.*Thread 5.*" "thr app 1 3 5"
406 # Switch again, and test that others continue on a "next"
407 # This test _could_ fail due to timing issues, but that's
410 gdb_test "thr 7" ".*Switching to thread.*" ""
412 # Make sure that "up" stops at __pthread_exit, or
413 # __pthread_create, the pseudo-roots, and that we
414 # only see that pseudo-root once.
418 -re ".*Error accessing memory address.*" { fail "bt" }
419 -re ".*pthread_create.*pthread_create.*" { fail "bt" }
420 -re ".*worker.*pthread_create.*" { pass "bt" }
421 -re ".*pthread_exit.*" { pass "bt" }
422 timeout { fail "timeout on bt" }
425 gdb_test "up" ".*" ""
426 gdb_test "up" ".*" ""
427 gdb_test "up" ".*144.*" "Up 3"
428 gdb_test "up" ".*pthread_.*" "Up 4"
429 gdb_test "up" ".*Initial frame selected; you cannot go up.*" "catch end of thread stack"
431 #=====================
433 # Things get iffy here; when we step, sometimes the step
434 # completes, sometimes it doesn't. When it doesn't, we
435 # hit a bp somewhere else and the step never completes
436 # (wait_for_inferior just evaporates it).
438 # I think the right answer is that any failures here
439 # should stick around to trigger later fixing.
443 # Bps at 148 (5) and 154 (6) on thread 7 (two bps so we
444 # see the difference between going around the loop and
445 # reporting the same bp hit twice).
447 # Bp at 144 on thread 3.
449 # Step out of a library routine.
451 # Either the step will finish or a bp will hit. Try to
452 # handle all the cases.
454 gdb_test "b 148 thr 7" ".*Breakpoint.*148.*" ""
455 gdb_test "b 154 thr 7" ".*Breakpoint.*154.*" "set bpt 2"
464 gdb_test "i b" ".*" ""
468 -re ".*Single stepping.*_lwp_cond_timedwait.*$gdb_prompt $" {
471 -re ".*is 7.*$gdb_prompt $" {
473 pass "completed step in library code"
475 -re ".*$gdb_prompt $" {
476 fail "completed step in library code, but in wrong thread"
478 timeout { fail "timeout" }
481 -re ".*Single stepping.*Switched to thread 3.*Breakpoint.*$gdb_prompt $" {
482 pass "step cancelled; hit bp due to thread parallelism"
485 -re ".*Single stepping.*Switched to thread 7.*Breakpoint.*148.*$gdb_prompt $" {
486 pass "step cancelled; hit bp due to thread parallelism"
489 -re ".*Single stepping.*Switched to thread 7.*Breakpoint.*154.*$gdb_prompt $" {
490 pass "step cancelled; hit bp due to thread parallelism"
493 -re ".*$gdb_prompt $" {
496 -re ".*is 7.*$gdb_prompt $" {
499 -re ".*$gdb_prompt $" {
502 timeout { fail "timeout" }
505 timeout { fail "timeout" }
508 # Sometimes used to get SIGTRAP here; that should be fixed
511 # Expect appropriate hits of bpt; too much work to parse
512 # result and check...
514 gdb_test "i b" ".*" ""
518 -re ".*SIGTRAP.*$gdb_prompt $" {
521 -re ".*Switched to thread 7.*Breakpoint.*154.*$gdb_prompt $" {
522 if { $hit_154_bp == 1 } {
525 pass "continue; hit parallel event after continue"
529 -re ".*Switched to thread 7.*Breakpoint.*148.*$gdb_prompt $" {
530 if { $hit_148_bp == 1 } {
533 pass "continue; hit parallel event after continue"
537 -re ".*Breakpoint.*154.*$gdb_prompt $" {
538 if { $hit_154_bp == 1 } {
543 -re ".*is 7.*$gdb_prompt $" {
544 pass "continue; hit parallel event after continue"
546 -re ".*$gdb_prompt $" {
547 fail "hit bp in wrong thread"
549 timeout { fail "timeout" }
554 -re ".*Breakpoint.*148.*$gdb_prompt $" {
555 if { $hit_148_bp == 1 } {
560 -re ".*is 7.*$gdb_prompt $" {
561 pass "continue; hit parallel event after continue"
563 -re ".*$gdb_prompt $" {
564 fail "hit bp in wrong thread"
566 timeout { fail "timeout" }
571 -re ".*Breakpoint.*145.*$gdb_prompt $" {
572 if { $hit_145_bp == 1 } {
577 -re ".*is 3.*$gdb_prompt $" {
578 pass "continue; hit parallel event after continue"
580 -re ".*$gdb_prompt $" {
581 fail "hit bp in wrong thread"
583 timeout { fail "timeout" }
588 -re ".*_lwp_cond_timedwait.*$gdb_prompt $" {
589 pass "continue; hit step completion after continue"
591 -re ".*Program exited normally.*" {
592 fail "Program ended? HOW?"
594 -re ".*$gdb_prompt $" {
595 fail "Unexpected event"
597 timeout { fail "timeout" }
600 # There are a number of places we _could_ be now;
601 # this is the price of really running in parallel.
605 -re ".*Switched to thread 7.*pthread_cond_wait.*$gdb_prompt $" {
606 if { $step_completed } {
607 fail "step already completed"
612 -re ".*pthread_cond_wait.*$gdb_prompt $" {
614 # Unlikely, but we might finish the range step from inside
615 # ksleep, before anything else.
617 if { $step_completed } {
618 fail "step already completed"
622 -re ".*is 7.*$gdb_prompt $" {
625 -re ".*$gdb_prompt $" {
626 fail "step in wrong thread"
628 timeout { fail "timeout" }
632 -re ".*Switched to thread.*Breakpoint.*145.*$gdb_prompt $" {
633 pass "auto-switch thread"
635 -re ".*Breakpoint.*145.*$gdb_prompt $" {
636 pass "auto-switch not needed, ok"
638 -re ".*140.*while.*n_pile.*$gdb_prompt $" {
640 # This is just going around the loop from the 154 bp.
644 -re ".*is 7.*$gdb_prompt $" {
647 -re ".*$gdb_prompt $" {
648 fail "step in wrong thread"
650 timeout { fail "timeout" }
653 -re ".*149.*ptr = wp.*pile.*$gdb_prompt $" {
655 # This is just going around the loop from the 148 bp.
660 -re ".*is 7.*$gdb_prompt $" {
663 -re ".*$gdb_prompt $" {
664 fail "step in wrong thread"
666 timeout { fail "timeout" }
669 pass "step from 149 but didn't hit it first"
672 -re ".*Breakpoint 5.*154.*$gdb_prompt $" {
673 gdb_test "i b" ".*" ""
680 -re ".*Breakpoint 5.*148.*$gdb_prompt $" {
681 gdb_test "i b" ".*" ""
688 -re ".*$gdb_prompt $" {
689 fail "no step finished"
691 timeout { fail "timeout on 'next'" }
694 # Let's get into some kind of known state again.
696 gdb_test "thr 7" ".*" ""
697 gdb_test "info thread" ".*" ""
698 #gdb_test "i b" ".*" ""
700 # Leave breakpoint "154 thr 7" as only live bp.
702 gdb_test "d 1" ".*" "del main bp"
703 gdb_test "d 4" ".*" "thread-specific bpt delete"
704 gdb_test "d 5" ".*" "other bp delete"
707 -re ".*breakpoint.*breakpoint.*$gdb_prompt $" {
708 fail "more than one bp left"
710 -re ".*breakpoint.*154.*thread.*7.*$gdb_prompt $" {
711 pass "Only one bp left"
713 -re ".*$gdb_prompt $" {
714 fail "Wrong or no bp left"
716 timeout { fail "timeout on info b" }
721 -re ".*SIGTRAP.*Switched to thread.*$gdb_prompt $" {
722 fail "SIGTRAP error; lost thread-specific bpt"
724 -re ".*SIGTRAP.*Switched to thread.*154.*$gdb_prompt $" {
725 fail "SIGTRAP, but hit right thread-specific bpt"
727 -re ".*Switched to thread.*Breakpoint.*154.*$gdb_prompt $" {
728 pass "auto-switch back"
730 -re ".*Breakpoint.*154.*$gdb_prompt $" {
733 -re ".*$gdb_prompt $" {
734 fail "auto-switch back"
736 -re ".*Program exited normally.*$gdb_prompt $" {
745 gdb_test "cle" ".*Deleted breakpoint.*" "delete last breakpoint"
747 # Sometimes get SIGTRAP here. Continue sometimes gets another...
751 -re ".*SIGTRAP.*154.*154.*$gdb_prompt $" {
752 fail "SIGTRAP on deleted bp 154 "
755 -re ".*$gdb_prompt $" { pass "fixup"}
756 timeout { fail "fixup" }
759 -re ".*SIGTRAP.*144.*145.*$gdb_prompt $" {
760 fail "SIGTRAP on deleted bp 145 "
763 -re ".*$gdb_prompt $" { pass "fixup"}
764 timeout { fail "fixup" }
767 -re ".*SIGTRAP.*148.*148.*$gdb_prompt $" {
768 fail "SIGTRAP on deleted bp 148 "
771 -re ".*$gdb_prompt $" { pass "fixup"}
772 timeout { fail "fixup" }
775 -re ".*SIGTRAP.*$gdb_prompt $" {
776 fail "unknown SIGTRAP"
779 -re ".*$gdb_prompt $" { pass "fixup"}
780 timeout { fail "fixup" }
783 -re ".*Program exited.*$gdb_prompt $" {
786 -re ".*$gdb_prompt $" {
790 -re ".*$gdb_prompt $" { pass "fixup"}
791 timeout { fail "fixup" }
794 timeout { fail "timeout" }
797 gdb_test "p \$pc" ".*No registers.*" "program done"
803 set timeout $oldtimeout
804 set verbose $oldverbose
806 # execute_anywhere "rm -f ${binfile}"