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