* Contribute CGEN simulator build support code.
[binutils-gdb.git] / gdb / testsuite / gdb.c++ / member-ptr.exp
blobb7c6206cb766501211d67f532e1acfde9437e1c6
1 # Copyright (C) 1998, 1999 Free Software Foundation, Inc.
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.  
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
22 # This file is part of the gdb testsuite
25 if $tracelevel then {
26         strace $tracelevel
27         }
29 if { [skip_cplus_tests] } { continue }
32 # test running programs
35 # Start with a fresh gdb
36 gdb_exit
37 gdb_start
38 gdb_reinitialize_dir $srcdir/$subdir
40 set prms_id 0
41 set bug_id 0
43 set testfile "member-ptr"
44 set srcfile ${testfile}.cc
45 set binfile ${objdir}/${subdir}/${testfile}
47 # Create and source the file that provides information about the compiler
48 # used to compile the test case.
50 if [get_compiler_info ${binfile} "c++"] {
51     return -1
54 # Nearly all of these tests fail when compiled with G++, so just give up
55 # until GDB gets enhanced. -sts 1999-06-22
57 if {$gcc_compiled} {
58     continue 
61 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
62      gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
66 gdb_exit
67 gdb_start
68 gdb_reinitialize_dir $srcdir/$subdir
69 gdb_load ${binfile}
72 if ![runto_main] then {
73     perror "couldn't run to breakpoint"
74     continue
77 send_gdb "break 83\n"
78 gdb_expect {
79    -re "Breakpoint \[0-9\]*.*line 83\\.\r\n$gdb_prompt $" {
80       pass "set break at 83"
81     }
82     -re ".*$gdb_prompt $" { fail "set break at 83" }
83     timeout { fail "(timeout) set break at 83" }
86 send_gdb "continue\n"
87 gdb_expect {
88    -re "Continuing\\.\r\n\r\nBreakpoint.*at.*member-ptr\\.cc:83\r\n83\[ \t]*pmi = NULL;\r\n$gdb_prompt $" {
89       pass "continue to 83"
90     }
91     -re ".*$gdb_prompt $" { fail "continue to 83" }
92     timeout { fail "(timeout) continue to 83" }
95 # ptype on pointer to data member
97 send_gdb "ptype pmi\n"
98 gdb_expect {
99    -re "type = int \\( A::\\*\\)\r\n$gdb_prompt $" {
100       pass "ptype pmi"
101     }
102     -re ".*$gdb_prompt $" { fail "ptype pmi" }
103     timeout { fail "(timeout) ptype pmi" }
106 # print pointer to data member
108 setup_xfail "hppa*-*-*" CLLbs16901
109 send_gdb "print pmi\n"
110 gdb_expect {
111    -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::j\r\n$gdb_prompt $" {
112       pass "print pmi"
113     }
114     -re ".*$gdb_prompt $" { fail "print pmi" }
115     timeout { fail "(timeout) print pmi" }
119 # print dereferenced pointer to data member
121 setup_xfail "hppa*-*-*" CLLbs16901
122 send_gdb "print a.*pmi\n"
123 gdb_expect {
124    -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
125       pass "print a.*pmi"
126     }
127     -re ".*$gdb_prompt $" { fail "print a.*pmi" }
128     timeout { fail "(timeout) print a.*pmi" }
131 # print dereferenced pointer to data member
132 # this time, dereferenced through a pointer
134 setup_xfail "hppa*-*-*" CLLbs16901
135 send_gdb "print a_p->*pmi\n"
136 gdb_expect {
137    -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
138       pass "print a->*pmi"
139     }
140     -re ".*$gdb_prompt $" { fail "print a->*pmi" }
141     timeout { fail "(timeout) print a->*pmi" }
145 # set the pointer to data member
147 send_gdb "set var pmi = &A::jj\n"
148 gdb_expect {
149    -re "$gdb_prompt $" {
150       pass "set var (not really a pass)"
151     }
152     timeout { fail "(timeout) " }
155 # Now print the pointer again
157 send_gdb "print pmi\n"
158 gdb_expect {
159    -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
160       pass "print pmi after setting"
161     }
162     -re ".*$gdb_prompt $" { fail "print pmi after setting" }
163     timeout { fail "(timeout) print pmi after setting" }
166 # print dereferenced pointer to data member again
168 send_gdb "print a.*pmi\n"
169 gdb_expect {
170    -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
171       pass "print a.*pmi after setting"
172     }
173     -re ".*$gdb_prompt $" { fail "print a.*pmi after setting" }
174     timeout { fail "(timeout) print a.*pmi after setting" }
177 # set the pointer to data member back to A::j
179 send_gdb "set var pmi = &A::j\n"
180 gdb_expect {
181    -re "$gdb_prompt $" {
182       pass "set var back to A::j (not really a pass)"
183     }
184     timeout { fail "(timeout) set var pmi" }
187 # print dereferenced pointer to data member yet again (extra check, why not)
189 send_gdb "print a.*pmi\n"
190 gdb_expect {
191    -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
192       pass "print a.*pmi after resetting"
193     }
194     -re ".*$gdb_prompt $" { fail "print a.*pmi after resetting" }
195     timeout { fail "(timeout) print a.*pmi after resetting" }
198 # Set the data member pointed to.
200 send_gdb "print a.*pmi = 33\n"
201 gdb_expect {
202    -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" {
203       pass "print command to set"
204     }
205     -re ".*$gdb_prompt $" { fail "print command to set" }
206     timeout { fail "(timeout) print command to set" }
209 # Now check that the data really was changed
210 send_gdb "print a.*pmi\n"
211 gdb_expect {
212    -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" {
213       pass "print a.*pmi after setting member pointed to"
214     }
215     -re ".*$gdb_prompt $" { fail "print a.*pmi after setting member pointed to" }
216     timeout { fail "(timeout) print a.*pmi after setting member pointed to" }
219 # Double-check by printing a.
220 setup_xfail "hppa*-*-*" CLLbs16901
221 send_gdb "print a\n"
222 gdb_expect {
223    -re "\\$\[0-9\]* = \{c = 120 'x', j = 33, jj = 1331, static s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
224       pass "print a after setting member pointed to by pmi"
225     }
226     -re ".*$gdb_prompt $" { fail "print a after setting member pointed to by pmi" }
227     timeout { fail "(timeout) print a after setting member pointed to by pmi" }
231 # Set the data member pointed to, using ->*
233 send_gdb "print a_p->*pmi = 44\n"
234 gdb_expect {
235    -re "\\$\[0-9\]* = 44\r\n$gdb_prompt $" {
236       pass "print command to set (->)"
237     }
238     -re ".*$gdb_prompt $" { fail "print command to set (->)" }
239     timeout { fail "(timeout) print command to set (->)" }
242 # Now check that the data really was changed
243 send_gdb "print a_p->*pmi\n"
244 gdb_expect {
245    -re "\\$\[0-9\]* = 44\r\n$gdb_prompt $" {
246       pass "print a_p->*pmi after setting member pointed to"
247     }
248     -re ".*$gdb_prompt $" { fail "print a_p->*pmi after setting member pointed to" }
249     timeout { fail "(timeout) print a_p->*pmi after setting member pointed to" }
252 # Double-check by printing a.
253 setup_xfail "hppa*-*-*" CLLbs16901
254 send_gdb "print a\n"
255 gdb_expect {
256    -re "\\$\[0-9\]* = \{c = 120 'x', j = 44, jj = 1331, static s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
257       pass "print a after setting member pointed to by pmi (->) "
258     }
259     -re ".*$gdb_prompt $" { fail "print a after setting member pointed to by pmi (->) " }
260     timeout { fail "(timeout) print a after setting member pointed to by pmi (->) " }
264 # Do a ptype on the dereferenced pointer to member
265 # pai/1997-08-20 Doesn't work
267 # send_gdb "ptype a.*pmi\n"
268 # gdb_expect {
269 #   -re "type = int\r\n$gdb_prompt $" {
270 #      pass "ptype a.*pmi"
271 #    }
272 #    -re ".*$gdb_prompt $" { fail "ptype a.*pmi" }
273 #    timeout { fail "(timeout) ptype a.*pmi" }
276 # Try to dereference the pointer to data member without any object
278 send_gdb "print *pmi\n"
279 gdb_expect {
280    -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
281       pass "attempt to print ptr to member without object"
282     }
283     -re ".*$gdb_prompt $" { fail "attempt to print ptr to member without object" }
284     timeout { fail "(timeout) attempt to print ptr to member without object" }
287 # Try to ptype a dereference of the pointer to data member without any object
289 send_gdb "ptype *pmi\n"
290 gdb_expect {
291    -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
292       pass "attempt to ptype ptr to member without object"
293     }
294     -re ".*$gdb_prompt $" { fail "attempt to ptype ptr to member without object" }
295     timeout { fail "(timeout) attempt to ptype ptr to member without object" }
298 # Ptype a pointer to a method.
300 setup_xfail "hppa*-*-*" CLLbs16901
301 send_gdb "ptype pmf\n"
302 gdb_expect {
303    -re "type = int \\( A::\\*\\)\\(\\.\\.\\.\\)\r\n$gdb_prompt $" {
304       pass "ptype pmf"
305     }
306     -re ".*$gdb_prompt $" { fail "ptype pmf" }
307     timeout { fail "(timeout) ptype pmf" }
310 # print a pointer to a method
312 setup_xfail "hppa*-*-*" CLLbs16901
313 send_gdb "print pmf\n"
314 gdb_expect {
315    -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\(\\.\\.\\.\\)\\) \\?\\? <not supported with HP aCC>\r\n$gdb_prompt $" {
316       pass "print pmf"
317     }
318     -re ".*$gdb_prompt $" { fail "print pmf" }
319     timeout { fail "(timeout) print pmf" }
323 # Ptype a pointer to a pointer to a method
325 setup_xfail "hppa*-*-*" CLLbs16901
326 send_gdb "ptype pmf_p\n"
327 gdb_expect {
328    -re "type = int \\( A::\\*\\*\\)\\(\\.\\.\\.\\)\r\n$gdb_prompt $" {
329       pass "ptype pmf_p"
330     }
331     -re ".*$gdb_prompt $" { fail "ptype pmf_p" }
332     timeout { fail "(timeout) ptype pmf_p" }
335 # print a pointer to a pointer to a method
337 setup_xfail "hppa*-*-*" CLLbs16901
338 send_gdb "print pmf_p\n"
339 gdb_expect {
340    -re "\\$\[0-9\]* = \\(int \\( A::\\*\\*\\)\\(\\.\\.\\.\\)\\) $hex\r\n$gdb_prompt $" {
341       pass "print pmf_p"
342     }
343     -re ".*$gdb_prompt $" { fail "print pmf_p" }
344     timeout { fail "(timeout) print pmf_p" }
347 # print dereferenced pointer to method
349 setup_xfail "hppa*-*-*" CLLbs16901
350 send_gdb "print a.*pmf\n"
351 gdb_expect {
352    -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
353       pass "print a.*pmf (known aCC limitation)"
354     }
355     -re ".*$gdb_prompt $" { fail "print a.*pmf" }
356     timeout { fail "(timeout) print a.*pmf" }
359 # print dereferenced pointer to method, using ->*
361 setup_xfail "hppa*-*-*" CLLbs16901
362 send_gdb "print a_p->*pmf\n"
363 gdb_expect {
364    -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
365       pass "print a_p->*pmf (known aCC limitation)"
366     }
367     -re ".*$gdb_prompt $" { fail "print a_p->*pmf" }
368     timeout { fail "(timeout) print a_p->*pmf" }
371 # set the pointer to data member
373 setup_xfail "hppa*-*-*"
374 send_gdb "set var pmf = &A::foo\n"
375 gdb_expect {
376    -re "Assignment to pointers to methods not implemented with HP aCC\r\n$gdb_prompt $" {
377       pass "set var pmf (known aCC limitation)"
378     }
379     -re ".*$gdb_prompt $" { fail "set var pmf" }
380     timeout { fail "(timeout) set var pmf" }
383 # Try to dereference the pointer to method without any object
385 setup_xfail "hppa*-*-*" CLLbs16901
386 send_gdb "print *pmf\n"
387 gdb_expect {
388    -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
389       pass "attempt to print  ptr to method without object"
390     }
391     -re ".*$gdb_prompt $" { fail "attempt to print ptr to method without object" }
392     timeout { fail "(timeout) attempt to print ptr to method without object" }
395 # Try to ptype a dereference of the pointer to method without any object
397 send_gdb "ptype *pmi\n"
398 gdb_expect {
399    -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
400       pass "attempt to ptype ptr to member without object"
401     }
402     -re ".*$gdb_prompt $" { fail "attempt to ptype ptr to member without object" }
403     timeout { fail "(timeout) attempt to ptype ptr to member without object" }
406 # Check cast of pointer to member to integer
407 setup_xfail "hppa*-*-*" CLLbs16901
408 send_gdb "print (int) pmi\n"
409 gdb_expect {
410    -re "\\$\[0-9\]* = 8\r\n$gdb_prompt $" {
411       pass "casting pmi to int"
412     }
413     -re ".*$gdb_prompt $" { fail "casting pmi to int" }
414     timeout { fail "(timeout) casting pmi to int" }
417 # Check cast of pointer to method to integer
418 setup_xfail "hppa*-*-*" CLLbs16901
419 send_gdb "print (int) pmf\n"
420 gdb_expect {
421    -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
422       pass "casting pmf to int (known aCC limitation)"
423     }
424     -re ".*$gdb_prompt $" { fail "casting pmf to int" }
425     timeout { fail "(timeout) casting pmf to int" }
428 # Try to invoke a function through a pointer to data member
429 setup_xfail "hppa*-*-*" CLLbs16901
430 send_gdb "print (a.*pmi)(3)\n"
431 gdb_expect {
432    -re "Not implemented: function invocation through pointer to method with HP aCC\r\n$gdb_prompt $" {
433       pass "print (a.*pmi)(3) -- error message should be different"
434     }
435     -re ".*$gdb_prompt $" { fail "print (a.*pmi)(3)" }
436     timeout { fail "(timeout) print (a.*pmi)(3)" }
439 # Try to invoke a function through a pointer to a method
440 setup_xfail "hppa*-*-*" CLLbs16901
441 send_gdb "print (a.*pmf)(3)\n"
442 gdb_expect {
443    -re "Not implemented: function invocation through pointer to method with HP aCC\r\n$gdb_prompt $" {
444       pass "print (a.*pmi)(3) -- known aCC limitation"
445     }
446     -re ".*$gdb_prompt $" { fail "print (a.*pmf)(3)" }
447     timeout { fail "(timeout) print (a.*pmf)(3)" }
451 # Go past assignment of NULL to pmi
452 setup_xfail "hppa*-*-*" CLLbs16901
453 send_gdb "next\n"
454 gdb_expect {
455    -re "\r\n85\[ \t\]*k = \\(a.\\*pmf\\)\\(3\\);\r\n$gdb_prompt $" {
456       pass "next past 83"
457     }
458     -re ".*$gdb_prompt $" { fail "next past 83" }
459     timeout { fail "(timeout) next past 83" }
462 #send_gdb "print pmi\n"
463 #gdb_expect {
464 #   -re "Attempted dereference of null pointer-to-member\r\n$gdb_prompt $" {
465 #      pass ""
466 #    }
467 #    -re ".*$gdb_prompt $" { fail "" }
468 #    timeout { fail "(timeout) " }
471 # Dereference the null pointer to member
472 setup_xfail "hppa*-*-*" CLLbs16901
473 send_gdb "print a.*pmi\n"
474 gdb_expect {
475    -re "Attempted dereference of null pointer-to-member\r\n$gdb_prompt $" {
476       pass "print a.*NULL"
477     }
478     -re ".*$gdb_prompt $" { fail "print a.*NULL" }
479     timeout { fail "(timeout) print a.*NULL" }
483 # Go to another part of the program
484 send_gdb "break 91\n"
485 gdb_expect {
486    -re "Breakpoint \[0-9\]*.*line 91\\.\r\n$gdb_prompt $" {
487       pass "set break at 91"
488     }
489     -re ".*$gdb_prompt $" { fail "set break at 91" }
490     timeout { fail "(timeout) set break at 91" }
493 setup_xfail "hppa*-*-*" CLLbs16901
494 send_gdb "continue\n"
495 gdb_expect {
496    -re "Continuing\\.\r\n\r\nBreakpoint.*at.*member-ptr\\.cc:91\r\n91\[ \t]*k = \\(a.\\*pmf\\)\\(4\\);\r\n$gdb_prompt $" {
497       pass "continue to 91"
498     }
499     -re ".*$gdb_prompt $" { fail "continue to 91" }
500     timeout { fail "(timeout) continue to 91" }
504 # Now check again that pmi works even when not set to
505 # something that's at the beginning of the object
507 setup_xfail "hppa*-*-*" CLLbs16901
508 send_gdb "print pmi\n"
509 gdb_expect {
510    -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
511       pass "print pmi (2)"
512     }
513     -re ".*$gdb_prompt $" { fail "print pmi (2)" }
514     timeout { fail "(timeout) print pmi (2)" }
518 # print dereferenced pointer to data member
520 setup_xfail "hppa*-*-*" CLLbs16901
521 send_gdb "print a.*pmi\n"
522 gdb_expect {
523    -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
524       pass "print a.*pmi (2)"
525     }
526     -re ".*$gdb_prompt $" { fail "print a.*pmi (2)" }
527     timeout { fail "(timeout) print a.*pmi (2)" }
530 # print dereferenced pointer to data member
531 # this time, dereferenced through a pointer
533 setup_xfail "hppa*-*-*" CLLbs16901
534 send_gdb "print a_p->*pmi\n"
535 gdb_expect {
536    -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
537       pass "print a->*pmi"
538     }
539     -re ".*$gdb_prompt $" { fail "print a->*pmi (2)" }
540     timeout { fail "(timeout) print a->*pmi (2)" }
544 # p a.*pmf - fail
546 # p pmi
548 # p a.*pmi