1 # thr-lib.exp -- Expect script to test thread-local storage in lib
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 # Thread stuff is _slow_; prepare for long waits.
27 # Further, this test has some "null" lines designed
28 # to consume output from gdb that was too late to be
29 # matched (sequence is "gdb_test" sends; timeout and
30 # on to next send; result finally comes in; mismatch).
32 # The null command is 'gdb_test "p \$pc" ".*" ""'
33 # NOTE: this command undoes any up/down stuff!
38 set timeout [expr "$timeout + 100"]
41 proc post_timeout {} {
45 set timeout $oldtimeout
46 gdb_test "p \$pc" ".*" ""
53 if { ![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"] } {
54 verbose "HPUX thread test ignored for non-hppa or pre-HP/UX-10.30 targets."
59 set srcfile ${srcdir}/${subdir}/${testfile}.c
60 set libsrc ${srcdir}/${subdir}/${testfile}lib.c
61 set mainobj ${objdir}/${testfile}.o
62 set libobj ${objdir}/${testfile}lib.o
63 set libsl ${objdir}/${subdir}/${testfile}lib.sl
64 set binfile ${objdir}/${subdir}/${testfile}
66 # To build the executable we need to do this:
68 # cc -c -Aa -g -D_HPUX_SOURCE -D_REENTRANT +DA1.0 ./gdb.hp/thr-lib.c
69 # cc -c -Aa -g -D_HPUX_SOURCE -D_REENTRANT +DA1.0 +z ./gdb.hp/thr-liblib.c
70 # ld -o thread_local_in_lib.lib.sl -b ./gdb.hp/thr-liblib.o
71 # ld -a archive /opt/langtools/lib/crt0.o /opt/langtools/lib/end.o \
72 # > thr-lib.o ./gdb.hp/thr-liblib.sl \
73 # > -o thr-lib -lpthread -lc
75 remote_exec build "$CC ${srcfile} -c -Aa -g -D_HPUX_SOURCE -D_REENTRANT +DA1.0"
76 remote_exec build "$CC ${libsrc} -c -Aa -g -D_HPUX_SOURCE -D_REENTRANT +DA1.0 +z"
77 remote_exec build "ld -o ${libsl} -b ${libobj}"
78 remote_exec build "ld -a archive /opt/langtools/lib/crt0.o /opt/langtools/lib/end.o ${mainobj} ${libsl} -lpthread -lc -o ${binfile}"
82 gdb_reinitialize_dir $srcdir/$subdir
84 set oldtimeout $timeout
85 #set timeout [expr "$timeout + 200"]
86 set oldverbose $verbose
90 # Here we go: test various things.
92 gdb_test "b adder" ".*Cannot break on adder without a running program.*" "shared loc, needs to run"
93 gdb_test "b main" ".*" ""
94 gdb_test "run" ".*Breakpoint 1, main.*" ""
96 # Set a bp to inspect the results
98 gdb_test "b 67" ".*Breakpoint 2.*" ""
100 # get to a point where we can set the collection breakpoint.
102 gdb_test "tb adder" ".*Breakpoint 3.*line 47.*" "set bp in shared lib"
103 gdb_test "c" ".*Switched to.*adder.*" "run to shared lib rtn"
105 # Check locations of things
107 gdb_test "i ad sum" ".*Symbol \"sum\" is a thread-local variable.*offset.*from the thread base register mpsfu_high.*" "find sum"
108 gdb_test "i add x" ".*Symbol \"x\" is a thread-local variable.*" "find x"
110 # Set a breakpoint later on in "adder" and
111 # collect the thread local's value.
113 gdb_test "b 61" ".*Breakpoint 4.*61.*" "Set collection bp"
115 # extra check for grins, expect to hit "adder" in thread 2 first
116 # but could be wrong...
118 gdb_test "info thread" ".*\\\* 2.*thread.*thread.*" "two threads"
120 # Can't use "gdb_test", as it uses "$gdb_prompt $" in
121 # testing the result. Our new prompt is ">", with
122 # no trailing space, so we can't do this just by
125 # Anyway, I couldn't get expect to see the ">" prompt,
126 # during the command addition, so I just punted.
127 # _You_ are welcome to try, if you want!
129 send_gdb "commands 4\n"
131 -re "(.*Type commands.*\"end\"\.\r\n\>)" {
132 pass "start commands"
134 -re ".*$gdb_prompt $" {
135 fail "start commands"
139 # Assume we're in commands-input mode. (Self-debug stuff turned off)
144 #send_gdb "p x\[j\]\n"
145 send_gdb "set debugger_saw\[id\]\[j\] = x\[j\]\n"
146 send_gdb "continue\n"
150 -re ".*set.*cont.*$gdb_prompt $" {
153 -re ".*$gdb_prompt $" {
158 # Check out of paranoia.
160 send_gdb "info break 4\n"
162 -re ".*breakpoint.*set debugger_saw.*continue.*$gdb_prompt $" {
163 pass "Commands added"
165 -re ".*$gdb_prompt $" {
166 fail "Commands not added."
170 # We now expect to run through the whole application
171 # Since this'll run for while, set a generous timeout.
173 set timeout [expr "$timeout + 30"]
176 -re ".*Program exited normally.*$gdb_prompt $" {
177 fail "program runaway"
179 -re ".*Breakpoint 2.*67.*$gdb_prompt $" {
182 -re ".*$gdb_prompt $" {
185 timeout { fail "timeout" }
187 set timeout $oldtimeout
189 gdb_test "p debugger_saw" ".*5, 1, 9.*4, 6, 10.*3, 7, 12.*2, 8, 11.*" "check results"
191 # Often only one misses; let's get detailed!
193 gdb_test "p debugger_saw\[0\]\[0\]" ".*= 5.*" "1"
194 gdb_test "p debugger_saw\[0\]\[1\]" ".*= 1.*" "2"
195 gdb_test "p debugger_saw\[0\]\[2\]" ".*= 9.*" "3"
196 gdb_test "p debugger_saw\[1\]\[0\]" ".*= 4.*" "4"
197 gdb_test "p debugger_saw\[1\]\[1\]" ".*= 6.*" "5"
198 gdb_test "p debugger_saw\[1\]\[2\]" ".*= 10.*" "6"
199 gdb_test "p debugger_saw\[2\]\[0\]" ".*= 3.*" "7"
200 gdb_test "p debugger_saw\[2\]\[1\]" ".*= 7.*" "8"
201 gdb_test "p debugger_saw\[2\]\[2\]" ".*= 12.*" "9"
202 gdb_test "p debugger_saw\[3\]\[0\]" ".*= 2.*" "10"
203 gdb_test "p debugger_saw\[3\]\[1\]" ".*= 8.*" "11"
204 gdb_test "p debugger_saw\[3\]\[2\]" ".*= 11.*" "12"
208 -re ".* 1.*system thread.* 2.*system thread.*$gdb_prompt $" {
209 fail "Too many threads left"
211 -re ".*\\\* 1.*system thread.*main.*$gdb_prompt $" {
212 pass "Expect only base thread"
214 -re ".*No stack.*$gdb_prompt $" {
217 -re ".*$gdb_prompt $" {
220 timeout { fail "timeout" }
223 gdb_test "c" ".*exited normally.*" "run to completion"
229 set timeout $oldtimeout
230 set verbose $oldverbose
232 # execute_anywhere "rm -f ${binfile}"