]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/derivation.exp
PR 15519
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / derivation.exp
CommitLineData
28e7fd62 1# Copyright 1998-2013 Free Software Foundation, Inc.
c906108c
SS
2
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
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.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 15
c906108c 16# This file was written by Elena Zannoni (ezannoni@cygnus.com)
6b7a4c0e 17# And rewritten by Michael Chastain <mec.gnu@mindspring.com>
c906108c
SS
18
19# This file is part of the gdb testsuite
c906108c 20
6b7a4c0e
MC
21# tests for inheritance, with several derivations types combinations
22# (private, public, protected)
c906108c 23# classes have simple members and member functions.
c906108c 24
6b7a4c0e
MC
25set ws "\[\r\n\t \]+"
26set nl "\[\r\n\]+"
c906108c 27
6b7a4c0e 28# Start program.
c906108c 29
c906108c 30
d4f3574e
SS
31if { [skip_cplus_tests] } { continue }
32
78c90502
MC
33load_lib "cp-support.exp"
34
69fc87c2 35standard_testfile derivation.cc derivation2.cc
c906108c 36
69fc87c2
DE
37if {[prepare_for_testing $testfile.exp $testfile \
38 [list $srcfile $srcfile2] {debug c++}]} {
f5f3a911 39 return -1
c906108c
SS
40}
41
8dea366b 42# Check inheritance of typedefs.
69fc87c2 43foreach klass {"A" "D" "E" "F" "A2" "D2"} {
8dea366b
KS
44 gdb_test "ptype ${klass}::value_type" "type = int"
45 gdb_test "whatis ${klass}::value_type" "type = int"
46 gdb_test "p (${klass}::value_type) 0" " = 0"
47}
48foreach klass {"Z" "ZZ"} {
49 gdb_test "ptype ${klass}::value_type" "type = float"
50 gdb_test "whatis ${klass}::value_type" "type = float"
51 gdb_test "p (${klass}::value_type) 0" " = 0"
52}
53
6b7a4c0e 54# Set it up at a breakpoint so we can play with the variable values.
c906108c 55
f266096b
MC
56if ![runto 'marker1'] then {
57 perror "couldn't run to marker1"
58 continue
59}
60
69fc87c2
DE
61# Check inheritance of typedefs again, but this time with an active block.
62foreach klass {"A" "D" "A2" "D2"} {
63 gdb_test "ptype ${klass}::value_type" "type = int"
64 gdb_test "whatis ${klass}::value_type" "type = int"
65 gdb_test "p (${klass}::value_type) 0" " = 0"
66}
67
f266096b 68gdb_test "up" ".*main.*" "up from marker1"
c906108c 69
6b7a4c0e 70# Print class types and values.
c906108c 71
6b7a4c0e 72# class A
c906108c 73
184ad485
MC
74gdb_test "print a_instance" "\\$\[0-9\]+ = \{a = 1, aa = 2\}" "print value of a_instance"
75
78c90502 76cp_test_ptype_class \
b3720c3a 77 "a_instance" "" "class" "A" \
78c90502 78 {
8dea366b
KS
79 { field public "A::value_type a;" }
80 { field public "A::value_type aa;" }
78c90502 81 { method public "A();" }
8dea366b
KS
82 { method public "A::value_type afoo();" }
83 { method public "A::value_type foo();" }
84 { typedef public "typedef int value_type;" }
184ad485 85 }
c906108c 86
6b7a4c0e
MC
87# class D
88
184ad485
MC
89gdb_test_multiple "print d_instance" "print value of d_instance" {
90 -re "\\$\[0-9\]+ = \{<(class A|A)> = \{a = 1, aa = 2\}, <(class B|B)> = \{b = 3, bb = 4\}, <(class C|C)> = \{c = 5, cc = 6\}, d = 7, dd = 8\}$nl$gdb_prompt $" {
91 pass "print value of d_instance"
92 }
93}
94
78c90502 95cp_test_ptype_class \
b3720c3a 96 "d_instance" "" "class" "D" \
78c90502
MC
97 {
98 { base "private A" }
99 { base "public B" }
100 { base "protected C" }
8dea366b
KS
101 { field public "A::value_type d;" }
102 { field public "A::value_type dd;" }
78c90502 103 { method public "D();" }
8dea366b
KS
104 { method public "A::value_type dfoo();" }
105 { method public "A::value_type foo();" }
78c90502
MC
106 } \
107 "" \
108 {
109 { "protected C" "private C" { setup_xfail "*-*-*" "gcc/13539" } }
6b7a4c0e 110 }
c906108c 111
6b7a4c0e 112# class E
c906108c 113
184ad485
MC
114gdb_test_multiple "print e_instance" "print value of e_instance" {
115 -re "\\$\[0-9\]+ = \{<(class A|A)> = \{a = 1, aa = 2\}, <(class B|B)> = \{b = 3, bb = 4\}, <(class C|C)> = \{c = 5, cc = 6\}, e = 9, ee = 10\}$nl$gdb_prompt $" {
116 pass "print value of e_instance"
117 }
118}
119
78c90502 120cp_test_ptype_class \
b3720c3a 121 "e_instance" "" "class" "E" \
78c90502
MC
122 {
123 { base "public A" }
124 { base "private B" }
125 { base "protected C" }
8dea366b
KS
126 { field public "A::value_type e;" }
127 { field public "A::value_type ee;" }
78c90502 128 { method public "E();" }
8dea366b
KS
129 { method public "A::value_type efoo();" }
130 { method public "A::value_type foo();" }
78c90502
MC
131 } \
132 "" \
133 {
134 { "protected C" "private C" { setup_xfail "*-*-*" "gcc/13539" } }
adf40b2e 135 }
6b7a4c0e
MC
136
137# class F
c906108c 138
6b7a4c0e
MC
139gdb_test_multiple "print f_instance" "print value of f_instance" {
140 -re "\\$\[0-9\]+ = \{<(class A|A)> = \{a = 1, aa = 2\}, <(class B|B)> = \{b = 3, bb = 4\}, <(class C|C)> = \{c = 5, cc = 6\}, f = 11, ff = 12\}$nl$gdb_prompt $" {
141 pass "print value of f_instance"
142 }
143}
144
78c90502 145cp_test_ptype_class \
b3720c3a 146 "f_instance" "" "class" "F" \
78c90502
MC
147 {
148 { base "private A" }
149 { base "public B" }
150 { base "private C" }
8dea366b
KS
151 { field public "A::value_type f;" }
152 { field public "A::value_type ff;" }
78c90502 153 { method public "F();" }
8dea366b
KS
154 { method public "A::value_type ffoo();" }
155 { method public "A::value_type foo();" }
184ad485 156 }
184ad485 157
345f514a
KS
158# class G
159cp_test_ptype_class \
b3720c3a 160 "g_instance" "" "class" "G" \
345f514a
KS
161 {
162 { base "private A" }
163 { base "public B" }
164 { base "protected C" }
165 { field public "int g;" }
166 { field public "int gg;" }
167 { field public "int a;" }
168 { field public "int b;" }
169 { field public "int c;" }
170 { method public "int gfoo();" }
171 { method public "int foo();" }
172 }
173
6b7a4c0e
MC
174# Print individual fields.
175
176gdb_test "print d_instance.a" "\\$\[0-9\]+ = 1" "print value of d_instance.a"
177gdb_test "print d_instance.aa" "\\$\[0-9\]+ = 2" "print value of d_instance.aa"
178gdb_test "print d_instance.b" "\\$\[0-9\]+ = 3" "print value of d_instance.b"
179gdb_test "print d_instance.bb" "\\$\[0-9\]+ = 4" "print value of d_instance.bb"
180gdb_test "print d_instance.c" "\\$\[0-9\]+ = 5" "print value of d_instance.c"
181gdb_test "print d_instance.cc" "\\$\[0-9\]+ = 6" "print value of d_instance.cc"
182gdb_test "print d_instance.d" "\\$\[0-9\]+ = 7" "print value of d_instance.d"
183gdb_test "print d_instance.dd" "\\$\[0-9\]+ = 8" "print value of d_instance.dd"
184
185# Print some fields which are defined in the top of class G
186# and in its base classes. This is not be ambiguous.
187
188gdb_test "print g_instance.a" "\\$\[0-9\]+ = 15" "print value of g_instance.a"
189gdb_test "print g_instance.b" "\\$\[0-9\]+ = 16" "print value of g_instance.b"
190gdb_test "print g_instance.c" "\\$\[0-9\]+ = 17" "print value of g_instance.c"
191
192# Print a function call.
193
194gdb_test "print g_instance.afoo()" "\\$\[0-9\]+ = 1" "print value of g_instance.afoo()"
5624293a
JB
195
196# If GDB fails to restore the selected frame properly after the
197# inferior function call above (see GDB PR 1155 for an explanation of
198# why this might happen), all the subsequent tests will fail. We
199# should detect report that failure, but let the marker call finish so
200# that the rest of the tests can run undisturbed.
6b7a4c0e 201
5624293a
JB
202gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" {
203 -re "#0 marker1.*$gdb_prompt $" {
204 setup_kfail "gdb/1155" s390-*-linux-gnu
205 fail "re-selected 'main' frame after inferior call"
93201743 206 gdb_test "finish" ".*main.*at .*derivation.cc:.*// marker1-returns-here.*" \
5624293a
JB
207 "finish call to marker1"
208 }
209 -re "#1 ($hex in )?main.*$gdb_prompt $" {
210 pass "re-selected 'main' frame after inferior call"
211 }
212}
6b7a4c0e
MC
213
214gdb_test "print g_instance.bfoo()" "\\$\[0-9\]+ = 2" "print value of g_instance.bfoo()"
215gdb_test "print g_instance.cfoo()" "\\$\[0-9\]+ = 3" "print value of g_instance.cfoo()"
7977e5d2 216
8dea366b
KS
217# Check typedefs of fields
218foreach Klass {"C" "G"} {
219 set klass [string tolower $Klass]
220 set instance "${klass}_instance"
221 set var "${instance}.$klass"
222 gdb_test "whatis $var" "int"
223 gdb_test "ptype $var" "int"
224}
225
226foreach Klass {"A" "B" "D" "E" "F"} {
227 set klass [string tolower $Klass]
228 set instance "${klass}_instance"
229 set var "${instance}.$klass"
230 gdb_test "whatis $var" "A::value_type"
231 gdb_test "ptype $var" "int"
232 if {![string equal $Klass "B"]} {
233 gdb_test "p (${Klass}::value_type) 0" " = 0"
234 }
235}
236
237foreach Klass {"Z" "ZZ"} {
238 set klass [string tolower $Klass]
239 set instance "${klass}_instance"
240 set var "${instance}.$klass"
241 gdb_test "whatis $var" "Z::value_type"
242 gdb_test "ptype $var" "float"
243 gdb_test "p (${Klass}::value_type) 0" " = 0"
244}
245
7977e5d2
TT
246# This is a regression test for a bug that caused a crash when trying
247# to print the vtbl pointer. We don't care about the output so much
248# here (it is tested elsewhere), just that gdb doesn't crash. We test
249# "ptype" first because, before the gdb fix, that was the only code
250# path calling get_vptr_fieldno.
251gdb_test "ptype vderived" "type = .*"
252gdb_test "print vderived" " = {.* inter = 0.*x = 0}"
8dea366b
KS
253
254# Test whether inheritance of typedefs is properly
255# reported when stopped.
256gdb_test "ptype N::value_type" "type = double"
257gdb_test "ptype N::Derived::value_type" "type = int"
258
259# Now run to N::Derived::doit and get the type of "value_type"
260if {![runto "N::Derived::doit"]} {
261 perrro "couldn't run to N::Derived::doit"
262 continue
263}
264
265gdb_test "ptype value_type" "type = int"