Commit | Line | Data |
---|---|---|
ecd75fc8 | 1 | # Copyright 1998-2014 Free Software Foundation, Inc. |
a0644324 MC |
2 | |
3 | # This file is part of the gdb testsuite | |
c906108c SS |
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 | |
e22f8b7c | 7 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 8 | # (at your option) any later version. |
e22f8b7c | 9 | # |
c906108c SS |
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. | |
e22f8b7c | 14 | # |
c906108c | 15 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 17 | |
c906108c SS |
18 | # Tests for pointer-to-member support |
19 | # Written by Satish Pai <pai@apollo.hp.com> 1997-08-19 | |
a0644324 | 20 | # Rewritten by Michael Chastain <mec.gnu@mindspring.com> 2004-01-11 |
c906108c | 21 | |
a0644324 | 22 | set vhn "\\$\[0-9\]+" |
c906108c | 23 | |
d4f3574e SS |
24 | if { [skip_cplus_tests] } { continue } |
25 | ||
c906108c | 26 | |
f5f3a911 | 27 | standard_testfile .cc |
c906108c | 28 | |
4c93b1db | 29 | if [get_compiler_info "c++"] { |
085dd6e6 JM |
30 | return -1 |
31 | } | |
32 | ||
f5f3a911 TT |
33 | if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { |
34 | return -1 | |
c906108c SS |
35 | } |
36 | ||
c906108c SS |
37 | if ![runto_main] then { |
38 | perror "couldn't run to breakpoint" | |
39 | continue | |
40 | } | |
41 | ||
0d5de010 | 42 | gdb_breakpoint [gdb_get_line_number "Breakpoint 1 here"] |
a0644324 | 43 | gdb_continue_to_breakpoint "continue to pmi = NULL" |
c906108c | 44 | |
a0644324 MC |
45 | # ====================== |
46 | # pointer to member data | |
47 | # ====================== | |
48 | ||
c906108c SS |
49 | # ptype on pointer to data member |
50 | ||
a0644324 MC |
51 | set name "ptype pmi (A::j)" |
52 | gdb_test_multiple "ptype pmi" $name { | |
0d5de010 | 53 | -re "type = int A::\\*\r\n$gdb_prompt $" { |
a0644324 MC |
54 | pass $name |
55 | } | |
c906108c SS |
56 | } |
57 | ||
58 | # print pointer to data member | |
59 | ||
a0644324 MC |
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 | |
c906108c | 86 | } |
c906108c SS |
87 | } |
88 | ||
c906108c SS |
89 | # print dereferenced pointer to data member |
90 | ||
a0644324 MC |
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 | |
c906108c | 105 | } |
c906108c SS |
106 | } |
107 | ||
108 | # print dereferenced pointer to data member | |
109 | # this time, dereferenced through a pointer | |
110 | ||
a0644324 MC |
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 | |
c906108c | 125 | } |
c906108c SS |
126 | } |
127 | ||
a0644324 | 128 | # set the pointer to a different data member |
c906108c | 129 | |
a0644324 MC |
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 | |
c906108c | 142 | } |
c906108c SS |
143 | } |
144 | ||
a0644324 | 145 | # print the pointer again |
c906108c | 146 | |
a0644324 MC |
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 | |
c906108c | 165 | } |
c906108c SS |
166 | } |
167 | ||
168 | # print dereferenced pointer to data member again | |
169 | ||
a0644324 MC |
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 | |
c906108c | 179 | } |
c906108c SS |
180 | } |
181 | ||
182 | # set the pointer to data member back to A::j | |
183 | ||
a0644324 MC |
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 | |
c906108c | 196 | } |
c906108c SS |
197 | } |
198 | ||
199 | # print dereferenced pointer to data member yet again (extra check, why not) | |
200 | ||
a0644324 MC |
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 | |
c906108c | 210 | } |
c906108c SS |
211 | } |
212 | ||
213 | # Set the data member pointed to. | |
214 | ||
a0644324 MC |
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 | |
c906108c | 224 | } |
c906108c SS |
225 | } |
226 | ||
227 | # Now check that the data really was changed | |
c906108c | 228 | |
a0644324 MC |
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 | |
c906108c | 238 | } |
c906108c SS |
239 | } |
240 | ||
a0644324 | 241 | # Double-check by printing a. |
c906108c | 242 | |
a0644324 MC |
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 | |
c906108c | 247 | } |
a0644324 MC |
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 | |
c906108c | 250 | } |
410528f0 | 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 $" { |
a0644324 MC |
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 | |
c906108c | 258 | } |
c906108c SS |
259 | } |
260 | ||
a0644324 | 261 | # Set the data member pointed to, using ->* |
c906108c | 262 | |
a0644324 MC |
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 | |
c906108c | 272 | } |
c906108c SS |
273 | } |
274 | ||
a0644324 | 275 | # Check that the data really was changed |
c906108c | 276 | |
a0644324 MC |
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 | |
c906108c | 286 | } |
c906108c SS |
287 | } |
288 | ||
a0644324 | 289 | # Double-check by printing a. |
c906108c | 290 | |
a0644324 MC |
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 | } | |
410528f0 | 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 $" { |
a0644324 MC |
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 | |
c906108c | 306 | } |
c906108c SS |
307 | } |
308 | ||
a0644324 | 309 | # ptype the dereferenced pointer to member. |
c906108c | 310 | |
a0644324 MC |
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 | |
c906108c | 320 | } |
c906108c SS |
321 | } |
322 | ||
a0644324 MC |
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 | |
c906108c | 325 | |
a0644324 MC |
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 | |
c906108c | 339 | } |
c906108c SS |
340 | } |
341 | ||
a0644324 MC |
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 | |
c906108c | 344 | |
a0644324 MC |
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 | |
c906108c | 355 | } |
c906108c SS |
356 | } |
357 | ||
a0644324 MC |
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". | |
c906108c | 361 | |
a0644324 MC |
362 | set name "print (int) pmi" |
363 | gdb_test_multiple "print (int) pmi" $name { | |
0d5de010 | 364 | -re "$vhn = (4|8|12)\r\n$gdb_prompt" { |
a0644324 | 365 | pass $name |
c906108c | 366 | } |
c906108c SS |
367 | } |
368 | ||
a0644324 | 369 | # Check "(int) pmi" explicitly for equality. |
c906108c | 370 | |
a0644324 MC |
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 | |
c906108c | 375 | } |
c906108c SS |
376 | } |
377 | ||
5edf51fe YQ |
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 | ||
a0644324 MC |
405 | # ========================== |
406 | # pointer to member function | |
407 | # ========================== | |
408 | ||
409 | # ptype a pointer to a method | |
c906108c | 410 | |
a0644324 MC |
411 | set name "ptype pmf" |
412 | gdb_test_multiple "ptype pmf" $name { | |
3ce3b1ba | 413 | -re "type = int \\( ?A::\\*\\)\\(A \\*( const)?, int\\)\r\n$gdb_prompt $" { |
a0644324 MC |
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 | |
c906108c | 428 | } |
c906108c SS |
429 | } |
430 | ||
a0644324 | 431 | # print a pointer to a method |
c906108c | 432 | |
a0644324 MC |
433 | set name "print pmf" |
434 | gdb_test_multiple "print pmf" $name { | |
3ce3b1ba | 435 | -re "$vhn = \\(int \\(A::\\*\\)\\(A \\*( const)?, int\\)\\) $hex <A::bar\\(int\\)>\r\n$gdb_prompt $" { |
a0644324 MC |
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 | |
c906108c | 450 | } |
c906108c SS |
451 | } |
452 | ||
a0644324 | 453 | # ptype a pointer to a pointer to a method |
c906108c | 454 | |
a0644324 MC |
455 | set name "ptype pmf_p" |
456 | gdb_test_multiple "ptype pmf_p" $name { | |
3ce3b1ba | 457 | -re "type = int \\( ?A::\\*\\*\\)\\(A \\*( const)?, int\\)\r\n$gdb_prompt $" { |
a0644324 | 458 | pass $name |
c906108c | 459 | } |
a0644324 MC |
460 | -re "type = int \\( ?A::\\*\\*\\)\\(void\\)\r\n$gdb_prompt $" { |
461 | # hpacc A.03.45 | |
462 | kfail "gdb/NNNN" $name | |
c906108c | 463 | } |
a0644324 MC |
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 | |
c906108c | 472 | } |
c906108c SS |
473 | } |
474 | ||
a0644324 | 475 | # print a pointer to a pointer to a method |
c906108c | 476 | |
a0644324 MC |
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 | |
c906108c | 492 | } |
c906108c SS |
493 | } |
494 | ||
a0644324 | 495 | # print dereferenced pointer to method |
c906108c | 496 | |
a0644324 MC |
497 | set name "print a.*pmf" |
498 | gdb_test_multiple "print a.*pmf" $name { | |
3ce3b1ba | 499 | -re "$vhn = {int \\(A \\*( const)?, int\\)} $hex <A::bar\\(int\\)>\r\n$gdb_prompt $" { |
a0644324 MC |
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 | |
c906108c | 514 | } |
c906108c SS |
515 | } |
516 | ||
a0644324 | 517 | # print dereferenced pointer to method, using ->* |
c906108c | 518 | |
a0644324 MC |
519 | set name "print a_p->*pmf" |
520 | gdb_test_multiple "print a_p->*pmf" $name { | |
3ce3b1ba | 521 | -re "$vhn = {int \\(A \\*( const)?, int\\)} $hex <A::bar\\(int\\)>\r\n$gdb_prompt $" { |
a0644324 MC |
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 | |
c906108c | 536 | } |
c906108c SS |
537 | } |
538 | ||
a0644324 | 539 | # set the pointer to data member |
c906108c | 540 | |
a0644324 MC |
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 | |
c906108c | 548 | } |
a0644324 MC |
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 | |
c906108c | 560 | } |
c906108c SS |
561 | } |
562 | ||
a0644324 MC |
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 | |
c906108c | 565 | |
a0644324 MC |
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 | |
c906108c | 579 | } |
c906108c SS |
580 | } |
581 | ||
a0644324 MC |
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 | |
c906108c | 584 | |
a0644324 MC |
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 | |
c906108c | 598 | } |
c906108c SS |
599 | } |
600 | ||
a0644324 | 601 | # Call a function through a pmf. |
c906108c | 602 | |
a0644324 MC |
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 | |
c906108c | 620 | } |
c906108c | 621 | } |
0d5de010 | 622 | |
3ce3b1ba | 623 | gdb_test "ptype a.*pmf" "type = int \\(A \\*( const)?, int\\)" |
5edf51fe | 624 | gdb_test "ptype (a.*pmf)(3)" "type = int" |
cec808ec | 625 | |
0d5de010 DJ |
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" \ | |
3ce3b1ba | 636 | "$vhn = {int \\(Diamond \\*( const)?\\)} $hex <Base::get_x\\((void|)\\)>" |
0d5de010 | 637 | gdb_test "print diamond.*right_pmf" \ |
3ce3b1ba | 638 | "$vhn = {int \\(Diamond \\*( const)?\\)} $hex <Base::get_x\\((void|)\\)>" |
0d5de010 DJ |
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" \ | |
3ce3b1ba | 646 | "$vhn = {int \\(Diamond \\*( const)?\\)} $hex <Left::vget\\((void|)\\)>" |
0d5de010 | 647 | gdb_test "print diamond.*right_vpmf" \ |
3ce3b1ba | 648 | "$vhn = {int \\(Diamond \\*( const)?\\)} $hex <Right::vget\\((void|)\\)>" |
0d5de010 DJ |
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" | |
3ce3b1ba | 676 | gdb_test "print null_pmf = &A::foo" "$vhn = \\(int \\(A::\\*\\)\\(A \\*( const)?, int\\)\\) $hex <A::foo ?\\(int\\)>" |
0d5de010 | 677 | gdb_test "print null_pmf = 0" "$vhn = NULL" |