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