blob: 5ffa9b38e12c1addd6dff19a3ff393300995192d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
# Copyright 1992-2016 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This file was written by Fred Fish. (fnf@cygnus.com)
# And rewritten by Michael Chastain <mec.gnu@mindspring.com>.
set nl "\[\r\n\]+"
if { [skip_cplus_tests] } { continue }
load_lib "cp-support.exp"
standard_testfile .cc
if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
return -1
}
proc test_ptype_of_classes {} {
# class VA
cp_test_ptype_class \
"VA" "" "class" "VA" \
{
{ field public "int va;" }
}
# class VB
cp_test_ptype_class \
"VB" "" "class" "VB" \
{
{ field public "int vb;" }
{ method public "int fvb();" }
{ method public "virtual int vvb();" }
}
# class V
cp_test_ptype_class \
"V" "" "class" "V" \
{
{ base "public VA" }
{ base "public VB" }
{ field public "int w;" }
{ method public "int f();" }
{ method public "virtual int vv();" }
}
# class A
cp_test_ptype_class \
"A" "" "class" "A" \
{
{ base "public virtual V" }
{ vbase "V" }
{ field private "int a;" }
{ method public "virtual int f();" }
}
# class B
cp_test_ptype_class \
"B" "" "class" "B" \
{
{ base "public A" }
{ field private "int b;" }
{ method public "virtual int f();" }
}
# class C
cp_test_ptype_class \
"C" "" "class" "C" \
{
{ base "public virtual V" }
{ vbase "V" }
{ field public "int c;" }
}
# class AD
cp_test_ptype_class \
"AD" "" "class" "AD" \
{
{ method public "virtual int vg();" }
}
# class D
cp_test_ptype_class \
"D" "" "class" "D" \
{
{ base "public AD" }
{ base "public virtual V" }
{ vbase "V" }
{ method public "static void s();" }
{ method public "virtual int vg();" }
{ method public "virtual int vd();" }
{ method public "int fd();" }
{ field public "int d;" }
}
# class E
cp_test_ptype_class \
"E" "" "class" "E" \
{
{ base "public B" }
{ base "public virtual V" }
{ base "public D" }
{ base "public C" }
{ vbase "V" }
{ method public "virtual int f();" }
{ method public "virtual int vg();" }
{ method public "virtual int vv();" }
{ field public "int e;" }
}
# An instance of D
cp_test_ptype_class "dd" "" "class" "D" ibid
# An instance of D *
cp_test_ptype_class "ppd" "" "class" "D" ibid "*"
# An instance of AD *
# TODO: this should be named pADd, not pAd.
cp_test_ptype_class "pAd" "" "class" "AD" ibid "*"
# Instances of these classes.
cp_test_ptype_class "a" "" "class" "A" ibid
cp_test_ptype_class "b" "" "class" "B" ibid
cp_test_ptype_class "c" "" "class" "C" ibid
cp_test_ptype_class "d" "" "class" "D" ibid
cp_test_ptype_class "e" "" "class" "E" ibid
cp_test_ptype_class "v" "" "class" "V" ibid
cp_test_ptype_class "vb" "" "class" "VB" ibid
# Instances of pointers to these classes.
cp_test_ptype_class "pAa" "" "class" "A" ibid "*"
cp_test_ptype_class "pAe" "" "class" "A" ibid "*"
cp_test_ptype_class "pBe" "" "class" "B" ibid "*"
cp_test_ptype_class "pDd" "" "class" "D" ibid "*"
cp_test_ptype_class "pDe" "" "class" "D" ibid "*"
cp_test_ptype_class "pVa" "" "class" "V" ibid "*"
cp_test_ptype_class "pVv" "" "class" "V" ibid "*"
cp_test_ptype_class "pVe" "" "class" "V" ibid "*"
cp_test_ptype_class "pVd" "" "class" "V" ibid "*"
cp_test_ptype_class "pADe" "" "class" "AD" ibid "*"
cp_test_ptype_class "pEe" "" "class" "E" ibid "*"
cp_test_ptype_class "pVB" "" "class" "VB" ibid "*"
}
# Call virtual functions.
proc test_virtual_calls {} {
global gdb_prompt
global nl
if [target_info exists gdb,cannot_call_functions] {
unsupported "this target can not call functions"
return 0
}
gdb_test "print pAe->f()" "\\$\[0-9\]+ = 20"
gdb_test "print pAa->f()" "\\$\[0-9\]+ = 1"
gdb_test "print pDe->vg()" "\\$\[0-9\]+ = 202"
gdb_test "print pADe->vg()" "\\$\[0-9\]+ = 202"
gdb_test "print pDd->vg()" "\\$\[0-9\]+ = 101"
gdb_test "print pEe->vvb()" "\\$\[0-9\]+ = 411"
gdb_test "print pVB->vvb()" "\\$\[0-9\]+ = 407"
gdb_test "print pBe->vvb()" "\\$\[0-9\]+ = 411"
gdb_test "print pDe->vvb()" "\\$\[0-9\]+ = 411"
gdb_test "print pEe->vd()" "\\$\[0-9\]+ = 282"
gdb_test "print pEe->fvb()" "\\$\[0-9\]+ = 311"
# more recent results:
# wrong value "202"
# gcc 2.95.3 -gdwarf-2
# gcc 2.95.3 -gstabs+
# attempt to take addres of value not located in memory
# gcc 3.3.2 -gdwarf-2
# gcc 3.3.2 -gstabs+
#
# -- chastain 2003-12-31
gdb_test_multiple "print pEe->D::vg()" "print pEe->D::vg()" {
-re "\\$\[0-9]+ = 102$nl$gdb_prompt $" {
pass "print pEe->D::vg()"
}
-re "\\$\[0-9]+ = 202$nl$gdb_prompt $" {
# To get this result, we have called pEe->*(&D::vg) ().
# That's how GDB interprets this, but it's wrong; in fact
# the explicit D:: means to bypass virtual function lookup,
# and call D::vg as if it were non-virtual. We still have
# to e.g. adjust "this", though.
kfail "gdb/1064" "print pEe->D::vg()"
}
-re "Attempt to take address of value not located in memory.$nl$gdb_prompt $" {
kfail "gdb/1064" "print pEe->D::vg()"
}
}
}
# A helper proc that creates a regular expression matching a
# particular vtable. NAME is the type name. Each element of ARGS is
# the name of a function in the vtable.
proc make_one_vtable_result {name args} {
global hex
set nls "\[\r\n\]+"
set result "vtable for '${name}' @ $hex .subobject @ $hex.:$nls"
set count 0
foreach func $args {
append result ".${count}.:( @$hex:)? $hex <(\.)?$func..>${nls}"
incr count
}
return $result
}
# Test "info vtbl".
proc test_info_vtbl {} {
global hex
set nls "\[\r\n\]+"
set vt_A [make_one_vtable_result A A::f]
set vt_B [make_one_vtable_result B B::f]
set vt_V [make_one_vtable_result V VB::vvb V::vv]
set vt_V2 [make_one_vtable_result V VB::vvb "virtual thunk to E::vv"]
set vt_D [make_one_vtable_result D D::vg D::vd]
set vt_D2 [make_one_vtable_result D "non-virtual thunk to E::vg" D::vd]
set vt_E [make_one_vtable_result E E::f E::vg E::vv]
gdb_test "info vtbl a" "${vt_A}${vt_V}"
gdb_test "info vtbl b" "${vt_B}${vt_V}"
gdb_test "info vtbl c" "${vt_V}"
gdb_test "info vtbl d" "${vt_D}${vt_V}"
gdb_test "info vtbl e" "${vt_E}${vt_D2}${vt_V2}"
gdb_test "info vtbl pEe" "${vt_E}${vt_D2}${vt_V2}"
gdb_test "info vtbl" "Argument required.*"
gdb_test "info vtbl va" \
"This object does not have a virtual function table.*"
gdb_test "info vtbl all_count" \
"This object does not have a virtual function table.*"
}
proc do_tests {} {
gdb_test_no_output "set language c++" ""
gdb_test_no_output "set width 0" ""
if ![runto_main] then {
perror "couldn't run to breakpoint"
return
}
test_ptype_of_classes
test_info_vtbl
gdb_breakpoint test_calls
gdb_test "continue" ".*Breakpoint .* test_calls.*" ""
test_virtual_calls
gdb_test "next" ".*pAa->f.*" "next to pAa->f call"
gdb_test "next" ".*pDe->vg.*" "next to pDe->vg call"
gdb_test "step" ".*E::vg.*" "step through thunk into E::vg"
}
do_tests
|