import gdb-19990422 snapshot
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.hp / thr-lib.exp
1 # thr-lib.exp -- Expect script to test thread-local storage in lib
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 # Thread stuff is _slow_; prepare for long waits.
26 #
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).
31 #
32 # The null command is 'gdb_test "p \$pc" ".*" ""'
33 # NOTE: this command undoes any up/down stuff!
34 #
35 proc pre_timeout {} {
36 global timeout
37
38 set timeout [expr "$timeout + 100"]
39 }
40
41 proc post_timeout {} {
42 global timeout
43 global oldtimeout
44
45 set timeout $oldtimeout
46 gdb_test "p \$pc" ".*" ""
47 }
48
49 if $tracelevel then {
50 strace $tracelevel
51 }
52
53 if { [skip_hp_tests] } then { continue }
54
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."
57 return 0
58 }
59
60 set testfile thr-lib
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}
67
68 # To build the executable we need to do this:
69 #
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
76 #
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}"
81
82 gdb_exit
83 gdb_start
84 gdb_reinitialize_dir $srcdir/$subdir
85
86 set oldtimeout $timeout
87 #set timeout [expr "$timeout + 200"]
88 set oldverbose $verbose
89
90 gdb_load ${binfile}
91
92 # Here we go: test various things.
93 #
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.*" ""
97
98 # Set a bp to inspect the results
99 #
100 gdb_test "b 67" ".*Breakpoint 2.*" ""
101
102 # get to a point where we can set the collection breakpoint.
103 #
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"
106
107 # Check locations of things
108 #
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"
111
112 # Set a breakpoint later on in "adder" and
113 # collect the thread local's value.
114 #
115 gdb_test "b 61" ".*Breakpoint 4.*61.*" "Set collection bp"
116
117 # extra check for grins, expect to hit "adder" in thread 2 first
118 # but could be wrong...
119 #
120 gdb_test "info thread" ".*\\\* 2.*thread.*thread.*" "two threads"
121
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
125 # changing "prompt".
126 #
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!
130 #
131 send_gdb "commands 4\n"
132 gdb_expect {
133 -re "(.*Type commands.*\"end\"\.\r\n\>)" {
134 pass "start commands"
135 }
136 -re ".*$gdb_prompt $" {
137 fail "start commands"
138 }
139 }
140
141 # Assume we're in commands-input mode. (Self-debug stuff turned off)
142 #
143 send_gdb "silent\n"
144 #send_gdb "p id\n"
145 #send_gdb "p j\n"
146 #send_gdb "p x\[j\]\n"
147 send_gdb "set debugger_saw\[id\]\[j\] = x\[j\]\n"
148 send_gdb "continue\n"
149 send_gdb "end\n"
150
151 gdb_expect {
152 -re ".*set.*cont.*$gdb_prompt $" {
153 pass "add commands"
154 }
155 -re ".*$gdb_prompt $" {
156 fail "add commands"
157 }
158 }
159
160 # Check out of paranoia.
161 #
162 send_gdb "info break 4\n"
163 gdb_expect {
164 -re ".*breakpoint.*set debugger_saw.*continue.*$gdb_prompt $" {
165 pass "Commands added"
166 }
167 -re ".*$gdb_prompt $" {
168 fail "Commands not added."
169 }
170 }
171
172 # We now expect to run through the whole application
173 # Since this'll run for while, set a generous timeout.
174 #
175 set timeout [expr "$timeout + 30"]
176 send_gdb "c\n"
177 gdb_expect {
178 -re ".*Program exited normally.*$gdb_prompt $" {
179 fail "program runaway"
180 }
181 -re ".*Breakpoint 2.*67.*$gdb_prompt $" {
182 pass "get to end"
183 }
184 -re ".*$gdb_prompt $" {
185 fail "No progress?"
186 }
187 timeout { fail "timeout" }
188 }
189 set timeout $oldtimeout
190
191 gdb_test "p debugger_saw" ".*5, 1, 9.*4, 6, 10.*3, 7, 12.*2, 8, 11.*" "check results"
192
193 # Often only one misses; let's get detailed!
194 #
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"
207
208 send_gdb "i th\n"
209 gdb_expect {
210 -re ".* 1.*system thread.* 2.*system thread.*$gdb_prompt $" {
211 fail "Too many threads left"
212 }
213 -re ".*\\\* 1.*system thread.*main.*$gdb_prompt $" {
214 pass "Expect only base thread"
215 }
216 -re ".*No stack.*$gdb_prompt $" {
217 fail "runaway"
218 }
219 -re ".*$gdb_prompt $" {
220 fail "Hunh?"
221 }
222 timeout { fail "timeout" }
223 }
224
225 gdb_test "c" ".*exited normally.*" "run to completion"
226
227 # Done!
228 #
229 gdb_exit
230
231 set timeout $oldtimeout
232 set verbose $oldverbose
233
234 # execute_anywhere "rm -f ${binfile}"
235 #
236 return 0
This page took 0.040295 seconds and 4 git commands to generate.