1# Copyright (C) 1996, 1997, 2002, 2003, 2007 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16# Please email any bugs, comments, and/or additions to this file to: 17# bug-gdb@prep.ai.mit.edu 18 19# This file was written by Daniel Jacobowitz <drow@mvista.com> 20# (parts based on pthreads.exp by Fred Fish (fnf@cygnus.com). 21# 22# It tests miscellaneous actions with multiple threads, including 23# handling for thread exit. 24 25if $tracelevel then { 26 strace $tracelevel 27} 28 29set prms_id 0 30set bug_id 0 31 32set testfile "print-threads" 33set srcfile ${testfile}.c 34set binfile ${objdir}/${subdir}/${testfile} 35 36# regexp for "horizontal" text (i.e. doesn't include newline or 37# carriage return) 38set horiz "\[^\n\r\]*" 39 40if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } { 41 return -1 42} 43 44# Now we can proceed with the real testing. 45 46# Start with a fresh gdb. 47 48gdb_exit 49gdb_start 50gdb_reinitialize_dir $srcdir/$subdir 51gdb_load ${binfile} 52 53gdb_test "set print sevenbit-strings" "" 54#gdb_test "set print address off" "" 55gdb_test "set width 0" "" 56 57# We'll need this when we send_gdb a ^C to GDB. Need to do it before we 58# run the program and gdb starts saving and restoring tty states. 59# On Ultrix, we don't need it and it is really slow (because shell_escape 60# doesn't use vfork). 61if ![istarget "*-*-ultrix*"] then { 62 gdb_test "shell stty intr '^C'" "" 63} 64 65proc test_all_threads { name kill } { 66 global gdb_prompt 67 68 set i 0 69 set j 0 70 send_gdb "continue\n" 71 gdb_expect { 72 -re "Breakpoint \[0-9\]+, thread_function \\(arg=.*\\) at .*print-threads.c:\[0-9\]+.*$gdb_prompt" { 73 set i [expr $i + 1] 74 pass "Hit thread_function breakpoint, $i ($name)" 75 send_gdb "continue\n" 76 exp_continue 77 } 78 -re "Breakpoint \[0-9\]+, .* kill \\(.*\\) .*$gdb_prompt" { 79 set j [expr $j + 1] 80 if { $kill == 1 } { 81 pass "Hit kill breakpoint, $j ($name)" 82 } else { 83 fail "Hit kill breakpoint, $j ($name) (unexpected)" 84 } 85 send_gdb "continue\n" 86 exp_continue 87 } 88 -re "Program exited normally\\.\[\r\n\]+$gdb_prompt" { 89 pass "program exited normally" 90 if {$i == 5} { 91 pass "all threads ran once ($name)" 92 } else { 93 fail "all threads ran once ($name) (total $i threads ran)" 94 } 95 } 96 -re "Program received signal SIGTRAP.*(Thread \[-0-9a-fx\]* \\(zombie\\)|0x00000000 in ).*$gdb_prompt $" { 97 if { $kill == 1 } { 98 kfail "gdb/1265" "Running threads ($name) (zombie thread)" 99 } else { 100 fail "Running threads ($name) (unknown output)" 101 } 102 } 103 -re "$gdb_prompt" { 104 fail "Running threads ($name) (unknown output)" 105 } 106 timeout { 107 fail "Running threads ($name) (timeout)" 108 } 109 } 110} 111 112runto_main 113gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." 114gdb_test "set var slow = 0" "" 115test_all_threads "fast" 0 116 117runto_main 118gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (2)" 119gdb_test "set var slow = 1" "" 120test_all_threads "slow" 0 121 122runto_main 123gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (3)" 124gdb_test "set var slow = 1" "" "set var slow = 1 (2)" 125gdb_breakpoint "kill" 126test_all_threads "slow with kill breakpoint" 1 127 128return 0 129