1 # Copyright 1998, 1999, 2003, 2004 Free Software Foundation, Inc.
3 # This file is part of the gdb testsuite
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # Tests for pointer-to-member support
20 # Written by Satish Pai <pai@apollo.hp.com> 1997-08-19
21 # Rewritten by Michael Chastain <mec.gnu@mindspring.com> 2004-01-11
23 # TODO: copyright notice for member-ptr.cc
31 if { [skip_cplus_tests] } { continue }
36 set testfile "member-ptr"
37 set srcfile ${testfile}.cc
38 set binfile ${objdir}/${subdir}/${testfile}
40 if [get_compiler_info ${binfile} "c++"] {
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
45 untested member-ptr.exp
51 gdb_reinitialize_dir $srcdir/$subdir
54 if ![runto_main] then {
55 perror "couldn't run to breakpoint"
59 gdb_breakpoint [gdb_get_line_number "pmi = NULL"]
60 gdb_continue_to_breakpoint "continue to pmi = NULL"
62 # gcc is not ready for production
63 # -- chastain 2004-01-12
65 if { [test_compiler_info "gcc-*"] } {
69 # ======================
70 # pointer to member data
71 # ======================
73 # ptype on pointer to data member
75 set name "ptype pmi (A::j)"
76 gdb_test_multiple "ptype pmi" $name {
77 -re "type = int *\\( ?A::\\*\\)\r\n$gdb_prompt $" {
80 -re "type = int *A::\r\n$gdb_prompt $" {
81 # gcc HEAD 2004-01-10 -gdwarf-2
82 # gcc HEAD 2004-01-10 -gstabs+
83 kfail "gdb/NNNN" $name
87 # print pointer to data member
89 set name "print pmi (A::j) "
90 gdb_test_multiple "print pmi" $name {
91 -re "$vhn = &A::j\r\n$gdb_prompt $" {
94 -re "$vhn = \\(int ?\\( ?A::\\*\\)\\) &A::j\r\n$gdb_prompt $" {
97 -re "$vhn = \\(int ?\\( ?A::\\*\\)\\) ?&A::j ?\\+ ?1 bytes\r\n$gdb_prompt $" {
98 # gcc 2.95.3 -gdwarf-2
99 kfail "gdb/NNNN" $name
101 -re "$vhn = &A::j ?\\+ ?1 bytes\r\n$gdb_prompt $" {
102 # gcc 2.95.3 -gstabs+
103 kfail "gdb/NNNN" $name
105 -re "$vhn = not implemented: member type in c_val_print\r\n$gdb_prompt $" {
106 # gcc HEAD 2004-01-11 05:33:21 -gdwarf-2
107 # gcc HEAD 2004-01-11 05:33:21 -gstabs+
108 kfail "gdb/NNNN" $name
110 -re "$vhn = \\(int ?\\( A::\\*\\)\\) 536870920\r\n$gdb_prompt $" {
111 # the value is 0x20000008 hex. 0x20000000 is an internal flag.
112 # Use '|' to add in more values as needed.
114 kfail "gdb/NNNN" $name
118 # print dereferenced pointer to data member
120 set name "print a.*pmi (A::j)"
121 gdb_test_multiple "print a.*pmi" $name {
122 -re "$vhn = 121\r\n$gdb_prompt $" {
125 -re "$vhn = 855638016\r\n$gdb_prompt $" {
126 # gcc 2.95.3 -gdwarf-2
127 # gcc 2.95.3 -gstabs+
128 kfail "gdb/NNNN" $name
130 -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
131 # gcc HEAD 2004-01-10 -gdwarf-2
132 # gcc HEAD 2004-01-10 -gstabs+
133 kfail "gdb/NNNN" $name
137 # print dereferenced pointer to data member
138 # this time, dereferenced through a pointer
140 set name "print a_p->*pmi (A::j)"
141 gdb_test_multiple "print a_p->*pmi" $name {
142 -re "$vhn = 121\r\n$gdb_prompt $" {
145 -re "$vhn = 855638016\r\n$gdb_prompt $" {
146 # gcc 2.95.3 -gdwarf-2
147 # gcc 2.95.3 -gstabs+
148 kfail "gdb/NNNN" $name
150 -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
151 # gcc HEAD 2004-01-10 -gdwarf-2
152 # gcc HEAD 2004-01-10 -gstabs+
153 kfail "gdb/NNNN" $name
157 # set the pointer to a different data member
159 set name "set var pmi = &A::jj"
160 gdb_test_multiple "set var pmi = &A::jj" $name {
161 -re "Invalid cast.\r\n$gdb_prompt $" {
162 # gcc HEAD 2004-01-10 -gdwarf-2
163 # gcc HEAD 2004-01-10 -gstabs+
164 kfail "gdb/NNNN" $name
166 -re "set var pmi = &A::jj\r\n$gdb_prompt $" {
167 # I have to match the echo'ed input explicitly here.
168 # If I leave it out, the pattern becomes too general
169 # and matches anything that ends in "$gdb_prompt $".
174 # print the pointer again
176 set name "print pmi (A::jj)"
177 gdb_test_multiple "print pmi" $name {
178 -re "$vhn = &A::jj\r\n$gdb_prompt $" {
181 -re "$vhn = \\(int ?\\( ?A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
184 -re "$vhn = not implemented: member type in c_val_print\r\n$gdb_prompt $" {
185 # gcc HEAD 2004-01-11 05:33:21 -gdwarf-2
186 # gcc HEAD 2004-01-11 05:33:21 -gstabs+
187 kfail "gdb/NNNN" $name
189 -re "$vhn = \\(int ?\\( A::\\*\\)\\) 536870924\r\n$gdb_prompt $" {
190 # the value is 0x20000008 hex. 0x20000000 is an internal flag.
191 # Use '|' to add in more values as needed.
193 kfail "gdb/NNNN" $name
197 # print dereferenced pointer to data member again
199 set name "print a.*pmi (A::jj)"
200 gdb_test_multiple "print a.*pmi" $name {
201 -re "$vhn = 1331\r\n$gdb_prompt $" {
204 -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
205 # gcc HEAD 2004-01-10 -gdwarf-2
206 # gcc HEAD 2004-01-10 -gstabs+
207 kfail "gdb/NNNN" $name
211 # set the pointer to data member back to A::j
213 set name "set var pmi = &A::j"
214 gdb_test_multiple "set var pmi = &A::j" $name {
215 -re "Invalid cast.\r\n$gdb_prompt $" {
216 # gcc HEAD 2004-01-10 -gdwarf-2
217 # gcc HEAD 2004-01-10 -gstabs+
218 kfail "gdb/NNNN" $name
220 -re "set var pmi = &A::j\r\n$gdb_prompt $" {
221 # I have to match the echo'ed input explicitly here.
222 # If I leave it out, the pattern becomes too general
223 # and matches anything that ends in "$gdb_prompt $".
228 # print dereferenced pointer to data member yet again (extra check, why not)
230 set name "print a.*pmi (A::j) (again)"
231 gdb_test_multiple "print a.*pmi" $name {
232 -re "$vhn = 121\r\n$gdb_prompt $" {
235 -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
236 # gcc HEAD 2004-01-10 -gdwarf-2
237 # gcc HEAD 2004-01-10 -gstabs+
238 kfail "gdb/NNNN" $name
242 # Set the data member pointed to.
244 set name "print a.*pmi = 33"
245 gdb_test_multiple "print a.*pmi = 33" $name {
246 -re "$vhn = 33\r\n$gdb_prompt $" {
249 -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
250 # gcc HEAD 2004-01-10 -gdwarf-2
251 # gcc HEAD 2004-01-10 -gstabs+
252 kfail "gdb/NNNN" $name
256 # Now check that the data really was changed
258 set name "print a.*pmi (A::j) (33)"
259 gdb_test_multiple "print a.*pmi" $name {
260 -re "$vhn = 33\r\n$gdb_prompt $" {
263 -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
264 # gcc HEAD 2004-01-10 -gdwarf-2
265 # gcc HEAD 2004-01-10 -gstabs+
266 kfail "gdb/NNNN" $name
270 # Double-check by printing a.
272 set name "print a (j = 33)"
273 gdb_test_multiple "print a" $name {
274 -re "$vhn = \{c = 120 'x', j = 33, jj = 1331, (static|static int) s = 10, (_vptr.A|_vptr\\$) = ($hex|$hex <A virtual table>)\}\r\n$gdb_prompt $" {
277 -re "$vhn = \{c = 120 'x', j = 33, jj = 1331, (static|static int) s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
280 -re "$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 33, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" {
283 -re "$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 121, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" {
284 # gcc HEAD 2004-01-10 -gdwarf-2
285 # gcc HEAD 2004-01-10 -gstabs+
286 kfail "gdb/NNNN" $name
290 # Set the data member pointed to, using ->*
292 set name "print a_p->*pmi = 44"
293 gdb_test_multiple "print a_p->*pmi = 44" $name {
294 -re "$vhn = 44\r\n$gdb_prompt $" {
297 -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
298 # gcc HEAD 2004-01-10 -gdwarf-2
299 # gcc HEAD 2004-01-10 -gstabs+
300 kfail "gdb/NNNN" $name
304 # Check that the data really was changed
306 set name "print a_p->*pmi (44)"
307 gdb_test_multiple "print a_p->*pmi" $name {
308 -re "$vhn = 44\r\n$gdb_prompt $" {
311 -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
312 # gcc HEAD 2004-01-10 -gdwarf-2
313 # gcc HEAD 2004-01-10 -gstabs+
314 kfail "gdb/NNNN" $name
318 # Double-check by printing a.
320 set name "print a (j = 44)"
321 gdb_test_multiple "print a" $name {
322 -re "$vhn = \{c = 120 'x', j = 44, jj = 1331, (static|static int) s = 10, (_vptr.A|_vptr\\$) = ($hex|$hex <A virtual table>)\}\r\n$gdb_prompt $" {
325 -re "$vhn = \{c = 120 'x', j = 44, jj = 1331, (static|static int) s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
328 -re "$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 44, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" {
331 -re "$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 121, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" {
332 # gcc HEAD 2004-01-10 -gdwarf-2
333 # gcc HEAD 2004-01-10 -gstabs+
334 kfail "gdb/NNNN" $name
338 # ptype the dereferenced pointer to member.
340 set name "ptype a.*pmi"
341 gdb_test_multiple "ptype a.*pmi" $name {
342 -re "type = int\r\n$gdb_prompt" {
345 -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
346 # gcc HEAD 2004-01-10 -gdwarf-2
347 # gcc HEAD 2004-01-10 -gstabs+
348 kfail "gdb/NNNN" $name
352 # dereference the pointer to data member without any object
353 # this is not allowed: a pmi must be bound to an object to dereference
355 set name "print *pmi"
356 gdb_test_multiple "print *pmi" $name {
357 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
360 -re "Cannot access memory at address 0x4\r\n$gdb_prompt $" {
361 # gcc 2.95.3 -gstabs+
362 kfail "gdb/NNNN" $name
364 -re "Cannot access memory at address 0x8\r\n$gdb_prompt $" {
365 # gcc 3.3.2 -gdwarf-2
367 kfail "gdb/NNNN" $name
371 # dereference the pointer to data member without any object
372 # this is not allowed: a pmi must be bound to an object to dereference
374 set name "ptype *pmi"
375 gdb_test_multiple "ptype *pmi" $name {
376 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
379 -re "type = int A::\r\n$gdb_prompt $" {
380 # gcc 2.95.3 -gstabs+
381 # gcc HEAD 2004-01-10 -gdwarf-2
382 # gcc HEAD 2004-01-10 -gstabs+
383 kfail "gdb/NNNN" $name
387 # Check cast of pointer to member to integer.
388 # This is similar to "offset-of".
389 # such as "A a; print (size_t) &A.j - (size_t) &A".
391 set name "print (int) pmi"
392 gdb_test_multiple "print (int) pmi" $name {
393 -re "$vhn = (4|8)\r\n$gdb_prompt" {
398 # Check "(int) pmi" explicitly for equality.
400 set name "print ((int) pmi) == ((char *) &a.j - (char *) &a)"
401 gdb_test_multiple "print ((int) pmi) == ((char *) &a.j - (char *) & a)" $name {
402 -re "$vhn = true\r\n$gdb_prompt" {
407 # ==========================
408 # pointer to member function
409 # ==========================
411 # ptype a pointer to a method
414 gdb_test_multiple "ptype pmf" $name {
415 -re "type = int \\( ?A::\\*\\)\\(int\\)\r\n$gdb_prompt $" {
418 -re "type = int \\( ?A::\\*\\)\\(void\\)\r\n$gdb_prompt $" {
420 kfail "gdb/NNNN" $name
422 -re "type = struct \{.*\}\r\n$gdb_prompt $" {
423 # gcc 2.95.3 -gdwarf-2
424 # gcc 2.95.3 -gstabs+
425 # gcc 3.2.2 -gdwarf-2
427 # gcc HEAD 2004-01-10 -gdwarf-2
428 # gcc HEAD 2004-01-10 -gstabs+
429 kfail "gdb/NNNN" $name
433 # print a pointer to a method
436 gdb_test_multiple "print pmf" $name {
437 -re "$vhn = &A::bar\r\n$gdb_prompt $" {
440 -re "$vhn = .*not supported with HP aCC.*\r\n$gdb_prompt $" {
442 kfail "gdb/NNNN" $name
444 -re "$vhn = \{.*\}\r\n$gdb_prompt $" {
445 # gcc 2.95.3 -gdwarf-2
446 # gcc 2.95.3 -gstabs+
447 # gcc 3.2.2 -gdwarf-2
449 # gcc HEAD 2004-01-10 -gdwarf-2
450 # gcc HEAD 2004-01-10 -gstabs+
451 kfail "gdb/NNNN" $name
455 # ptype a pointer to a pointer to a method
457 set name "ptype pmf_p"
458 gdb_test_multiple "ptype pmf_p" $name {
459 -re "type = int \\( ?A::\\*\\*\\)\\(int\\)\r\n$gdb_prompt $" {
462 -re "type = int \\( ?A::\\*\\*\\)\\(void\\)\r\n$gdb_prompt $" {
464 kfail "gdb/NNNN" $name
466 -re "type = struct \{.*\} \\*\r\n$gdb_prompt $" {
467 # gcc 2.95.3 -gdwarf-2
468 # gcc 2.95.3 -gstabs+
469 # gcc 3.2.2 -gdwarf-2
471 # gcc HEAD 2004-01-10 -gdwarf-2
472 # gcc HEAD 2004-01-10 -gstabs+
473 kfail "gdb/NNNN" $name
477 # print a pointer to a pointer to a method
479 set name "print pmf_p"
480 gdb_test_multiple "print pmf_p" $name {
481 -re "$vhn = \\(int \\( ?A::\\*\\*\\)\\)\\(int\\)\\) $hex\r\n$gdb_prompt $" {
484 -re "$vhn = \\(PMF \\*\\) $hex\r\n$gdb_prompt $" {
487 -re "$vhn = \\(int \\( ?A::\\*\\*\\)\\(void\\)\\) $hex\r\n$gdb_prompt $" {
489 kfail "gdb/NNNN" $name
491 -re "$vhn = \\(struct \{.*\} \\*\\) $hex\r\n$gdb_prompt $" {
492 # gcc 2.95.3 -gdwarf-2
493 kfail "gdb/NNNN" $name
497 # print dereferenced pointer to method
499 set name "print a.*pmf"
500 gdb_test_multiple "print a.*pmf" $name {
501 -re "$vhn = \\(int \\(\\*\\)\\(int\\)\\) $hex <A::bar\\(int\\)>\r\n$gdb_prompt$ " {
504 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
506 kfail "gdb/NNNN" $name
508 -re "Value can't be converted to integer.\r\n$gdb_prompt $" {
509 # gcc 2.95.3 -gdwarf-2
510 # gcc 2.95.3 -gstabs+
511 # gcc 3.2.2 -gdwarf-2
513 # gcc HEAD 2004-01-10 -gdwarf-2
514 # gcc HEAD 2004-01-10 -gstabs+
515 kfail "gdb/NNNN" $name
519 # print dereferenced pointer to method, using ->*
521 set name "print a_p->*pmf"
522 gdb_test_multiple "print a_p->*pmf" $name {
523 -re "$vhn = \\(int \\(\\*\\)\\(int\\)\\) $hex <A::bar\\(int\\)>\r\n$gdb_prompt$ " {
526 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
528 kfail "gdb/NNNN" $name
530 -re "Value can't be converted to integer.\r\n$gdb_prompt $" {
531 # gcc 2.95.3 -gdwarf-2
532 # gcc 2.95.3 -gstabs+
533 # gcc 3.2.2 -gdwarf-2
535 # gcc HEAD 2004-01-10 -gdwarf-2
536 # gcc HEAD 2004-01-10 -gstabs+
537 kfail "gdb/NNNN" $name
541 # set the pointer to data member
543 set name "set var pmf = &A::foo"
544 gdb_test_multiple "set var pmf = &A::foo" $name {
545 -re "set var pmf = &A::foo\r\n$gdb_prompt $" {
546 # I have to match the echo'ed input explicitly here.
547 # If I leave it out, the pattern becomes too general
548 # and matches anything that ends in "$gdb_prompt $".
551 -re "Invalid cast.\r\n$gdb_prompt $" {
552 # gcc 2.95.3 -gdwarf-2
553 # gcc 2.95.3 -gstabs+
554 # gcc 3.2.2 -gdwarf-2
556 # gcc HEAD 2004-01-10 -gdwarf-2
557 # gcc HEAD 2004-01-10 -gstabs+
558 kfail "gdb/NNNN" $name
560 -re "Assignment to pointers to methods not implemented with HP aCC\r\n$gdb_prompt $" {
561 kfail "gdb/NNNN" $name
565 # dereference the pointer to data member without any object
566 # this is not allowed: a pmf must be bound to an object to dereference
568 set name "print *pmf"
569 gdb_test_multiple "print *pmf" $name {
570 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
573 -re "Structure has no component named operator\\*.\r\n$gdb_prompt $" {
574 # gcc 2.95.3 -gdwarf-2
575 # gcc 2.95.3 -gstabs+
576 # gcc 3.3.2 -gdwarf-2
578 # gcc HEAD 2004-01-10 -gdwarf-2
579 # gcc HEAD 2004-01-10 -gstabs+
580 kfail "gdb/NNNN" $name
584 # dereference the pointer to data member without any object
585 # this is not allowed: a pmf must be bound to an object to dereference
587 set name "ptype *pmf"
588 gdb_test_multiple "ptype *pmf" $name {
589 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
592 -re "Structure has no component named operator\\*.\r\n$gdb_prompt $" {
593 # gcc 2.95.3 -gdwarf-2
594 # gcc 2.95.3 -gstabs+
595 # gcc 3.3.2 -gdwarf-2
597 # gcc HEAD 2004-01-10 -gdwarf-2
598 # gcc HEAD 2004-01-10 -gstabs+
599 kfail "gdb/NNNN" $name
603 # Call a function through a pmf.
605 set name "print (a.*pmf)(3)"
606 gdb_test_multiple "print (a.*pmf)(3)" $name {
607 -re "$vhn = 50\r\n$gdb_prompt $" {
610 -re "Not implemented: function invocation through pointer to method with HP aCC\r\n$gdb_prompt $" {
612 kfail "gdb/NNNN" $name
614 -re "Value can't be converted to integer.\r\n$gdb_prompt $" {
615 # gcc 2.95.3 -gdwarf-2
616 # gcc 2.95.3 -gstabs+
617 # gcc 3.3.2 -gdwarf-2
619 # gcc HEAD 2004-01-10 -gdwarf-2
620 # gcc HEAD 2004-01-10 -gstabs+
621 kfail "gdb/NNNN" $name