Commit | Line | Data |
---|---|---|
0d5de010 | 1 | # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, |
0fb0cc75 | 2 | # 2006, 2007, 2008, 2009 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 | |
e22f8b7c | 6 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
c906108c SS |
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. | |
e22f8b7c | 13 | # |
c906108c | 14 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 16 | |
c906108c | 17 | # This file was written by Fred Fish. (fnf@cygnus.com) |
51615d72 | 18 | # And rewritten by Michael Chastain <mec.gnu@mindspring.com>. |
c906108c | 19 | |
184ad485 | 20 | set nl "\[\r\n\]+" |
c906108c SS |
21 | |
22 | if $tracelevel then { | |
51615d72 | 23 | strace $tracelevel |
c906108c SS |
24 | } |
25 | ||
d4f3574e SS |
26 | if { [skip_cplus_tests] } { continue } |
27 | ||
78c90502 MC |
28 | load_lib "cp-support.exp" |
29 | ||
c906108c SS |
30 | set testfile "virtfunc" |
31 | set srcfile ${testfile}.cc | |
32 | set binfile ${objdir}/${subdir}/${testfile} | |
33 | ||
f2dd3617 | 34 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } { |
b60f0898 JB |
35 | untested virtfunc.exp |
36 | return -1 | |
c906108c SS |
37 | } |
38 | ||
184ad485 | 39 | proc test_ptype_of_classes {} { |
51615d72 | 40 | |
184ad485 | 41 | # class VA |
51615d72 | 42 | |
78c90502 MC |
43 | cp_test_ptype_class \ |
44 | "ptype VA" "" "class" "VA" \ | |
45 | { | |
46 | { field public "int va;" } | |
47 | } | |
c906108c | 48 | |
184ad485 | 49 | # class VB |
c2d11a7d | 50 | |
78c90502 MC |
51 | cp_test_ptype_class \ |
52 | "ptype VB" "" "class" "VB" \ | |
53 | { | |
54 | { field public "int vb;" } | |
55 | { method public "int fvb();" } | |
56 | { method public "virtual int vvb();" } | |
57 | } | |
c906108c | 58 | |
51615d72 | 59 | # class V |
c906108c | 60 | |
78c90502 MC |
61 | cp_test_ptype_class \ |
62 | "ptype V" "" "class" "V" \ | |
63 | { | |
64 | { base "public VA" } | |
65 | { base "public VB" } | |
66 | { field public "int w;" } | |
67 | { method public "int f();" } | |
68 | { method public "virtual int vv();" } | |
69 | } | |
c906108c | 70 | |
184ad485 | 71 | # class A |
c906108c | 72 | |
78c90502 MC |
73 | cp_test_ptype_class \ |
74 | "ptype A" "" "class" "A" \ | |
75 | { | |
76 | { base "public virtual V" } | |
77 | { vbase "V" } | |
78 | { field private "int a;" } | |
79 | { method public "virtual int f();" } | |
80 | } | |
c906108c | 81 | |
184ad485 | 82 | # class B |
c906108c | 83 | |
78c90502 MC |
84 | cp_test_ptype_class \ |
85 | "ptype B" "" "class" "B" \ | |
86 | { | |
87 | { base "public A" } | |
88 | { field private "int b;" } | |
89 | { method public "virtual int f();" } | |
90 | } | |
c906108c | 91 | |
184ad485 | 92 | # class C |
c906108c | 93 | |
78c90502 MC |
94 | cp_test_ptype_class \ |
95 | "ptype C" "" "class" "C" \ | |
96 | { | |
97 | { base "public virtual V" } | |
98 | { vbase "V" } | |
99 | { field public "int c;" } | |
100 | } | |
c906108c | 101 | |
184ad485 | 102 | # class AD |
c906108c | 103 | |
78c90502 MC |
104 | cp_test_ptype_class \ |
105 | "ptype AD" "" "class" "AD" \ | |
106 | { | |
107 | { method public "virtual int vg();" } | |
108 | } | |
c906108c | 109 | |
184ad485 | 110 | # class D |
c906108c | 111 | |
78c90502 MC |
112 | cp_test_ptype_class \ |
113 | "ptype D" "" "class" "D" \ | |
114 | { | |
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;" } | |
123 | } | |
c906108c | 124 | |
184ad485 | 125 | # class E |
51615d72 | 126 | |
78c90502 MC |
127 | cp_test_ptype_class \ |
128 | "ptype E" "" "class" "E" \ | |
129 | { | |
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;" } | |
139 | } | |
c906108c | 140 | |
184ad485 | 141 | # An instance of D |
51615d72 | 142 | |
78c90502 | 143 | cp_test_ptype_class "ptype dd" "" "class" "D" ibid |
c906108c | 144 | |
184ad485 | 145 | # An instance of D * |
51615d72 | 146 | |
78c90502 | 147 | cp_test_ptype_class "ptype ppd" "" "class" "D" ibid "*" |
c906108c | 148 | |
184ad485 MC |
149 | # An instance of AD * |
150 | # TODO: this should be named pADd, not pAd. | |
51615d72 | 151 | |
78c90502 MC |
152 | cp_test_ptype_class "ptype pAd" "" "class" "AD" ibid "*" |
153 | ||
154 | # Instances of these classes. | |
155 | ||
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 | |
163 | ||
164 | # Instances of pointers to these classes. | |
165 | ||
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 "*" | |
184ad485 | 178 | |
51615d72 | 179 | } |
c906108c | 180 | |
51615d72 MC |
181 | # Call virtual functions. |
182 | ||
183 | proc test_virtual_calls {} { | |
184 | global gdb_prompt | |
185 | global nl | |
186 | ||
187 | if [target_info exists gdb,cannot_call_functions] { | |
188 | setup_xfail "*-*-*" 2416 | |
189 | fail "This target can not call functions" | |
190 | return 0 | |
c906108c SS |
191 | } |
192 | ||
51615d72 MC |
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" | |
204 | ||
51615d72 MC |
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+ | |
212 | # | |
213 | # -- chastain 2003-12-31 | |
214 | ||
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()" | |
218 | } | |
0d5de010 DJ |
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()" | |
226 | } | |
51615d72 MC |
227 | -re "Attempt to take address of value not located in memory.$nl$gdb_prompt $" { |
228 | kfail "gdb/1064" "print pEe->D::vg()" | |
229 | } | |
c906108c SS |
230 | } |
231 | } | |
232 | ||
233 | proc do_tests {} { | |
234 | global prms_id | |
235 | global bug_id | |
51615d72 MC |
236 | global srcdir subdir binfile |
237 | global gdb_prompt | |
c906108c SS |
238 | |
239 | set prms_id 0 | |
240 | set bug_id 0 | |
241 | ||
51615d72 MC |
242 | gdb_exit |
243 | gdb_start | |
244 | gdb_reinitialize_dir $srcdir/$subdir | |
245 | gdb_load $binfile | |
c906108c | 246 | |
51615d72 MC |
247 | gdb_test "set language c++" "" "" |
248 | gdb_test "set width 0" "" "" | |
c906108c | 249 | |
51615d72 | 250 | runto_main |
c906108c SS |
251 | test_ptype_of_classes |
252 | ||
51615d72 MC |
253 | gdb_breakpoint test_calls |
254 | gdb_test "continue" ".*Breakpoint .* test_calls.*" "" | |
255 | test_virtual_calls | |
b18be20d DJ |
256 | |
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" | |
c906108c SS |
260 | } |
261 | ||
262 | do_tests |