1# Copyright (C) 1996-2023 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# This file was written by Daniel Jacobowitz <drow@mvista.com> 17# (parts based on pthreads.exp by Fred Fish (fnf@cygnus.com). 18# 19# It tests miscellaneous actions with multiple threads, including 20# handling for thread exit. 21 22 23standard_testfile 24 25# regexp for "horizontal" text (i.e. doesn't include newline or 26# carriage return) 27set horiz "\[^\n\r\]*" 28 29if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != "" } { 30 return -1 31} 32 33# Now we can proceed with the real testing. 34 35clean_restart ${binfile} 36 37gdb_test_no_output "set print sevenbit-strings" 38#gdb_test_no_output "set print address off" 39gdb_test_no_output "set width 0" 40 41# We'll need this when we send_gdb a ^C to GDB. Need to do it before we 42# run the program and gdb starts saving and restoring tty states. 43gdb_test "shell stty intr '^C'" ".*" 44 45proc test_all_threads { name kill } { 46 global gdb_prompt inferior_exited_re 47 48 with_test_prefix $name { 49 set i 0 50 set j 0 51 gdb_test_multiple "continue" "all threads ran once" { 52 -re "Breakpoint \[0-9\]+, thread_function \\(arg=.*\\) at .*print-threads.c:\[0-9\]+.*$gdb_prompt" { 53 set i [expr $i + 1] 54 pass "hit thread_function breakpoint, $i" 55 send_gdb "continue\n" 56 exp_continue 57 } 58 -re "Breakpoint \[0-9\]+, .* kill \\(.*\\) .*$gdb_prompt" { 59 set j [expr $j + 1] 60 if { $kill == 1 } { 61 pass "hit kill breakpoint, $j" 62 } else { 63 fail "hit kill breakpoint, $j (unexpected)" 64 } 65 send_gdb "continue\n" 66 exp_continue 67 } 68 -re "$inferior_exited_re normally.\[\r\n\]+$gdb_prompt" { 69 pass "program exited normally" 70 if {$i == 5} { 71 pass "all threads ran once" 72 } else { 73 fail "all threads ran once (total $i threads ran)" 74 } 75 } 76 -re " received signal SIGTRAP.*(Thread \[-0-9a-fx\]* \\(zombie\\)|0x00000000 in ).*$gdb_prompt $" { 77 if { $kill == 1 } { 78 kfail "gdb/1265" "Running threads (zombie thread)" 79 } else { 80 fail "running threads (unknown output)" 81 } 82 } 83 } 84 } 85} 86 87# Record the old timeout, we need to extend it for slower tests. 88set oldtimeout $timeout 89 90runto_main 91gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." 92gdb_test_no_output "set var slow = 0" 93test_all_threads "fast" 0 94 95runto_main 96gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (2)" 97gdb_test_no_output "set var slow = 1" 98# Extend the timeout for slower tests. 99set timeout [expr $oldtimeout + 120] 100test_all_threads "slow" 0 101set timeout $oldtimeout 102 103runto_main 104gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (3)" 105gdb_test_no_output "set var slow = 1" "set var slow = 1 (2)" 106gdb_breakpoint "kill" 107# Extend the timeout for slower tests. 108set timeout [expr $oldtimeout + 120] 109test_all_threads "slow with kill breakpoint" 1 110set timeout $oldtimeout 111 112return 0 113