]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.c++/member-ptr.exp
Only support interworking and pic for ELF or COFF targets
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.c++ / member-ptr.exp
1 # Copyright (C) 1998 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19 # Tests for pointer-to-member support
20 # Written by Satish Pai <pai@apollo.hp.com> 1997-08-19
21
22 # This file is part of the gdb testsuite
23
24
25 if $tracelevel then {
26 strace $tracelevel
27 }
28
29 #
30 # test running programs
31 #
32
33 # Start with a fresh gdb
34 gdb_exit
35 gdb_start
36 gdb_reinitialize_dir $srcdir/$subdir
37
38 set prms_id 0
39 set bug_id 0
40
41 set testfile "member-ptr"
42 set srcfile ${testfile}.cc
43 set binfile ${objdir}/${subdir}/${testfile}
44
45 # Create and source the file that provides information about the compiler
46 # used to compile the test case.
47
48 if [get_compiler_info ${binfile} "c++"] {
49 return -1
50 }
51
52 # Nearly all of these tests fail when compiled with G++, so just give up
53 # until GDB gets enhanced. -sts 1999-06-22
54
55 if {$gcc_compiled} {
56 continue
57 }
58
59 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
60 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
61 }
62
63
64 gdb_exit
65 gdb_start
66 gdb_reinitialize_dir $srcdir/$subdir
67 gdb_load ${binfile}
68
69
70 if ![runto_main] then {
71 perror "couldn't run to breakpoint"
72 continue
73 }
74
75 send_gdb "break 83\n"
76 gdb_expect {
77 -re "Breakpoint \[0-9\]*.*line 83\\.\r\n$gdb_prompt $" {
78 pass "set break at 83"
79 }
80 -re ".*$gdb_prompt $" { fail "set break at 83" }
81 timeout { fail "(timeout) set break at 83" }
82 }
83
84 send_gdb "continue\n"
85 gdb_expect {
86 -re "Continuing\\.\r\n\r\nBreakpoint.*at.*member-ptr\\.cc:83\r\n83\[ \t]*pmi = NULL;\r\n$gdb_prompt $" {
87 pass "continue to 83"
88 }
89 -re ".*$gdb_prompt $" { fail "continue to 83" }
90 timeout { fail "(timeout) continue to 83" }
91 }
92
93 # ptype on pointer to data member
94
95 send_gdb "ptype pmi\n"
96 gdb_expect {
97 -re "type = int \\( A::\\*\\)\r\n$gdb_prompt $" {
98 pass "ptype pmi"
99 }
100 -re ".*$gdb_prompt $" { fail "ptype pmi" }
101 timeout { fail "(timeout) ptype pmi" }
102 }
103
104 # print pointer to data member
105
106 setup_xfail "hppa*-*-*" CLLbs16901
107 send_gdb "print pmi\n"
108 gdb_expect {
109 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::j\r\n$gdb_prompt $" {
110 pass "print pmi"
111 }
112 -re ".*$gdb_prompt $" { fail "print pmi" }
113 timeout { fail "(timeout) print pmi" }
114 }
115
116
117 # print dereferenced pointer to data member
118
119 setup_xfail "hppa*-*-*" CLLbs16901
120 send_gdb "print a.*pmi\n"
121 gdb_expect {
122 -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
123 pass "print a.*pmi"
124 }
125 -re ".*$gdb_prompt $" { fail "print a.*pmi" }
126 timeout { fail "(timeout) print a.*pmi" }
127 }
128
129 # print dereferenced pointer to data member
130 # this time, dereferenced through a pointer
131
132 setup_xfail "hppa*-*-*" CLLbs16901
133 send_gdb "print a_p->*pmi\n"
134 gdb_expect {
135 -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
136 pass "print a->*pmi"
137 }
138 -re ".*$gdb_prompt $" { fail "print a->*pmi" }
139 timeout { fail "(timeout) print a->*pmi" }
140 }
141
142
143 # set the pointer to data member
144
145 send_gdb "set var pmi = &A::jj\n"
146 gdb_expect {
147 -re "$gdb_prompt $" {
148 pass "set var (not really a pass)"
149 }
150 timeout { fail "(timeout) " }
151 }
152
153 # Now print the pointer again
154
155 send_gdb "print pmi\n"
156 gdb_expect {
157 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
158 pass "print pmi after setting"
159 }
160 -re ".*$gdb_prompt $" { fail "print pmi after setting" }
161 timeout { fail "(timeout) print pmi after setting" }
162 }
163
164 # print dereferenced pointer to data member again
165
166 send_gdb "print a.*pmi\n"
167 gdb_expect {
168 -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
169 pass "print a.*pmi after setting"
170 }
171 -re ".*$gdb_prompt $" { fail "print a.*pmi after setting" }
172 timeout { fail "(timeout) print a.*pmi after setting" }
173 }
174
175 # set the pointer to data member back to A::j
176
177 send_gdb "set var pmi = &A::j\n"
178 gdb_expect {
179 -re "$gdb_prompt $" {
180 pass "set var back to A::j (not really a pass)"
181 }
182 timeout { fail "(timeout) set var pmi" }
183 }
184
185 # print dereferenced pointer to data member yet again (extra check, why not)
186
187 send_gdb "print a.*pmi\n"
188 gdb_expect {
189 -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
190 pass "print a.*pmi after resetting"
191 }
192 -re ".*$gdb_prompt $" { fail "print a.*pmi after resetting" }
193 timeout { fail "(timeout) print a.*pmi after resetting" }
194 }
195
196 # Set the data member pointed to.
197
198 send_gdb "print a.*pmi = 33\n"
199 gdb_expect {
200 -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" {
201 pass "print command to set"
202 }
203 -re ".*$gdb_prompt $" { fail "print command to set" }
204 timeout { fail "(timeout) print command to set" }
205 }
206
207 # Now check that the data really was changed
208 send_gdb "print a.*pmi\n"
209 gdb_expect {
210 -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" {
211 pass "print a.*pmi after setting member pointed to"
212 }
213 -re ".*$gdb_prompt $" { fail "print a.*pmi after setting member pointed to" }
214 timeout { fail "(timeout) print a.*pmi after setting member pointed to" }
215 }
216
217 # Double-check by printing a.
218 setup_xfail "hppa*-*-*" CLLbs16901
219 send_gdb "print a\n"
220 gdb_expect {
221 -re "\\$\[0-9\]* = \{c = 120 'x', j = 33, jj = 1331, static s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
222 pass "print a after setting member pointed to by pmi"
223 }
224 -re ".*$gdb_prompt $" { fail "print a after setting member pointed to by pmi" }
225 timeout { fail "(timeout) print a after setting member pointed to by pmi" }
226 }
227
228
229 # Set the data member pointed to, using ->*
230
231 send_gdb "print a_p->*pmi = 44\n"
232 gdb_expect {
233 -re "\\$\[0-9\]* = 44\r\n$gdb_prompt $" {
234 pass "print command to set (->)"
235 }
236 -re ".*$gdb_prompt $" { fail "print command to set (->)" }
237 timeout { fail "(timeout) print command to set (->)" }
238 }
239
240 # Now check that the data really was changed
241 send_gdb "print a_p->*pmi\n"
242 gdb_expect {
243 -re "\\$\[0-9\]* = 44\r\n$gdb_prompt $" {
244 pass "print a_p->*pmi after setting member pointed to"
245 }
246 -re ".*$gdb_prompt $" { fail "print a_p->*pmi after setting member pointed to" }
247 timeout { fail "(timeout) print a_p->*pmi after setting member pointed to" }
248 }
249
250 # Double-check by printing a.
251 setup_xfail "hppa*-*-*" CLLbs16901
252 send_gdb "print a\n"
253 gdb_expect {
254 -re "\\$\[0-9\]* = \{c = 120 'x', j = 44, jj = 1331, static s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
255 pass "print a after setting member pointed to by pmi (->) "
256 }
257 -re ".*$gdb_prompt $" { fail "print a after setting member pointed to by pmi (->) " }
258 timeout { fail "(timeout) print a after setting member pointed to by pmi (->) " }
259 }
260
261
262 # Do a ptype on the dereferenced pointer to member
263 # pai/1997-08-20 Doesn't work
264
265 # send_gdb "ptype a.*pmi\n"
266 # gdb_expect {
267 # -re "type = int\r\n$gdb_prompt $" {
268 # pass "ptype a.*pmi"
269 # }
270 # -re ".*$gdb_prompt $" { fail "ptype a.*pmi" }
271 # timeout { fail "(timeout) ptype a.*pmi" }
272 #}
273
274 # Try to dereference the pointer to data member without any object
275
276 send_gdb "print *pmi\n"
277 gdb_expect {
278 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
279 pass "attempt to print ptr to member without object"
280 }
281 -re ".*$gdb_prompt $" { fail "attempt to print ptr to member without object" }
282 timeout { fail "(timeout) attempt to print ptr to member without object" }
283 }
284
285 # Try to ptype a dereference of the pointer to data member without any object
286
287 send_gdb "ptype *pmi\n"
288 gdb_expect {
289 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
290 pass "attempt to ptype ptr to member without object"
291 }
292 -re ".*$gdb_prompt $" { fail "attempt to ptype ptr to member without object" }
293 timeout { fail "(timeout) attempt to ptype ptr to member without object" }
294 }
295
296 # Ptype a pointer to a method.
297
298 setup_xfail "hppa*-*-*" CLLbs16901
299 send_gdb "ptype pmf\n"
300 gdb_expect {
301 -re "type = int \\( A::\\*\\)\\(\\.\\.\\.\\)\r\n$gdb_prompt $" {
302 pass "ptype pmf"
303 }
304 -re ".*$gdb_prompt $" { fail "ptype pmf" }
305 timeout { fail "(timeout) ptype pmf" }
306 }
307
308 # print a pointer to a method
309
310 setup_xfail "hppa*-*-*" CLLbs16901
311 send_gdb "print pmf\n"
312 gdb_expect {
313 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\(\\.\\.\\.\\)\\) \\?\\? <not supported with HP aCC>\r\n$gdb_prompt $" {
314 pass "print pmf"
315 }
316 -re ".*$gdb_prompt $" { fail "print pmf" }
317 timeout { fail "(timeout) print pmf" }
318 }
319
320
321 # Ptype a pointer to a pointer to a method
322
323 setup_xfail "hppa*-*-*" CLLbs16901
324 send_gdb "ptype pmf_p\n"
325 gdb_expect {
326 -re "type = int \\( A::\\*\\*\\)\\(\\.\\.\\.\\)\r\n$gdb_prompt $" {
327 pass "ptype pmf_p"
328 }
329 -re ".*$gdb_prompt $" { fail "ptype pmf_p" }
330 timeout { fail "(timeout) ptype pmf_p" }
331 }
332
333 # print a pointer to a pointer to a method
334
335 setup_xfail "hppa*-*-*" CLLbs16901
336 send_gdb "print pmf_p\n"
337 gdb_expect {
338 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\*\\)\\(\\.\\.\\.\\)\\) $hex\r\n$gdb_prompt $" {
339 pass "print pmf_p"
340 }
341 -re ".*$gdb_prompt $" { fail "print pmf_p" }
342 timeout { fail "(timeout) print pmf_p" }
343 }
344
345 # print dereferenced pointer to method
346
347 setup_xfail "hppa*-*-*" CLLbs16901
348 send_gdb "print a.*pmf\n"
349 gdb_expect {
350 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
351 pass "print a.*pmf (known aCC limitation)"
352 }
353 -re ".*$gdb_prompt $" { fail "print a.*pmf" }
354 timeout { fail "(timeout) print a.*pmf" }
355 }
356
357 # print dereferenced pointer to method, using ->*
358
359 setup_xfail "hppa*-*-*" CLLbs16901
360 send_gdb "print a_p->*pmf\n"
361 gdb_expect {
362 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
363 pass "print a_p->*pmf (known aCC limitation)"
364 }
365 -re ".*$gdb_prompt $" { fail "print a_p->*pmf" }
366 timeout { fail "(timeout) print a_p->*pmf" }
367 }
368
369 # set the pointer to data member
370
371 setup_xfail "hppa*-*-*"
372 send_gdb "set var pmf = &A::foo\n"
373 gdb_expect {
374 -re "Assignment to pointers to methods not implemented with HP aCC\r\n$gdb_prompt $" {
375 pass "set var pmf (known aCC limitation)"
376 }
377 -re ".*$gdb_prompt $" { fail "set var pmf" }
378 timeout { fail "(timeout) set var pmf" }
379 }
380
381 # Try to dereference the pointer to method without any object
382
383 setup_xfail "hppa*-*-*" CLLbs16901
384 send_gdb "print *pmf\n"
385 gdb_expect {
386 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
387 pass "attempt to print ptr to method without object"
388 }
389 -re ".*$gdb_prompt $" { fail "attempt to print ptr to method without object" }
390 timeout { fail "(timeout) attempt to print ptr to method without object" }
391 }
392
393 # Try to ptype a dereference of the pointer to method without any object
394
395 send_gdb "ptype *pmi\n"
396 gdb_expect {
397 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
398 pass "attempt to ptype ptr to member without object"
399 }
400 -re ".*$gdb_prompt $" { fail "attempt to ptype ptr to member without object" }
401 timeout { fail "(timeout) attempt to ptype ptr to member without object" }
402 }
403
404 # Check cast of pointer to member to integer
405 setup_xfail "hppa*-*-*" CLLbs16901
406 send_gdb "print (int) pmi\n"
407 gdb_expect {
408 -re "\\$\[0-9\]* = 8\r\n$gdb_prompt $" {
409 pass "casting pmi to int"
410 }
411 -re ".*$gdb_prompt $" { fail "casting pmi to int" }
412 timeout { fail "(timeout) casting pmi to int" }
413 }
414
415 # Check cast of pointer to method to integer
416 setup_xfail "hppa*-*-*" CLLbs16901
417 send_gdb "print (int) pmf\n"
418 gdb_expect {
419 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
420 pass "casting pmf to int (known aCC limitation)"
421 }
422 -re ".*$gdb_prompt $" { fail "casting pmf to int" }
423 timeout { fail "(timeout) casting pmf to int" }
424 }
425
426 # Try to invoke a function through a pointer to data member
427 setup_xfail "hppa*-*-*" CLLbs16901
428 send_gdb "print (a.*pmi)(3)\n"
429 gdb_expect {
430 -re "Not implemented: function invocation through pointer to method with HP aCC\r\n$gdb_prompt $" {
431 pass "print (a.*pmi)(3) -- error message should be different"
432 }
433 -re ".*$gdb_prompt $" { fail "print (a.*pmi)(3)" }
434 timeout { fail "(timeout) print (a.*pmi)(3)" }
435 }
436
437 # Try to invoke a function through a pointer to a method
438 setup_xfail "hppa*-*-*" CLLbs16901
439 send_gdb "print (a.*pmf)(3)\n"
440 gdb_expect {
441 -re "Not implemented: function invocation through pointer to method with HP aCC\r\n$gdb_prompt $" {
442 pass "print (a.*pmi)(3) -- known aCC limitation"
443 }
444 -re ".*$gdb_prompt $" { fail "print (a.*pmf)(3)" }
445 timeout { fail "(timeout) print (a.*pmf)(3)" }
446 }
447
448
449 # Go past assignment of NULL to pmi
450 setup_xfail "hppa*-*-*" CLLbs16901
451 send_gdb "next\n"
452 gdb_expect {
453 -re "\r\n85\[ \t\]*k = \\(a.\\*pmf\\)\\(3\\);\r\n$gdb_prompt $" {
454 pass "next past 83"
455 }
456 -re ".*$gdb_prompt $" { fail "next past 83" }
457 timeout { fail "(timeout) next past 83" }
458 }
459
460 #send_gdb "print pmi\n"
461 #gdb_expect {
462 # -re "Attempted dereference of null pointer-to-member\r\n$gdb_prompt $" {
463 # pass ""
464 # }
465 # -re ".*$gdb_prompt $" { fail "" }
466 # timeout { fail "(timeout) " }
467 #}
468
469 # Dereference the null pointer to member
470 setup_xfail "hppa*-*-*" CLLbs16901
471 send_gdb "print a.*pmi\n"
472 gdb_expect {
473 -re "Attempted dereference of null pointer-to-member\r\n$gdb_prompt $" {
474 pass "print a.*NULL"
475 }
476 -re ".*$gdb_prompt $" { fail "print a.*NULL" }
477 timeout { fail "(timeout) print a.*NULL" }
478 }
479
480
481 # Go to another part of the program
482 send_gdb "break 91\n"
483 gdb_expect {
484 -re "Breakpoint \[0-9\]*.*line 91\\.\r\n$gdb_prompt $" {
485 pass "set break at 91"
486 }
487 -re ".*$gdb_prompt $" { fail "set break at 91" }
488 timeout { fail "(timeout) set break at 91" }
489 }
490
491 setup_xfail "hppa*-*-*" CLLbs16901
492 send_gdb "continue\n"
493 gdb_expect {
494 -re "Continuing\\.\r\n\r\nBreakpoint.*at.*member-ptr\\.cc:91\r\n91\[ \t]*k = \\(a.\\*pmf\\)\\(4\\);\r\n$gdb_prompt $" {
495 pass "continue to 91"
496 }
497 -re ".*$gdb_prompt $" { fail "continue to 91" }
498 timeout { fail "(timeout) continue to 91" }
499 }
500
501
502 # Now check again that pmi works even when not set to
503 # something that's at the beginning of the object
504
505 setup_xfail "hppa*-*-*" CLLbs16901
506 send_gdb "print pmi\n"
507 gdb_expect {
508 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
509 pass "print pmi (2)"
510 }
511 -re ".*$gdb_prompt $" { fail "print pmi (2)" }
512 timeout { fail "(timeout) print pmi (2)" }
513 }
514
515
516 # print dereferenced pointer to data member
517
518 setup_xfail "hppa*-*-*" CLLbs16901
519 send_gdb "print a.*pmi\n"
520 gdb_expect {
521 -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
522 pass "print a.*pmi (2)"
523 }
524 -re ".*$gdb_prompt $" { fail "print a.*pmi (2)" }
525 timeout { fail "(timeout) print a.*pmi (2)" }
526 }
527
528 # print dereferenced pointer to data member
529 # this time, dereferenced through a pointer
530
531 setup_xfail "hppa*-*-*" CLLbs16901
532 send_gdb "print a_p->*pmi\n"
533 gdb_expect {
534 -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
535 pass "print a->*pmi"
536 }
537 -re ".*$gdb_prompt $" { fail "print a->*pmi (2)" }
538 timeout { fail "(timeout) print a->*pmi (2)" }
539 }
540
541
542 # p a.*pmf - fail
543
544 # p pmi
545
546 # p a.*pmi
547