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 { [skip_hp_tests] } then { continue }
55 if { ![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"] } {
56 verbose "HPUX thread test ignored for non-hppa or pre-HP/UX-10.30 targets."
61 set srcfile ${srcdir}/${subdir}/${testfile}.c
62 set libsrc ${srcdir}/${subdir}/${testfile}lib.c
63 set mainobj ${objdir}/${testfile}.o
64 set libobj ${objdir}/${testfile}lib.o
65 set libsl ${objdir}/${subdir}/${testfile}lib.sl
66 set binfile ${objdir}/${subdir}/${testfile}
68 # To build the executable we need to do this:
70 # cc -c -Aa -g -D_HPUX_SOURCE -D_REENTRANT +DA1.0 ./gdb.hp/thr-lib.c
71 # cc -c -Aa -g -D_HPUX_SOURCE -D_REENTRANT +DA1.0 +z ./gdb.hp/thr-liblib.c
72 # ld -o thread_local_in_lib.lib.sl -b ./gdb.hp/thr-liblib.o
73 # ld -a archive /opt/langtools/lib/crt0.o /opt/langtools/lib/end.o \
74 # > thr-lib.o ./gdb.hp/thr-liblib.sl \
75 # > -o thr-lib -lpthread -lc
77 remote_exec build "$CC ${srcfile} -c -Aa -g -D_HPUX_SOURCE -D_REENTRANT +DA1.0"
78 remote_exec build "$CC ${libsrc} -c -Aa -g -D_HPUX_SOURCE -D_REENTRANT +DA1.0 +z"
79 remote_exec build "ld -o ${libsl} -b ${libobj}"
80 remote_exec build "ld -a archive /opt/langtools/lib/crt0.o /opt/langtools/lib/end.o ${mainobj} ${libsl} -lpthread -lc -o ${binfile}"
84 gdb_reinitialize_dir $srcdir/$subdir
86 set oldtimeout $timeout
87 #set timeout [expr "$timeout + 200"]
88 set oldverbose $verbose
92 # Here we go: test various things.
94 gdb_test "b adder" ".*Cannot break on adder without a running program.*" "shared loc, needs to run"
95 gdb_test "b main" ".*" ""
96 gdb_test "run" ".*Breakpoint 1, main.*" ""
98 # Set a bp to inspect the results
100 gdb_test "b 67" ".*Breakpoint 2.*" ""
102 # get to a point where we can set the collection breakpoint.
104 gdb_test "tb adder" ".*Breakpoint 3.*line 47.*" "set bp in shared lib"
105 gdb_test "c" ".*Switched to.*adder.*" "run to shared lib rtn"
107 # Check locations of things
109 gdb_test "i ad sum" ".*Symbol \"sum\" is a thread-local variable.*offset.*from the thread base register mpsfu_high.*" "find sum"
110 gdb_test "i add x" ".*Symbol \"x\" is a thread-local variable.*" "find x"
112 # Set a breakpoint later on in "adder" and
113 # collect the thread local's value.
115 gdb_test "b 61" ".*Breakpoint 4.*61.*" "Set collection bp"
117 # extra check for grins, expect to hit "adder" in thread 2 first
118 # but could be wrong...
120 gdb_test "info thread" ".*\\\* 2.*thread.*thread.*" "two threads"
122 # Can't use "gdb_test", as it uses "$gdb_prompt $" in
123 # testing the result. Our new prompt is ">", with
124 # no trailing space, so we can't do this just by
127 # Anyway, I couldn't get expect to see the ">" prompt,
128 # during the command addition, so I just punted.
129 # _You_ are welcome to try, if you want!
131 send_gdb "commands 4\n"
133 -re "(.*Type commands.*\"end\"\.\r\n\>)" {
134 pass "start commands"
136 -re ".*$gdb_prompt $" {
137 fail "start commands"
141 # Assume we're in commands-input mode. (Self-debug stuff turned off)
146 #send_gdb "p x\[j\]\n"
147 send_gdb "set debugger_saw\[id\]\[j\] = x\[j\]\n"
148 send_gdb "continue\n"
152 -re ".*set.*cont.*$gdb_prompt $" {
155 -re ".*$gdb_prompt $" {
160 # Check out of paranoia.
162 send_gdb "info break 4\n"
164 -re ".*breakpoint.*set debugger_saw.*continue.*$gdb_prompt $" {
165 pass "Commands added"
167 -re ".*$gdb_prompt $" {
168 fail "Commands not added."
172 # We now expect to run through the whole application
173 # Since this'll run for while, set a generous timeout.
175 set timeout [expr "$timeout + 30"]
178 -re ".*Program exited normally.*$gdb_prompt $" {
179 fail "program runaway"
181 -re ".*Breakpoint 2.*67.*$gdb_prompt $" {
184 -re ".*$gdb_prompt $" {
187 timeout { fail "timeout" }
189 set timeout $oldtimeout
191 gdb_test "p debugger_saw" ".*5, 1, 9.*4, 6, 10.*3, 7, 12.*2, 8, 11.*" "check results"
193 # Often only one misses; let's get detailed!
195 gdb_test "p debugger_saw\[0\]\[0\]" ".*= 5.*" "1"
196 gdb_test "p debugger_saw\[0\]\[1\]" ".*= 1.*" "2"
197 gdb_test "p debugger_saw\[0\]\[2\]" ".*= 9.*" "3"
198 gdb_test "p debugger_saw\[1\]\[0\]" ".*= 4.*" "4"
199 gdb_test "p debugger_saw\[1\]\[1\]" ".*= 6.*" "5"
200 gdb_test "p debugger_saw\[1\]\[2\]" ".*= 10.*" "6"
201 gdb_test "p debugger_saw\[2\]\[0\]" ".*= 3.*" "7"
202 gdb_test "p debugger_saw\[2\]\[1\]" ".*= 7.*" "8"
203 gdb_test "p debugger_saw\[2\]\[2\]" ".*= 12.*" "9"
204 gdb_test "p debugger_saw\[3\]\[0\]" ".*= 2.*" "10"
205 gdb_test "p debugger_saw\[3\]\[1\]" ".*= 8.*" "11"
206 gdb_test "p debugger_saw\[3\]\[2\]" ".*= 11.*" "12"
210 -re ".* 1.*system thread.* 2.*system thread.*$gdb_prompt $" {
211 fail "Too many threads left"
213 -re ".*\\\* 1.*system thread.*main.*$gdb_prompt $" {
214 pass "Expect only base thread"
216 -re ".*No stack.*$gdb_prompt $" {
219 -re ".*$gdb_prompt $" {
222 timeout { fail "timeout" }
225 gdb_test "c" ".*exited normally.*" "run to completion"
231 set timeout $oldtimeout
232 set verbose $oldverbose
234 # execute_anywhere "rm -f ${binfile}"