1 # attach.exp -- Expect script to test attaching to a threaded pgm
2 # Copyright (C) 1992 Free Software Foundation, Inc.
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.
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.
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. */
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
25 # Temporarily comment out - hanging
32 if { [skip_hp_tests] } then { continue }
34 # Thread stuff is _slow_; prepare for long waits.
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).
41 # The null command is 'gdb_test "p \$pc" ".*" ""'
42 # NOTE: this command undoes any up/down stuff!
44 proc pre_timeout { how_long } {
47 set timeout [expr "$timeout + $how_long"]
50 proc post_timeout {} {
54 set timeout $oldtimeout
55 gdb_test "p \$pc" ".*" ""
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."
63 # We used to wait 5 seconds , but tiamat is faster than
64 # hydra...or is it that the OS allocates time differently(?).
67 if { ![istarget "hppa*-*-hpux11.*"] } {
71 set testfile quicksort
72 set srcfile ${srcdir}/${subdir}/${testfile}.c
73 set binfile ${objdir}/${subdir}/${testfile}
75 if [get_compiler_info ${binfile}] {
79 set oldtimeout $timeout
80 #set timeout [expr "$timeout + 100"]
81 set oldverbose $verbose
84 # To build the executable we need to link against the thread library.
86 # cc -Ae -g -o quicksort -lpthread quicksort.c
88 #remote_exec build "${srcfile} -Ae -g -lpthread -o ${binfile}"
89 #gdb_compile "${srcfile} -Ae -g -lpthread -o ${binfile}"
91 if {$gcc_compiled == 0} {
92 set additional_flags "additional_flags=-Ae"
94 set additional_flags ""
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."
100 remote_exec build "ld /usr/ccs/lib/crt0.o ${binfile}.o -lcl -lpthread -lc /opt/langtools/lib/end.o -o ${binfile}"
105 gdb_reinitialize_dir $srcdir/$subdir
107 # Start the application running and get its pid.
108 # Then we wait for it to get started and attach.
110 set testpid [eval exec $binfile 1 &]
113 # Now attach to the file.
116 gdb_test "attach $testpid" ".*Attaching to process.*Reading symbols from.*done.*" "attach to target"
119 # Wait for things to quiesce.
129 -re ".*sleep.*work_init.*main.*$gdb_prompt $" {
130 pass "at expected location"
132 -re ".*drand48.*$gdb_prompt $" {
135 -re ".*pthread_mutex_lock.*$gdb_prompt $" {
138 -re ".*pthread_mutex_unlock.*$gdb_prompt $" {
141 -re ".*main.*$gdb_prompt $" {
144 -re ".*No stack.*$gdb_prompt $" {
145 fail "Failed attach, change wait amount down, rest would fail"
148 -re ".*$gdb_prompt $" {
155 fail "timeout on bt, avoiding rest of test"
160 # Too late; just give up.
163 set timeout $oldtimeout
164 set verbose $oldverbose
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.
172 gdb_test "tb 118" ".*Breakpoint 1.*118.*" ""
173 if { $do_go_to_118 } {
177 -re ".*at.*118.*118.*$gdb_prompt $" {
178 # Ok, just keep going
180 -re ".*Program exited.*$gdb_prompt $" {
181 fail "Attached too late, set wait amount downwards"
182 set timeout $oldtimeout
183 set verbose $oldverbose
186 -re ".*$gdb_prompt $" {
187 fail "Unexpected result on attach"
188 set timeout $oldtimeout
189 set verbose $oldverbose
193 fail "timeout on continue "
199 # Look at the threads.
202 gdb_test "info thread" ".*7.*6.*5.*4.*3.*2.*\\\* 1.*thread.*" "first info thread"
205 # We expect to be inside the "sleep" call, so check that.
207 if { [expr "!$do_go_to_118"] } {
208 gdb_test "up" ".*\#1.*nanosleep.*" "up 1"
209 gdb_test "up" ".*\#2.*sleep.*" "up 2"
211 gdb_test "up" ".*\#3.*work_init.*$testfile.*c:118.*sleep.*" "up 3"
214 send_user "Skipped three tests\n"
217 # Get out of that call.
219 gdb_test "b 120" ".*Breakpoint 2.*120.*" "set bp"
221 gdb_test "c" ".*Breakpoint 2.*at.*120.*" "hit bp"
224 # Look at the threads.
227 gdb_test "info thread" ".*7.*6.*5.*4.*3.*2.*1.*thread.*$testfile.*c*120.*" "2nd info thread"
230 # Do some more stuff, to make sure we can
232 gdb_test "thread 3" ".*Switching to.*thread.*ksleep.*" "switch thread"
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"
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" ".*" ""
244 gdb_test "c" ".*Breakpoint 3.*145.*" "hit thread-specific bp"
245 gdb_test "i th" ".*\\\* 3.*145.*" "at correct thread"
248 gdb_test "n" ".*146.*" "next from thread-specific bp"
251 gdb_test "d 3" ".*" ""
252 gdb_test "c" ".*Program exited normally\..*" "run to finish"
258 set timeout $oldtimeout
259 set verbose $oldverbose
261 # execute_anywhere "rm -f ${binfile}"