1 # Copyright (C) 1996, 1997, 2002, 2003, 2007 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@prep.ai.mit.edu
19 # This file was written by Daniel Jacobowitz <drow@mvista.com>
20 # (parts based on pthreads.exp by Fred Fish (fnf@cygnus.com).
22 # It tests miscellaneous actions with multiple threads, including
23 # handling for thread exit.
32 set testfile "print-threads"
33 set srcfile ${testfile}.c
34 set binfile ${objdir}/${subdir}/${testfile}
36 # regexp for "horizontal" text (i.e. doesn't include newline or
38 set horiz "\[^\n\r\]*"
40 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
44 # Now we can proceed with the real testing.
46 # Start with a fresh gdb.
50 gdb_reinitialize_dir $srcdir/$subdir
53 gdb_test "set print sevenbit-strings" ""
54 #gdb_test "set print address off" ""
55 gdb_test "set width 0" ""
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
61 if ![istarget "*-*-ultrix*"] then {
62 gdb_test "shell stty intr '^C'" ""
65 proc test_all_threads { name kill } {
72 -re "Breakpoint \[0-9\]+, thread_function \\(arg=.*\\) at .*print-threads.c:\[0-9\]+.*$gdb_prompt" {
74 pass "Hit thread_function breakpoint, $i ($name)"
78 -re "Breakpoint \[0-9\]+, .* kill \\(.*\\) .*$gdb_prompt" {
81 pass "Hit kill breakpoint, $j ($name)"
83 fail "Hit kill breakpoint, $j ($name) (unexpected)"
88 -re "Program exited normally\\.\[\r\n\]+$gdb_prompt" {
89 pass "program exited normally"
91 pass "all threads ran once ($name)"
93 fail "all threads ran once ($name) (total $i threads ran)"
96 -re "Program received signal SIGTRAP.*(Thread \[-0-9a-fx\]* \\(zombie\\)|0x00000000 in ).*$gdb_prompt $" {
98 kfail "gdb/1265" "Running threads ($name) (zombie thread)"
100 fail "Running threads ($name) (unknown output)"
104 fail "Running threads ($name) (unknown output)"
107 fail "Running threads ($name) (timeout)"
113 gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\."
114 gdb_test "set var slow = 0" ""
115 test_all_threads "fast" 0
118 gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (2)"
119 gdb_test "set var slow = 1" ""
120 test_all_threads "slow" 0
123 gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (3)"
124 gdb_test "set var slow = 1" "" "set var slow = 1 (2)"
125 gdb_breakpoint "kill"
126 test_all_threads "slow with kill breakpoint" 1