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