Correct gas microblaze ChangeLog entry
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / virtfunc.exp
CommitLineData
0b302171
JB
1# Copyright 1992, 1994-1999, 2001-2004, 2006-2012 Free Software
2# Foundation, Inc.
c906108c
SS
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c 17# This file was written by Fred Fish. (fnf@cygnus.com)
51615d72 18# And rewritten by Michael Chastain <mec.gnu@mindspring.com>.
c906108c 19
184ad485 20set nl "\[\r\n\]+"
c906108c 21
d4f3574e
SS
22if { [skip_cplus_tests] } { continue }
23
78c90502
MC
24load_lib "cp-support.exp"
25
f5f3a911 26standard_testfile .cc
c906108c 27
f5f3a911
TT
28if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
29 return -1
c906108c
SS
30}
31
184ad485 32proc test_ptype_of_classes {} {
51615d72 33
184ad485 34 # class VA
51615d72 35
78c90502
MC
36 cp_test_ptype_class \
37 "ptype VA" "" "class" "VA" \
38 {
39 { field public "int va;" }
40 }
c906108c 41
184ad485 42 # class VB
c2d11a7d 43
78c90502
MC
44 cp_test_ptype_class \
45 "ptype VB" "" "class" "VB" \
46 {
47 { field public "int vb;" }
48 { method public "int fvb();" }
49 { method public "virtual int vvb();" }
50 }
c906108c 51
51615d72 52 # class V
c906108c 53
78c90502
MC
54 cp_test_ptype_class \
55 "ptype V" "" "class" "V" \
56 {
57 { base "public VA" }
58 { base "public VB" }
59 { field public "int w;" }
60 { method public "int f();" }
61 { method public "virtual int vv();" }
62 }
c906108c 63
184ad485 64 # class A
c906108c 65
78c90502
MC
66 cp_test_ptype_class \
67 "ptype A" "" "class" "A" \
68 {
69 { base "public virtual V" }
70 { vbase "V" }
71 { field private "int a;" }
72 { method public "virtual int f();" }
73 }
c906108c 74
184ad485 75 # class B
c906108c 76
78c90502
MC
77 cp_test_ptype_class \
78 "ptype B" "" "class" "B" \
79 {
80 { base "public A" }
81 { field private "int b;" }
82 { method public "virtual int f();" }
83 }
c906108c 84
184ad485 85 # class C
c906108c 86
78c90502
MC
87 cp_test_ptype_class \
88 "ptype C" "" "class" "C" \
89 {
90 { base "public virtual V" }
91 { vbase "V" }
92 { field public "int c;" }
93 }
c906108c 94
184ad485 95 # class AD
c906108c 96
78c90502
MC
97 cp_test_ptype_class \
98 "ptype AD" "" "class" "AD" \
99 {
100 { method public "virtual int vg();" }
101 }
c906108c 102
184ad485 103 # class D
c906108c 104
78c90502
MC
105 cp_test_ptype_class \
106 "ptype D" "" "class" "D" \
107 {
108 { base "public AD" }
109 { base "public virtual V" }
110 { vbase "V" }
111 { method public "static void s();" }
112 { method public "virtual int vg();" }
113 { method public "virtual int vd();" }
114 { method public "int fd();" }
115 { field public "int d;" }
116 }
c906108c 117
184ad485 118 # class E
51615d72 119
78c90502
MC
120 cp_test_ptype_class \
121 "ptype E" "" "class" "E" \
122 {
123 { base "public B" }
124 { base "public virtual V" }
125 { base "public D" }
126 { base "public C" }
127 { vbase "V" }
128 { method public "virtual int f();" }
129 { method public "virtual int vg();" }
130 { method public "virtual int vv();" }
131 { field public "int e;" }
132 }
c906108c 133
184ad485 134 # An instance of D
51615d72 135
78c90502 136 cp_test_ptype_class "ptype dd" "" "class" "D" ibid
c906108c 137
184ad485 138 # An instance of D *
51615d72 139
78c90502 140 cp_test_ptype_class "ptype ppd" "" "class" "D" ibid "*"
c906108c 141
184ad485
MC
142 # An instance of AD *
143 # TODO: this should be named pADd, not pAd.
51615d72 144
78c90502
MC
145 cp_test_ptype_class "ptype pAd" "" "class" "AD" ibid "*"
146
147 # Instances of these classes.
148
149 cp_test_ptype_class "ptype a" "" "class" "A" ibid
150 cp_test_ptype_class "ptype b" "" "class" "B" ibid
151 cp_test_ptype_class "ptype c" "" "class" "C" ibid
152 cp_test_ptype_class "ptype d" "" "class" "D" ibid
153 cp_test_ptype_class "ptype e" "" "class" "E" ibid
154 cp_test_ptype_class "ptype v" "" "class" "V" ibid
155 cp_test_ptype_class "ptype vb" "" "class" "VB" ibid
156
157 # Instances of pointers to these classes.
158
159 cp_test_ptype_class "ptype pAa" "" "class" "A" ibid "*"
160 cp_test_ptype_class "ptype pAe" "" "class" "A" ibid "*"
161 cp_test_ptype_class "ptype pBe" "" "class" "B" ibid "*"
162 cp_test_ptype_class "ptype pDd" "" "class" "D" ibid "*"
163 cp_test_ptype_class "ptype pDe" "" "class" "D" ibid "*"
164 cp_test_ptype_class "ptype pVa" "" "class" "V" ibid "*"
165 cp_test_ptype_class "ptype pVv" "" "class" "V" ibid "*"
166 cp_test_ptype_class "ptype pVe" "" "class" "V" ibid "*"
167 cp_test_ptype_class "ptype pVd" "" "class" "V" ibid "*"
168 cp_test_ptype_class "ptype pADe" "" "class" "AD" ibid "*"
169 cp_test_ptype_class "ptype pEe" "" "class" "E" ibid "*"
170 cp_test_ptype_class "ptype pVB" "" "class" "VB" ibid "*"
184ad485 171
51615d72 172}
c906108c 173
51615d72
MC
174# Call virtual functions.
175
176proc test_virtual_calls {} {
177 global gdb_prompt
178 global nl
179
180 if [target_info exists gdb,cannot_call_functions] {
181 setup_xfail "*-*-*" 2416
182 fail "This target can not call functions"
183 return 0
c906108c
SS
184 }
185
51615d72
MC
186 gdb_test "print pAe->f()" "\\$\[0-9\]+ = 20"
187 gdb_test "print pAa->f()" "\\$\[0-9\]+ = 1"
188 gdb_test "print pDe->vg()" "\\$\[0-9\]+ = 202"
189 gdb_test "print pADe->vg()" "\\$\[0-9\]+ = 202"
190 gdb_test "print pDd->vg()" "\\$\[0-9\]+ = 101"
191 gdb_test "print pEe->vvb()" "\\$\[0-9\]+ = 411"
192 gdb_test "print pVB->vvb()" "\\$\[0-9\]+ = 407"
193 gdb_test "print pBe->vvb()" "\\$\[0-9\]+ = 411"
194 gdb_test "print pDe->vvb()" "\\$\[0-9\]+ = 411"
195 gdb_test "print pEe->vd()" "\\$\[0-9\]+ = 282"
196 gdb_test "print pEe->fvb()" "\\$\[0-9\]+ = 311"
197
51615d72
MC
198 # more recent results:
199 # wrong value "202"
200 # gcc 2.95.3 -gdwarf-2
201 # gcc 2.95.3 -gstabs+
202 # attempt to take addres of value not located in memory
203 # gcc 3.3.2 -gdwarf-2
204 # gcc 3.3.2 -gstabs+
205 #
206 # -- chastain 2003-12-31
207
208 gdb_test_multiple "print pEe->D::vg()" "print pEe->D::vg()" {
209 -re "\\$\[0-9]+ = 102$nl$gdb_prompt $" {
210 pass "print pEe->D::vg()"
211 }
0d5de010
DJ
212 -re "\\$\[0-9]+ = 202$nl$gdb_prompt $" {
213 # To get this result, we have called pEe->*(&D::vg) ().
214 # That's how GDB interprets this, but it's wrong; in fact
215 # the explicit D:: means to bypass virtual function lookup,
216 # and call D::vg as if it were non-virtual. We still have
217 # to e.g. adjust "this", though.
218 kfail "gdb/1064" "print pEe->D::vg()"
219 }
51615d72
MC
220 -re "Attempt to take address of value not located in memory.$nl$gdb_prompt $" {
221 kfail "gdb/1064" "print pEe->D::vg()"
222 }
c906108c
SS
223 }
224}
225
c4aeac85
TT
226# A helper proc that creates a regular expression matching a
227# particular vtable. NAME is the type name. Each element of ARGS is
228# the name of a function in the vtable.
229
230proc make_one_vtable_result {name args} {
231 global hex
232
233 set nls "\[\r\n\]+"
234
235 set result "vtable for '${name}' @ $hex .subobject @ $hex.:$nls"
236 set count 0
237 foreach func $args {
238 append result ".${count}.: $hex <$func..>${nls}"
239 incr count
240 }
241
242 return $result
243}
244
245# Test "info vtbl".
246
247proc test_info_vtbl {} {
248 global hex
249
250 set nls "\[\r\n\]+"
251
252 set vt_A [make_one_vtable_result A A::f]
253 set vt_B [make_one_vtable_result B B::f]
254 set vt_V [make_one_vtable_result V VB::vvb V::vv]
255 set vt_V2 [make_one_vtable_result V VB::vvb "virtual thunk to E::vv"]
256 set vt_D [make_one_vtable_result D D::vg D::vd]
257 set vt_D2 [make_one_vtable_result D "non-virtual thunk to E::vg" D::vd]
258 set vt_E [make_one_vtable_result E E::f E::vg E::vv]
259
260 gdb_test "info vtbl a" "${vt_A}${vt_V}"
261 gdb_test "info vtbl b" "${vt_B}${vt_V}"
262 gdb_test "info vtbl c" "${vt_V}"
263 gdb_test "info vtbl d" "${vt_D}${vt_V}"
264 gdb_test "info vtbl e" "${vt_E}${vt_D2}${vt_V2}"
265 gdb_test "info vtbl pEe" "${vt_E}${vt_D2}${vt_V2}"
266
267 gdb_test "info vtbl" "Argument required.*"
268 gdb_test "info vtbl va" \
269 "This object does not have a virtual function table.*"
270 gdb_test "info vtbl all_count" \
271 "This object does not have a virtual function table.*"
272}
273
c906108c 274proc do_tests {} {
35ec993f
MS
275 gdb_test_no_output "set language c++" ""
276 gdb_test_no_output "set width 0" ""
c906108c 277
a7881759
DJ
278 if ![runto_main] then {
279 perror "couldn't run to breakpoint"
280 return
281 }
c906108c 282 test_ptype_of_classes
c4aeac85 283 test_info_vtbl
c906108c 284
51615d72
MC
285 gdb_breakpoint test_calls
286 gdb_test "continue" ".*Breakpoint .* test_calls.*" ""
287 test_virtual_calls
b18be20d
DJ
288
289 gdb_test "next" ".*pAa->f.*" "next to pAa->f call"
290 gdb_test "next" ".*pDe->vg.*" "next to pDe->vg call"
291 gdb_test "step" ".*E::vg.*" "step through thunk into E::vg"
c906108c
SS
292}
293
294do_tests
This page took 1.392446 seconds and 4 git commands to generate.