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 # Thread stuff is _slow_; prepare for long waits.
34 # Further, this test has some "null" lines designed
35 # to consume output from gdb that was too late to be
36 # matched (sequence is "gdb_test" sends; timeout and
37 # on to next send; result finally comes in; mismatch).
39 # The null command is 'gdb_test "p \$pc" ".*" ""'
40 # NOTE: this command undoes any up/down stuff!
42 proc pre_timeout { how_long } {
45 set timeout [expr "$timeout + $how_long"]
48 proc post_timeout {} {
52 set timeout $oldtimeout
53 gdb_test "p \$pc" ".*" ""
56 if { ![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"] } {
57 verbose "HPUX thread test ignored for non-hppa or pre-HP/UX-10.30 targets."
61 # We used to wait 5 seconds , but tiamat is faster than
62 # hydra...or is it that the OS allocates time differently(?).
65 if { ![istarget "hppa*-*-hpux11.*"] } {
69 set testfile quicksort
70 set srcfile ${srcdir}/${subdir}/${testfile}.c
71 set binfile ${objdir}/${subdir}/${testfile}
73 if [get_compiler_info ${binfile}] {
77 set oldtimeout $timeout
78 #set timeout [expr "$timeout + 100"]
79 set oldverbose $verbose
82 # To build the executable we need to link against the thread library.
84 # cc -Ae -g -o quicksort -lpthread quicksort.c
86 #remote_exec build "${srcfile} -Ae -g -lpthread -o ${binfile}"
87 #gdb_compile "${srcfile} -Ae -g -lpthread -o ${binfile}"
89 if {$gcc_compiled == 0} {
90 set additional_flags "additional_flags=-Ae"
92 set additional_flags ""
95 if { [gdb_compile "${srcdir}/${subdir}/${testfile}.c" "${binfile}.o" object [list debug $additional_flags]] != "" } {
96 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
98 remote_exec build "ld /usr/ccs/lib/crt0.o ${binfile}.o -lcl -lpthread -lc /opt/langtools/lib/end.o -o ${binfile}"
103 gdb_reinitialize_dir $srcdir/$subdir
105 # Start the application running and get its pid.
106 # Then we wait for it to get started and attach.
108 set testpid [eval exec $binfile 1 &]
111 # Now attach to the file.
114 gdb_test "attach $testpid" ".*Attaching to process.*Reading symbols from.*done.*" "attach to target"
117 # Wait for things to quiesce.
127 -re ".*sleep.*work_init.*main.*$gdb_prompt $" {
128 pass "at expected location"
130 -re ".*drand48.*$gdb_prompt $" {
133 -re ".*pthread_mutex_lock.*$gdb_prompt $" {
136 -re ".*pthread_mutex_unlock.*$gdb_prompt $" {
139 -re ".*main.*$gdb_prompt $" {
142 -re ".*No stack.*$gdb_prompt $" {
143 fail "Failed attach, change wait amount down, rest would fail"
146 -re ".*$gdb_prompt $" {
153 fail "timeout on bt, avoiding rest of test"
158 # Too late; just give up.
161 set timeout $oldtimeout
162 set verbose $oldverbose
166 # Maybe too early--set a temp break and continue.
167 # We have to set this on both paths, so that we can
168 # know what numbers breakpoints will be.
170 gdb_test "tb 118" ".*Breakpoint 1.*118.*" ""
171 if { $do_go_to_118 } {
175 -re ".*at.*118.*118.*$gdb_prompt $" {
176 # Ok, just keep going
178 -re ".*Program exited.*$gdb_prompt $" {
179 fail "Attached too late, set wait amount downwards"
180 set timeout $oldtimeout
181 set verbose $oldverbose
184 -re ".*$gdb_prompt $" {
185 fail "Unexpected result on attach"
186 set timeout $oldtimeout
187 set verbose $oldverbose
191 fail "timeout on continue "
197 # Look at the threads.
200 gdb_test "info thread" ".*7.*6.*5.*4.*3.*2.*\\\* 1.*thread.*" "first info thread"
203 # We expect to be inside the "sleep" call, so check that.
205 if { [expr "!$do_go_to_118"] } {
206 gdb_test "up" ".*\#1.*nanosleep.*" "up 1"
207 gdb_test "up" ".*\#2.*sleep.*" "up 2"
209 gdb_test "up" ".*\#3.*work_init.*$testfile.*c:118.*sleep.*" "up 3"
212 send_user "Skipped three tests\n"
215 # Get out of that call.
217 gdb_test "b 120" ".*Breakpoint 2.*120.*" "set bp"
219 gdb_test "c" ".*Breakpoint 2.*at.*120.*" "hit bp"
222 # Look at the threads.
225 gdb_test "info thread" ".*7.*6.*5.*4.*3.*2.*1.*thread.*$testfile.*c*120.*" "2nd info thread"
228 # Do some more stuff, to make sure we can
230 gdb_test "thread 3" ".*Switching to.*thread.*ksleep.*" "switch thread"
232 gdb_test "up" ".*_lwp_cond_timedwait.*" "up 5"
233 gdb_test "up" ".*pthread_cond_wait.*" "up 6"
234 gdb_test "up" ".*\#3.*worker.*144.*" "up 7"
235 gdb_test "up" ".*__pthread_exit.*" "up 8"
236 gdb_test "up" ".*Initial.*cannot go up.*" "found thread base"
238 gdb_test "b 145 thr 3" ".*Breakpoint 3.*145.*" "thread-specific bp"
239 gdb_test "i b" ".*2.*breakpoint.*at.*120.*3.*breakpoint.*at.*145 thread 3.*" "show thread-specific bp"
240 gdb_test "del 2" ".*" ""
242 gdb_test "c" ".*Breakpoint 3.*145.*" "hit thread-specific bp"
243 gdb_test "i th" ".*\\\* 3.*145.*" "at correct thread"
246 gdb_test "n" ".*146.*" "next from thread-specific bp"
249 gdb_test "d 3" ".*" ""
250 gdb_test "c" ".*Program exited normally\..*" "run to finish"
256 set timeout $oldtimeout
257 set verbose $oldverbose
259 # execute_anywhere "rm -f ${binfile}"