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