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