Initial import
[gdb.git] / gdb / testsuite / gdb.cp / virtfunc.exp
blob98f8a35eba591c27aac2efaec33a8a6b9e120bdc
1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004,
2 # 2006, 2007 Free Software Foundation, Inc.
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 3 of the License, or
7 # (at your option) any later version.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file was written by Fred Fish. (fnf@cygnus.com)
18 # And rewritten by Michael Chastain <mec.gnu@mindspring.com>.
20 set nl "\[\r\n\]+"
22 if $tracelevel then {
23 strace $tracelevel
26 if { [skip_cplus_tests] } { continue }
28 load_lib "cp-support.exp"
30 set testfile "virtfunc"
31 set srcfile ${testfile}.cc
32 set binfile ${objdir}/${subdir}/${testfile}
34 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } {
35 untested virtfunc.exp
36 return -1
39 proc test_ptype_of_classes {} {
41 # class VA
43 cp_test_ptype_class \
44 "ptype VA" "" "class" "VA" \
46 { field public "int va;" }
49 # class VB
51 cp_test_ptype_class \
52 "ptype VB" "" "class" "VB" \
54 { field public "int vb;" }
55 { method public "int fvb();" }
56 { method public "virtual int vvb();" }
59 # class V
61 cp_test_ptype_class \
62 "ptype V" "" "class" "V" \
64 { base "public VA" }
65 { base "public VB" }
66 { field public "int w;" }
67 { method public "int f();" }
68 { method public "virtual int vv();" }
71 # class A
73 cp_test_ptype_class \
74 "ptype A" "" "class" "A" \
76 { base "public virtual V" }
77 { vbase "V" }
78 { field private "int a;" }
79 { method public "virtual int f();" }
82 # class B
84 cp_test_ptype_class \
85 "ptype B" "" "class" "B" \
87 { base "public A" }
88 { field private "int b;" }
89 { method public "virtual int f();" }
92 # class C
94 cp_test_ptype_class \
95 "ptype C" "" "class" "C" \
97 { base "public virtual V" }
98 { vbase "V" }
99 { field public "int c;" }
102 # class AD
104 cp_test_ptype_class \
105 "ptype AD" "" "class" "AD" \
107 { method public "virtual int vg();" }
110 # class D
112 cp_test_ptype_class \
113 "ptype D" "" "class" "D" \
115 { base "public AD" }
116 { base "public virtual V" }
117 { vbase "V" }
118 { method public "static void s();" }
119 { method public "virtual int vg();" }
120 { method public "virtual int vd();" }
121 { method public "int fd();" }
122 { field public "int d;" }
125 # class E
127 cp_test_ptype_class \
128 "ptype E" "" "class" "E" \
130 { base "public B" }
131 { base "public virtual V" }
132 { base "public D" }
133 { base "public C" }
134 { vbase "V" }
135 { method public "virtual int f();" }
136 { method public "virtual int vg();" }
137 { method public "virtual int vv();" }
138 { field public "int e;" }
141 # An instance of D
143 cp_test_ptype_class "ptype dd" "" "class" "D" ibid
145 # An instance of D *
147 cp_test_ptype_class "ptype ppd" "" "class" "D" ibid "*"
149 # An instance of AD *
150 # TODO: this should be named pADd, not pAd.
152 cp_test_ptype_class "ptype pAd" "" "class" "AD" ibid "*"
154 # Instances of these classes.
156 cp_test_ptype_class "ptype a" "" "class" "A" ibid
157 cp_test_ptype_class "ptype b" "" "class" "B" ibid
158 cp_test_ptype_class "ptype c" "" "class" "C" ibid
159 cp_test_ptype_class "ptype d" "" "class" "D" ibid
160 cp_test_ptype_class "ptype e" "" "class" "E" ibid
161 cp_test_ptype_class "ptype v" "" "class" "V" ibid
162 cp_test_ptype_class "ptype vb" "" "class" "VB" ibid
164 # Instances of pointers to these classes.
166 cp_test_ptype_class "ptype pAa" "" "class" "A" ibid "*"
167 cp_test_ptype_class "ptype pAe" "" "class" "A" ibid "*"
168 cp_test_ptype_class "ptype pBe" "" "class" "B" ibid "*"
169 cp_test_ptype_class "ptype pDd" "" "class" "D" ibid "*"
170 cp_test_ptype_class "ptype pDe" "" "class" "D" ibid "*"
171 cp_test_ptype_class "ptype pVa" "" "class" "V" ibid "*"
172 cp_test_ptype_class "ptype pVv" "" "class" "V" ibid "*"
173 cp_test_ptype_class "ptype pVe" "" "class" "V" ibid "*"
174 cp_test_ptype_class "ptype pVd" "" "class" "V" ibid "*"
175 cp_test_ptype_class "ptype pADe" "" "class" "AD" ibid "*"
176 cp_test_ptype_class "ptype pEe" "" "class" "E" ibid "*"
177 cp_test_ptype_class "ptype pVB" "" "class" "VB" ibid "*"
181 # Call virtual functions.
183 proc test_virtual_calls {} {
184 global gdb_prompt
185 global nl
187 if [target_info exists gdb,cannot_call_functions] {
188 setup_xfail "*-*-*" 2416
189 fail "This target can not call functions"
190 return 0
193 gdb_test "print pAe->f()" "\\$\[0-9\]+ = 20"
194 gdb_test "print pAa->f()" "\\$\[0-9\]+ = 1"
195 gdb_test "print pDe->vg()" "\\$\[0-9\]+ = 202"
196 gdb_test "print pADe->vg()" "\\$\[0-9\]+ = 202"
197 gdb_test "print pDd->vg()" "\\$\[0-9\]+ = 101"
198 gdb_test "print pEe->vvb()" "\\$\[0-9\]+ = 411"
199 gdb_test "print pVB->vvb()" "\\$\[0-9\]+ = 407"
200 gdb_test "print pBe->vvb()" "\\$\[0-9\]+ = 411"
201 gdb_test "print pDe->vvb()" "\\$\[0-9\]+ = 411"
202 gdb_test "print pEe->vd()" "\\$\[0-9\]+ = 282"
203 gdb_test "print pEe->fvb()" "\\$\[0-9\]+ = 311"
205 # more recent results:
206 # wrong value "202"
207 # gcc 2.95.3 -gdwarf-2
208 # gcc 2.95.3 -gstabs+
209 # attempt to take addres of value not located in memory
210 # gcc 3.3.2 -gdwarf-2
211 # gcc 3.3.2 -gstabs+
213 # -- chastain 2003-12-31
215 gdb_test_multiple "print pEe->D::vg()" "print pEe->D::vg()" {
216 -re "\\$\[0-9]+ = 102$nl$gdb_prompt $" {
217 pass "print pEe->D::vg()"
219 -re "\\$\[0-9]+ = 202$nl$gdb_prompt $" {
220 # To get this result, we have called pEe->*(&D::vg) ().
221 # That's how GDB interprets this, but it's wrong; in fact
222 # the explicit D:: means to bypass virtual function lookup,
223 # and call D::vg as if it were non-virtual. We still have
224 # to e.g. adjust "this", though.
225 kfail "gdb/1064" "print pEe->D::vg()"
227 -re "Attempt to take address of value not located in memory.$nl$gdb_prompt $" {
228 kfail "gdb/1064" "print pEe->D::vg()"
233 proc do_tests {} {
234 global prms_id
235 global bug_id
236 global srcdir subdir binfile
237 global gdb_prompt
239 set prms_id 0
240 set bug_id 0
242 gdb_exit
243 gdb_start
244 gdb_reinitialize_dir $srcdir/$subdir
245 gdb_load $binfile
247 gdb_test "set language c++" "" ""
248 gdb_test "set width 0" "" ""
250 runto_main
251 test_ptype_of_classes
253 gdb_breakpoint test_calls
254 gdb_test "continue" ".*Breakpoint .* test_calls.*" ""
255 test_virtual_calls
257 gdb_test "next" ".*pAa->f.*" "next to pAa->f call"
258 gdb_test "next" ".*pDe->vg.*" "next to pDe->vg call"
259 gdb_test "step" ".*E::vg.*" "step through thunk into E::vg"
262 do_tests