]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/opaque.exp
Use gdb_run_cmd
[thirdparty/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 # Set breakpoint on main, where struct foo is incomplete.
162
163 send "break main\n"
164 expect {
165 -re "Breakpoint.*at.* file .*opaque0.c, line.*$prompt $" {}
166 -re ".*$prompt $" { fail "setting breakpoint at main" }
167 timeout { fail "(timeout) setting breakpoint" }
168 }
169
170
171 # Run until break at main. Struct foo is opaque in the file containing
172 # main().
173
174 gdb_run_cmd
175 expect {
176 -re "Breakpoint 1.*$prompt $" {}
177 -re ".*$prompt $" { fail "run until main()" }
178 timeout { fail "(timeout) run until main()" }
179 }
180
181
182 # The current source file is now the one containing main(). The structure foo
183 # is defined in a different file, but we have a pointer to an instance of
184 # the opaque structure in the current file. Ensure we know it's type.
185
186 setup_xfail_on_opaque_pointer
187 send "whatis foop\n"
188 expect {
189 -re "whatis foop\r
190 type = struct foo \[*\]+\r
191 $prompt $" { pass "whatis on opaque struct pointer (dynamically)"}
192 -re ".*$prompt $" { fail "whatis on opaque struct pointer" }
193 timeout { fail "(timeout) whatis on opaque struct ptr" }
194 }
195
196
197 # Ensure that we know the form of the thing foop points to.
198
199 setup_xfail_on_opaque_pointer
200 send "ptype foop\n"
201 expect {
202 -re "ptype foop\r
203 type = struct foo \{\r
204 int a;\r
205 int b;\r
206 \} \[*\]+\r
207 $prompt $" { pass "ptype on opaque struct pointer (dynamically)" }
208 -re ".*$prompt $" { fail "ptype on opaque struct *" }
209 timeout { fail "(timeout) ptype on opaque struct *" }
210 }
211
212
213 send "whatis afoo\n"
214 expect {
215 -re "whatis afoo\r
216 type = struct foo\r
217 $prompt $" { pass "whatis on opaque struct instance (dynamically)" }
218 -re ".*$prompt $" { fail "whatis on opaque struct" }
219 timeout { fail "(timeout) whatis on opaque struct" }
220 }
221
222
223 # Ensure that we know the form of afoo, an instance of a struct foo.
224
225 send "ptype afoo\n"
226 expect {
227 -re "ptype afoo\r
228 type = struct foo \{\r
229 int a;\r
230 int b;\r
231 \}\r
232 $prompt $" { pass "ptype on opaque struct instance (dynamically)" }
233 -re ".*$prompt $" { fail "ptype on opaque struct instance" }
234 timeout { fail "(timeout) ptype on opaque struct" }
235 }
236
237
238 # Ensure that we know the form of an explicit struct foo.
239
240 send "ptype struct foo\n"
241 expect {
242 -re "ptype struct foo\r
243 type = struct foo \{\r
244 int a;\r
245 int b;\r
246 \}\r
247 $prompt $" { pass "ptype on opaque struct tagname (dynamically)" }
248 -re ".*$prompt $" { fail "ptype on opaque struct" }
249 timeout { fail "(timeout) ptype on opaque struct" }
250 }
251
252
253 # Now reload the symbols again so we forget about anything we might
254 # have learned reading the symbols during the previous tests.
255
256 gdb_reinitialize_dir $srcdir/$subdir
257 gdb_load $objdir/$subdir/$binfile
258
259 # Disable the breakoint on main().
260 # Set breakpoint on getfoo, where struct foo is complete.
261
262 send "disable 1\n"
263 expect {
264 -re ".*$prompt $" {}
265 timeout { fail "(timeout) disabling breakpoint" }
266 }
267
268
269 send "break getfoo\n"
270 expect {
271 -re "Breakpoint.*at.* file .*opaque1\.c, line.*$prompt $" {}
272 -re ".*$prompt $" { fail "setting breakpoint at getfoo" }
273 timeout { fail "(timeout) setting breakpoint" }
274 }
275
276
277 # Run until break at getfoo(). Struct foo is defined here.
278 # Retry all the tests we we tried at main() where struct foo was opaque.
279
280 gdb_run_cmd
281 expect {
282 -re "Breakpoint.*$prompt $" {}
283 -re ".*$prompt $" { fail "run until getfoo()" }
284 timeout { fail "(timeout) run until getfoo()" }
285 }
286
287
288 # Ensure that we know what foop is.
289
290 setup_xfail_on_opaque_pointer
291 send "whatis foop\n"
292 expect {
293 -re "whatis foop\r
294 type = struct foo \[*\]+\r
295 $prompt $" { pass "whatis on opaque struct pointer (dynamically)"}
296 -re ".*$prompt $" { fail "whatis on opaque struct pointer" }
297 timeout { fail "(timeout) whatis on opaque struct ptr" }
298 }
299
300
301 # Ensure that we know the form of the thing foop points to.
302
303 setup_xfail_on_opaque_pointer
304 send "ptype foop\n"
305 expect {
306 -re "ptype foop\r
307 type = struct foo \{\r
308 int a;\r
309 int b;\r
310 \} \[*\]+\r
311 $prompt $" { pass "ptype on opaque struct pointer (dynamically)" }
312 -re ".*$prompt $" { fail "ptype on opaque struct *" }
313 timeout { fail "(timeout) ptype on opaque struct *" }
314 }
315
316
317 send "whatis afoo\n"
318 expect {
319 -re "whatis afoo\r
320 type = struct foo\r
321 $prompt $" { pass "whatis on opaque struct instance (dynamically)" }
322 -re ".*$prompt $" { fail "whatis on opaque struct" }
323 timeout { fail "(timeout) whatis on opaque struct" }
324 }
325
326
327 # Ensure that we know the form of afoo, an instance of a struct foo.
328
329 send "ptype afoo\n"
330 expect {
331 -re "ptype afoo\r
332 type = struct foo \{\r
333 int a;\r
334 int b;\r
335 \}\r
336 $prompt $" { pass "ptype on opaque struct instance (dynamically)" }
337 -re ".*$prompt $" { fail "ptype on opaque struct instance" }
338 timeout { fail "(timeout) ptype on opaque struct" }
339 }
340
341
342 # Ensure that we know the form of an explicit struct foo.
343
344 send "ptype struct foo\n"
345 expect {
346 -re "ptype struct foo\r
347 type = struct foo \{\r
348 int a;\r
349 int b;\r
350 \}\r
351 $prompt $" { pass "ptype on opaque struct tagname (dynamically)" }
352 -re ".*$prompt $" { fail "ptype on opaque struct" }
353 timeout { fail "(timeout) ptype on opaque struct" }
354 }