OSDN Git Service

12a25b95ba119fd62c0a602fa33051af075bf9b2
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.threads / manythreads.exp
1 # manythreads.exp -- Expect script to test stopping many threads
2 # Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010, 2011
3 # Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 # This file was written by Jeff Johnston. (jjohnstn@redhat.com)
19
20 if $tracelevel then {
21         strace $tracelevel
22 }
23
24
25 set testfile "manythreads"
26 set srcfile ${testfile}.c
27 set binfile ${objdir}/${subdir}/${testfile}
28
29 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
30     return -1
31 }
32
33 gdb_start
34 gdb_reinitialize_dir $srcdir/$subdir
35 gdb_load ${binfile}
36 gdb_test_no_output "set print sevenbit-strings"
37 runto_main
38
39 # We'll need this when we send_gdb a ^C to GDB.  Need to do it before we
40 # run the program and gdb starts saving and restoring tty states.
41 # On Ultrix, we don't need it and it is really slow (because shell_escape
42 # doesn't use vfork).
43 if ![istarget "*-*-ultrix*"] then {
44     gdb_test "shell stty intr '^C'" ".*"
45 }
46
47 set message "first continue"
48 gdb_test_multiple "continue" "first continue" {
49   -re "error:.*$gdb_prompt $" {
50     fail "$message"
51   }
52   -re "Continuing" {
53     pass "$message"
54   }
55 }
56
57 # Wait one second.  This is better than the TCL "after" command, because
58 # we don't lose GDB's output while we do it.
59 remote_expect host 1 { timeout { } }
60
61 # Send a Ctrl-C and verify that we can do info threads and continue
62 send_gdb "\003"
63 set message "stop threads 1"
64 gdb_test_multiple "" "stop threads 1" {
65   -re "\\\[New \[^\]\]*\\\]\r\n" {
66     exp_continue
67   }
68   -re "\\\[\[^\]\]* exited\\\]\r\n" {
69     exp_continue
70   }
71   -re "Thread \[^\n\]* executing\r\n" {
72     exp_continue
73   }
74   -re "Program received signal SIGINT.*$gdb_prompt $" {
75     pass "$message"
76   }
77   timeout {
78     fail "$message (timeout)"
79   }
80 }
81
82 set cmd "info threads"
83 set ok 0
84 gdb_test_multiple $cmd $cmd {
85     -re " 1 *Thread " {
86         set ok 1
87         exp_continue
88     }
89     -re ".*\r\n" {
90         # Eat this line and continue, to prevent the buffer overflowing.
91         exp_continue
92     }
93     -re "$gdb_prompt $" {
94         if { $ok } {
95             pass $cmd
96         } else {
97             fail $cmd
98         }
99     }
100 }
101
102 gdb_test_no_output "thread name zardoz" "give a name to the thread"
103 gdb_test "info threads" ".*zardoz.*" "check thread name"
104
105 set message "second continue"
106 gdb_test_multiple "continue" "second continue" {
107   -re "error:.*$gdb_prompt $" {
108     fail "$message"
109   }
110   -re "Continuing" {
111     pass "$message"
112   }
113 }
114
115 # Wait another second.  If the program stops on its own, GDB has failed
116 # to handle duplicate SIGINTs sent to multiple threads.
117 set failed 0
118 remote_expect host 1 {
119   -re "\\\[New \[^\]\]*\\\]\r\n" {
120     exp_continue -continue_timer
121   }
122   -re "\\\[\[^\]\]* exited\\\]\r\n" {
123     exp_continue -continue_timer
124   }
125   -re "Thread \[^\n\]* executing\r\n" {
126     exp_continue -continue_timer
127   }
128   -re "Program received signal SIGINT.*$gdb_prompt $" {
129     if { $failed == 0 } {
130       fail "check for duplicate SIGINT"
131     }
132     send_gdb "continue\n"
133     set failed 1
134     exp_continue
135   }
136   timeout {
137     if { $failed == 0 } {
138       pass "check for duplicate SIGINT"
139     }
140   }
141 }
142
143 # Send another Ctrl-C and verify that we can do info threads and quit
144 send_gdb "\003"
145 set message "stop threads 2"
146 gdb_test_multiple "" "stop threads 2" {
147   -re "\\\[New \[^\]\]*\\\]\r\n" {
148     exp_continue
149   }
150   -re "\\\[\[^\]\]* exited\\\]\r\n" {
151     exp_continue
152   }
153   -re "Thread \[^\n\]* executing\r\n" {
154     exp_continue
155   }
156   -re "Program received signal SIGINT.*$gdb_prompt $" {
157     pass "$message"
158   }
159   timeout {
160     fail "$message (timeout)"
161   }
162
163
164 gdb_test_multiple "quit" "GDB exits after stopping multithreaded program" {
165     -re "Quit anyway\\? \\(y or n\\) $" {
166         send_gdb "y\n"
167         exp_continue
168     }
169     eof {
170         pass "GDB exits after stopping multithreaded program"
171     }
172     timeout {
173         fail "GDB exits after stopping multithreaded program (timeout)"
174     }
175 }
176