* NEWS: Mention pointer to member improvements.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / virtfunc.exp
1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004,
2 # 2006
3 # Free Software Foundation, Inc.
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
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
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.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 # This file was written by Fred Fish. (fnf@cygnus.com)
20 # And rewritten by Michael Chastain <mec.gnu@mindspring.com>.
21
22 set nl "\[\r\n\]+"
23
24 if $tracelevel then {
25 strace $tracelevel
26 }
27
28 if { [skip_cplus_tests] } { continue }
29
30 load_lib "cp-support.exp"
31
32 set testfile "virtfunc"
33 set srcfile ${testfile}.cc
34 set binfile ${objdir}/${subdir}/${testfile}
35
36 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } {
37 untested virtfunc.exp
38 return -1
39 }
40
41 proc test_ptype_of_classes {} {
42
43 # class VA
44
45 cp_test_ptype_class \
46 "ptype VA" "" "class" "VA" \
47 {
48 { field public "int va;" }
49 }
50
51 # class VB
52
53 cp_test_ptype_class \
54 "ptype VB" "" "class" "VB" \
55 {
56 { field public "int vb;" }
57 { method public "int fvb();" }
58 { method public "virtual int vvb();" }
59 }
60
61 # class V
62
63 cp_test_ptype_class \
64 "ptype V" "" "class" "V" \
65 {
66 { base "public VA" }
67 { base "public VB" }
68 { field public "int w;" }
69 { method public "int f();" }
70 { method public "virtual int vv();" }
71 }
72
73 # class A
74
75 cp_test_ptype_class \
76 "ptype A" "" "class" "A" \
77 {
78 { base "public virtual V" }
79 { vbase "V" }
80 { field private "int a;" }
81 { method public "virtual int f();" }
82 }
83
84 # class B
85
86 cp_test_ptype_class \
87 "ptype B" "" "class" "B" \
88 {
89 { base "public A" }
90 { field private "int b;" }
91 { method public "virtual int f();" }
92 }
93
94 # class C
95
96 cp_test_ptype_class \
97 "ptype C" "" "class" "C" \
98 {
99 { base "public virtual V" }
100 { vbase "V" }
101 { field public "int c;" }
102 }
103
104 # class AD
105
106 cp_test_ptype_class \
107 "ptype AD" "" "class" "AD" \
108 {
109 { method public "virtual int vg();" }
110 }
111
112 # class D
113
114 cp_test_ptype_class \
115 "ptype D" "" "class" "D" \
116 {
117 { base "public AD" }
118 { base "public virtual V" }
119 { vbase "V" }
120 { method public "static void s();" }
121 { method public "virtual int vg();" }
122 { method public "virtual int vd();" }
123 { method public "int fd();" }
124 { field public "int d;" }
125 }
126
127 # class E
128
129 cp_test_ptype_class \
130 "ptype E" "" "class" "E" \
131 {
132 { base "public B" }
133 { base "public virtual V" }
134 { base "public D" }
135 { base "public C" }
136 { vbase "V" }
137 { method public "virtual int f();" }
138 { method public "virtual int vg();" }
139 { method public "virtual int vv();" }
140 { field public "int e;" }
141 }
142
143 # An instance of D
144
145 cp_test_ptype_class "ptype dd" "" "class" "D" ibid
146
147 # An instance of D *
148
149 cp_test_ptype_class "ptype ppd" "" "class" "D" ibid "*"
150
151 # An instance of AD *
152 # TODO: this should be named pADd, not pAd.
153
154 cp_test_ptype_class "ptype pAd" "" "class" "AD" ibid "*"
155
156 # Instances of these classes.
157
158 cp_test_ptype_class "ptype a" "" "class" "A" ibid
159 cp_test_ptype_class "ptype b" "" "class" "B" ibid
160 cp_test_ptype_class "ptype c" "" "class" "C" ibid
161 cp_test_ptype_class "ptype d" "" "class" "D" ibid
162 cp_test_ptype_class "ptype e" "" "class" "E" ibid
163 cp_test_ptype_class "ptype v" "" "class" "V" ibid
164 cp_test_ptype_class "ptype vb" "" "class" "VB" ibid
165
166 # Instances of pointers to these classes.
167
168 cp_test_ptype_class "ptype pAa" "" "class" "A" ibid "*"
169 cp_test_ptype_class "ptype pAe" "" "class" "A" ibid "*"
170 cp_test_ptype_class "ptype pBe" "" "class" "B" ibid "*"
171 cp_test_ptype_class "ptype pDd" "" "class" "D" ibid "*"
172 cp_test_ptype_class "ptype pDe" "" "class" "D" ibid "*"
173 cp_test_ptype_class "ptype pVa" "" "class" "V" ibid "*"
174 cp_test_ptype_class "ptype pVv" "" "class" "V" ibid "*"
175 cp_test_ptype_class "ptype pVe" "" "class" "V" ibid "*"
176 cp_test_ptype_class "ptype pVd" "" "class" "V" ibid "*"
177 cp_test_ptype_class "ptype pADe" "" "class" "AD" ibid "*"
178 cp_test_ptype_class "ptype pEe" "" "class" "E" ibid "*"
179 cp_test_ptype_class "ptype pVB" "" "class" "VB" ibid "*"
180
181 }
182
183 # Call virtual functions.
184
185 proc test_virtual_calls {} {
186 global gdb_prompt
187 global nl
188
189 if [target_info exists gdb,cannot_call_functions] {
190 setup_xfail "*-*-*" 2416
191 fail "This target can not call functions"
192 return 0
193 }
194
195 gdb_test "print pAe->f()" "\\$\[0-9\]+ = 20"
196 gdb_test "print pAa->f()" "\\$\[0-9\]+ = 1"
197 gdb_test "print pDe->vg()" "\\$\[0-9\]+ = 202"
198 gdb_test "print pADe->vg()" "\\$\[0-9\]+ = 202"
199 gdb_test "print pDd->vg()" "\\$\[0-9\]+ = 101"
200 gdb_test "print pEe->vvb()" "\\$\[0-9\]+ = 411"
201 gdb_test "print pVB->vvb()" "\\$\[0-9\]+ = 407"
202 gdb_test "print pBe->vvb()" "\\$\[0-9\]+ = 411"
203 gdb_test "print pDe->vvb()" "\\$\[0-9\]+ = 411"
204 gdb_test "print pEe->vd()" "\\$\[0-9\]+ = 282"
205 gdb_test "print pEe->fvb()" "\\$\[0-9\]+ = 311"
206
207 # more recent results:
208 # wrong value "202"
209 # gcc 2.95.3 -gdwarf-2
210 # gcc 2.95.3 -gstabs+
211 # attempt to take addres of value not located in memory
212 # gcc 3.3.2 -gdwarf-2
213 # gcc 3.3.2 -gstabs+
214 #
215 # -- chastain 2003-12-31
216
217 gdb_test_multiple "print pEe->D::vg()" "print pEe->D::vg()" {
218 -re "\\$\[0-9]+ = 102$nl$gdb_prompt $" {
219 pass "print pEe->D::vg()"
220 }
221 -re "\\$\[0-9]+ = 202$nl$gdb_prompt $" {
222 # To get this result, we have called pEe->*(&D::vg) ().
223 # That's how GDB interprets this, but it's wrong; in fact
224 # the explicit D:: means to bypass virtual function lookup,
225 # and call D::vg as if it were non-virtual. We still have
226 # to e.g. adjust "this", though.
227 kfail "gdb/1064" "print pEe->D::vg()"
228 }
229 -re "Attempt to take address of value not located in memory.$nl$gdb_prompt $" {
230 kfail "gdb/1064" "print pEe->D::vg()"
231 }
232 }
233 }
234
235 proc do_tests {} {
236 global prms_id
237 global bug_id
238 global srcdir subdir binfile
239 global gdb_prompt
240
241 set prms_id 0
242 set bug_id 0
243
244 gdb_exit
245 gdb_start
246 gdb_reinitialize_dir $srcdir/$subdir
247 gdb_load $binfile
248
249 gdb_test "set language c++" "" ""
250 gdb_test "set width 0" "" ""
251
252 runto_main
253 test_ptype_of_classes
254
255 gdb_breakpoint test_calls
256 gdb_test "continue" ".*Breakpoint .* test_calls.*" ""
257 test_virtual_calls
258 }
259
260 do_tests
This page took 0.034319 seconds and 4 git commands to generate.