Imported Upstream version 7.9
[platform/upstream/gdb.git] / gdb / testsuite / gdb.cp / member-ptr.exp
1 # Copyright 1998-2015 Free Software Foundation, Inc.
2
3 # This file is part of the gdb testsuite
4
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 3 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.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 # Tests for pointer-to-member support
19 # Written by Satish Pai <pai@apollo.hp.com> 1997-08-19
20 # Rewritten by Michael Chastain <mec.gnu@mindspring.com> 2004-01-11
21
22 set vhn "\\$\[0-9\]+"
23
24 if { [skip_cplus_tests] } { continue }
25
26
27 standard_testfile .cc
28
29 if [get_compiler_info "c++"] {
30     return -1
31 }
32
33 if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
34     return -1
35 }
36
37 if ![runto_main] then {
38     perror "couldn't run to breakpoint"
39     continue
40 }
41
42 gdb_breakpoint [gdb_get_line_number "Breakpoint 1 here"]
43 gdb_continue_to_breakpoint "continue to pmi = NULL"
44
45 # ======================
46 # pointer to member data
47 # ======================
48
49 # ptype on pointer to data member
50
51 set name "ptype pmi (A::j)"
52 gdb_test_multiple "ptype pmi" $name {
53     -re "type = int A::\\*\r\n$gdb_prompt $" {
54         pass $name
55     }
56 }
57
58 # print pointer to data member
59
60 set name "print pmi (A::j) "
61 gdb_test_multiple "print pmi" $name {
62     -re "$vhn = &A::j\r\n$gdb_prompt $" {
63         pass $name
64     }
65     -re "$vhn = \\(int ?\\( ?A::\\*\\)\\) &A::j\r\n$gdb_prompt $" {
66         pass $name
67     }
68     -re "$vhn = \\(int ?\\( ?A::\\*\\)\\) ?&A::j ?\\+ ?1 bytes\r\n$gdb_prompt $" {
69         # gcc 2.95.3 -gdwarf-2
70         kfail "gdb/NNNN" $name
71     }
72     -re "$vhn = &A::j ?\\+ ?1 bytes\r\n$gdb_prompt $" {
73         # gcc 2.95.3 -gstabs+
74         kfail "gdb/NNNN" $name
75     }
76     -re "$vhn = not implemented: member type in c_val_print\r\n$gdb_prompt $" {
77         # gcc HEAD 2004-01-11 05:33:21 -gdwarf-2
78         # gcc HEAD 2004-01-11 05:33:21 -gstabs+
79         kfail "gdb/NNNN" $name
80     }
81     -re "$vhn = \\(int ?\\( A::\\*\\)\\) 536870920\r\n$gdb_prompt $" {
82         # the value is 0x20000008 hex.   0x20000000 is an internal flag.
83         # Use '|' to add in more values as needed.
84         # hpacc A.03.45
85         kfail "gdb/NNNN" $name
86     }
87 }
88
89 # print dereferenced pointer to data member
90
91 set name "print a.*pmi (A::j)"
92 gdb_test_multiple "print a.*pmi" $name {
93     -re "$vhn = 121\r\n$gdb_prompt $" {
94         pass $name
95     }
96     -re "$vhn = 855638016\r\n$gdb_prompt $" {
97         # gcc 2.95.3 -gdwarf-2
98         # gcc 2.95.3 -gstabs+
99         kfail "gdb/NNNN" $name
100     }
101     -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
102         # gcc HEAD 2004-01-10 -gdwarf-2
103         # gcc HEAD 2004-01-10 -gstabs+
104         kfail "gdb/NNNN" $name
105     }
106 }
107
108 # print dereferenced pointer to data member
109 # this time, dereferenced through a pointer
110
111 set name "print a_p->*pmi (A::j)"
112 gdb_test_multiple "print a_p->*pmi" $name {
113     -re "$vhn = 121\r\n$gdb_prompt $" {
114         pass $name
115     }
116     -re "$vhn = 855638016\r\n$gdb_prompt $" {
117         # gcc 2.95.3 -gdwarf-2
118         # gcc 2.95.3 -gstabs+
119         kfail "gdb/NNNN" $name
120     }
121     -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
122         # gcc HEAD 2004-01-10 -gdwarf-2
123         # gcc HEAD 2004-01-10 -gstabs+
124         kfail "gdb/NNNN" $name
125     }
126 }
127
128 # set the pointer to a different data member
129
130 set name "set var pmi = &A::jj"
131 gdb_test_multiple "set var pmi = &A::jj" $name {
132     -re "Invalid cast.\r\n$gdb_prompt $" {
133         # gcc HEAD 2004-01-10 -gdwarf-2
134         # gcc HEAD 2004-01-10 -gstabs+
135         kfail "gdb/NNNN" $name
136     }
137     -re "set var pmi = &A::jj\r\n$gdb_prompt $" {
138         # I have to match the echo'ed input explicitly here.
139         # If I leave it out, the pattern becomes too general
140         # and matches anything that ends in "$gdb_prompt $".
141         pass $name
142     }
143 }
144
145 # print the pointer again
146
147 set name "print pmi (A::jj)"
148 gdb_test_multiple "print pmi" $name {
149     -re "$vhn = &A::jj\r\n$gdb_prompt $" {
150         pass $name
151     }
152     -re "$vhn = \\(int ?\\( ?A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
153         pass $name
154     }
155     -re "$vhn = not implemented: member type in c_val_print\r\n$gdb_prompt $" {
156         # gcc HEAD 2004-01-11 05:33:21 -gdwarf-2
157         # gcc HEAD 2004-01-11 05:33:21 -gstabs+
158         kfail "gdb/NNNN" $name
159     }
160     -re "$vhn = \\(int ?\\( A::\\*\\)\\) 536870924\r\n$gdb_prompt $" {
161         # the value is 0x20000008 hex.   0x20000000 is an internal flag.
162         # Use '|' to add in more values as needed.
163         # hpacc A.03.45
164         kfail "gdb/NNNN" $name
165     }
166 }
167
168 # print dereferenced pointer to data member again
169
170 set name "print a.*pmi (A::jj)"
171 gdb_test_multiple "print a.*pmi" $name {
172     -re "$vhn = 1331\r\n$gdb_prompt $" {
173         pass $name
174     }
175     -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
176         # gcc HEAD 2004-01-10 -gdwarf-2
177         # gcc HEAD 2004-01-10 -gstabs+
178         kfail "gdb/NNNN" $name
179     }
180 }
181
182 # set the pointer to data member back to A::j
183
184 set name "set var pmi = &A::j"
185 gdb_test_multiple "set var pmi = &A::j" $name {
186     -re "Invalid cast.\r\n$gdb_prompt $" {
187         # gcc HEAD 2004-01-10 -gdwarf-2
188         # gcc HEAD 2004-01-10 -gstabs+
189         kfail "gdb/NNNN" $name
190     }
191     -re "set var pmi = &A::j\r\n$gdb_prompt $" {
192         # I have to match the echo'ed input explicitly here.
193         # If I leave it out, the pattern becomes too general
194         # and matches anything that ends in "$gdb_prompt $".
195         pass $name
196     }
197 }
198
199 # print dereferenced pointer to data member yet again (extra check, why not)
200
201 set name "print a.*pmi (A::j) (again)"
202 gdb_test_multiple "print a.*pmi" $name {
203     -re "$vhn = 121\r\n$gdb_prompt $" {
204         pass $name
205     }
206     -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
207         # gcc HEAD 2004-01-10 -gdwarf-2
208         # gcc HEAD 2004-01-10 -gstabs+
209         kfail "gdb/NNNN" $name
210     }
211 }
212
213 # Set the data member pointed to.
214
215 set name "print a.*pmi = 33"
216 gdb_test_multiple "print a.*pmi = 33" $name {
217     -re "$vhn = 33\r\n$gdb_prompt $" {
218         pass $name
219     }
220     -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
221         # gcc HEAD 2004-01-10 -gdwarf-2
222         # gcc HEAD 2004-01-10 -gstabs+
223         kfail "gdb/NNNN" $name
224     }
225 }
226
227 # Now check that the data really was changed
228
229 set name "print a.*pmi (A::j) (33)"
230 gdb_test_multiple "print a.*pmi" $name {
231     -re "$vhn = 33\r\n$gdb_prompt $" {
232         pass $name
233     }
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
238     }
239 }
240
241 # Double-check by printing a.
242
243 set name "print a (j = 33)"
244 gdb_test_multiple "print a" $name {
245     -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 $" {
246         pass $name
247     }
248     -re "$vhn = \{c = 120 'x', j = 33, jj = 1331, (static|static int) s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
249         pass $name
250     }
251     -re "$vhn = \{(_vptr.A|_vptr\\$) = ${hex}( <vtable for A.*>)?, c = 120 'x', j = 33, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" {
252         pass $name
253     }
254     -re "$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 121, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" {
255         # gcc HEAD 2004-01-10 -gdwarf-2
256         # gcc HEAD 2004-01-10 -gstabs+
257         kfail "gdb/NNNN" $name
258     }
259 }
260
261 # Set the data member pointed to, using ->*
262
263 set name "print a_p->*pmi = 44"
264 gdb_test_multiple "print a_p->*pmi = 44" $name {
265     -re "$vhn = 44\r\n$gdb_prompt $" {
266         pass $name
267     }
268     -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
269         # gcc HEAD 2004-01-10 -gdwarf-2
270         # gcc HEAD 2004-01-10 -gstabs+
271         kfail "gdb/NNNN" $name
272     }
273 }
274
275 # Check that the data really was changed
276
277 set name "print a_p->*pmi (44)"
278 gdb_test_multiple "print a_p->*pmi" $name {
279     -re "$vhn = 44\r\n$gdb_prompt $" {
280         pass $name
281     }
282     -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
283         # gcc HEAD 2004-01-10 -gdwarf-2
284         # gcc HEAD 2004-01-10 -gstabs+
285         kfail "gdb/NNNN" $name
286     }
287 }
288
289 # Double-check by printing a.
290
291 set name "print a (j = 44)"
292 gdb_test_multiple "print a" $name {
293     -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 $" {
294         pass $name
295     }
296     -re "$vhn = \{c = 120 'x', j = 44, jj = 1331, (static|static int) s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
297         pass $name
298     }
299     -re "$vhn = \{(_vptr.A|_vptr\\$) = ${hex}( <vtable for A.*>), c = 120 'x', j = 44, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" {
300         pass $name
301     }
302     -re "$vhn = \{(_vptr.A|_vptr\\$) = $hex, c = 120 'x', j = 121, jj = 1331, (static|static int) s = 10\}\r\n$gdb_prompt $" {
303         # gcc HEAD 2004-01-10 -gdwarf-2
304         # gcc HEAD 2004-01-10 -gstabs+
305         kfail "gdb/NNNN" $name
306     }
307 }
308
309 # ptype the dereferenced pointer to member.
310
311 set name "ptype a.*pmi"
312 gdb_test_multiple "ptype a.*pmi" $name {
313     -re "type = int\r\n$gdb_prompt" {
314         pass $name
315     }
316     -re "not implemented: member types in unpack_long\r\n$gdb_prompt $" {
317         # gcc HEAD 2004-01-10 -gdwarf-2
318         # gcc HEAD 2004-01-10 -gstabs+
319         kfail "gdb/NNNN" $name
320     }
321 }
322
323 # dereference the pointer to data member without any object
324 # this is not allowed: a pmi must be bound to an object to dereference
325
326 set name "print *pmi"
327 gdb_test_multiple "print *pmi" $name {
328     -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
329         pass $name
330     }
331     -re "Cannot access memory at address 0x4\r\n$gdb_prompt $" {
332         # gcc 2.95.3 -gstabs+
333         kfail "gdb/NNNN" $name
334     }
335     -re "Cannot access memory at address 0x8\r\n$gdb_prompt $" {
336         # gcc 3.3.2 -gdwarf-2
337         # gcc 3.3.2 -gstabs+
338         kfail "gdb/NNNN" $name
339     }
340 }
341
342 # dereference the pointer to data member without any object
343 # this is not allowed: a pmi must be bound to an object to dereference
344
345 set name "ptype *pmi"
346 gdb_test_multiple "ptype *pmi" $name {
347     -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
348         pass $name
349     }
350     -re "type = int  A::\r\n$gdb_prompt $" {
351         # gcc 2.95.3 -gstabs+
352         # gcc HEAD 2004-01-10 -gdwarf-2
353         # gcc HEAD 2004-01-10 -gstabs+
354         kfail "gdb/NNNN" $name
355     }
356 }
357
358 # Check cast of pointer to member to integer.
359 # This is similar to "offset-of".
360 # such as "A a; print (size_t) &A.j - (size_t) &A".
361
362 set name "print (int) pmi"
363 gdb_test_multiple "print (int) pmi" $name {
364     -re "$vhn = (4|8|12)\r\n$gdb_prompt" {
365         pass $name
366     }
367 }
368
369 # Check "(int) pmi" explicitly for equality.
370
371 set name "print ((int) pmi) == ((char *) &a.j - (char *) &a)"
372 gdb_test_multiple "print ((int) pmi) == ((char *) &a.j - (char *) & a)" $name {
373     -re "$vhn = true\r\n$gdb_prompt" {
374         pass $name
375     }
376 }
377
378 # Check pointers to data members, which are themselves pointers to
379 # functions.  These behave like data members, not like pointers to
380 # member functions.
381
382 gdb_test "ptype diamond_pfunc_ptr" \
383     "type = int \\(\\*Diamond::\\*\\)\\(int\\)"
384
385 gdb_test "ptype diamond.*diamond_pfunc_ptr" \
386     "type = int \\(\\*\\)\\(int\\)"
387
388 # This one is invalid; () binds more tightly than .*, so it tries to
389 # call the member pointer as a normal pointer-to-function.
390
391 gdb_test "print diamond.*diamond_pfunc_ptr (20)" \
392     "Invalid data type for function to be called."
393
394 # With parentheses, it is valid.
395
396 gdb_test "print (diamond.*diamond_pfunc_ptr) (20)" \
397     "$vhn = 39"
398
399 # Make sure that we do not interpret this as either a member pointer
400 # call or a member function call.
401
402 gdb_test "print diamond.func_ptr (20)" \
403     "$vhn = 39"
404
405 # ==========================
406 # pointer to member function
407 # ==========================
408
409 # ptype a pointer to a method
410
411 set name "ptype pmf"
412 gdb_test_multiple "ptype pmf" $name {
413     -re "type = int \\( ?A::\\*\\)\\(A \\*( const)?, int\\)\r\n$gdb_prompt $" {
414         pass $name
415     }
416     -re "type = int \\( ?A::\\*\\)\\(void\\)\r\n$gdb_prompt $" {
417         # hpacc A.03.45
418         kfail "gdb/NNNN" $name
419     }
420     -re "type = struct \{.*\}\r\n$gdb_prompt $" {
421         # gcc 2.95.3 -gdwarf-2
422         # gcc 2.95.3 -gstabs+
423         # gcc 3.2.2 -gdwarf-2
424         # gcc 3.2.2 -gstabs+
425         # gcc HEAD 2004-01-10 -gdwarf-2
426         # gcc HEAD 2004-01-10 -gstabs+
427         kfail "gdb/NNNN" $name
428     }
429 }
430
431 # print a pointer to a method
432
433 set name "print pmf"
434 gdb_test_multiple "print pmf" $name {
435     -re "$vhn = \\(int \\(A::\\*\\)\\(A \\*( const)?, int\\)\\) $hex <A::bar\\(int\\)>\r\n$gdb_prompt $" {
436         pass $name
437     }
438     -re "$vhn = .*not supported with HP aCC.*\r\n$gdb_prompt $" {
439         # hpacc A.03.45
440         kfail "gdb/NNNN" $name
441     }
442     -re "$vhn = \{.*\}\r\n$gdb_prompt $" {
443         # gcc 2.95.3 -gdwarf-2
444         # gcc 2.95.3 -gstabs+
445         # gcc 3.2.2 -gdwarf-2
446         # gcc 3.2.2 -gstabs+
447         # gcc HEAD 2004-01-10 -gdwarf-2
448         # gcc HEAD 2004-01-10 -gstabs+
449         kfail "gdb/NNNN" $name
450     }
451 }
452
453 # ptype a pointer to a pointer to a method
454
455 set name "ptype pmf_p"
456 gdb_test_multiple "ptype pmf_p" $name {
457     -re "type = int \\( ?A::\\*\\*\\)\\(A \\*( const)?, int\\)\r\n$gdb_prompt $" {
458         pass $name
459     }
460     -re "type = int \\( ?A::\\*\\*\\)\\(void\\)\r\n$gdb_prompt $" {
461         # hpacc A.03.45
462         kfail "gdb/NNNN" $name
463     }
464     -re "type = struct \{.*\} \\*\r\n$gdb_prompt $" {
465         # gcc 2.95.3 -gdwarf-2
466         # gcc 2.95.3 -gstabs+
467         # gcc 3.2.2 -gdwarf-2
468         # gcc 3.2.2 -gstabs+
469         # gcc HEAD 2004-01-10 -gdwarf-2
470         # gcc HEAD 2004-01-10 -gstabs+
471         kfail "gdb/NNNN" $name
472     }
473 }
474
475 # print a pointer to a pointer to a method
476
477 set name "print pmf_p"
478 gdb_test_multiple "print pmf_p" $name {
479     -re "$vhn = \\(int \\( ?A::\\*\\*\\)\\)\\(int\\)\\) $hex\r\n$gdb_prompt $" {
480         pass $name
481     }
482     -re "$vhn = \\(PMF \\*\\) $hex\r\n$gdb_prompt $" {
483         pass "gdb/NNNN"
484     }
485     -re "$vhn = \\(int \\( ?A::\\*\\*\\)\\(void\\)\\) $hex\r\n$gdb_prompt $" {
486         # hpacc A.03.45
487         kfail "gdb/NNNN" $name
488     }
489     -re "$vhn = \\(struct \{.*\} \\*\\) $hex\r\n$gdb_prompt $" {
490         # gcc 2.95.3 -gdwarf-2
491         kfail "gdb/NNNN" $name
492     }
493 }
494
495 # print dereferenced pointer to method
496
497 set name "print a.*pmf"
498 gdb_test_multiple "print a.*pmf" $name {
499     -re "$vhn = {int \\(A \\*( const)?, int\\)} $hex <A::bar\\(int\\)>\r\n$gdb_prompt $" {
500         pass $name
501     }
502     -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
503         # hpacc A.03.45
504         kfail "gdb/NNNN" $name
505     }
506     -re "Value can't be converted to integer.\r\n$gdb_prompt $" {
507         # gcc 2.95.3 -gdwarf-2
508         # gcc 2.95.3 -gstabs+
509         # gcc 3.2.2 -gdwarf-2
510         # gcc 3.2.2 -gstabs+
511         # gcc HEAD 2004-01-10 -gdwarf-2
512         # gcc HEAD 2004-01-10 -gstabs+
513         kfail "gdb/NNNN" $name
514     }
515 }
516
517 # print dereferenced pointer to method, using ->*
518
519 set name "print a_p->*pmf"
520 gdb_test_multiple "print a_p->*pmf" $name {
521     -re "$vhn = {int \\(A \\*( const)?, int\\)} $hex <A::bar\\(int\\)>\r\n$gdb_prompt $" {
522         pass $name
523     }
524     -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
525         # hpacc A.03.45
526         kfail "gdb/NNNN" $name
527     }
528     -re "Value can't be converted to integer.\r\n$gdb_prompt $" {
529         # gcc 2.95.3 -gdwarf-2
530         # gcc 2.95.3 -gstabs+
531         # gcc 3.2.2 -gdwarf-2
532         # gcc 3.2.2 -gstabs+
533         # gcc HEAD 2004-01-10 -gdwarf-2
534         # gcc HEAD 2004-01-10 -gstabs+
535         kfail "gdb/NNNN" $name
536     }
537 }
538
539 # set the pointer to data member
540
541 set name "set var pmf = &A::foo"
542 gdb_test_multiple "set var pmf = &A::foo" $name {
543     -re "set var pmf = &A::foo\r\n$gdb_prompt $" {
544         # I have to match the echo'ed input explicitly here.
545         # If I leave it out, the pattern becomes too general
546         # and matches anything that ends in "$gdb_prompt $".
547         pass $name
548     }
549     -re "Invalid cast.\r\n$gdb_prompt $" {
550         # gcc 2.95.3 -gdwarf-2
551         # gcc 2.95.3 -gstabs+
552         # gcc 3.2.2 -gdwarf-2
553         # gcc 3.2.2 -gstabs+
554         # gcc HEAD 2004-01-10 -gdwarf-2
555         # gcc HEAD 2004-01-10 -gstabs+
556         kfail "gdb/NNNN" $name
557     }
558     -re "Assignment to pointers to methods not implemented with HP aCC\r\n$gdb_prompt $" {
559         kfail "gdb/NNNN" $name
560     }
561 }
562
563 # dereference the pointer to data member without any object
564 # this is not allowed: a pmf must be bound to an object to dereference
565
566 set name "print *pmf"
567 gdb_test_multiple "print *pmf" $name {
568     -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
569         pass $name
570     }
571     -re "Structure has no component named operator\\*.\r\n$gdb_prompt $" {
572         # gcc 2.95.3 -gdwarf-2
573         # gcc 2.95.3 -gstabs+
574         # gcc 3.3.2 -gdwarf-2
575         # gcc 3.3.2 -gstabs+
576         # gcc HEAD 2004-01-10 -gdwarf-2
577         # gcc HEAD 2004-01-10 -gstabs+
578         kfail "gdb/NNNN" $name
579     }
580 }
581
582 # dereference the pointer to data member without any object
583 # this is not allowed: a pmf must be bound to an object to dereference
584
585 set name "ptype *pmf"
586 gdb_test_multiple "ptype *pmf" $name {
587     -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
588         pass $name
589     }
590     -re "Structure has no component named operator\\*.\r\n$gdb_prompt $" {
591         # gcc 2.95.3 -gdwarf-2
592         # gcc 2.95.3 -gstabs+
593         # gcc 3.3.2 -gdwarf-2
594         # gcc 3.3.2 -gstabs+
595         # gcc HEAD 2004-01-10 -gdwarf-2
596         # gcc HEAD 2004-01-10 -gstabs+
597         kfail "gdb/NNNN" $name
598     }
599 }
600
601 # Call a function through a pmf.
602
603 set name "print (a.*pmf)(3)"
604 gdb_test_multiple "print (a.*pmf)(3)" $name {
605     -re "$vhn = 50\r\n$gdb_prompt $" {
606         pass $name
607     }
608     -re "Not implemented: function invocation through pointer to method with HP aCC\r\n$gdb_prompt $" {
609         # hpacc A.03.45
610         kfail "gdb/NNNN" $name
611     }
612     -re "Value can't be converted to integer.\r\n$gdb_prompt $" {
613         # gcc 2.95.3 -gdwarf-2
614         # gcc 2.95.3 -gstabs+
615         # gcc 3.3.2 -gdwarf-2
616         # gcc 3.3.2 -gstabs+
617         # gcc HEAD 2004-01-10 -gdwarf-2
618         # gcc HEAD 2004-01-10 -gstabs+
619         kfail "gdb/NNNN" $name
620     }
621 }
622
623 gdb_test "ptype a.*pmf" "type = int \\(A \\*( const)?, int\\)"
624 gdb_test "ptype (a.*pmf)(3)" "type = int"
625
626 # Print out a pointer to data member which requires looking into
627 # a base class.
628 gdb_test "print diamond_pmi" "$vhn = &Base::x"
629 gdb_test "print diamond.*diamond_pmi" "$vhn = 77"
630
631 # Examine some more complicated pmfs, which require adjusting "this"
632 # and looking through virtual tables.
633
634 # These two have a different object adjustment, but call the same method.
635 gdb_test "print diamond.*left_pmf" \
636     "$vhn = {int \\(Diamond \\*( const)?\\)} $hex <Base::get_x\\((void|)\\)>"
637 gdb_test "print diamond.*right_pmf" \
638     "$vhn = {int \\(Diamond \\*( const)?\\)} $hex <Base::get_x\\((void|)\\)>"
639
640 gdb_test "print (diamond.*left_pmf) ()" "$vhn = 77"
641 gdb_test "print (diamond.*right_pmf) ()" "$vhn = 88"
642
643 # These two point to different methods, although they have the same
644 # virtual table offsets.
645 gdb_test "print diamond.*left_vpmf" \
646     "$vhn = {int \\(Diamond \\*( const)?\\)} $hex <Left::vget\\((void|)\\)>"
647 gdb_test "print diamond.*right_vpmf" \
648     "$vhn = {int \\(Diamond \\*( const)?\\)} $hex <Right::vget\\((void|)\\)>"
649
650 gdb_test "print (diamond.*left_vpmf) ()" "$vhn = 177"
651 gdb_test "print (diamond.*left_base_vpmf) ()" "$vhn = 2077"
652 gdb_test "print (diamond.*right_vpmf) ()" "$vhn = 288"
653
654 # We should be able to figure out left_vpmf even without an object,
655 # because it comes from a non-virtual base.  The same for right_vpmf.
656 gdb_test "print left_vpmf" "$vhn = &virtual Left::vget\\(\\)"
657 gdb_test "print right_vpmf" "$vhn = &virtual Right::vget\\(\\)"
658
659 # But we should gracefully fail to figure out base_vpmf, because
660 # its runtime type is more derived than its static type.  This
661 # is a valid but unspecified cast (it is value preserving, i.e.
662 # can be casted back to the correct type and used).
663 gdb_test "print base_vpmf" \
664     "$vhn = &virtual table offset \[0-9\]*, this adjustment -\[0-9\]*"
665
666 # Make sure we parse this correctly; it's invalid.
667 gdb_test "print diamond.*left_vpmf ()" \
668     "Invalid data type for function to be called\\."
669
670 # NULL pointer to member tests.
671 gdb_test "print null_pmi" "$vhn = NULL"
672 gdb_test "print null_pmi = &A::j" "$vhn = &A::j"
673 gdb_test "print null_pmi = 0" "$vhn = NULL"
674
675 gdb_test "print null_pmf" "$vhn = NULL"
676 gdb_test "print null_pmf = &A::foo" "$vhn = \\(int \\(A::\\*\\)\\(A \\*( const)?, int\\)\\) $hex <A::foo ?\\(int\\)>"
677 gdb_test "print null_pmf = 0" "$vhn = NULL"