1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004
2 # 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 2 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, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # This file was written by Fred Fish. (fnf@cygnus.com)
19 # And rewritten by Michael Chastain <mec.gnu@mindspring.com>.
27 if { [skip_cplus_tests] } { continue }
29 load_lib "cp-support.exp"
31 set testfile "virtfunc"
32 set srcfile ${testfile}.cc
33 set binfile ${objdir}/${subdir}/${testfile}
35 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } {
40 proc test_ptype_of_classes {} {
45 "ptype VA" "" "class" "VA" \
47 { field public "int va;" }
53 "ptype VB" "" "class" "VB" \
55 { field public "int vb;" }
56 { method public "int fvb();" }
57 { method public "virtual int vvb();" }
63 "ptype V" "" "class" "V" \
67 { field public "int w;" }
68 { method public "int f();" }
69 { method public "virtual int vv();" }
75 "ptype A" "" "class" "A" \
77 { base "public virtual V" }
79 { field private "int a;" }
80 { method public "virtual int f();" }
86 "ptype B" "" "class" "B" \
89 { field private "int b;" }
90 { method public "virtual int f();" }
96 "ptype C" "" "class" "C" \
98 { base "public virtual V" }
100 { field public "int c;" }
105 cp_test_ptype_class \
106 "ptype AD" "" "class" "AD" \
108 { method public "virtual int vg();" }
113 cp_test_ptype_class \
114 "ptype D" "" "class" "D" \
117 { base "public virtual 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;" }
128 cp_test_ptype_class \
129 "ptype E" "" "class" "E" \
132 { base "public virtual V" }
136 { method public "virtual int f();" }
137 { method public "virtual int vg();" }
138 { method public "virtual int vv();" }
139 { field public "int e;" }
144 cp_test_ptype_class "ptype dd" "" "class" "D" ibid
148 cp_test_ptype_class "ptype ppd" "" "class" "D" ibid "*"
150 # An instance of AD *
151 # TODO: this should be named pADd, not pAd.
153 cp_test_ptype_class "ptype pAd" "" "class" "AD" ibid "*"
155 # Instances of these classes.
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
165 # Instances of pointers to these classes.
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 "*"
182 # Call virtual functions.
184 proc test_virtual_calls {} {
188 if [target_info exists gdb,cannot_call_functions] {
189 setup_xfail "*-*-*" 2416
190 fail "This target can not call functions"
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"
206 # more recent results:
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
214 # -- chastain 2003-12-31
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()"
220 -re "Attempt to take address of value not located in memory.$nl$gdb_prompt $" {
221 kfail "gdb/1064" "print pEe->D::vg()"
229 global srcdir subdir binfile
237 gdb_reinitialize_dir $srcdir/$subdir
240 gdb_test "set language c++" "" ""
241 gdb_test "set width 0" "" ""
244 test_ptype_of_classes
246 gdb_breakpoint test_calls
247 gdb_test "continue" ".*Breakpoint .* test_calls.*" ""