OSDN Git Service

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