]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.hp/attach2.exp
import gdb-19990422 snapshot
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.hp / attach2.exp
1 # attach.exp -- Expect script to test attaching to a threaded pgm
2 # Copyright (C) 1992 Free Software 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 2 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, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
20
21 # use this to debug:
22 #
23 #log_user 1
24
25 # Temporarily comment out - hanging
26 #return 0
27
28 if $tracelevel then {
29 strace $tracelevel
30 }
31
32 if { [skip_hp_tests] } then { continue }
33
34 # Thread stuff is _slow_; prepare for long waits.
35 #
36 # Further, this test has some "null" lines designed
37 # to consume output from gdb that was too late to be
38 # matched (sequence is "gdb_test" sends; timeout and
39 # on to next send; result finally comes in; mismatch).
40 #
41 # The null command is 'gdb_test "p \$pc" ".*" ""'
42 # NOTE: this command undoes any up/down stuff!
43 #
44 proc pre_timeout { how_long } {
45 global timeout
46
47 set timeout [expr "$timeout + $how_long"]
48 }
49
50 proc post_timeout {} {
51 global timeout
52 global oldtimeout
53
54 set timeout $oldtimeout
55 gdb_test "p \$pc" ".*" ""
56 }
57
58 if { ![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"] } {
59 verbose "HPUX thread test ignored for non-hppa or pre-HP/UX-10.30 targets."
60 return 0
61 }
62
63 # We used to wait 5 seconds , but tiamat is faster than
64 # hydra...or is it that the OS allocates time differently(?).
65 #
66 set delay 5
67 if { ![istarget "hppa*-*-hpux11.*"] } {
68 set delay 45
69 }
70
71 set testfile quicksort
72 set srcfile ${srcdir}/${subdir}/${testfile}.c
73 set binfile ${objdir}/${subdir}/${testfile}
74
75 if [get_compiler_info ${binfile}] {
76 return -1
77 }
78
79 set oldtimeout $timeout
80 #set timeout [expr "$timeout + 100"]
81 set oldverbose $verbose
82 #set verbose 40
83
84 # To build the executable we need to link against the thread library.
85 #
86 # cc -Ae -g -o quicksort -lpthread quicksort.c
87 #
88 #remote_exec build "${srcfile} -Ae -g -lpthread -o ${binfile}"
89 #gdb_compile "${srcfile} -Ae -g -lpthread -o ${binfile}"
90
91 if {$gcc_compiled == 0} {
92 set additional_flags "additional_flags=-Ae"
93 } else {
94 set additional_flags ""
95 }
96
97 if { [gdb_compile "${srcdir}/${subdir}/${testfile}.c" "${binfile}.o" object [list debug $additional_flags]] != "" } {
98 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
99 }
100 remote_exec build "ld /usr/ccs/lib/crt0.o ${binfile}.o -lcl -lpthread -lc /opt/langtools/lib/end.o -o ${binfile}"
101
102
103 gdb_exit
104 gdb_start
105 gdb_reinitialize_dir $srcdir/$subdir
106
107 # Start the application running and get its pid.
108 # Then we wait for it to get started and attach.
109 #
110 set testpid [eval exec $binfile 1 &]
111 exec sleep $delay
112
113 # Now attach to the file.
114 #
115 pre_timeout 100
116 gdb_test "attach $testpid" ".*Attaching to process.*Reading symbols from.*done.*" "attach to target"
117 post_timeout
118
119 # Wait for things to quiesce.
120 #
121 exec sleep 0
122
123 send_gdb "bt\n"
124
125 set do_return 0
126 set do_go_to_118 0
127 pre_timeout 400
128 gdb_expect {
129 -re ".*sleep.*work_init.*main.*$gdb_prompt $" {
130 pass "at expected location"
131 }
132 -re ".*drand48.*$gdb_prompt $" {
133 set do_go_to_118 1
134 }
135 -re ".*pthread_mutex_lock.*$gdb_prompt $" {
136 set do_go_to_118 1
137 }
138 -re ".*pthread_mutex_unlock.*$gdb_prompt $" {
139 set do_go_to_118 1
140 }
141 -re ".*main.*$gdb_prompt $" {
142 set do_go_to_118 1
143 }
144 -re ".*No stack.*$gdb_prompt $" {
145 fail "Failed attach, change wait amount down, rest would fail"
146 set do_return 1
147 }
148 -re ".*$gdb_prompt $" {
149 # Who knows?
150 #
151 set do_go_to_118 1
152 }
153 timeout {
154 set do_return 1
155 fail "timeout on bt, avoiding rest of test"
156 }
157 }
158 post_timeout
159
160 # Too late; just give up.
161 #
162 if { $do_return } {
163 set timeout $oldtimeout
164 set verbose $oldverbose
165 return 0
166 }
167
168 # Maybe too early--set a temp break and continue.
169 # We have to set this on both paths, so that we can
170 # know what numbers breakpoints will be.
171 #
172 gdb_test "tb 118" ".*Breakpoint 1.*118.*" ""
173 if { $do_go_to_118 } {
174 pre_timeout 100
175 send_gdb "c\n"
176 gdb_expect {
177 -re ".*at.*118.*118.*$gdb_prompt $" {
178 # Ok, just keep going
179 }
180 -re ".*Program exited.*$gdb_prompt $" {
181 fail "Attached too late, set wait amount downwards"
182 set timeout $oldtimeout
183 set verbose $oldverbose
184 return 0
185 }
186 -re ".*$gdb_prompt $" {
187 fail "Unexpected result on attach"
188 set timeout $oldtimeout
189 set verbose $oldverbose
190 return 0
191 }
192 timeout {
193 fail "timeout on continue "
194 }
195 }
196 post_timeout
197 }
198
199 # Look at the threads.
200 #
201 pre_timeout 100
202 gdb_test "info thread" ".*7.*6.*5.*4.*3.*2.*\\\* 1.*thread.*" "first info thread"
203 post_timeout
204
205 # We expect to be inside the "sleep" call, so check that.
206 #
207 if { [expr "!$do_go_to_118"] } {
208 gdb_test "up" ".*\#1.*nanosleep.*" "up 1"
209 gdb_test "up" ".*\#2.*sleep.*" "up 2"
210 pre_timeout 100
211 gdb_test "up" ".*\#3.*work_init.*$testfile.*c:118.*sleep.*" "up 3"
212 post_timeout
213 } else {
214 send_user "Skipped three tests\n"
215 }
216
217 # Get out of that call.
218 #
219 gdb_test "b 120" ".*Breakpoint 2.*120.*" "set bp"
220 pre_timeout 100
221 gdb_test "c" ".*Breakpoint 2.*at.*120.*" "hit bp"
222 post_timeout
223
224 # Look at the threads.
225 #
226 pre_timeout 100
227 gdb_test "info thread" ".*7.*6.*5.*4.*3.*2.*1.*thread.*$testfile.*c*120.*" "2nd info thread"
228 post_timeout
229
230 # Do some more stuff, to make sure we can
231 #
232 gdb_test "thread 3" ".*Switching to.*thread.*ksleep.*" "switch thread"
233
234 gdb_test "up" ".*_lwp_cond_timedwait.*" "up 5"
235 gdb_test "up" ".*pthread_cond_wait.*" "up 6"
236 gdb_test "up" ".*\#3.*worker.*144.*" "up 7"
237 gdb_test "up" ".*__pthread_exit.*" "up 8"
238 gdb_test "up" ".*Initial.*cannot go up.*" "found thread base"
239
240 gdb_test "b 145 thr 3" ".*Breakpoint 3.*145.*" "thread-specific bp"
241 gdb_test "i b" ".*2.*breakpoint.*at.*120.*3.*breakpoint.*at.*145 thread 3.*" "show thread-specific bp"
242 gdb_test "del 2" ".*" ""
243
244 gdb_test "c" ".*Breakpoint 3.*145.*" "hit thread-specific bp"
245 gdb_test "i th" ".*\\\* 3.*145.*" "at correct thread"
246
247 pre_timeout 100
248 gdb_test "n" ".*146.*" "next from thread-specific bp"
249 post_timeout
250
251 gdb_test "d 3" ".*" ""
252 gdb_test "c" ".*Program exited normally\..*" "run to finish"
253
254 # Done!
255 #
256 gdb_exit
257
258 set timeout $oldtimeout
259 set verbose $oldverbose
260
261 # execute_anywhere "rm -f ${binfile}"
262 #
263 return 0
264
265