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