* gdb.arch/altivec-abi.exp: Replace gdb_suppress_entire_file with
[external/binutils.git] / gdb / testsuite / gdb.cp / virtfunc.exp
1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004
2 # Free Software Foundation, Inc.
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
18 # This file was written by Fred Fish. (fnf@cygnus.com)
19 # And rewritten by Michael Chastain <mec.gnu@mindspring.com>.
20
21 set nl          "\[\r\n\]+"
22
23 if $tracelevel then {
24     strace $tracelevel
25 }
26
27 if { [skip_cplus_tests] } { continue }
28
29 load_lib "cp-support.exp"
30
31 set testfile "virtfunc"
32 set srcfile ${testfile}.cc
33 set binfile ${objdir}/${subdir}/${testfile}
34
35 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } {
36      untested virtfunc.exp
37      return -1
38 }
39
40 proc test_ptype_of_classes {} {
41
42     # class VA
43
44     cp_test_ptype_class \
45         "ptype VA" "" "class" "VA" \
46         {
47             { field public "int va;" }
48         }
49
50     # class VB
51
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         }
59
60     # class V
61
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         }
71
72     # class A
73
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         }
82
83     # class B
84
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         }
92
93     # class C
94
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         }
102
103     # class AD
104
105     cp_test_ptype_class \
106         "ptype AD" "" "class" "AD" \
107         {
108             { method public "virtual int vg();" }
109         }
110
111     # class D
112
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         }
125
126     # class E
127
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         }
141
142     # An instance of D
143
144     cp_test_ptype_class "ptype dd" "" "class" "D" ibid
145
146     # An instance of D *
147
148     cp_test_ptype_class "ptype ppd" "" "class" "D" ibid "*"
149
150     # An instance of AD *
151     # TODO: this should be named pADd, not pAd.
152
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 "*"
179
180 }
181
182 # Call virtual functions.
183
184 proc 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
192     }
193
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
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         }
220         -re "Attempt to take address of value not located in memory.$nl$gdb_prompt $" {
221             kfail "gdb/1064" "print pEe->D::vg()"
222         }
223     }
224 }
225
226 proc do_tests {} {
227     global prms_id
228     global bug_id
229     global srcdir subdir binfile
230     global gdb_prompt
231
232     set prms_id 0
233     set bug_id 0
234
235     gdb_exit
236     gdb_start
237     gdb_reinitialize_dir $srcdir/$subdir
238     gdb_load $binfile
239
240     gdb_test "set language c++" "" ""
241     gdb_test "set width 0" "" ""
242
243     runto_main
244     test_ptype_of_classes
245
246     gdb_breakpoint test_calls
247     gdb_test "continue" ".*Breakpoint .* test_calls.*" ""
248     test_virtual_calls
249 }
250
251 do_tests