No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / testsuite / gdb.cp / member-ptr.exp
blobf6a9d4039b060e02b0342e85943f798e449b5302
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.
9 #
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
25 set vhn "\\$\[0-9\]+"
27 if $tracelevel then {
28 strace $tracelevel
31 if { [skip_cplus_tests] } { continue }
33 set prms_id 0
34 set bug_id 0
36 set testfile "member-ptr"
37 set srcfile ${testfile}.cc
38 set binfile ${objdir}/${subdir}/${testfile}
40 if [get_compiler_info ${binfile} "c++"] {
41 return -1
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."
48 gdb_exit
49 gdb_start
50 gdb_reinitialize_dir $srcdir/$subdir
51 gdb_load ${binfile}
53 if ![runto_main] then {
54 perror "couldn't run to breakpoint"
55 continue
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-*"] } {
65 continue
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 $" {
77 pass $name
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 $" {
91 pass $name
93 -re "$vhn = \\(int ?\\( ?A::\\*\\)\\) &A::j\r\n$gdb_prompt $" {
94 pass $name
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.
112 # hpacc A.03.45
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 $" {
122 pass $name
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 $" {
142 pass $name
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 $".
169 pass $name
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 $" {
178 pass $name
180 -re "$vhn = \\(int ?\\( ?A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
181 pass $name
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.
191 # hpacc A.03.45
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 $" {
201 pass $name
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 $".
223 pass $name
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 $" {
232 pass $name
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 $" {
246 pass $name
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 $" {
260 pass $name
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 $" {
274 pass $name
276 -re "$vhn = \{c = 120 'x', j = 33, jj = 1331, (static|static int) s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
277 pass $name
279 -re "$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 33, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" {
280 pass $name
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 $" {
294 pass $name
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 $" {
308 pass $name
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 $" {
322 pass $name
324 -re "$vhn = \{c = 120 'x', j = 44, jj = 1331, (static|static int) s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
325 pass $name
327 -re "$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 44, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" {
328 pass $name
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" {
342 pass $name
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 $" {
357 pass $name
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
365 # gcc 3.3.2 -gstabs+
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 $" {
376 pass $name
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" {
393 pass $name
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" {
402 pass $name
406 # ==========================
407 # pointer to member function
408 # ==========================
410 # ptype a pointer to a method
412 set name "ptype pmf"
413 gdb_test_multiple "ptype pmf" $name {
414 -re "type = int \\( ?A::\\*\\)\\(int\\)\r\n$gdb_prompt $" {
415 pass $name
417 -re "type = int \\( ?A::\\*\\)\\(void\\)\r\n$gdb_prompt $" {
418 # hpacc A.03.45
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
425 # gcc 3.2.2 -gstabs+
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
434 set name "print pmf"
435 gdb_test_multiple "print pmf" $name {
436 -re "$vhn = &A::bar\r\n$gdb_prompt $" {
437 pass $name
439 -re "$vhn = .*not supported with HP aCC.*\r\n$gdb_prompt $" {
440 # hpacc A.03.45
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
447 # gcc 3.2.2 -gstabs+
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 $" {
459 pass $name
461 -re "type = int \\( ?A::\\*\\*\\)\\(void\\)\r\n$gdb_prompt $" {
462 # hpacc A.03.45
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
469 # gcc 3.2.2 -gstabs+
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 $" {
481 pass $name
483 -re "$vhn = \\(PMF \\*\\) $hex\r\n$gdb_prompt $" {
484 pass "gdb/NNNN"
486 -re "$vhn = \\(int \\( ?A::\\*\\*\\)\\(void\\)\\) $hex\r\n$gdb_prompt $" {
487 # hpacc A.03.45
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$ " {
501 pass $name
503 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
504 # hpacc A.03.45
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
511 # gcc 3.2.2 -gstabs+
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$ " {
523 pass $name
525 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
526 # hpacc A.03.45
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
533 # gcc 3.2.2 -gstabs+
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 $".
548 pass $name
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
554 # gcc 3.2.2 -gstabs+
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 $" {
570 pass $name
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
576 # gcc 3.3.2 -gstabs+
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 $" {
589 pass $name
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
595 # gcc 3.3.2 -gstabs+
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 $" {
607 pass $name
609 -re "Not implemented: function invocation through pointer to method with HP aCC\r\n$gdb_prompt $" {
610 # hpacc A.03.45
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
617 # gcc 3.3.2 -gstabs+
618 # gcc HEAD 2004-01-10 -gdwarf-2
619 # gcc HEAD 2004-01-10 -gstabs+
620 kfail "gdb/NNNN" $name