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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Daniel Jacobowitz <drow@mvista.com>
21 # (parts based on pthreads.exp by Fred Fish (fnf@cygnus.com).
23 # It tests miscellaneous actions with multiple threads, including
24 # handling for thread exit.
33 set testfile "print-threads"
34 set srcfile ${testfile}.c
35 set binfile ${objdir}/${subdir}/${testfile}
37 # regexp for "horizontal" text (i.e. doesn't include newline or
39 set horiz "\[^\n\r\]*"
41 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
45 # Now we can proceed with the real testing.
47 # Start with a fresh gdb.
51 gdb_reinitialize_dir $srcdir/$subdir
54 gdb_test "set print sevenbit-strings" ""
55 #gdb_test "set print address off" ""
56 gdb_test "set width 0" ""
58 # We'll need this when we send_gdb a ^C to GDB. Need to do it before we
59 # run the program and gdb starts saving and restoring tty states.
60 # On Ultrix, we don't need it and it is really slow (because shell_escape
62 if ![istarget "*-*-ultrix*"] then {
63 gdb_test "shell stty intr '^C'" ""
66 proc test_all_threads { name kill } {
73 -re "Breakpoint \[0-9\]+, thread_function \\(arg=.*\\) at .*print-threads.c:\[0-9\]+.*$gdb_prompt" {
75 pass "Hit thread_function breakpoint, $i ($name)"
79 -re "Breakpoint \[0-9\]+, .* kill \\(.*\\) .*$gdb_prompt" {
82 pass "Hit kill breakpoint, $j ($name)"
84 fail "Hit kill breakpoint, $j ($name) (unexpected)"
89 -re "Program exited normally\\.\[\r\n\]+$gdb_prompt" {
90 pass "program exited normally"
92 pass "all threads ran once ($name)"
94 fail "all threads ran once ($name) (total $i threads ran)"
97 -re "Program received signal SIGTRAP.*(Thread \[0-9\]* \\(zombie\\)|0x00000000 in ).*$gdb_prompt $" {
99 kfail "gdb/1265" "Running threads ($name) (zombie thread)"
101 fail "Running threads ($name) (unknown output)"
105 fail "Running threads ($name) (unknown output)"
108 fail "Running threads ($name) (timeout)"
114 gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\."
115 gdb_test "set var slow = 0" ""
116 test_all_threads "fast" 0
119 gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (2)"
120 gdb_test "set var slow = 1" ""
121 test_all_threads "slow" 0
124 gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (3)"
125 gdb_test "set var slow = 1" "" "set var slow = 1 (2)"
126 gdb_breakpoint "kill"
127 test_all_threads "slow with kill breakpoint" 1