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 gdb_suppress_entire_file
"Testcase compile failed, so all tests in this file will automatically fail."
50 gdb_reinitialize_dir $srcdir
/$subdir
53 if ![runto_main
] then {
54 perror
"couldn't run to breakpoint"
58 gdb_breakpoint
[gdb_get_line_number
"pmi = NULL"]
59 gdb_continue_to_breakpoint
"continue to pmi = NULL"
61 # gcc is not ready
for production
62 #
-- chastain
2004-01-12
64 if { [test_compiler_info
"gcc-*"] } {
68 #
======================
69 # pointer to member data
70 #
======================
72 # ptype
on pointer to data member
74 set name "ptype pmi (A::j)"
75 gdb_test_multiple
"ptype pmi" $name {
76 -re
"type = int *\\( ?A::\\*\\)\r\n$gdb_prompt $" {
79 -re
"type = int *A::\r\n$gdb_prompt $" {
80 # gcc HEAD
2004-01-10 -gdwarf
-2
81 # gcc HEAD
2004-01-10 -gstabs
+
82 kfail
"gdb/NNNN" $name
86 # print pointer to data member
88 set name "print pmi (A::j) "
89 gdb_test_multiple
"print pmi" $name {
90 -re
"$vhn = &A::j\r\n$gdb_prompt $" {
93 -re
"$vhn = \\(int ?\\( ?A::\\*\\)\\) &A::j\r\n$gdb_prompt $" {
96 -re
"$vhn = \\(int ?\\( ?A::\\*\\)\\) ?&A::j ?\\+ ?1 bytes\r\n$gdb_prompt $" {
97 # gcc
2.95.3 -gdwarf
-2
98 kfail
"gdb/NNNN" $name
100 -re
"$vhn = &A::j ?\\+ ?1 bytes\r\n$gdb_prompt $" {
101 # gcc
2.95.3 -gstabs
+
102 kfail
"gdb/NNNN" $name
104 -re
"$vhn = not implemented: member type in c_val_print\r\n$gdb_prompt $" {
105 # gcc HEAD
2004-01-11 05:33:21 -gdwarf
-2
106 # gcc HEAD
2004-01-11 05:33:21 -gstabs
+
107 kfail
"gdb/NNNN" $name
109 -re
"$vhn = \\(int ?\\( A::\\*\\)\\) 536870920\r\n$gdb_prompt $" {
110 # the value is
0x20000008 hex.
0x20000000 is an internal flag.
111 # Use
'|' to add in more
values as needed.
113 kfail
"gdb/NNNN" $name
117 # print dereferenced pointer to data member
119 set name "print a.*pmi (A::j)"
120 gdb_test_multiple
"print a.*pmi" $name {
121 -re
"$vhn = 121\r\n$gdb_prompt $" {
124 -re
"$vhn = 855638016\r\n$gdb_prompt $" {
125 # gcc
2.95.3 -gdwarf
-2
126 # gcc
2.95.3 -gstabs
+
127 kfail
"gdb/NNNN" $name
129 -re
"not implemented: member types in unpack_long\r\n$gdb_prompt $" {
130 # gcc HEAD
2004-01-10 -gdwarf
-2
131 # gcc HEAD
2004-01-10 -gstabs
+
132 kfail
"gdb/NNNN" $name
136 # print dereferenced pointer to data member
137 # this time
, dereferenced through a pointer
139 set name "print a_p->*pmi (A::j)"
140 gdb_test_multiple
"print a_p->*pmi" $name {
141 -re
"$vhn = 121\r\n$gdb_prompt $" {
144 -re
"$vhn = 855638016\r\n$gdb_prompt $" {
145 # gcc
2.95.3 -gdwarf
-2
146 # gcc
2.95.3 -gstabs
+
147 kfail
"gdb/NNNN" $name
149 -re
"not implemented: member types in unpack_long\r\n$gdb_prompt $" {
150 # gcc HEAD
2004-01-10 -gdwarf
-2
151 # gcc HEAD
2004-01-10 -gstabs
+
152 kfail
"gdb/NNNN" $name
156 #
set the pointer to a different data member
158 set name "set var pmi = &A::jj"
159 gdb_test_multiple
"set var pmi = &A::jj" $name {
160 -re
"Invalid cast.\r\n$gdb_prompt $" {
161 # gcc HEAD
2004-01-10 -gdwarf
-2
162 # gcc HEAD
2004-01-10 -gstabs
+
163 kfail
"gdb/NNNN" $name
165 -re
"set var pmi = &A::jj\r\n$gdb_prompt $" {
166 # I have to match the echo
'ed input explicitly here.
167 # If I leave it out, the pattern becomes too general
168 # and matches anything that ends in "$gdb_prompt $".
173 # print the pointer again
175 set name "print pmi (A::jj)"
176 gdb_test_multiple "print pmi" $name {
177 -re "$vhn = &A::jj\r\n$gdb_prompt $" {
180 -re "$vhn = \\(int ?\\( ?A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
183 -re "$vhn = not implemented: member type in c_val_print\r\n$gdb_prompt $" {
184 # gcc HEAD 2004-01-11 05:33:21 -gdwarf-2
185 # gcc HEAD 2004-01-11 05:33:21 -gstabs+
186 kfail "gdb/NNNN" $name
188 -re "$vhn = \\(int ?\\( A::\\*\\)\\) 536870924\r\n$gdb_prompt $" {
189 # the value is 0x20000008 hex. 0x20000000 is an internal flag.
190 # Use '|
' to add in more values as needed.
192 kfail "gdb/NNNN" $name
196 # print dereferenced pointer to data member again
198 set name "print a.*pmi (A::jj)"
199 gdb_test_multiple "print a.*pmi" $name {
200 -re "$vhn = 1331\r\n$gdb_prompt $" {
203 -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
204 # gcc HEAD 2004-01-10 -gdwarf-2
205 # gcc HEAD 2004-01-10 -gstabs+
206 kfail "gdb/NNNN" $name
210 # set the pointer to data member back to A::j
212 set name "set var pmi = &A::j"
213 gdb_test_multiple "set var pmi = &A::j" $name {
214 -re "Invalid cast.\r\n$gdb_prompt $" {
215 # gcc HEAD 2004-01-10 -gdwarf-2
216 # gcc HEAD 2004-01-10 -gstabs+
217 kfail "gdb/NNNN" $name
219 -re "set var pmi = &A::j\r\n$gdb_prompt $" {
220 # I have to match the echo'ed input explicitly here.
221 #
If I leave it out
, the pattern becomes too general
222 # and matches anything that ends in
"$gdb_prompt $".
227 # print dereferenced pointer to data member yet again
(extra check
, why not
)
229 set name "print a.*pmi (A::j) (again)"
230 gdb_test_multiple
"print a.*pmi" $name {
231 -re
"$vhn = 121\r\n$gdb_prompt $" {
234 -re
"not implemented: member types in unpack_long\r\n$gdb_prompt $" {
235 # gcc HEAD
2004-01-10 -gdwarf
-2
236 # gcc HEAD
2004-01-10 -gstabs
+
237 kfail
"gdb/NNNN" $name
241 #
Set the data member pointed to.
243 set name "print a.*pmi = 33"
244 gdb_test_multiple
"print a.*pmi = 33" $name {
245 -re
"$vhn = 33\r\n$gdb_prompt $" {
248 -re
"not implemented: member types in unpack_long\r\n$gdb_prompt $" {
249 # gcc HEAD
2004-01-10 -gdwarf
-2
250 # gcc HEAD
2004-01-10 -gstabs
+
251 kfail
"gdb/NNNN" $name
255 # Now check that the data really was changed
257 set name "print a.*pmi (A::j) (33)"
258 gdb_test_multiple
"print a.*pmi" $name {
259 -re
"$vhn = 33\r\n$gdb_prompt $" {
262 -re
"not implemented: member types in unpack_long\r\n$gdb_prompt $" {
263 # gcc HEAD
2004-01-10 -gdwarf
-2
264 # gcc HEAD
2004-01-10 -gstabs
+
265 kfail
"gdb/NNNN" $name
269 # Double
-check by printing a.
271 set name "print a (j = 33)"
272 gdb_test_multiple
"print a" $name {
273 -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 $" {
276 -re
"$vhn = \{c = 120 'x', j = 33, jj = 1331, (static|static int) s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
279 -re
"$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 33, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" {
282 -re
"$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 121, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" {
283 # gcc HEAD
2004-01-10 -gdwarf
-2
284 # gcc HEAD
2004-01-10 -gstabs
+
285 kfail
"gdb/NNNN" $name
289 #
Set the data member pointed to
, using
->*
291 set name "print a_p->*pmi = 44"
292 gdb_test_multiple
"print a_p->*pmi = 44" $name {
293 -re
"$vhn = 44\r\n$gdb_prompt $" {
296 -re
"not implemented: member types in unpack_long\r\n$gdb_prompt $" {
297 # gcc HEAD
2004-01-10 -gdwarf
-2
298 # gcc HEAD
2004-01-10 -gstabs
+
299 kfail
"gdb/NNNN" $name
303 # Check that the data really was changed
305 set name "print a_p->*pmi (44)"
306 gdb_test_multiple
"print a_p->*pmi" $name {
307 -re
"$vhn = 44\r\n$gdb_prompt $" {
310 -re
"not implemented: member types in unpack_long\r\n$gdb_prompt $" {
311 # gcc HEAD
2004-01-10 -gdwarf
-2
312 # gcc HEAD
2004-01-10 -gstabs
+
313 kfail
"gdb/NNNN" $name
317 # Double
-check by printing a.
319 set name "print a (j = 44)"
320 gdb_test_multiple
"print a" $name {
321 -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 $" {
324 -re
"$vhn = \{c = 120 'x', j = 44, jj = 1331, (static|static int) s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
327 -re
"$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 44, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" {
330 -re
"$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 121, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" {
331 # gcc HEAD
2004-01-10 -gdwarf
-2
332 # gcc HEAD
2004-01-10 -gstabs
+
333 kfail
"gdb/NNNN" $name
337 # ptype the dereferenced pointer to member.
339 set name "ptype a.*pmi"
340 gdb_test_multiple
"ptype a.*pmi" $name {
341 -re
"type = int\r\n$gdb_prompt" {
344 -re
"not implemented: member types in unpack_long\r\n$gdb_prompt $" {
345 # gcc HEAD
2004-01-10 -gdwarf
-2
346 # gcc HEAD
2004-01-10 -gstabs
+
347 kfail
"gdb/NNNN" $name
351 # dereference the pointer to data member without
any object
352 # this is not allowed
: a pmi must be bound to an object to dereference
354 set name "print *pmi"
355 gdb_test_multiple
"print *pmi" $name {
356 -re
"Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
359 -re
"Cannot access memory at address 0x4\r\n$gdb_prompt $" {
360 # gcc
2.95.3 -gstabs
+
361 kfail
"gdb/NNNN" $name
363 -re
"Cannot access memory at address 0x8\r\n$gdb_prompt $" {
364 # gcc
3.3.2 -gdwarf
-2
366 kfail
"gdb/NNNN" $name
370 # dereference the pointer to data member without
any object
371 # this is not allowed
: a pmi must be bound to an object to dereference
373 set name "ptype *pmi"
374 gdb_test_multiple
"ptype *pmi" $name {
375 -re
"Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
378 -re
"type = int A::\r\n$gdb_prompt $" {
379 # gcc
2.95.3 -gstabs
+
380 # gcc HEAD
2004-01-10 -gdwarf
-2
381 # gcc HEAD
2004-01-10 -gstabs
+
382 kfail
"gdb/NNNN" $name
386 # Check cast of pointer to member to
integer.
387 # This is similar to
"offset-of".
388 # such as
"A a; print (size_t) &A.j - (size_t) &A".
390 set name "print (int) pmi"
391 gdb_test_multiple
"print (int) pmi" $name {
392 -re
"$vhn = (4|8)\r\n$gdb_prompt" {
397 # Check
"(int) pmi" explicitly for equality.
399 set name "print ((int) pmi) == ((char *) &a.j - (char *) &a)"
400 gdb_test_multiple
"print ((int) pmi) == ((char *) &a.j - (char *) & a)" $name {
401 -re
"$vhn = true\r\n$gdb_prompt" {
406 #
==========================
407 # pointer to member function
408 #
==========================
410 # ptype a pointer to a method
413 gdb_test_multiple
"ptype pmf" $name {
414 -re
"type = int \\( ?A::\\*\\)\\(int\\)\r\n$gdb_prompt $" {
417 -re
"type = int \\( ?A::\\*\\)\\(void\\)\r\n$gdb_prompt $" {
419 kfail
"gdb/NNNN" $name
421 -re
"type = struct \{.*\}\r\n$gdb_prompt $" {
422 # gcc
2.95.3 -gdwarf
-2
423 # gcc
2.95.3 -gstabs
+
424 # gcc
3.2.2 -gdwarf
-2
426 # gcc HEAD
2004-01-10 -gdwarf
-2
427 # gcc HEAD
2004-01-10 -gstabs
+
428 kfail
"gdb/NNNN" $name
432 # print a pointer to a method
435 gdb_test_multiple
"print pmf" $name {
436 -re
"$vhn = &A::bar\r\n$gdb_prompt $" {
439 -re
"$vhn = .*not supported with HP aCC.*\r\n$gdb_prompt $" {
441 kfail
"gdb/NNNN" $name
443 -re
"$vhn = \{.*\}\r\n$gdb_prompt $" {
444 # gcc
2.95.3 -gdwarf
-2
445 # gcc
2.95.3 -gstabs
+
446 # gcc
3.2.2 -gdwarf
-2
448 # gcc HEAD
2004-01-10 -gdwarf
-2
449 # gcc HEAD
2004-01-10 -gstabs
+
450 kfail
"gdb/NNNN" $name
454 # ptype a pointer to a pointer to a method
456 set name "ptype pmf_p"
457 gdb_test_multiple
"ptype pmf_p" $name {
458 -re
"type = int \\( ?A::\\*\\*\\)\\(int\\)\r\n$gdb_prompt $" {
461 -re
"type = int \\( ?A::\\*\\*\\)\\(void\\)\r\n$gdb_prompt $" {
463 kfail
"gdb/NNNN" $name
465 -re
"type = struct \{.*\} \\*\r\n$gdb_prompt $" {
466 # gcc
2.95.3 -gdwarf
-2
467 # gcc
2.95.3 -gstabs
+
468 # gcc
3.2.2 -gdwarf
-2
470 # gcc HEAD
2004-01-10 -gdwarf
-2
471 # gcc HEAD
2004-01-10 -gstabs
+
472 kfail
"gdb/NNNN" $name
476 # print a pointer to a pointer to a method
478 set name "print pmf_p"
479 gdb_test_multiple
"print pmf_p" $name {
480 -re
"$vhn = \\(int \\( ?A::\\*\\*\\)\\)\\(int\\)\\) $hex\r\n$gdb_prompt $" {
483 -re
"$vhn = \\(PMF \\*\\) $hex\r\n$gdb_prompt $" {
486 -re
"$vhn = \\(int \\( ?A::\\*\\*\\)\\(void\\)\\) $hex\r\n$gdb_prompt $" {
488 kfail
"gdb/NNNN" $name
490 -re
"$vhn = \\(struct \{.*\} \\*\\) $hex\r\n$gdb_prompt $" {
491 # gcc
2.95.3 -gdwarf
-2
492 kfail
"gdb/NNNN" $name
496 # print dereferenced pointer to method
498 set name "print a.*pmf"
499 gdb_test_multiple
"print a.*pmf" $name {
500 -re
"$vhn = \\(int \\(\\*\\)\\(int\\)\\) $hex <A::bar\\(int\\)>\r\n$gdb_prompt$ " {
503 -re
"Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
505 kfail
"gdb/NNNN" $name
507 -re
"Value can't be converted to integer.\r\n$gdb_prompt $" {
508 # gcc
2.95.3 -gdwarf
-2
509 # gcc
2.95.3 -gstabs
+
510 # gcc
3.2.2 -gdwarf
-2
512 # gcc HEAD
2004-01-10 -gdwarf
-2
513 # gcc HEAD
2004-01-10 -gstabs
+
514 kfail
"gdb/NNNN" $name
518 # print dereferenced pointer to method
, using
->*
520 set name "print a_p->*pmf"
521 gdb_test_multiple
"print a_p->*pmf" $name {
522 -re
"$vhn = \\(int \\(\\*\\)\\(int\\)\\) $hex <A::bar\\(int\\)>\r\n$gdb_prompt$ " {
525 -re
"Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
527 kfail
"gdb/NNNN" $name
529 -re
"Value can't be converted to integer.\r\n$gdb_prompt $" {
530 # gcc
2.95.3 -gdwarf
-2
531 # gcc
2.95.3 -gstabs
+
532 # gcc
3.2.2 -gdwarf
-2
534 # gcc HEAD
2004-01-10 -gdwarf
-2
535 # gcc HEAD
2004-01-10 -gstabs
+
536 kfail
"gdb/NNNN" $name
540 #
set the pointer to data member
542 set name "set var pmf = &A::foo"
543 gdb_test_multiple
"set var pmf = &A::foo" $name {
544 -re
"set var pmf = &A::foo\r\n$gdb_prompt $" {
545 # I have to match the echo
'ed input explicitly here.
546 # If I leave it out, the pattern becomes too general
547 # and matches anything that ends in "$gdb_prompt $".
550 -re "Invalid cast.\r\n$gdb_prompt $" {
551 # gcc 2.95.3 -gdwarf-2
552 # gcc 2.95.3 -gstabs+
553 # gcc 3.2.2 -gdwarf-2
555 # gcc HEAD 2004-01-10 -gdwarf-2
556 # gcc HEAD 2004-01-10 -gstabs+
557 kfail "gdb/NNNN" $name
559 -re "Assignment to pointers to methods not implemented with HP aCC\r\n$gdb_prompt $" {
560 kfail "gdb/NNNN" $name
564 # dereference the pointer to data member without any object
565 # this is not allowed: a pmf must be bound to an object to dereference
567 set name "print *pmf"
568 gdb_test_multiple "print *pmf" $name {
569 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
572 -re "Structure has no component named operator\\*.\r\n$gdb_prompt $" {
573 # gcc 2.95.3 -gdwarf-2
574 # gcc 2.95.3 -gstabs+
575 # gcc 3.3.2 -gdwarf-2
577 # gcc HEAD 2004-01-10 -gdwarf-2
578 # gcc HEAD 2004-01-10 -gstabs+
579 kfail "gdb/NNNN" $name
583 # dereference the pointer to data member without any object
584 # this is not allowed: a pmf must be bound to an object to dereference
586 set name "ptype *pmf"
587 gdb_test_multiple "ptype *pmf" $name {
588 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
591 -re "Structure has no component named operator\\*.\r\n$gdb_prompt $" {
592 # gcc 2.95.3 -gdwarf-2
593 # gcc 2.95.3 -gstabs+
594 # gcc 3.3.2 -gdwarf-2
596 # gcc HEAD 2004-01-10 -gdwarf-2
597 # gcc HEAD 2004-01-10 -gstabs+
598 kfail "gdb/NNNN" $name
602 # Call a function through a pmf.
604 set name "print (a.*pmf)(3)"
605 gdb_test_multiple "print (a.*pmf)(3)" $name {
606 -re "$vhn = 50\r\n$gdb_prompt $" {
609 -re "Not implemented: function invocation through pointer to method with HP aCC\r\n$gdb_prompt $" {
611 kfail "gdb/NNNN" $name
613 -re "Value can't be converted to
integer.
\r\n$gdb_prompt $
" {
614 # gcc
2.95.3 -gdwarf
-2
615 # gcc
2.95.3 -gstabs
+
616 # gcc
3.3.2 -gdwarf
-2
618 # gcc HEAD
2004-01-10 -gdwarf
-2
619 # gcc HEAD
2004-01-10 -gstabs
+
620 kfail
"gdb/NNNN" $name