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