1 # Copyright (C) 1998 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
30 # test running programs
33 # Start with a fresh gdb
36 gdb_reinitialize_dir $srcdir/$subdir
41 set testfile "member-ptr"
42 set srcfile ${testfile}.cc
43 set binfile ${objdir}/${subdir}/${testfile}
45 # Create and source the file that provides information about the compiler
46 # used to compile the test case.
48 if [get_compiler_info ${binfile} "c++"] {
52 # Nearly all of these tests fail when compiled with G++, so just give up
53 # until GDB gets enhanced. -sts 1999-06-22
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."
66 gdb_reinitialize_dir $srcdir/$subdir
70 if ![runto_main] then {
71 perror "couldn't run to breakpoint"
77 -re "Breakpoint \[0-9\]*.*line 83\\.\r\n$gdb_prompt $" {
78 pass "set break at 83"
80 -re ".*$gdb_prompt $" { fail "set break at 83" }
81 timeout { fail "(timeout) set break at 83" }
86 -re "Continuing\\.\r\n\r\nBreakpoint.*at.*member-ptr\\.cc:83\r\n83\[ \t]*pmi = NULL;\r\n$gdb_prompt $" {
89 -re ".*$gdb_prompt $" { fail "continue to 83" }
90 timeout { fail "(timeout) continue to 83" }
93 # ptype on pointer to data member
95 send_gdb "ptype pmi\n"
97 -re "type = int \\( A::\\*\\)\r\n$gdb_prompt $" {
100 -re ".*$gdb_prompt $" { fail "ptype pmi" }
101 timeout { fail "(timeout) ptype pmi" }
104 # print pointer to data member
106 setup_xfail "hppa*-*-*" CLLbs16901
107 send_gdb "print pmi\n"
109 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::j\r\n$gdb_prompt $" {
112 -re ".*$gdb_prompt $" { fail "print pmi" }
113 timeout { fail "(timeout) print pmi" }
117 # print dereferenced pointer to data member
119 setup_xfail "hppa*-*-*" CLLbs16901
120 send_gdb "print a.*pmi\n"
122 -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
125 -re ".*$gdb_prompt $" { fail "print a.*pmi" }
126 timeout { fail "(timeout) print a.*pmi" }
129 # print dereferenced pointer to data member
130 # this time, dereferenced through a pointer
132 setup_xfail "hppa*-*-*" CLLbs16901
133 send_gdb "print a_p->*pmi\n"
135 -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
138 -re ".*$gdb_prompt $" { fail "print a->*pmi" }
139 timeout { fail "(timeout) print a->*pmi" }
143 # set the pointer to data member
145 send_gdb "set var pmi = &A::jj\n"
147 -re "$gdb_prompt $" {
148 pass "set var (not really a pass)"
150 timeout { fail "(timeout) " }
153 # Now print the pointer again
155 send_gdb "print pmi\n"
157 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
158 pass "print pmi after setting"
160 -re ".*$gdb_prompt $" { fail "print pmi after setting" }
161 timeout { fail "(timeout) print pmi after setting" }
164 # print dereferenced pointer to data member again
166 send_gdb "print a.*pmi\n"
168 -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
169 pass "print a.*pmi after setting"
171 -re ".*$gdb_prompt $" { fail "print a.*pmi after setting" }
172 timeout { fail "(timeout) print a.*pmi after setting" }
175 # set the pointer to data member back to A::j
177 send_gdb "set var pmi = &A::j\n"
179 -re "$gdb_prompt $" {
180 pass "set var back to A::j (not really a pass)"
182 timeout { fail "(timeout) set var pmi" }
185 # print dereferenced pointer to data member yet again (extra check, why not)
187 send_gdb "print a.*pmi\n"
189 -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
190 pass "print a.*pmi after resetting"
192 -re ".*$gdb_prompt $" { fail "print a.*pmi after resetting" }
193 timeout { fail "(timeout) print a.*pmi after resetting" }
196 # Set the data member pointed to.
198 send_gdb "print a.*pmi = 33\n"
200 -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" {
201 pass "print command to set"
203 -re ".*$gdb_prompt $" { fail "print command to set" }
204 timeout { fail "(timeout) print command to set" }
207 # Now check that the data really was changed
208 send_gdb "print a.*pmi\n"
210 -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" {
211 pass "print a.*pmi after setting member pointed to"
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" }
217 # Double-check by printing a.
218 setup_xfail "hppa*-*-*" CLLbs16901
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"
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" }
229 # Set the data member pointed to, using ->*
231 send_gdb "print a_p->*pmi = 44\n"
233 -re "\\$\[0-9\]* = 44\r\n$gdb_prompt $" {
234 pass "print command to set (->)"
236 -re ".*$gdb_prompt $" { fail "print command to set (->)" }
237 timeout { fail "(timeout) print command to set (->)" }
240 # Now check that the data really was changed
241 send_gdb "print a_p->*pmi\n"
243 -re "\\$\[0-9\]* = 44\r\n$gdb_prompt $" {
244 pass "print a_p->*pmi after setting member pointed to"
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" }
250 # Double-check by printing a.
251 setup_xfail "hppa*-*-*" CLLbs16901
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 (->) "
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 (->) " }
262 # Do a ptype on the dereferenced pointer to member
263 # pai/1997-08-20 Doesn't work
265 # send_gdb "ptype a.*pmi\n"
267 # -re "type = int\r\n$gdb_prompt $" {
268 # pass "ptype a.*pmi"
270 # -re ".*$gdb_prompt $" { fail "ptype a.*pmi" }
271 # timeout { fail "(timeout) ptype a.*pmi" }
274 # Try to dereference the pointer to data member without any object
276 send_gdb "print *pmi\n"
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"
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" }
285 # Try to ptype a dereference of the pointer to data member without any object
287 send_gdb "ptype *pmi\n"
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"
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" }
296 # Ptype a pointer to a method.
298 setup_xfail "hppa*-*-*" CLLbs16901
299 send_gdb "ptype pmf\n"
301 -re "type = int \\( A::\\*\\)\\(\\.\\.\\.\\)\r\n$gdb_prompt $" {
304 -re ".*$gdb_prompt $" { fail "ptype pmf" }
305 timeout { fail "(timeout) ptype pmf" }
308 # print a pointer to a method
310 setup_xfail "hppa*-*-*" CLLbs16901
311 send_gdb "print pmf\n"
313 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\(\\.\\.\\.\\)\\) \\?\\? <not supported with HP aCC>\r\n$gdb_prompt $" {
316 -re ".*$gdb_prompt $" { fail "print pmf" }
317 timeout { fail "(timeout) print pmf" }
321 # Ptype a pointer to a pointer to a method
323 setup_xfail "hppa*-*-*" CLLbs16901
324 send_gdb "ptype pmf_p\n"
326 -re "type = int \\( A::\\*\\*\\)\\(\\.\\.\\.\\)\r\n$gdb_prompt $" {
329 -re ".*$gdb_prompt $" { fail "ptype pmf_p" }
330 timeout { fail "(timeout) ptype pmf_p" }
333 # print a pointer to a pointer to a method
335 setup_xfail "hppa*-*-*" CLLbs16901
336 send_gdb "print pmf_p\n"
338 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\*\\)\\(\\.\\.\\.\\)\\) $hex\r\n$gdb_prompt $" {
341 -re ".*$gdb_prompt $" { fail "print pmf_p" }
342 timeout { fail "(timeout) print pmf_p" }
345 # print dereferenced pointer to method
347 setup_xfail "hppa*-*-*" CLLbs16901
348 send_gdb "print a.*pmf\n"
350 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
351 pass "print a.*pmf (known aCC limitation)"
353 -re ".*$gdb_prompt $" { fail "print a.*pmf" }
354 timeout { fail "(timeout) print a.*pmf" }
357 # print dereferenced pointer to method, using ->*
359 setup_xfail "hppa*-*-*" CLLbs16901
360 send_gdb "print a_p->*pmf\n"
362 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
363 pass "print a_p->*pmf (known aCC limitation)"
365 -re ".*$gdb_prompt $" { fail "print a_p->*pmf" }
366 timeout { fail "(timeout) print a_p->*pmf" }
369 # set the pointer to data member
371 setup_xfail "hppa*-*-*"
372 send_gdb "set var pmf = &A::foo\n"
374 -re "Assignment to pointers to methods not implemented with HP aCC\r\n$gdb_prompt $" {
375 pass "set var pmf (known aCC limitation)"
377 -re ".*$gdb_prompt $" { fail "set var pmf" }
378 timeout { fail "(timeout) set var pmf" }
381 # Try to dereference the pointer to method without any object
383 setup_xfail "hppa*-*-*" CLLbs16901
384 send_gdb "print *pmf\n"
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"
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" }
393 # Try to ptype a dereference of the pointer to method without any object
395 send_gdb "ptype *pmi\n"
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"
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" }
404 # Check cast of pointer to member to integer
405 setup_xfail "hppa*-*-*" CLLbs16901
406 send_gdb "print (int) pmi\n"
408 -re "\\$\[0-9\]* = 8\r\n$gdb_prompt $" {
409 pass "casting pmi to int"
411 -re ".*$gdb_prompt $" { fail "casting pmi to int" }
412 timeout { fail "(timeout) casting pmi to int" }
415 # Check cast of pointer to method to integer
416 setup_xfail "hppa*-*-*" CLLbs16901
417 send_gdb "print (int) pmf\n"
419 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
420 pass "casting pmf to int (known aCC limitation)"
422 -re ".*$gdb_prompt $" { fail "casting pmf to int" }
423 timeout { fail "(timeout) casting pmf to int" }
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"
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"
433 -re ".*$gdb_prompt $" { fail "print (a.*pmi)(3)" }
434 timeout { fail "(timeout) print (a.*pmi)(3)" }
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"
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"
444 -re ".*$gdb_prompt $" { fail "print (a.*pmf)(3)" }
445 timeout { fail "(timeout) print (a.*pmf)(3)" }
449 # Go past assignment of NULL to pmi
450 setup_xfail "hppa*-*-*" CLLbs16901
453 -re "\r\n85\[ \t\]*k = \\(a.\\*pmf\\)\\(3\\);\r\n$gdb_prompt $" {
456 -re ".*$gdb_prompt $" { fail "next past 83" }
457 timeout { fail "(timeout) next past 83" }
460 #send_gdb "print pmi\n"
462 # -re "Attempted dereference of null pointer-to-member\r\n$gdb_prompt $" {
465 # -re ".*$gdb_prompt $" { fail "" }
466 # timeout { fail "(timeout) " }
469 # Dereference the null pointer to member
470 setup_xfail "hppa*-*-*" CLLbs16901
471 send_gdb "print a.*pmi\n"
473 -re "Attempted dereference of null pointer-to-member\r\n$gdb_prompt $" {
476 -re ".*$gdb_prompt $" { fail "print a.*NULL" }
477 timeout { fail "(timeout) print a.*NULL" }
481 # Go to another part of the program
482 send_gdb "break 91\n"
484 -re "Breakpoint \[0-9\]*.*line 91\\.\r\n$gdb_prompt $" {
485 pass "set break at 91"
487 -re ".*$gdb_prompt $" { fail "set break at 91" }
488 timeout { fail "(timeout) set break at 91" }
491 setup_xfail "hppa*-*-*" CLLbs16901
492 send_gdb "continue\n"
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"
497 -re ".*$gdb_prompt $" { fail "continue to 91" }
498 timeout { fail "(timeout) continue to 91" }
502 # Now check again that pmi works even when not set to
503 # something that's at the beginning of the object
505 setup_xfail "hppa*-*-*" CLLbs16901
506 send_gdb "print pmi\n"
508 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
511 -re ".*$gdb_prompt $" { fail "print pmi (2)" }
512 timeout { fail "(timeout) print pmi (2)" }
516 # print dereferenced pointer to data member
518 setup_xfail "hppa*-*-*" CLLbs16901
519 send_gdb "print a.*pmi\n"
521 -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
522 pass "print a.*pmi (2)"
524 -re ".*$gdb_prompt $" { fail "print a.*pmi (2)" }
525 timeout { fail "(timeout) print a.*pmi (2)" }
528 # print dereferenced pointer to data member
529 # this time, dereferenced through a pointer
531 setup_xfail "hppa*-*-*" CLLbs16901
532 send_gdb "print a_p->*pmi\n"
534 -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
537 -re ".*$gdb_prompt $" { fail "print a->*pmi (2)" }
538 timeout { fail "(timeout) print a->*pmi (2)" }