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.
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.
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
29 if { [skip_cplus_tests] } { continue }
32 # test running programs
35 # Start with a fresh gdb
38 gdb_reinitialize_dir $srcdir/$subdir
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++"] {
54 # Nearly all of these tests fail when compiled with G++, so just give up
55 # until GDB gets enhanced. -sts 1999-06-22
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."
68 gdb_reinitialize_dir $srcdir/$subdir
72 if ![runto_main] then {
73 perror "couldn't run to breakpoint"
79 -re "Breakpoint \[0-9\]*.*line 83\\.\r\n$gdb_prompt $" {
80 pass "set break at 83"
82 -re ".*$gdb_prompt $" { fail "set break at 83" }
83 timeout { fail "(timeout) set break at 83" }
88 -re "Continuing\\.\r\n\r\nBreakpoint.*at.*member-ptr\\.cc:83\r\n83\[ \t]*pmi = NULL;\r\n$gdb_prompt $" {
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"
99 -re "type = int \\( A::\\*\\)\r\n$gdb_prompt $" {
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"
111 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::j\r\n$gdb_prompt $" {
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"
124 -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
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"
137 -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
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"
149 -re "$gdb_prompt $" {
150 pass "set var (not really a pass)"
152 timeout { fail "(timeout) " }
155 # Now print the pointer again
157 send_gdb "print pmi\n"
159 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
160 pass "print pmi after setting"
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"
170 -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
171 pass "print a.*pmi after setting"
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"
181 -re "$gdb_prompt $" {
182 pass "set var back to A::j (not really a pass)"
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"
191 -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
192 pass "print a.*pmi after resetting"
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"
202 -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" {
203 pass "print command to set"
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"
212 -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" {
213 pass "print a.*pmi after setting member pointed to"
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
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"
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"
235 -re "\\$\[0-9\]* = 44\r\n$gdb_prompt $" {
236 pass "print command to set (->)"
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"
245 -re "\\$\[0-9\]* = 44\r\n$gdb_prompt $" {
246 pass "print a_p->*pmi after setting member pointed to"
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
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 (->) "
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"
269 # -re "type = int\r\n$gdb_prompt $" {
270 # pass "ptype a.*pmi"
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"
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"
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"
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"
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"
303 -re "type = int \\( A::\\*\\)\\(\\.\\.\\.\\)\r\n$gdb_prompt $" {
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"
315 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\(\\.\\.\\.\\)\\) \\?\\? <not supported with HP aCC>\r\n$gdb_prompt $" {
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"
328 -re "type = int \\( A::\\*\\*\\)\\(\\.\\.\\.\\)\r\n$gdb_prompt $" {
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"
340 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\*\\)\\(\\.\\.\\.\\)\\) $hex\r\n$gdb_prompt $" {
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"
352 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
353 pass "print a.*pmf (known aCC limitation)"
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"
364 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
365 pass "print a_p->*pmf (known aCC limitation)"
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"
376 -re "Assignment to pointers to methods not implemented with HP aCC\r\n$gdb_prompt $" {
377 pass "set var pmf (known aCC limitation)"
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"
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"
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"
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"
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"
410 -re "\\$\[0-9\]* = 8\r\n$gdb_prompt $" {
411 pass "casting pmi to int"
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"
421 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
422 pass "casting pmf to int (known aCC limitation)"
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"
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"
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"
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"
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
455 -re "\r\n85\[ \t\]*k = \\(a.\\*pmf\\)\\(3\\);\r\n$gdb_prompt $" {
458 -re ".*$gdb_prompt $" { fail "next past 83" }
459 timeout { fail "(timeout) next past 83" }
462 #send_gdb "print pmi\n"
464 # -re "Attempted dereference of null pointer-to-member\r\n$gdb_prompt $" {
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"
475 -re "Attempted dereference of null pointer-to-member\r\n$gdb_prompt $" {
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"
486 -re "Breakpoint \[0-9\]*.*line 91\\.\r\n$gdb_prompt $" {
487 pass "set break at 91"
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"
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"
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"
510 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
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"
523 -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
524 pass "print a.*pmi (2)"
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"
536 -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
539 -re ".*$gdb_prompt $" { fail "print a->*pmi (2)" }
540 timeout { fail "(timeout) print a->*pmi (2)" }