Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright 1998-2016 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 | } | |
c906108c SS |
81 | } |
82 | ||
c906108c SS |
83 | # print dereferenced pointer to data member |
84 | ||
a0644324 MC |
85 | set name "print a.*pmi (A::j)" |
86 | gdb_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 | |
c906108c | 99 | } |
c906108c SS |
100 | } |
101 | ||
102 | # print dereferenced pointer to data member | |
103 | # this time, dereferenced through a pointer | |
104 | ||
a0644324 MC |
105 | set name "print a_p->*pmi (A::j)" |
106 | gdb_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 | |
c906108c | 119 | } |
c906108c SS |
120 | } |
121 | ||
a0644324 | 122 | # set the pointer to a different data member |
c906108c | 123 | |
a0644324 MC |
124 | set name "set var pmi = &A::jj" |
125 | gdb_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 | |
c906108c | 136 | } |
c906108c SS |
137 | } |
138 | ||
a0644324 | 139 | # print the pointer again |
c906108c | 140 | |
a0644324 MC |
141 | set name "print pmi (A::jj)" |
142 | gdb_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 | } | |
c906108c SS |
154 | } |
155 | ||
156 | # print dereferenced pointer to data member again | |
157 | ||
a0644324 MC |
158 | set name "print a.*pmi (A::jj)" |
159 | gdb_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 | |
c906108c | 167 | } |
c906108c SS |
168 | } |
169 | ||
170 | # set the pointer to data member back to A::j | |
171 | ||
a0644324 MC |
172 | set name "set var pmi = &A::j" |
173 | gdb_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 | |
c906108c | 184 | } |
c906108c SS |
185 | } |
186 | ||
187 | # print dereferenced pointer to data member yet again (extra check, why not) | |
188 | ||
a0644324 MC |
189 | set name "print a.*pmi (A::j) (again)" |
190 | gdb_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 | |
c906108c | 198 | } |
c906108c SS |
199 | } |
200 | ||
201 | # Set the data member pointed to. | |
202 | ||
a0644324 MC |
203 | set name "print a.*pmi = 33" |
204 | gdb_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 | |
c906108c | 212 | } |
c906108c SS |
213 | } |
214 | ||
215 | # Now check that the data really was changed | |
c906108c | 216 | |
a0644324 MC |
217 | set name "print a.*pmi (A::j) (33)" |
218 | gdb_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 | |
c906108c | 226 | } |
c906108c SS |
227 | } |
228 | ||
a0644324 | 229 | # Double-check by printing a. |
c906108c | 230 | |
a0644324 MC |
231 | set name "print a (j = 33)" |
232 | gdb_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 | |
c906108c | 235 | } |
a0644324 MC |
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 | |
c906108c | 238 | } |
410528f0 | 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 $" { |
a0644324 MC |
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 | |
c906108c | 246 | } |
c906108c SS |
247 | } |
248 | ||
a0644324 | 249 | # Set the data member pointed to, using ->* |
c906108c | 250 | |
a0644324 MC |
251 | set name "print a_p->*pmi = 44" |
252 | gdb_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 | |
c906108c | 260 | } |
c906108c SS |
261 | } |
262 | ||
a0644324 | 263 | # Check that the data really was changed |
c906108c | 264 | |
a0644324 MC |
265 | set name "print a_p->*pmi (44)" |
266 | gdb_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 | |
c906108c | 274 | } |
c906108c SS |
275 | } |
276 | ||
a0644324 | 277 | # Double-check by printing a. |
c906108c | 278 | |
a0644324 MC |
279 | set name "print a (j = 44)" |
280 | gdb_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 | } | |
410528f0 | 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 $" { |
a0644324 MC |
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 | |
c906108c | 294 | } |
c906108c SS |
295 | } |
296 | ||
a0644324 | 297 | # ptype the dereferenced pointer to member. |
c906108c | 298 | |
a0644324 MC |
299 | set name "ptype a.*pmi" |
300 | gdb_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 | |
c906108c | 308 | } |
c906108c SS |
309 | } |
310 | ||
a0644324 MC |
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 | |
c906108c | 313 | |
a0644324 MC |
314 | set name "print *pmi" |
315 | gdb_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 | |
c906108c | 327 | } |
c906108c SS |
328 | } |
329 | ||
a0644324 MC |
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 | |
c906108c | 332 | |
a0644324 MC |
333 | set name "ptype *pmi" |
334 | gdb_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 | |
c906108c | 343 | } |
c906108c SS |
344 | } |
345 | ||
a0644324 MC |
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". | |
c906108c | 349 | |
a0644324 MC |
350 | set name "print (int) pmi" |
351 | gdb_test_multiple "print (int) pmi" $name { | |
0d5de010 | 352 | -re "$vhn = (4|8|12)\r\n$gdb_prompt" { |
a0644324 | 353 | pass $name |
c906108c | 354 | } |
c906108c SS |
355 | } |
356 | ||
a0644324 | 357 | # Check "(int) pmi" explicitly for equality. |
c906108c | 358 | |
a0644324 MC |
359 | set name "print ((int) pmi) == ((char *) &a.j - (char *) &a)" |
360 | gdb_test_multiple "print ((int) pmi) == ((char *) &a.j - (char *) & a)" $name { | |
361 | -re "$vhn = true\r\n$gdb_prompt" { | |
362 | pass $name | |
c906108c | 363 | } |
c906108c SS |
364 | } |
365 | ||
5edf51fe YQ |
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 | ||
370 | gdb_test "ptype diamond_pfunc_ptr" \ | |
371 | "type = int \\(\\*Diamond::\\*\\)\\(int\\)" | |
372 | ||
373 | gdb_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 | ||
379 | gdb_test "print diamond.*diamond_pfunc_ptr (20)" \ | |
380 | "Invalid data type for function to be called." | |
381 | ||
382 | # With parentheses, it is valid. | |
383 | ||
384 | gdb_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 | ||
390 | gdb_test "print diamond.func_ptr (20)" \ | |
391 | "$vhn = 39" | |
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 { | |
3ce3b1ba | 401 | -re "type = int \\( ?A::\\*\\)\\(A \\*( const)?, int\\)\r\n$gdb_prompt $" { |
a0644324 MC |
402 | pass $name |
403 | } | |
a0644324 MC |
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 | |
c906108c | 412 | } |
c906108c SS |
413 | } |
414 | ||
a0644324 | 415 | # print a pointer to a method |
c906108c | 416 | |
a0644324 MC |
417 | set name "print pmf" |
418 | gdb_test_multiple "print pmf" $name { | |
3ce3b1ba | 419 | -re "$vhn = \\(int \\(A::\\*\\)\\(A \\*( const)?, int\\)\\) $hex <A::bar\\(int\\)>\r\n$gdb_prompt $" { |
a0644324 MC |
420 | pass $name |
421 | } | |
a0644324 MC |
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 | |
c906108c | 430 | } |
c906108c SS |
431 | } |
432 | ||
a0644324 | 433 | # ptype a pointer to a pointer to a method |
c906108c | 434 | |
a0644324 MC |
435 | set name "ptype pmf_p" |
436 | gdb_test_multiple "ptype pmf_p" $name { | |
3ce3b1ba | 437 | -re "type = int \\( ?A::\\*\\*\\)\\(A \\*( const)?, int\\)\r\n$gdb_prompt $" { |
a0644324 | 438 | pass $name |
c906108c | 439 | } |
a0644324 MC |
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 | |
c906108c | 448 | } |
c906108c SS |
449 | } |
450 | ||
a0644324 | 451 | # print a pointer to a pointer to a method |
c906108c | 452 | |
a0644324 MC |
453 | set name "print pmf_p" |
454 | gdb_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 | } | |
a0644324 MC |
461 | -re "$vhn = \\(struct \{.*\} \\*\\) $hex\r\n$gdb_prompt $" { |
462 | # gcc 2.95.3 -gdwarf-2 | |
463 | kfail "gdb/NNNN" $name | |
c906108c | 464 | } |
c906108c SS |
465 | } |
466 | ||
a0644324 | 467 | # print dereferenced pointer to method |
c906108c | 468 | |
a0644324 MC |
469 | set name "print a.*pmf" |
470 | gdb_test_multiple "print a.*pmf" $name { | |
3ce3b1ba | 471 | -re "$vhn = {int \\(A \\*( const)?, int\\)} $hex <A::bar\\(int\\)>\r\n$gdb_prompt $" { |
a0644324 MC |
472 | pass $name |
473 | } | |
a0644324 MC |
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 | |
c906108c | 482 | } |
c906108c SS |
483 | } |
484 | ||
a0644324 | 485 | # print dereferenced pointer to method, using ->* |
c906108c | 486 | |
a0644324 MC |
487 | set name "print a_p->*pmf" |
488 | gdb_test_multiple "print a_p->*pmf" $name { | |
3ce3b1ba | 489 | -re "$vhn = {int \\(A \\*( const)?, int\\)} $hex <A::bar\\(int\\)>\r\n$gdb_prompt $" { |
a0644324 MC |
490 | pass $name |
491 | } | |
a0644324 MC |
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 | # set the pointer to data member |
c906108c | 504 | |
a0644324 MC |
505 | set name "set var pmf = &A::foo" |
506 | gdb_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 | |
c906108c | 512 | } |
a0644324 MC |
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 | } | |
c906108c SS |
522 | } |
523 | ||
a0644324 MC |
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 | |
c906108c | 526 | |
a0644324 MC |
527 | set name "print *pmf" |
528 | gdb_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 | |
c906108c | 540 | } |
c906108c SS |
541 | } |
542 | ||
a0644324 MC |
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 | |
c906108c | 545 | |
a0644324 MC |
546 | set name "ptype *pmf" |
547 | gdb_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 | |
c906108c | 559 | } |
c906108c SS |
560 | } |
561 | ||
a0644324 | 562 | # Call a function through a pmf. |
c906108c | 563 | |
a0644324 MC |
564 | set name "print (a.*pmf)(3)" |
565 | gdb_test_multiple "print (a.*pmf)(3)" $name { | |
566 | -re "$vhn = 50\r\n$gdb_prompt $" { | |
567 | pass $name | |
568 | } | |
a0644324 MC |
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 | |
c906108c | 577 | } |
c906108c | 578 | } |
0d5de010 | 579 | |
3ce3b1ba | 580 | gdb_test "ptype a.*pmf" "type = int \\(A \\*( const)?, int\\)" |
5edf51fe | 581 | gdb_test "ptype (a.*pmf)(3)" "type = int" |
cec808ec | 582 | |
0d5de010 DJ |
583 | # Print out a pointer to data member which requires looking into |
584 | # a base class. | |
585 | gdb_test "print diamond_pmi" "$vhn = &Base::x" | |
586 | gdb_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. | |
592 | gdb_test "print diamond.*left_pmf" \ | |
3ce3b1ba | 593 | "$vhn = {int \\(Diamond \\*( const)?\\)} $hex <Base::get_x\\((void|)\\)>" |
0d5de010 | 594 | gdb_test "print diamond.*right_pmf" \ |
3ce3b1ba | 595 | "$vhn = {int \\(Diamond \\*( const)?\\)} $hex <Base::get_x\\((void|)\\)>" |
0d5de010 DJ |
596 | |
597 | gdb_test "print (diamond.*left_pmf) ()" "$vhn = 77" | |
598 | gdb_test "print (diamond.*right_pmf) ()" "$vhn = 88" | |
599 | ||
600 | # These two point to different methods, although they have the same | |
601 | # virtual table offsets. | |
602 | gdb_test "print diamond.*left_vpmf" \ | |
3ce3b1ba | 603 | "$vhn = {int \\(Diamond \\*( const)?\\)} $hex <Left::vget\\((void|)\\)>" |
0d5de010 | 604 | gdb_test "print diamond.*right_vpmf" \ |
3ce3b1ba | 605 | "$vhn = {int \\(Diamond \\*( const)?\\)} $hex <Right::vget\\((void|)\\)>" |
0d5de010 DJ |
606 | |
607 | gdb_test "print (diamond.*left_vpmf) ()" "$vhn = 177" | |
608 | gdb_test "print (diamond.*left_base_vpmf) ()" "$vhn = 2077" | |
609 | gdb_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. | |
613 | gdb_test "print left_vpmf" "$vhn = &virtual Left::vget\\(\\)" | |
614 | gdb_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). | |
620 | gdb_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. | |
624 | gdb_test "print diamond.*left_vpmf ()" \ | |
625 | "Invalid data type for function to be called\\." | |
626 | ||
627 | # NULL pointer to member tests. | |
628 | gdb_test "print null_pmi" "$vhn = NULL" | |
629 | gdb_test "print null_pmi = &A::j" "$vhn = &A::j" | |
630 | gdb_test "print null_pmi = 0" "$vhn = NULL" | |
631 | ||
632 | gdb_test "print null_pmf" "$vhn = NULL" | |
3ce3b1ba | 633 | gdb_test "print null_pmf = &A::foo" "$vhn = \\(int \\(A::\\*\\)\\(A \\*( const)?, int\\)\\) $hex <A::foo ?\\(int\\)>" |
0d5de010 | 634 | gdb_test "print null_pmf = 0" "$vhn = NULL" |