]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.c++/member-ptr.exp
import gdb-1999-09-08 snapshot
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.c++ / member-ptr.exp
CommitLineData
d4f3574e 1# Copyright (C) 1998, 1999 Free Software Foundation, Inc.
c906108c
SS
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-gdb@prep.ai.mit.edu
19# Tests for pointer-to-member support
20# Written by Satish Pai <pai@apollo.hp.com> 1997-08-19
21
22# This file is part of the gdb testsuite
23
24
25if $tracelevel then {
26 strace $tracelevel
27 }
28
d4f3574e
SS
29if { [skip_cplus_tests] } { continue }
30
c906108c
SS
31#
32# test running programs
33#
34
35# Start with a fresh gdb
36gdb_exit
37gdb_start
38gdb_reinitialize_dir $srcdir/$subdir
39
40set prms_id 0
41set bug_id 0
42
43set testfile "member-ptr"
44set srcfile ${testfile}.cc
45set binfile ${objdir}/${subdir}/${testfile}
46
085dd6e6
JM
47# Create and source the file that provides information about the compiler
48# used to compile the test case.
49
50if [get_compiler_info ${binfile} "c++"] {
51 return -1
52}
53
54# Nearly all of these tests fail when compiled with G++, so just give up
55# until GDB gets enhanced. -sts 1999-06-22
56
57if {$gcc_compiled} {
58 continue
59}
60
c906108c
SS
61if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
62 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
63}
64
65
66gdb_exit
67gdb_start
68gdb_reinitialize_dir $srcdir/$subdir
69gdb_load ${binfile}
70
71
72if ![runto_main] then {
73 perror "couldn't run to breakpoint"
74 continue
75}
76
77send_gdb "break 83\n"
78gdb_expect {
79 -re "Breakpoint \[0-9\]*.*line 83\\.\r\n$gdb_prompt $" {
80 pass "set break at 83"
81 }
82 -re ".*$gdb_prompt $" { fail "set break at 83" }
83 timeout { fail "(timeout) set break at 83" }
84}
85
86send_gdb "continue\n"
87gdb_expect {
88 -re "Continuing\\.\r\n\r\nBreakpoint.*at.*member-ptr\\.cc:83\r\n83\[ \t]*pmi = NULL;\r\n$gdb_prompt $" {
89 pass "continue to 83"
90 }
91 -re ".*$gdb_prompt $" { fail "continue to 83" }
92 timeout { fail "(timeout) continue to 83" }
93}
94
95# ptype on pointer to data member
96
97send_gdb "ptype pmi\n"
98gdb_expect {
99 -re "type = int \\( A::\\*\\)\r\n$gdb_prompt $" {
100 pass "ptype pmi"
101 }
102 -re ".*$gdb_prompt $" { fail "ptype pmi" }
103 timeout { fail "(timeout) ptype pmi" }
104}
105
106# print pointer to data member
107
a0b3c4fd 108setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
109send_gdb "print pmi\n"
110gdb_expect {
111 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::j\r\n$gdb_prompt $" {
112 pass "print pmi"
113 }
114 -re ".*$gdb_prompt $" { fail "print pmi" }
115 timeout { fail "(timeout) print pmi" }
116}
117
118
119# print dereferenced pointer to data member
120
a0b3c4fd 121setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
122send_gdb "print a.*pmi\n"
123gdb_expect {
124 -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
125 pass "print a.*pmi"
126 }
127 -re ".*$gdb_prompt $" { fail "print a.*pmi" }
128 timeout { fail "(timeout) print a.*pmi" }
129}
130
131# print dereferenced pointer to data member
132# this time, dereferenced through a pointer
133
a0b3c4fd 134setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
135send_gdb "print a_p->*pmi\n"
136gdb_expect {
137 -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
138 pass "print a->*pmi"
139 }
140 -re ".*$gdb_prompt $" { fail "print a->*pmi" }
141 timeout { fail "(timeout) print a->*pmi" }
142}
143
144
145# set the pointer to data member
146
147send_gdb "set var pmi = &A::jj\n"
148gdb_expect {
149 -re "$gdb_prompt $" {
150 pass "set var (not really a pass)"
151 }
152 timeout { fail "(timeout) " }
153}
154
155# Now print the pointer again
156
157send_gdb "print pmi\n"
158gdb_expect {
159 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
160 pass "print pmi after setting"
161 }
162 -re ".*$gdb_prompt $" { fail "print pmi after setting" }
163 timeout { fail "(timeout) print pmi after setting" }
164}
165
166# print dereferenced pointer to data member again
167
168send_gdb "print a.*pmi\n"
169gdb_expect {
170 -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
171 pass "print a.*pmi after setting"
172 }
173 -re ".*$gdb_prompt $" { fail "print a.*pmi after setting" }
174 timeout { fail "(timeout) print a.*pmi after setting" }
175}
176
177# set the pointer to data member back to A::j
178
179send_gdb "set var pmi = &A::j\n"
180gdb_expect {
181 -re "$gdb_prompt $" {
182 pass "set var back to A::j (not really a pass)"
183 }
184 timeout { fail "(timeout) set var pmi" }
185}
186
187# print dereferenced pointer to data member yet again (extra check, why not)
188
189send_gdb "print a.*pmi\n"
190gdb_expect {
191 -re "\\$\[0-9\]* = 121\r\n$gdb_prompt $" {
192 pass "print a.*pmi after resetting"
193 }
194 -re ".*$gdb_prompt $" { fail "print a.*pmi after resetting" }
195 timeout { fail "(timeout) print a.*pmi after resetting" }
196}
197
198# Set the data member pointed to.
199
200send_gdb "print a.*pmi = 33\n"
201gdb_expect {
202 -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" {
203 pass "print command to set"
204 }
205 -re ".*$gdb_prompt $" { fail "print command to set" }
206 timeout { fail "(timeout) print command to set" }
207}
208
209# Now check that the data really was changed
210send_gdb "print a.*pmi\n"
211gdb_expect {
212 -re "\\$\[0-9\]* = 33\r\n$gdb_prompt $" {
213 pass "print a.*pmi after setting member pointed to"
214 }
215 -re ".*$gdb_prompt $" { fail "print a.*pmi after setting member pointed to" }
216 timeout { fail "(timeout) print a.*pmi after setting member pointed to" }
217}
218
219# Double-check by printing a.
a0b3c4fd 220setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
221send_gdb "print a\n"
222gdb_expect {
223 -re "\\$\[0-9\]* = \{c = 120 'x', j = 33, jj = 1331, static s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
224 pass "print a after setting member pointed to by pmi"
225 }
226 -re ".*$gdb_prompt $" { fail "print a after setting member pointed to by pmi" }
227 timeout { fail "(timeout) print a after setting member pointed to by pmi" }
228}
229
230
231# Set the data member pointed to, using ->*
232
233send_gdb "print a_p->*pmi = 44\n"
234gdb_expect {
235 -re "\\$\[0-9\]* = 44\r\n$gdb_prompt $" {
236 pass "print command to set (->)"
237 }
238 -re ".*$gdb_prompt $" { fail "print command to set (->)" }
239 timeout { fail "(timeout) print command to set (->)" }
240}
241
242# Now check that the data really was changed
243send_gdb "print a_p->*pmi\n"
244gdb_expect {
245 -re "\\$\[0-9\]* = 44\r\n$gdb_prompt $" {
246 pass "print a_p->*pmi after setting member pointed to"
247 }
248 -re ".*$gdb_prompt $" { fail "print a_p->*pmi after setting member pointed to" }
249 timeout { fail "(timeout) print a_p->*pmi after setting member pointed to" }
250}
251
252# Double-check by printing a.
a0b3c4fd 253setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
254send_gdb "print a\n"
255gdb_expect {
256 -re "\\$\[0-9\]* = \{c = 120 'x', j = 44, jj = 1331, static s = 10, Virtual table at $hex\}\r\n$gdb_prompt $" {
257 pass "print a after setting member pointed to by pmi (->) "
258 }
259 -re ".*$gdb_prompt $" { fail "print a after setting member pointed to by pmi (->) " }
260 timeout { fail "(timeout) print a after setting member pointed to by pmi (->) " }
261}
262
263
264# Do a ptype on the dereferenced pointer to member
265# pai/1997-08-20 Doesn't work
266
267# send_gdb "ptype a.*pmi\n"
268# gdb_expect {
269# -re "type = int\r\n$gdb_prompt $" {
270# pass "ptype a.*pmi"
271# }
272# -re ".*$gdb_prompt $" { fail "ptype a.*pmi" }
273# timeout { fail "(timeout) ptype a.*pmi" }
274#}
275
276# Try to dereference the pointer to data member without any object
277
278send_gdb "print *pmi\n"
279gdb_expect {
280 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
281 pass "attempt to print ptr to member without object"
282 }
283 -re ".*$gdb_prompt $" { fail "attempt to print ptr to member without object" }
284 timeout { fail "(timeout) attempt to print ptr to member without object" }
285}
286
287# Try to ptype a dereference of the pointer to data member without any object
288
289send_gdb "ptype *pmi\n"
290gdb_expect {
291 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
292 pass "attempt to ptype ptr to member without object"
293 }
294 -re ".*$gdb_prompt $" { fail "attempt to ptype ptr to member without object" }
295 timeout { fail "(timeout) attempt to ptype ptr to member without object" }
296}
297
298# Ptype a pointer to a method.
299
a0b3c4fd 300setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
301send_gdb "ptype pmf\n"
302gdb_expect {
303 -re "type = int \\( A::\\*\\)\\(\\.\\.\\.\\)\r\n$gdb_prompt $" {
304 pass "ptype pmf"
305 }
306 -re ".*$gdb_prompt $" { fail "ptype pmf" }
307 timeout { fail "(timeout) ptype pmf" }
308}
309
310# print a pointer to a method
311
a0b3c4fd 312setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
313send_gdb "print pmf\n"
314gdb_expect {
315 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\(\\.\\.\\.\\)\\) \\?\\? <not supported with HP aCC>\r\n$gdb_prompt $" {
316 pass "print pmf"
317 }
318 -re ".*$gdb_prompt $" { fail "print pmf" }
319 timeout { fail "(timeout) print pmf" }
320}
321
322
323# Ptype a pointer to a pointer to a method
324
a0b3c4fd 325setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
326send_gdb "ptype pmf_p\n"
327gdb_expect {
328 -re "type = int \\( A::\\*\\*\\)\\(\\.\\.\\.\\)\r\n$gdb_prompt $" {
329 pass "ptype pmf_p"
330 }
331 -re ".*$gdb_prompt $" { fail "ptype pmf_p" }
332 timeout { fail "(timeout) ptype pmf_p" }
333}
334
335# print a pointer to a pointer to a method
336
a0b3c4fd 337setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
338send_gdb "print pmf_p\n"
339gdb_expect {
340 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\*\\)\\(\\.\\.\\.\\)\\) $hex\r\n$gdb_prompt $" {
341 pass "print pmf_p"
342 }
343 -re ".*$gdb_prompt $" { fail "print pmf_p" }
344 timeout { fail "(timeout) print pmf_p" }
345}
346
347# print dereferenced pointer to method
348
a0b3c4fd 349setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
350send_gdb "print a.*pmf\n"
351gdb_expect {
352 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
353 pass "print a.*pmf (known aCC limitation)"
354 }
a0b3c4fd 355 -re ".*$gdb_prompt $" { fail "print a.*pmf" }
c906108c
SS
356 timeout { fail "(timeout) print a.*pmf" }
357}
358
359# print dereferenced pointer to method, using ->*
360
a0b3c4fd 361setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
362send_gdb "print a_p->*pmf\n"
363gdb_expect {
364 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
365 pass "print a_p->*pmf (known aCC limitation)"
366 }
a0b3c4fd 367 -re ".*$gdb_prompt $" { fail "print a_p->*pmf" }
c906108c
SS
368 timeout { fail "(timeout) print a_p->*pmf" }
369}
370
371# set the pointer to data member
372
a0b3c4fd 373setup_xfail "hppa*-*-*"
c906108c
SS
374send_gdb "set var pmf = &A::foo\n"
375gdb_expect {
376 -re "Assignment to pointers to methods not implemented with HP aCC\r\n$gdb_prompt $" {
377 pass "set var pmf (known aCC limitation)"
378 }
a0b3c4fd 379 -re ".*$gdb_prompt $" { fail "set var pmf" }
c906108c
SS
380 timeout { fail "(timeout) set var pmf" }
381}
382
383# Try to dereference the pointer to method without any object
384
a0b3c4fd 385setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
386send_gdb "print *pmf\n"
387gdb_expect {
388 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
389 pass "attempt to print ptr to method without object"
390 }
391 -re ".*$gdb_prompt $" { fail "attempt to print ptr to method without object" }
392 timeout { fail "(timeout) attempt to print ptr to method without object" }
393}
394
395# Try to ptype a dereference of the pointer to method without any object
396
397send_gdb "ptype *pmi\n"
398gdb_expect {
399 -re "Attempt to dereference pointer to member without an object\r\n$gdb_prompt $" {
400 pass "attempt to ptype ptr to member without object"
401 }
402 -re ".*$gdb_prompt $" { fail "attempt to ptype ptr to member without object" }
403 timeout { fail "(timeout) attempt to ptype ptr to member without object" }
404}
405
406# Check cast of pointer to member to integer
a0b3c4fd 407setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
408send_gdb "print (int) pmi\n"
409gdb_expect {
410 -re "\\$\[0-9\]* = 8\r\n$gdb_prompt $" {
411 pass "casting pmi to int"
412 }
413 -re ".*$gdb_prompt $" { fail "casting pmi to int" }
414 timeout { fail "(timeout) casting pmi to int" }
415}
416
417# Check cast of pointer to method to integer
a0b3c4fd 418setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
419send_gdb "print (int) pmf\n"
420gdb_expect {
421 -re "Pointers to methods not supported with HP aCC\r\n$gdb_prompt $" {
422 pass "casting pmf to int (known aCC limitation)"
423 }
a0b3c4fd 424 -re ".*$gdb_prompt $" { fail "casting pmf to int" }
c906108c
SS
425 timeout { fail "(timeout) casting pmf to int" }
426}
427
428# Try to invoke a function through a pointer to data member
a0b3c4fd 429setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
430send_gdb "print (a.*pmi)(3)\n"
431gdb_expect {
432 -re "Not implemented: function invocation through pointer to method with HP aCC\r\n$gdb_prompt $" {
433 pass "print (a.*pmi)(3) -- error message should be different"
434 }
a0b3c4fd 435 -re ".*$gdb_prompt $" { fail "print (a.*pmi)(3)" }
c906108c
SS
436 timeout { fail "(timeout) print (a.*pmi)(3)" }
437}
438
439# Try to invoke a function through a pointer to a method
a0b3c4fd 440setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
441send_gdb "print (a.*pmf)(3)\n"
442gdb_expect {
443 -re "Not implemented: function invocation through pointer to method with HP aCC\r\n$gdb_prompt $" {
444 pass "print (a.*pmi)(3) -- known aCC limitation"
445 }
a0b3c4fd 446 -re ".*$gdb_prompt $" { fail "print (a.*pmf)(3)" }
c906108c
SS
447 timeout { fail "(timeout) print (a.*pmf)(3)" }
448}
449
450
451# Go past assignment of NULL to pmi
a0b3c4fd 452setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
453send_gdb "next\n"
454gdb_expect {
455 -re "\r\n85\[ \t\]*k = \\(a.\\*pmf\\)\\(3\\);\r\n$gdb_prompt $" {
456 pass "next past 83"
457 }
458 -re ".*$gdb_prompt $" { fail "next past 83" }
459 timeout { fail "(timeout) next past 83" }
460}
461
462#send_gdb "print pmi\n"
463#gdb_expect {
464# -re "Attempted dereference of null pointer-to-member\r\n$gdb_prompt $" {
465# pass ""
466# }
467# -re ".*$gdb_prompt $" { fail "" }
468# timeout { fail "(timeout) " }
469#}
470
471# Dereference the null pointer to member
a0b3c4fd 472setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
473send_gdb "print a.*pmi\n"
474gdb_expect {
475 -re "Attempted dereference of null pointer-to-member\r\n$gdb_prompt $" {
476 pass "print a.*NULL"
477 }
478 -re ".*$gdb_prompt $" { fail "print a.*NULL" }
479 timeout { fail "(timeout) print a.*NULL" }
480}
481
482
483# Go to another part of the program
484send_gdb "break 91\n"
485gdb_expect {
486 -re "Breakpoint \[0-9\]*.*line 91\\.\r\n$gdb_prompt $" {
487 pass "set break at 91"
488 }
489 -re ".*$gdb_prompt $" { fail "set break at 91" }
490 timeout { fail "(timeout) set break at 91" }
491}
492
a0b3c4fd 493setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
494send_gdb "continue\n"
495gdb_expect {
496 -re "Continuing\\.\r\n\r\nBreakpoint.*at.*member-ptr\\.cc:91\r\n91\[ \t]*k = \\(a.\\*pmf\\)\\(4\\);\r\n$gdb_prompt $" {
497 pass "continue to 91"
498 }
499 -re ".*$gdb_prompt $" { fail "continue to 91" }
500 timeout { fail "(timeout) continue to 91" }
501}
502
503
504# Now check again that pmi works even when not set to
505# something that's at the beginning of the object
506
a0b3c4fd 507setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
508send_gdb "print pmi\n"
509gdb_expect {
510 -re "\\$\[0-9\]* = \\(int \\( A::\\*\\)\\) &A::jj\r\n$gdb_prompt $" {
511 pass "print pmi (2)"
512 }
513 -re ".*$gdb_prompt $" { fail "print pmi (2)" }
514 timeout { fail "(timeout) print pmi (2)" }
515}
516
517
518# print dereferenced pointer to data member
519
a0b3c4fd 520setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
521send_gdb "print a.*pmi\n"
522gdb_expect {
523 -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
524 pass "print a.*pmi (2)"
525 }
526 -re ".*$gdb_prompt $" { fail "print a.*pmi (2)" }
527 timeout { fail "(timeout) print a.*pmi (2)" }
528}
529
530# print dereferenced pointer to data member
531# this time, dereferenced through a pointer
532
a0b3c4fd 533setup_xfail "hppa*-*-*" CLLbs16901
c906108c
SS
534send_gdb "print a_p->*pmi\n"
535gdb_expect {
536 -re "\\$\[0-9\]* = 1331\r\n$gdb_prompt $" {
537 pass "print a->*pmi"
538 }
539 -re ".*$gdb_prompt $" { fail "print a->*pmi (2)" }
540 timeout { fail "(timeout) print a->*pmi (2)" }
541}
542
543
544# p a.*pmf - fail
545
546# p pmi
547
548# p a.*pmi
549