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