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