* configure.ac (enable_libgomp): Remove *-*-irix6*.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / virtfunc.exp
CommitLineData
0b302171
JB
1# Copyright 1992, 1994-1999, 2001-2004, 2006-2012 Free Software
2# 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 20set nl "\[\r\n\]+"
c906108c 21
d4f3574e
SS
22if { [skip_cplus_tests] } { continue }
23
78c90502
MC
24load_lib "cp-support.exp"
25
c906108c
SS
26set testfile "virtfunc"
27set srcfile ${testfile}.cc
28set binfile ${objdir}/${subdir}/${testfile}
29
f2dd3617 30if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } {
b60f0898
JB
31 untested virtfunc.exp
32 return -1
c906108c
SS
33}
34
184ad485 35proc test_ptype_of_classes {} {
51615d72 36
184ad485 37 # class VA
51615d72 38
78c90502
MC
39 cp_test_ptype_class \
40 "ptype VA" "" "class" "VA" \
41 {
42 { field public "int va;" }
43 }
c906108c 44
184ad485 45 # class VB
c2d11a7d 46
78c90502
MC
47 cp_test_ptype_class \
48 "ptype VB" "" "class" "VB" \
49 {
50 { field public "int vb;" }
51 { method public "int fvb();" }
52 { method public "virtual int vvb();" }
53 }
c906108c 54
51615d72 55 # class V
c906108c 56
78c90502
MC
57 cp_test_ptype_class \
58 "ptype V" "" "class" "V" \
59 {
60 { base "public VA" }
61 { base "public VB" }
62 { field public "int w;" }
63 { method public "int f();" }
64 { method public "virtual int vv();" }
65 }
c906108c 66
184ad485 67 # class A
c906108c 68
78c90502
MC
69 cp_test_ptype_class \
70 "ptype A" "" "class" "A" \
71 {
72 { base "public virtual V" }
73 { vbase "V" }
74 { field private "int a;" }
75 { method public "virtual int f();" }
76 }
c906108c 77
184ad485 78 # class B
c906108c 79
78c90502
MC
80 cp_test_ptype_class \
81 "ptype B" "" "class" "B" \
82 {
83 { base "public A" }
84 { field private "int b;" }
85 { method public "virtual int f();" }
86 }
c906108c 87
184ad485 88 # class C
c906108c 89
78c90502
MC
90 cp_test_ptype_class \
91 "ptype C" "" "class" "C" \
92 {
93 { base "public virtual V" }
94 { vbase "V" }
95 { field public "int c;" }
96 }
c906108c 97
184ad485 98 # class AD
c906108c 99
78c90502
MC
100 cp_test_ptype_class \
101 "ptype AD" "" "class" "AD" \
102 {
103 { method public "virtual int vg();" }
104 }
c906108c 105
184ad485 106 # class D
c906108c 107
78c90502
MC
108 cp_test_ptype_class \
109 "ptype D" "" "class" "D" \
110 {
111 { base "public AD" }
112 { base "public virtual V" }
113 { vbase "V" }
114 { method public "static void s();" }
115 { method public "virtual int vg();" }
116 { method public "virtual int vd();" }
117 { method public "int fd();" }
118 { field public "int d;" }
119 }
c906108c 120
184ad485 121 # class E
51615d72 122
78c90502
MC
123 cp_test_ptype_class \
124 "ptype E" "" "class" "E" \
125 {
126 { base "public B" }
127 { base "public virtual V" }
128 { base "public D" }
129 { base "public C" }
130 { vbase "V" }
131 { method public "virtual int f();" }
132 { method public "virtual int vg();" }
133 { method public "virtual int vv();" }
134 { field public "int e;" }
135 }
c906108c 136
184ad485 137 # An instance of D
51615d72 138
78c90502 139 cp_test_ptype_class "ptype dd" "" "class" "D" ibid
c906108c 140
184ad485 141 # An instance of D *
51615d72 142
78c90502 143 cp_test_ptype_class "ptype ppd" "" "class" "D" ibid "*"
c906108c 144
184ad485
MC
145 # An instance of AD *
146 # TODO: this should be named pADd, not pAd.
51615d72 147
78c90502
MC
148 cp_test_ptype_class "ptype pAd" "" "class" "AD" ibid "*"
149
150 # Instances of these classes.
151
152 cp_test_ptype_class "ptype a" "" "class" "A" ibid
153 cp_test_ptype_class "ptype b" "" "class" "B" ibid
154 cp_test_ptype_class "ptype c" "" "class" "C" ibid
155 cp_test_ptype_class "ptype d" "" "class" "D" ibid
156 cp_test_ptype_class "ptype e" "" "class" "E" ibid
157 cp_test_ptype_class "ptype v" "" "class" "V" ibid
158 cp_test_ptype_class "ptype vb" "" "class" "VB" ibid
159
160 # Instances of pointers to these classes.
161
162 cp_test_ptype_class "ptype pAa" "" "class" "A" ibid "*"
163 cp_test_ptype_class "ptype pAe" "" "class" "A" ibid "*"
164 cp_test_ptype_class "ptype pBe" "" "class" "B" ibid "*"
165 cp_test_ptype_class "ptype pDd" "" "class" "D" ibid "*"
166 cp_test_ptype_class "ptype pDe" "" "class" "D" ibid "*"
167 cp_test_ptype_class "ptype pVa" "" "class" "V" ibid "*"
168 cp_test_ptype_class "ptype pVv" "" "class" "V" ibid "*"
169 cp_test_ptype_class "ptype pVe" "" "class" "V" ibid "*"
170 cp_test_ptype_class "ptype pVd" "" "class" "V" ibid "*"
171 cp_test_ptype_class "ptype pADe" "" "class" "AD" ibid "*"
172 cp_test_ptype_class "ptype pEe" "" "class" "E" ibid "*"
173 cp_test_ptype_class "ptype pVB" "" "class" "VB" ibid "*"
184ad485 174
51615d72 175}
c906108c 176
51615d72
MC
177# Call virtual functions.
178
179proc test_virtual_calls {} {
180 global gdb_prompt
181 global nl
182
183 if [target_info exists gdb,cannot_call_functions] {
184 setup_xfail "*-*-*" 2416
185 fail "This target can not call functions"
186 return 0
c906108c
SS
187 }
188
51615d72
MC
189 gdb_test "print pAe->f()" "\\$\[0-9\]+ = 20"
190 gdb_test "print pAa->f()" "\\$\[0-9\]+ = 1"
191 gdb_test "print pDe->vg()" "\\$\[0-9\]+ = 202"
192 gdb_test "print pADe->vg()" "\\$\[0-9\]+ = 202"
193 gdb_test "print pDd->vg()" "\\$\[0-9\]+ = 101"
194 gdb_test "print pEe->vvb()" "\\$\[0-9\]+ = 411"
195 gdb_test "print pVB->vvb()" "\\$\[0-9\]+ = 407"
196 gdb_test "print pBe->vvb()" "\\$\[0-9\]+ = 411"
197 gdb_test "print pDe->vvb()" "\\$\[0-9\]+ = 411"
198 gdb_test "print pEe->vd()" "\\$\[0-9\]+ = 282"
199 gdb_test "print pEe->fvb()" "\\$\[0-9\]+ = 311"
200
51615d72
MC
201 # more recent results:
202 # wrong value "202"
203 # gcc 2.95.3 -gdwarf-2
204 # gcc 2.95.3 -gstabs+
205 # attempt to take addres of value not located in memory
206 # gcc 3.3.2 -gdwarf-2
207 # gcc 3.3.2 -gstabs+
208 #
209 # -- chastain 2003-12-31
210
211 gdb_test_multiple "print pEe->D::vg()" "print pEe->D::vg()" {
212 -re "\\$\[0-9]+ = 102$nl$gdb_prompt $" {
213 pass "print pEe->D::vg()"
214 }
0d5de010
DJ
215 -re "\\$\[0-9]+ = 202$nl$gdb_prompt $" {
216 # To get this result, we have called pEe->*(&D::vg) ().
217 # That's how GDB interprets this, but it's wrong; in fact
218 # the explicit D:: means to bypass virtual function lookup,
219 # and call D::vg as if it were non-virtual. We still have
220 # to e.g. adjust "this", though.
221 kfail "gdb/1064" "print pEe->D::vg()"
222 }
51615d72
MC
223 -re "Attempt to take address of value not located in memory.$nl$gdb_prompt $" {
224 kfail "gdb/1064" "print pEe->D::vg()"
225 }
c906108c
SS
226 }
227}
228
229proc do_tests {} {
51615d72
MC
230 global srcdir subdir binfile
231 global gdb_prompt
c906108c 232
c906108c 233
51615d72
MC
234 gdb_exit
235 gdb_start
236 gdb_reinitialize_dir $srcdir/$subdir
237 gdb_load $binfile
c906108c 238
35ec993f
MS
239 gdb_test_no_output "set language c++" ""
240 gdb_test_no_output "set width 0" ""
c906108c 241
a7881759
DJ
242 if ![runto_main] then {
243 perror "couldn't run to breakpoint"
244 return
245 }
c906108c
SS
246 test_ptype_of_classes
247
51615d72
MC
248 gdb_breakpoint test_calls
249 gdb_test "continue" ".*Breakpoint .* test_calls.*" ""
250 test_virtual_calls
b18be20d
DJ
251
252 gdb_test "next" ".*pAa->f.*" "next to pAa->f call"
253 gdb_test "next" ".*pDe->vg.*" "next to pDe->vg call"
254 gdb_test "step" ".*E::vg.*" "step through thunk into E::vg"
c906108c
SS
255}
256
257do_tests
This page took 1.319116 seconds and 4 git commands to generate.