Fix test names starting with uppercase output by basic functions
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / virtfunc.exp
CommitLineData
618f726f 1# Copyright 1992-2016 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] {
bc6c7af4 180 unsupported "this target can not call functions"
51615d72 181 return 0
c906108c
SS
182 }
183
51615d72
MC
184 gdb_test "print pAe->f()" "\\$\[0-9\]+ = 20"
185 gdb_test "print pAa->f()" "\\$\[0-9\]+ = 1"
186 gdb_test "print pDe->vg()" "\\$\[0-9\]+ = 202"
187 gdb_test "print pADe->vg()" "\\$\[0-9\]+ = 202"
188 gdb_test "print pDd->vg()" "\\$\[0-9\]+ = 101"
189 gdb_test "print pEe->vvb()" "\\$\[0-9\]+ = 411"
190 gdb_test "print pVB->vvb()" "\\$\[0-9\]+ = 407"
191 gdb_test "print pBe->vvb()" "\\$\[0-9\]+ = 411"
192 gdb_test "print pDe->vvb()" "\\$\[0-9\]+ = 411"
193 gdb_test "print pEe->vd()" "\\$\[0-9\]+ = 282"
194 gdb_test "print pEe->fvb()" "\\$\[0-9\]+ = 311"
195
51615d72
MC
196 # more recent results:
197 # wrong value "202"
198 # gcc 2.95.3 -gdwarf-2
199 # gcc 2.95.3 -gstabs+
200 # attempt to take addres of value not located in memory
201 # gcc 3.3.2 -gdwarf-2
202 # gcc 3.3.2 -gstabs+
203 #
204 # -- chastain 2003-12-31
205
206 gdb_test_multiple "print pEe->D::vg()" "print pEe->D::vg()" {
207 -re "\\$\[0-9]+ = 102$nl$gdb_prompt $" {
208 pass "print pEe->D::vg()"
209 }
0d5de010
DJ
210 -re "\\$\[0-9]+ = 202$nl$gdb_prompt $" {
211 # To get this result, we have called pEe->*(&D::vg) ().
212 # That's how GDB interprets this, but it's wrong; in fact
213 # the explicit D:: means to bypass virtual function lookup,
214 # and call D::vg as if it were non-virtual. We still have
215 # to e.g. adjust "this", though.
216 kfail "gdb/1064" "print pEe->D::vg()"
217 }
51615d72
MC
218 -re "Attempt to take address of value not located in memory.$nl$gdb_prompt $" {
219 kfail "gdb/1064" "print pEe->D::vg()"
220 }
c906108c
SS
221 }
222}
223
c4aeac85
TT
224# A helper proc that creates a regular expression matching a
225# particular vtable. NAME is the type name. Each element of ARGS is
226# the name of a function in the vtable.
227
228proc make_one_vtable_result {name args} {
229 global hex
230
231 set nls "\[\r\n\]+"
232
233 set result "vtable for '${name}' @ $hex .subobject @ $hex.:$nls"
234 set count 0
235 foreach func $args {
f993f39e 236 append result ".${count}.:( @$hex:)? $hex <(\.)?$func..>${nls}"
c4aeac85
TT
237 incr count
238 }
239
240 return $result
241}
242
243# Test "info vtbl".
244
245proc test_info_vtbl {} {
246 global hex
247
248 set nls "\[\r\n\]+"
249
250 set vt_A [make_one_vtable_result A A::f]
251 set vt_B [make_one_vtable_result B B::f]
252 set vt_V [make_one_vtable_result V VB::vvb V::vv]
253 set vt_V2 [make_one_vtable_result V VB::vvb "virtual thunk to E::vv"]
254 set vt_D [make_one_vtable_result D D::vg D::vd]
255 set vt_D2 [make_one_vtable_result D "non-virtual thunk to E::vg" D::vd]
256 set vt_E [make_one_vtable_result E E::f E::vg E::vv]
257
258 gdb_test "info vtbl a" "${vt_A}${vt_V}"
259 gdb_test "info vtbl b" "${vt_B}${vt_V}"
260 gdb_test "info vtbl c" "${vt_V}"
261 gdb_test "info vtbl d" "${vt_D}${vt_V}"
262 gdb_test "info vtbl e" "${vt_E}${vt_D2}${vt_V2}"
263 gdb_test "info vtbl pEe" "${vt_E}${vt_D2}${vt_V2}"
264
265 gdb_test "info vtbl" "Argument required.*"
266 gdb_test "info vtbl va" \
267 "This object does not have a virtual function table.*"
268 gdb_test "info vtbl all_count" \
269 "This object does not have a virtual function table.*"
270}
271
c906108c 272proc do_tests {} {
35ec993f
MS
273 gdb_test_no_output "set language c++" ""
274 gdb_test_no_output "set width 0" ""
c906108c 275
a7881759
DJ
276 if ![runto_main] then {
277 perror "couldn't run to breakpoint"
278 return
279 }
c906108c 280 test_ptype_of_classes
c4aeac85 281 test_info_vtbl
c906108c 282
51615d72
MC
283 gdb_breakpoint test_calls
284 gdb_test "continue" ".*Breakpoint .* test_calls.*" ""
285 test_virtual_calls
b18be20d
DJ
286
287 gdb_test "next" ".*pAa->f.*" "next to pAa->f call"
288 gdb_test "next" ".*pDe->vg.*" "next to pDe->vg call"
289 gdb_test "step" ".*E::vg.*" "step through thunk into E::vg"
c906108c
SS
290}
291
292do_tests
This page took 1.709462 seconds and 4 git commands to generate.