1 # Copyright
1992-2022 Free Software Foundation
, Inc.
3 # This
program is free software
; you can redistribute it and
/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation
; either version
3 of the License
, or
6 #
(at your option
) any later version.
8 # This
program is distributed in the hope that it will be useful
,
9 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License
for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this
program.
If not
, see
<http
://www.gnu.org
/licenses
/>.
16 # This file was written by Fred Fish.
(fnf@cygnus.com
)
17 # And rewritten by Michael Chastain
<mec.gnu@mindspring.com
>.
21 if { [skip_cplus_tests
] } { continue }
23 load_lib
"cp-support.exp"
27 if {[prepare_for_testing
"failed to prepare" $testfile $srcfile {debug c++}]} {
31 proc test_ptype_of_classes
{} {
36 "VA" "" "class" "VA" \
38 { field public
"int va;" }
44 "VB" "" "class" "VB" \
46 { field public
"int vb;" }
47 { method public
"int fvb();" }
48 { method public
"virtual int vvb();" }
58 { field public
"int w;" }
59 { method public
"int f();" }
60 { method public
"virtual int vv();" }
68 { base
"public virtual V" }
70 { field private
"int a;" }
71 { method public
"virtual int f();" }
80 { field private
"int b;" }
81 { method public
"virtual int f();" }
89 { base
"public virtual V" }
91 { field public
"int c;" }
97 "AD" "" "class" "AD" \
99 { method public
"virtual int vg();" }
104 cp_test_ptype_class \
108 { base
"public virtual V" }
110 { method public
"static void s();" }
111 { method public
"virtual int vg();" }
112 { method public
"virtual int vd();" }
113 { method public
"int fd();" }
114 { field public
"int d;" }
119 cp_test_ptype_class \
123 { base
"public virtual V" }
127 { method public
"virtual int f();" }
128 { method public
"virtual int vg();" }
129 { method public
"virtual int vv();" }
130 { field public
"int e;" }
135 cp_test_ptype_class
"dd" "" "class" "D" ibid
139 cp_test_ptype_class
"ppd" "" "class" "D" ibid "*"
141 # An instance of AD
*
142 # TODO
: this should be named pADd
, not pAd.
144 cp_test_ptype_class
"pAd" "" "class" "AD" ibid "*"
146 # Instances of these classes.
148 cp_test_ptype_class
"a" "" "class" "A" ibid
149 cp_test_ptype_class
"b" "" "class" "B" ibid
150 cp_test_ptype_class
"c" "" "class" "C" ibid
151 cp_test_ptype_class
"d" "" "class" "D" ibid
152 cp_test_ptype_class
"e" "" "class" "E" ibid
153 cp_test_ptype_class
"v" "" "class" "V" ibid
154 cp_test_ptype_class
"vb" "" "class" "VB" ibid
156 # Instances of pointers to these classes.
158 cp_test_ptype_class
"pAa" "" "class" "A" ibid "*"
159 cp_test_ptype_class
"pAe" "" "class" "A" ibid "*"
160 cp_test_ptype_class
"pBe" "" "class" "B" ibid "*"
161 cp_test_ptype_class
"pDd" "" "class" "D" ibid "*"
162 cp_test_ptype_class
"pDe" "" "class" "D" ibid "*"
163 cp_test_ptype_class
"pVa" "" "class" "V" ibid "*"
164 cp_test_ptype_class
"pVv" "" "class" "V" ibid "*"
165 cp_test_ptype_class
"pVe" "" "class" "V" ibid "*"
166 cp_test_ptype_class
"pVd" "" "class" "V" ibid "*"
167 cp_test_ptype_class
"pADe" "" "class" "AD" ibid "*"
168 cp_test_ptype_class
"pEe" "" "class" "E" ibid "*"
169 cp_test_ptype_class
"pVB" "" "class" "VB" ibid "*"
173 #
Call virtual functions.
175 proc test_virtual_calls
{} {
179 if [target_info
exists gdb
,cannot_call_functions
] {
180 unsupported
"this target can not call functions"
184 gdb_test
"print pAe->f()" "\\$\[0-9\]+ = 20"
185 gdb_test
"print pAa->f()" "\\$\[0-9\]+ = 1"
186 gdb_test
"print pDe->vg()" "\\$\[0-9\]+ = 202"
187 gdb_test
"print pADe->vg()" "\\$\[0-9\]+ = 202"
188 gdb_test
"print pDd->vg()" "\\$\[0-9\]+ = 101"
189 gdb_test
"print pEe->vvb()" "\\$\[0-9\]+ = 411"
190 gdb_test
"print pVB->vvb()" "\\$\[0-9\]+ = 407"
191 gdb_test
"print pBe->vvb()" "\\$\[0-9\]+ = 411"
192 gdb_test
"print pDe->vvb()" "\\$\[0-9\]+ = 411"
193 gdb_test
"print pEe->vd()" "\\$\[0-9\]+ = 282"
194 gdb_test
"print pEe->fvb()" "\\$\[0-9\]+ = 311"
196 # more recent results
:
198 # gcc
2.95.3 -gdwarf
-2
199 # gcc
2.95.3 -gstabs
+
200 # attempt to take addres of value not located in memory
201 # gcc
3.3.2 -gdwarf
-2
204 #
-- chastain
2003-12-31
206 gdb_test_multiple
"print pEe->D::vg()" "print pEe->D::vg()" {
207 -re
"\\$\[0-9]+ = 102$nl$gdb_prompt $" {
208 pass
"print pEe->D::vg()"
210 -re
"\\$\[0-9]+ = 202$nl$gdb_prompt $" {
211 # To
get this result
, we have called pEe
->*(&D
::vg
) ().
212 # That
's how GDB interprets this, but it's wrong
; in fact
213 # the explicit D
:: means to bypass virtual function lookup
,
214 # and
call D
::vg as
if it were non
-virtual. We still have
215 # to e.g. adjust
"this", though.
216 kfail
"gdb/1064" "print pEe->D::vg()"
218 -re
"Attempt to take address of value not located in memory.$nl$gdb_prompt $" {
219 kfail
"gdb/1064" "print pEe->D::vg()"
224 # A helper proc that creates a regular expression matching a
225 # particular vtable.
NAME is the type
name. Each element of
ARGS is
226 # the
name of a function in the vtable.
228 proc make_one_vtable_result
{name args} {
233 set result
"vtable for '${name}' @ $hex .subobject @ $hex.:$nls"
236 append result
".${count}.:( @$hex:)? $hex <(\.)?$func..>${nls}"
245 proc test_info_vtbl
{} {
250 set vt_A
[make_one_vtable_result A A
::f
]
251 set vt_B
[make_one_vtable_result B B
::f
]
252 set vt_V
[make_one_vtable_result V VB
::vvb V
::vv
]
253 set vt_V2
[make_one_vtable_result V VB
::vvb
"virtual thunk to E::vv"]
254 set vt_D
[make_one_vtable_result D D
::vg D
::vd
]
255 set vt_D2
[make_one_vtable_result D
"non-virtual thunk to E::vg" D::vd]
256 set vt_E
[make_one_vtable_result E E
::f E
::vg E
::vv
]
258 gdb_test
"info vtbl a" "${vt_A}${vt_V}"
259 gdb_test
"info vtbl b" "${vt_B}${vt_V}"
260 gdb_test
"info vtbl c" "${vt_V}"
261 gdb_test
"info vtbl d" "${vt_D}${vt_V}"
262 gdb_test
"info vtbl e" "${vt_E}${vt_D2}${vt_V2}"
263 gdb_test
"info vtbl pEe" "${vt_E}${vt_D2}${vt_V2}"
265 gdb_test
"info vtbl" "Argument required.*"
266 gdb_test
"info vtbl va" \
267 "This object does not have a virtual function table.*"
268 gdb_test
"info vtbl all_count" \
269 "This object does not have a virtual function table.*"
273 gdb_test_no_output
"set language c++" ""
274 gdb_test_no_output
"set width 0" ""
276 if ![runto_main
] then {
277 perror
"couldn't run to breakpoint"
280 test_ptype_of_classes
283 gdb_breakpoint test_calls
284 gdb_test
"continue" ".*Breakpoint .* test_calls.*" ""
287 gdb_test
"next" ".*pAa->f.*" "next to pAa->f call"
288 gdb_test
"next" ".*pDe->vg.*" "next to pDe->vg call"
289 gdb_test
"step" ".*E::vg.*" "step through thunk into E::vg"