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
>.
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}] != "" } {
39 proc test_ptype_of_classes
{} {
44 "ptype VA" "" "class" "VA" \
46 { field public
"int va;" }
52 "ptype VB" "" "class" "VB" \
54 { field public
"int vb;" }
55 { method public
"int fvb();" }
56 { method public
"virtual int vvb();" }
62 "ptype V" "" "class" "V" \
66 { field public
"int w;" }
67 { method public
"int f();" }
68 { method public
"virtual int vv();" }
74 "ptype A" "" "class" "A" \
76 { base
"public virtual V" }
78 { field private
"int a;" }
79 { method public
"virtual int f();" }
85 "ptype B" "" "class" "B" \
88 { field private
"int b;" }
89 { method public
"virtual int f();" }
95 "ptype C" "" "class" "C" \
97 { base
"public virtual V" }
99 { field public
"int c;" }
104 cp_test_ptype_class \
105 "ptype AD" "" "class" "AD" \
107 { method public
"virtual int vg();" }
112 cp_test_ptype_class \
113 "ptype D" "" "class" "D" \
116 { base
"public virtual 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;" }
127 cp_test_ptype_class \
128 "ptype E" "" "class" "E" \
131 { base
"public virtual V" }
135 { method public
"virtual int f();" }
136 { method public
"virtual int vg();" }
137 { method public
"virtual int vv();" }
138 { field public
"int e;" }
143 cp_test_ptype_class
"ptype dd" "" "class" "D" ibid
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
{} {
187 if [target_info
exists gdb
,cannot_call_functions
] {
188 setup_xfail
"*-*-*" 2416
189 fail
"This target can not call functions"
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
:
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
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()"
236 global srcdir subdir binfile
244 gdb_reinitialize_dir $srcdir
/$subdir
247 gdb_test
"set language c++" "" ""
248 gdb_test
"set width 0" "" ""
251 test_ptype_of_classes
253 gdb_breakpoint test_calls
254 gdb_test
"continue" ".*Breakpoint .* test_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"