* lib/gdb.exp (gdb_test): Between $pattern and $prompt, expect
[binutils-gdb.git] / gdb / testsuite / gdb.base / opaque.exp
1 # Copyright (C) 1992, 1994 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file was written by Fred Fish. (fnf@cygnus.com)
21
22 if $tracelevel then {
23 strace $tracelevel
24 }
25
26 set prms_id 0
27 set bug_id 0
28
29 set binfile "opaque"
30 set srcfile $binfile.c
31
32 if ![file exists $objdir/$subdir/$binfile] then {
33 perror "$objdir/$subdir/$binfile does not exist."
34 return 0
35 }
36
37 # Start with a fresh gdb.
38
39 gdb_exit
40 gdb_start
41 gdb_reinitialize_dir $srcdir/$subdir
42 gdb_load $objdir/$subdir/$binfile
43
44 source gdb.base/opaque-info.exp
45
46 #
47 # Test basic opaque structure handling (statically).
48 # The ordering of the tests is significant. We first try the things that
49 # might fail if gdb fails to connect the uses of opaque structures to
50 # the actual opaque structure definition.
51
52 # When we start up, gdb sets the file containing main() as the current
53 # source file. The actual structure foo is defined in a different file.
54 # A pointer (foop) to an instance of the opaque struct is defined in the same
55 # source file as main(). Ensure that gdb correctly "connected" the definition
56 # in the other file with the pointer to the opaque struct in the file containing
57 # "foop".
58
59 # Define a procedure to set up an xfail for all targets that do not support
60 # this sort of cross reference.
61 # Any target gcc that has a DBX_NO_XREFS definition in its config file will
62 # not support it.
63 # XCOFF does not seem to support it either. See the very end of gcc/xcoffout.h.
64 # Native alpha ecoff doesn't support it either.
65 # I don't think this type of cross reference works for any COFF target
66 # either.
67
68 proc setup_xfail_on_opaque_pointer {} {
69 global gcc_compiled
70
71 setup_xfail "rs6000-*-*" "a29k-*-udi" "vax-*-*" "i*86-sequent-bsd*"
72 if {!$gcc_compiled} then {
73 setup_xfail "alpha-*-*"
74 }
75 }
76
77 setup_xfail_on_opaque_pointer
78 send "whatis foop\n"
79 expect {
80 -re "whatis foop\r
81 type = struct foo \[*\]+\r
82 $prompt $" { pass "whatis on opaque struct pointer (statically)"}
83 -re ".*$prompt $" { fail "whatis on opaque struct *" }
84 timeout { fail "(timeout) whatis on opaque struct *" }
85 }
86
87
88 # Ensure that we know the form of the structure that foop points to.
89
90 setup_xfail_on_opaque_pointer
91 send "ptype foop\n"
92 expect {
93 -re "ptype foop\r
94 type = struct foo \{\r
95 int a;\r
96 int b;\r
97 \} \[*\]+\r
98 $prompt $" { pass "ptype on opaque struct pointer (statically)" }
99 -re ".*$prompt $" { fail "ptype on opaque struct *" }
100 timeout { fail "(timeout) ptype on opaque struct *" }
101 }
102
103
104 # An instance of the opaque structure (afoo) is defined in a different file.
105 # Ensure that we can locate afoo and the structure definition.
106
107 send "whatis afoo\n"
108 expect {
109 -re "whatis afoo\r
110 type = struct foo\r
111 $prompt $" { pass "whatis on opaque struct instance (statically)" }
112 -re ".*$prompt $" { fail "whatis on opaque struct" }
113 timeout { fail "(timeout) whatis on opaque struct" }
114 }
115
116
117 # Ensure that we know the form of "afoo".
118
119 send "ptype afoo\n"
120 expect {
121 -re "ptype afoo\r
122 type = struct foo \{\r
123 int a;\r
124 int b;\r
125 \}\r
126 $prompt $" { pass "ptype on opaque struct instance (statically)" }
127 -re ".*$prompt $" { fail "ptype on opaque struct instance" }
128 timeout { fail "(timeout) ptype on opaque struct" }
129 }
130
131
132 # Ensure that we know what a struct foo looks like.
133
134 send "ptype struct foo\n"
135 expect {
136 -re "ptype struct foo\r
137 type = struct foo \{\r
138 int a;\r
139 int b;\r
140 \}\r
141 $prompt $" { pass "ptype on opaque struct tagname (statically)" }
142 -re ".*$prompt $" { fail "ptype on opaque struct" }
143 timeout { fail "(timeout) ptype on opaque struct" }
144 }
145
146
147 #
148 # Done with static tests, now test dynamic opaque structure handling.
149 # We reload the symbol table so we forget about anything we might
150 # have learned during the static tests.
151 #
152
153 if [istarget "mips-idt-*"] then {
154 # Restart because IDT/SIM runs out of file descriptors.
155 gdb_exit
156 gdb_start
157 }
158 gdb_reinitialize_dir $srcdir/$subdir
159 gdb_load $objdir/$subdir/$binfile
160
161 # Run to main, where struct foo is incomplete.
162 if ![runto main] {
163 perror "cannot run to breakpoint at main"
164 }
165
166
167 # The current source file is now the one containing main(). The structure foo
168 # is defined in a different file, but we have a pointer to an instance of
169 # the opaque structure in the current file. Ensure we know it's type.
170
171 setup_xfail_on_opaque_pointer
172 send "whatis foop\n"
173 expect {
174 -re "whatis foop\r
175 type = struct foo \[*\]+\r
176 $prompt $" { pass "whatis on opaque struct pointer (dynamically)"}
177 -re ".*$prompt $" { fail "whatis on opaque struct pointer" }
178 timeout { fail "(timeout) whatis on opaque struct ptr" }
179 }
180
181
182 # Ensure that we know the form of the thing foop points to.
183
184 setup_xfail_on_opaque_pointer
185 send "ptype foop\n"
186 expect {
187 -re "ptype foop\r
188 type = struct foo \{\r
189 int a;\r
190 int b;\r
191 \} \[*\]+\r
192 $prompt $" { pass "ptype on opaque struct pointer (dynamically)" }
193 -re ".*$prompt $" { fail "ptype on opaque struct *" }
194 timeout { fail "(timeout) ptype on opaque struct *" }
195 }
196
197
198 send "whatis afoo\n"
199 expect {
200 -re "whatis afoo\r
201 type = struct foo\r
202 $prompt $" { pass "whatis on opaque struct instance (dynamically)" }
203 -re ".*$prompt $" { fail "whatis on opaque struct" }
204 timeout { fail "(timeout) whatis on opaque struct" }
205 }
206
207
208 # Ensure that we know the form of afoo, an instance of a struct foo.
209
210 send "ptype afoo\n"
211 expect {
212 -re "ptype afoo\r
213 type = struct foo \{\r
214 int a;\r
215 int b;\r
216 \}\r
217 $prompt $" { pass "ptype on opaque struct instance (dynamically)" }
218 -re ".*$prompt $" { fail "ptype on opaque struct instance" }
219 timeout { fail "(timeout) ptype on opaque struct" }
220 }
221
222
223 # Ensure that we know the form of an explicit struct foo.
224
225 send "ptype struct foo\n"
226 expect {
227 -re "ptype struct foo\r
228 type = struct foo \{\r
229 int a;\r
230 int b;\r
231 \}\r
232 $prompt $" { pass "ptype on opaque struct tagname (dynamically)" }
233 -re ".*$prompt $" { fail "ptype on opaque struct" }
234 timeout { fail "(timeout) ptype on opaque struct" }
235 }
236
237
238 # Now reload the symbols again so we forget about anything we might
239 # have learned reading the symbols during the previous tests.
240
241 if [istarget "mips-idt-*"] then {
242 # Restart because IDT/SIM runs out of file descriptors.
243 gdb_exit
244 gdb_start
245 }
246 gdb_reinitialize_dir $srcdir/$subdir
247 gdb_load $objdir/$subdir/$binfile
248
249 # Run to getfoo, where struct foo is complete.
250 if ![runto getfoo] {
251 perror "cannot run to breakpoint at getfoo"
252 }
253
254
255 # Ensure that we know what foop is.
256
257 setup_xfail_on_opaque_pointer
258 send "whatis foop\n"
259 expect {
260 -re "whatis foop\r
261 type = struct foo \[*\]+\r
262 $prompt $" { pass "whatis on opaque struct pointer (dynamically)"}
263 -re ".*$prompt $" { fail "whatis on opaque struct pointer" }
264 timeout { fail "(timeout) whatis on opaque struct ptr" }
265 }
266
267
268 # Ensure that we know the form of the thing foop points to.
269
270 setup_xfail_on_opaque_pointer
271 send "ptype foop\n"
272 expect {
273 -re "ptype foop\r
274 type = struct foo \{\r
275 int a;\r
276 int b;\r
277 \} \[*\]+\r
278 $prompt $" { pass "ptype on opaque struct pointer (dynamically)" }
279 -re ".*$prompt $" { fail "ptype on opaque struct *" }
280 timeout { fail "(timeout) ptype on opaque struct *" }
281 }
282
283
284 send "whatis afoo\n"
285 expect {
286 -re "whatis afoo\r
287 type = struct foo\r
288 $prompt $" { pass "whatis on opaque struct instance (dynamically)" }
289 -re ".*$prompt $" { fail "whatis on opaque struct" }
290 timeout { fail "(timeout) whatis on opaque struct" }
291 }
292
293
294 # Ensure that we know the form of afoo, an instance of a struct foo.
295
296 send "ptype afoo\n"
297 expect {
298 -re "ptype afoo\r
299 type = struct foo \{\r
300 int a;\r
301 int b;\r
302 \}\r
303 $prompt $" { pass "ptype on opaque struct instance (dynamically)" }
304 -re ".*$prompt $" { fail "ptype on opaque struct instance" }
305 timeout { fail "(timeout) ptype on opaque struct" }
306 }
307
308
309 # Ensure that we know the form of an explicit struct foo.
310
311 send "ptype struct foo\n"
312 expect {
313 -re "ptype struct foo\r
314 type = struct foo \{\r
315 int a;\r
316 int b;\r
317 \}\r
318 $prompt $" { pass "ptype on opaque struct tagname (dynamically)" }
319 -re ".*$prompt $" { fail "ptype on opaque struct" }
320 timeout { fail "(timeout) ptype on opaque struct" }
321 }