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