]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.hp/thr-lib.exp
Initial creation of sourceware repository
[thirdparty/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 { ![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"] } {
54 verbose "HPUX thread test ignored for non-hppa or pre-HP/UX-10.30 targets."
55 return 0
56 }
57
58 set testfile thr-lib
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}
65
66 # To build the executable we need to do this:
67 #
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
74 #
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}"
79
80 gdb_exit
81 gdb_start
82 gdb_reinitialize_dir $srcdir/$subdir
83
84 set oldtimeout $timeout
85 #set timeout [expr "$timeout + 200"]
86 set oldverbose $verbose
87
88 gdb_load ${binfile}
89
90 # Here we go: test various things.
91 #
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.*" ""
95
96 # Set a bp to inspect the results
97 #
98 gdb_test "b 67" ".*Breakpoint 2.*" ""
99
100 # get to a point where we can set the collection breakpoint.
101 #
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"
104
105 # Check locations of things
106 #
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"
109
110 # Set a breakpoint later on in "adder" and
111 # collect the thread local's value.
112 #
113 gdb_test "b 61" ".*Breakpoint 4.*61.*" "Set collection bp"
114
115 # extra check for grins, expect to hit "adder" in thread 2 first
116 # but could be wrong...
117 #
118 gdb_test "info thread" ".*\\\* 2.*thread.*thread.*" "two threads"
119
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
123 # changing "prompt".
124 #
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!
128 #
129 send_gdb "commands 4\n"
130 gdb_expect {
131 -re "(.*Type commands.*\"end\"\.\r\n\>)" {
132 pass "start commands"
133 }
134 -re ".*$gdb_prompt $" {
135 fail "start commands"
136 }
137 }
138
139 # Assume we're in commands-input mode. (Self-debug stuff turned off)
140 #
141 send_gdb "silent\n"
142 #send_gdb "p id\n"
143 #send_gdb "p j\n"
144 #send_gdb "p x\[j\]\n"
145 send_gdb "set debugger_saw\[id\]\[j\] = x\[j\]\n"
146 send_gdb "continue\n"
147 send_gdb "end\n"
148
149 gdb_expect {
150 -re ".*set.*cont.*$gdb_prompt $" {
151 pass "add commands"
152 }
153 -re ".*$gdb_prompt $" {
154 fail "add commands"
155 }
156 }
157
158 # Check out of paranoia.
159 #
160 send_gdb "info break 4\n"
161 gdb_expect {
162 -re ".*breakpoint.*set debugger_saw.*continue.*$gdb_prompt $" {
163 pass "Commands added"
164 }
165 -re ".*$gdb_prompt $" {
166 fail "Commands not added."
167 }
168 }
169
170 # We now expect to run through the whole application
171 # Since this'll run for while, set a generous timeout.
172 #
173 set timeout [expr "$timeout + 30"]
174 send_gdb "c\n"
175 gdb_expect {
176 -re ".*Program exited normally.*$gdb_prompt $" {
177 fail "program runaway"
178 }
179 -re ".*Breakpoint 2.*67.*$gdb_prompt $" {
180 pass "get to end"
181 }
182 -re ".*$gdb_prompt $" {
183 fail "No progress?"
184 }
185 timeout { fail "timeout" }
186 }
187 set timeout $oldtimeout
188
189 gdb_test "p debugger_saw" ".*5, 1, 9.*4, 6, 10.*3, 7, 12.*2, 8, 11.*" "check results"
190
191 # Often only one misses; let's get detailed!
192 #
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"
205
206 send_gdb "i th\n"
207 gdb_expect {
208 -re ".* 1.*system thread.* 2.*system thread.*$gdb_prompt $" {
209 fail "Too many threads left"
210 }
211 -re ".*\\\* 1.*system thread.*main.*$gdb_prompt $" {
212 pass "Expect only base thread"
213 }
214 -re ".*No stack.*$gdb_prompt $" {
215 fail "runaway"
216 }
217 -re ".*$gdb_prompt $" {
218 fail "Hunh?"
219 }
220 timeout { fail "timeout" }
221 }
222
223 gdb_test "c" ".*exited normally.*" "run to completion"
224
225 # Done!
226 #
227 gdb_exit
228
229 set timeout $oldtimeout
230 set verbose $oldverbose
231
232 # execute_anywhere "rm -f ${binfile}"
233 #
234 return 0