Commit | Line | Data |
---|---|---|
e53890ae AC |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
9b254dd1 DJ |
3 | # Copyright 1996, 1997, 1999, 2003, 2004, 2007, 2008 |
4 | # Free Software Foundation, Inc. | |
74cf1395 JM |
5 | |
6 | # This program is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 8 | # the Free Software Foundation; either version 3 of the License, or |
74cf1395 | 9 | # (at your option) any later version. |
e22f8b7c | 10 | # |
74cf1395 JM |
11 | # This program is distributed in the hope that it will be useful, |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
e22f8b7c | 15 | # |
74cf1395 | 16 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
74cf1395 JM |
18 | |
19 | # Please email any bugs, comments, and/or additions to this file to: | |
20 | # bug-gdb@prep.ai.mit.edu | |
21 | ||
74cf1395 JM |
22 | if $tracelevel then { |
23 | strace $tracelevel | |
24 | } | |
25 | ||
26 | set prms_id 0 | |
27 | set bug_id 0 | |
28 | ||
e53890ae AC |
29 | # Some targets can't call functions, so don't even bother with this |
30 | # test. | |
31 | ||
32 | if [target_info exists gdb,cannot_call_functions] { | |
33 | setup_xfail "*-*-*" | |
34 | fail "This target can not call functions" | |
35 | continue | |
36 | } | |
37 | ||
74cf1395 JM |
38 | set testfile "structs" |
39 | set srcfile ${testfile}.c | |
40 | set binfile ${objdir}/${subdir}/${testfile} | |
41 | ||
e53890ae AC |
42 | # Create and source the file that provides information about the |
43 | # compiler used to compile the test case. | |
853d6e5b | 44 | |
b4967060 AC |
45 | if [get_compiler_info ${binfile}] { |
46 | return -1; | |
853d6e5b AC |
47 | } |
48 | ||
e53890ae AC |
49 | # Compile a variant of structs.c using TYPES to specify the type of |
50 | # the first N struct elements (the remaining elements take the type of | |
51 | # the last TYPES field). Run the compmiled program up to "main". | |
52 | # Also updates the global "testfile" to reflect the most recent build. | |
853d6e5b | 53 | |
e53890ae AC |
54 | proc start_structs_test { types } { |
55 | global testfile | |
56 | global srcfile | |
57 | global binfile | |
58 | global objdir | |
59 | global subdir | |
60 | global srcdir | |
61 | global gdb_prompt | |
62 | ||
63 | # Create the additional flags | |
64 | set flags "debug" | |
65 | set testfile "structs" | |
66 | set n 0 | |
67 | for {set n 0} {$n<[llength ${types}]} {incr n} { | |
68 | set m [I2A ${n}] | |
69 | set t [lindex ${types} $n] | |
70 | lappend flags "additional_flags=-Dt${m}=${t}" | |
71 | append testfile "-" "$t" | |
72 | } | |
73 | ||
74 | set binfile ${objdir}/${subdir}/${testfile} | |
75 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "${flags}"] != "" } { | |
76 | # built the second test case since we can't use prototypes | |
77 | warning "Prototypes not supported, rebuilding with -DNO_PROTOTYPES" | |
78 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "${flags} additional_flags=-DNO_PROTOTYPES"] != "" } { | |
b60f0898 JB |
79 | untested structs.exp |
80 | return -1 | |
e53890ae AC |
81 | } |
82 | } | |
83 | ||
84 | # Start with a fresh gdb. | |
e42c7771 | 85 | gdb_exit |
e53890ae AC |
86 | gdb_start |
87 | gdb_reinitialize_dir $srcdir/$subdir | |
88 | gdb_load ${binfile} | |
89 | ||
90 | # Make certain that the output is consistent | |
91 | gdb_test "set print sevenbit-strings" "" \ | |
92 | "set print sevenbit-strings; ${testfile}" | |
93 | gdb_test "set print address off" "" \ | |
94 | "set print address off; ${testfile}" | |
95 | gdb_test "set width 0" "" \ | |
96 | "set width 0; ${testfile}" | |
97 | ||
98 | # Advance to main | |
99 | if { ![runto_main] } then { | |
100 | gdb_suppress_tests; | |
101 | } | |
b729099e MC |
102 | |
103 | # Get the debug format | |
104 | get_debug_format | |
e53890ae AC |
105 | |
106 | # check that at the struct containing all the relevant types is correct | |
107 | set foo_t "type = struct struct[llength ${types}] \{" | |
108 | for {set n 0} {$n<[llength ${types}]} {incr n} { | |
109 | append foo_t "\[\r\n \]+[lindex ${types} $n] [i2a $n];" | |
110 | } | |
111 | append foo_t "\[\r\n \]+\}" | |
112 | gdb_test "ptype foo[llength ${types}]" "${foo_t}" \ | |
113 | "ptype foo[llength ${types}]; ${testfile}" | |
74cf1395 JM |
114 | } |
115 | ||
e53890ae AC |
116 | # The expected value for fun${n}, L${n} and foo${n}. First element is |
117 | # empty to make indexing easier. "foo" returns the modified value, | |
118 | # "zed" returns the invalid value. | |
853d6e5b | 119 | |
e53890ae AC |
120 | proc foo { n } { |
121 | return [lindex { | |
122 | "{}" | |
123 | "{a = 49 '1'}" | |
124 | "{a = 97 'a', b = 50 '2'}" | |
125 | "{a = 49 '1', b = 98 'b', c = 51 '3'}" | |
126 | "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4'}" | |
127 | "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5'}" | |
128 | "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4', e = 101 'e', f = 54 '6'}" | |
129 | "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7'}" | |
130 | "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8'}" | |
131 | "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9'}" | |
132 | "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A'}" | |
133 | "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B'}" | |
134 | "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A', k = 107 'k', l = 67 'C'}" | |
135 | "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B', l = 108 'l', m = 68 'D'}" | |
136 | "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A', k = 107 'k', l = 67 'C', m = 109 'm', n = 69 'E'}" | |
137 | "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B', l = 108 'l', m = 68 'D', n = 110 'n', o = 70 'F'}" | |
138 | "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A', k = 107 'k', l = 67 'C', m = 109 'm', n = 69 'E', o = 111 'o', p = 71 'G'}" | |
139 | "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B', l = 108 'l', m = 68 'D', n = 110 'n', o = 70 'F', p = 112 'p', q = 72 'H'}" | |
140 | } $n] | |
141 | } | |
142 | ||
143 | proc zed { n } { | |
144 | return [lindex { | |
145 | "{}" | |
146 | "{a = 90 'Z'}" | |
147 | "{a = 90 'Z', b = 90 'Z'}" | |
148 | "{a = 90 'Z', b = 90 'Z', c = 90 'Z'}" | |
149 | "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z'}" | |
150 | "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z'}" | |
151 | "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z'}" | |
152 | "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z'}" | |
153 | "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z'}" | |
154 | "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z'}" | |
155 | "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z'}" | |
156 | "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z', k = 90 'Z'}" | |
157 | "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z', k = 90 'Z', l = 90 'Z'}" | |
158 | "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z', k = 90 'Z', l = 90 'Z', m = 90 'Z'}" | |
159 | "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z', k = 90 'Z', l = 90 'Z', m = 90 'Z', n = 90 'Z'}" | |
160 | "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z', k = 90 'Z', l = 90 'Z', m = 90 'Z', n = 90 'Z', o = 90 'Z'}" | |
161 | "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z', k = 90 'Z', l = 90 'Z', m = 90 'Z', n = 90 'Z', o = 90 'Z', p = 90 'Z'}" | |
162 | "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z', k = 90 'Z', l = 90 'Z', m = 90 'Z', n = 90 'Z', o = 90 'Z', p = 90 'Z', q = 90 'Z'}" | |
163 | } $n] | |
164 | } | |
165 | ||
987a9106 JB |
166 | proc any { n } { |
167 | return [lindex { | |
168 | "{}" | |
169 | "{a = \[^,\}\]*}" | |
170 | "{a = \[^,\}\]*, b = \[^,\}\]*}" | |
171 | "{a = \[^,\}\]*, b = \[^,\}\]*, c = \[^,\}\]*}" | |
172 | "{a = \[^,\}\]*, b = \[^,\}\]*, c = \[^,\}\]*, d = \[^,\}\]*}" | |
173 | "{a = \[^,\}\]*, b = \[^,\}\]*, c = \[^,\}\]*, d = \[^,\}\]*, e = \[^,\}\]*}" | |
174 | "{a = \[^,\}\]*, b = \[^,\}\]*, c = \[^,\}\]*, d = \[^,\}\]*, e = \[^,\}\]*, f = \[^,\}\]*}" | |
175 | "{a = \[^,\}\]*, b = \[^,\}\]*, c = \[^,\}\]*, d = \[^,\}\]*, e = \[^,\}\]*, f = \[^,\}\]*, g = \[^,\}\]*}" | |
176 | "{a = \[^,\}\]*, b = \[^,\}\]*, c = \[^,\}\]*, d = \[^,\}\]*, e = \[^,\}\]*, f = \[^,\}\]*, g = \[^,\}\]*, h = \[^,\}\]*}" | |
177 | "{a = \[^,\}\]*, b = \[^,\}\]*, c = \[^,\}\]*, d = \[^,\}\]*, e = \[^,\}\]*, f = \[^,\}\]*, g = \[^,\}\]*, h = \[^,\}\]*, i = \[^,\}\]*}" | |
178 | "{a = \[^,\}\]*, b = \[^,\}\]*, c = \[^,\}\]*, d = \[^,\}\]*, e = \[^,\}\]*, f = \[^,\}\]*, g = \[^,\}\]*, h = \[^,\}\]*, i = \[^,\}\]*, j = \[^,\}\]*}" | |
179 | "{a = \[^,\}\]*, b = \[^,\}\]*, c = \[^,\}\]*, d = \[^,\}\]*, e = \[^,\}\]*, f = \[^,\}\]*, g = \[^,\}\]*, h = \[^,\}\]*, i = \[^,\}\]*, j = \[^,\}\]*, k = \[^,\}\]*}" | |
180 | "{a = \[^,\}\]*, b = \[^,\}\]*, c = \[^,\}\]*, d = \[^,\}\]*, e = \[^,\}\]*, f = \[^,\}\]*, g = \[^,\}\]*, h = \[^,\}\]*, i = \[^,\}\]*, j = \[^,\}\]*, k = \[^,\}\]*, l = \[^,\}\]*}" | |
181 | "{a = \[^,\}\]*, b = \[^,\}\]*, c = \[^,\}\]*, d = \[^,\}\]*, e = \[^,\}\]*, f = \[^,\}\]*, g = \[^,\}\]*, h = \[^,\}\]*, i = \[^,\}\]*, j = \[^,\}\]*, k = \[^,\}\]*, l = \[^,\}\]*, m = \[^,\}\]*}" | |
182 | "{a = \[^,\}\]*, b = \[^,\}\]*, c = \[^,\}\]*, d = \[^,\}\]*, e = \[^,\}\]*, f = \[^,\}\]*, g = \[^,\}\]*, h = \[^,\}\]*, i = \[^,\}\]*, j = \[^,\}\]*, k = \[^,\}\]*, l = \[^,\}\]*, m = \[^,\}\]*, n = \[^,\}\]*}" | |
183 | "{a = \[^,\}\]*, b = \[^,\}\]*, c = \[^,\}\]*, d = \[^,\}\]*, e = \[^,\}\]*, f = \[^,\}\]*, g = \[^,\}\]*, h = \[^,\}\]*, i = \[^,\}\]*, j = \[^,\}\]*, k = \[^,\}\]*, l = \[^,\}\]*, m = \[^,\}\]*, n = \[^,\}\]*, o = \[^,\}\]*}" | |
184 | "{a = \[^,\}\]*, b = \[^,\}\]*, c = \[^,\}\]*, d = \[^,\}\]*, e = \[^,\}\]*, f = \[^,\}\]*, g = \[^,\}\]*, h = \[^,\}\]*, i = \[^,\}\]*, j = \[^,\}\]*, k = \[^,\}\]*, l = \[^,\}\]*, m = \[^,\}\]*, n = \[^,\}\]*, o = \[^,\}\]*, p = \[^,\}\]*}" | |
185 | "{a = \[^,\}\]*, b = \[^,\}\]*, c = \[^,\}\]*, d = \[^,\}\]*, e = \[^,\}\]*, f = \[^,\}\]*, g = \[^,\}\]*, h = \[^,\}\]*, i = \[^,\}\]*, j = \[^,\}\]*, k = \[^,\}\]*, l = \[^,\}\]*, m = \[^,\}\]*, n = \[^,\}\]*, o = \[^,\}\]*, p = \[^,\}\]*, q = \[^,\}\]*}" | |
186 | } $n] | |
187 | } | |
188 | ||
e53890ae AC |
189 | # Given N (0..25), return the corresponding alphabetic letter in lower |
190 | # or upper case. This is ment to be i18n proof. | |
191 | ||
192 | proc i2a { n } { | |
193 | return [string range "abcdefghijklmnopqrstuvwxyz" $n $n] | |
194 | } | |
195 | ||
196 | proc I2A { n } { | |
197 | return [string toupper [i2a $n]] | |
198 | } | |
199 | ||
200 | ||
201 | # Use the file name, compiler and tuples to set up any needed KFAILs. | |
202 | ||
203 | proc setup_kfails { file tuples bug } { | |
204 | global testfile | |
205 | if [string match $file $testfile] { | |
206 | foreach f $tuples { setup_kfail $f $bug } | |
853d6e5b | 207 | } |
74cf1395 JM |
208 | } |
209 | ||
e53890ae AC |
210 | proc setup_compiler_kfails { file compiler format tuples bug } { |
211 | global testfile | |
212 | if {[string match $file $testfile] && [test_compiler_info $compiler] && [test_debug_format $format]} { | |
213 | foreach f $tuples { setup_kfail $f $bug } | |
214 | } | |
215 | } | |
216 | ||
217 | # Test GDB's ability to make inferior function calls to functions | |
218 | # returning (or passing in a single structs. | |
219 | ||
220 | # N identifies the number of elements in the struct that will be used | |
221 | # for the test case. FAILS is a list of target tuples that will fail | |
222 | # this test. | |
853d6e5b | 223 | |
e53890ae AC |
224 | # start_structs_test() will have previously built a program with a |
225 | # specified combination of types for those elements. To ensure | |
226 | # robustness of the output, "p/c" is used. | |
227 | ||
228 | # This tests the code paths "which return-value convention?" and | |
229 | # "extract return-value from registers" called by "infcall.c". | |
230 | ||
231 | proc test_struct_calls { n } { | |
232 | global testfile | |
b4967060 | 233 | global gdb_prompt |
853d6e5b | 234 | |
e53890ae AC |
235 | # Check that GDB can always extract a struct-return value from an |
236 | # inferior function call. Since GDB always knows the location of an | |
237 | # inferior function call's return value these should never fail | |
238 | ||
239 | # Implemented by calling the parameterless function "fun$N" and then | |
240 | # examining the return value printed by GDB. | |
853d6e5b | 241 | |
e53890ae | 242 | set tests "call $n ${testfile}" |
853d6e5b | 243 | |
e53890ae | 244 | # Call fun${n}, checking the printed return-value. |
338e05af AC |
245 | setup_compiler_kfails structs-tc-tll gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455 |
246 | setup_compiler_kfails structs-tc-td gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455 | |
e53890ae | 247 | gdb_test "p/c fun${n}()" "[foo ${n}]" "p/c fun<n>(); ${tests}" |
853d6e5b | 248 | |
e53890ae AC |
249 | # Check that GDB can always pass a structure to an inferior function. |
250 | # This test can never fail. | |
251 | ||
252 | # Implemented by calling the one parameter function "Fun$N" which | |
253 | # stores its parameter in the global variable "L$N". GDB then | |
254 | # examining that global to confirm that the value is as expected. | |
255 | ||
256 | gdb_test "call Fun${n}(foo${n})" "" "call Fun<n>(foo<n>); ${tests}" | |
338e05af AC |
257 | setup_compiler_kfails structs-tc-tll gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455 |
258 | setup_compiler_kfails structs-tc-td gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455 | |
e53890ae | 259 | gdb_test "p/c L${n}" [foo ${n}] "p/c L<n>; ${tests}" |
b4967060 | 260 | } |
853d6e5b | 261 | |
e53890ae AC |
262 | # Test GDB's ability to both return a function (with "return" or |
263 | # "finish") and correctly extract/store any corresponding | |
264 | # return-value. | |
265 | ||
266 | # Check that GDB can consistently extract/store structure return | |
267 | # values. There are two cases - returned in registers and returned in | |
268 | # memory. For the latter case, the return value can't be found and a | |
269 | # failure is "expected". However GDB must still both return the | |
270 | # function and display the final source and line information. | |
271 | ||
272 | # N identifies the number of elements in the struct that will be used | |
273 | # for the test case. FAILS is a list of target tuples that will fail | |
274 | # this test. | |
275 | ||
276 | # This tests the code paths "which return-value convention?", "extract | |
277 | # return-value from registers", and "store return-value in registers". | |
278 | # Unlike "test struct calls", this test is expected to "fail" when the | |
279 | # return-value is in memory (GDB can't find the location). The test | |
280 | # is in three parts: test "return"; test "finish"; check that the two | |
281 | # are consistent. GDB can sometimes work for one command and not the | |
282 | # other. | |
283 | ||
284 | proc test_struct_returns { n } { | |
285 | global gdb_prompt | |
286 | global testfile | |
287 | ||
288 | set tests "return $n ${testfile}" | |
289 | ||
290 | ||
291 | # Check that "return" works. | |
292 | ||
293 | # GDB must always force the return of a function that has | |
294 | # a struct result. Dependant on the ABI, it may, or may not be | |
295 | # possible to store the return value in a register. | |
296 | ||
297 | # The relevant code looks like "L{n} = fun{n}()". The test forces | |
298 | # "fun{n}" to "return" with an explicit value. Since that code | |
299 | # snippet will store the the returned value in "L{n}" the return | |
300 | # is tested by examining "L{n}". This assumes that the | |
301 | # compiler implemented this as fun{n}(&L{n}) and hence that when | |
302 | # the value isn't stored "L{n}" remains unchanged. Also check for | |
303 | # consistency between this and the "finish" case. | |
304 | ||
305 | # Get into a call of fun${n} | |
306 | gdb_test "advance fun${n}" \ | |
307 | "fun${n} .*\[\r\n\]+\[0-9\].*return foo${n}.*" \ | |
308 | "advance to fun<n> for return; ${tests}" | |
309 | ||
310 | # Check that the program invalidated the relevant global. | |
1bfbbb9d | 311 | gdb_test "p/c L${n}" " = [zed $n]" "zed L<n> for return; ${tests}" |
e53890ae AC |
312 | |
313 | # Force the "return". This checks that the return is always | |
314 | # performed, and that GDB correctly reported this to the user. | |
315 | # GDB 6.0 and earlier, when the return-value's location wasn't | |
316 | # known, both failed to print a final "source and line" and misplaced | |
317 | # the frame ("No frame"). | |
318 | ||
319 | # The test is writen so that it only reports one FAIL/PASS for the | |
320 | # entire operation. The value returned is checked further down. | |
b5c0bfa2 AC |
321 | # "return_value_known", if non-zero, indicates that GDB knew where |
322 | # the return value was located. | |
e53890ae | 323 | |
e53890ae | 324 | set test "return foo<n>; ${tests}" |
b5c0bfa2 | 325 | set return_value_known 1 |
5266b69c | 326 | set return_value_unimplemented 0 |
d422fe19 | 327 | gdb_test_multiple "return foo${n}" "${test}" { |
e53890ae AC |
328 | -re "The location" { |
329 | # Ulgh, a struct return, remember this (still need prompt). | |
b5c0bfa2 | 330 | set return_value_known 0 |
e53890ae AC |
331 | exp_continue |
332 | } | |
333 | -re "A structure or union" { | |
334 | # Ulgh, a struct return, remember this (still need prompt). | |
b5c0bfa2 | 335 | set return_value_known 0 |
5266b69c AC |
336 | # Double ulgh. Architecture doesn't use return_value and |
337 | # hence hasn't implemented small structure return. | |
338 | set return_value_unimplemented 1 | |
e53890ae AC |
339 | exp_continue |
340 | } | |
341 | -re "Make fun${n} return now.*y or n. $" { | |
d422fe19 | 342 | gdb_test_multiple "y" "${test}" { |
e53890ae AC |
343 | -re "L${n} *= fun${n}.*${gdb_prompt} $" { |
344 | # Need to step off the function call | |
345 | gdb_test "next" "L.* *= fun.*" "${test}" | |
346 | } | |
347 | -re "L[expr ${n} + 1] *= fun[expr ${n} + 1].*${gdb_prompt} $" { | |
348 | pass "${test}" | |
349 | } | |
e53890ae AC |
350 | } |
351 | } | |
e53890ae AC |
352 | } |
353 | ||
354 | # Check that the return-value is as expected. At this stage we're | |
355 | # just checking that GDB has returned a value consistent with | |
b5c0bfa2 | 356 | # "return_value_known" set above. |
987a9106 JB |
357 | # |
358 | # Note that, when return_value_known is false, we can't make any | |
359 | # assumptions at all about the value L<n>: | |
360 | # | |
361 | # - If the caller passed the address of L<n> directly as fun<n>'s | |
362 | # return value buffer, then L<n> will be unchanged, because we | |
363 | # forced fun<n> to return before it could store anything in it. | |
364 | # | |
365 | # - If the caller passed the address of some temporary buffer to | |
366 | # fun<n>, and then copied the buffer into L<n>, then L<n> will | |
367 | # have been overwritten with whatever garbage was in the | |
368 | # uninitialized buffer. | |
369 | # | |
370 | # - However, if the temporary buffer just happened to have the | |
371 | # "right" value of foo<n> in it, then L<n> will, in fact, have | |
372 | # the value you'd expect to see if the 'return' had worked! | |
373 | # This has actually been observed to happen on the Renesas M32C. | |
374 | # | |
375 | # So, really, anything is acceptable unless return_value_known is | |
376 | # true. | |
e53890ae | 377 | |
e53890ae | 378 | set test "value foo<n> returned; ${tests}" |
d422fe19 | 379 | gdb_test_multiple "p/c L${n}" "${test}" { |
e53890ae | 380 | -re " = [foo ${n}].*${gdb_prompt} $" { |
987a9106 JB |
381 | # This answer is okay regardless of whether GDB claims to |
382 | # have set the return value: if it did, then this is what | |
383 | # we expected; and if it didn't, then any answer is okay. | |
384 | pass "${test}" | |
e53890ae | 385 | } |
987a9106 | 386 | -re " = [any $n].*${gdb_prompt} $" { |
b5c0bfa2 AC |
387 | if $return_value_known { |
388 | # This contradicts the above claim that GDB knew | |
987a9106 | 389 | # the location of the return value. |
b5c0bfa2 AC |
390 | fail "${test}" |
391 | } else { | |
987a9106 JB |
392 | # We expected L${n} to be set to garbage, so any |
393 | # answer is acceptable. | |
e53890ae | 394 | pass "${test}" |
e53890ae AC |
395 | } |
396 | } | |
5266b69c AC |
397 | -re ".*${gdb_prompt} $" { |
398 | if $return_value_unimplemented { | |
399 | # What a suprize. The architecture hasn't implemented | |
400 | # return_value, and hence has to fail. | |
401 | kfail "$test" gdb/1444 | |
402 | } else { | |
403 | fail "$test" | |
404 | } | |
405 | } | |
e53890ae AC |
406 | } |
407 | ||
408 | # Check that a "finish" works. | |
409 | ||
410 | # This is almost but not quite the same as "call struct funcs". | |
411 | # Architectures can have subtle differences in the two code paths. | |
412 | ||
413 | # The relevant code snippet is "L{n} = fun{n}()". The program is | |
414 | # advanced into a call to "fun{n}" and then that function is | |
415 | # finished. The returned value that GDB prints, reformatted using | |
416 | # "p/c", is checked. | |
417 | ||
418 | # Get into "fun${n}()". | |
419 | gdb_test "advance fun${n}" \ | |
420 | "fun${n} .*\[\r\n\]+\[0-9\].*return foo${n}.*" \ | |
421 | "advance to fun<n> for finish; ${tests}" | |
422 | ||
423 | # Check that the program invalidated the relevant global. | |
e53890ae AC |
424 | gdb_test "p/c L${n}" " = [zed $n]" "zed L<n> for finish; ${tests}" |
425 | ||
b5c0bfa2 AC |
426 | # Finish the function, set 'finish_value_known" to non-empty if |
427 | # the return-value was found. | |
428 | ||
6882279b | 429 | set test "finish foo<n>; ${tests}" |
b5c0bfa2 | 430 | set finish_value_known 1 |
d422fe19 | 431 | gdb_test_multiple "finish" "${test}" { |
e53890ae AC |
432 | -re "Value returned is .*${gdb_prompt} $" { |
433 | pass "${test}" | |
434 | } | |
435 | -re "Cannot determine contents.*${gdb_prompt} $" { | |
436 | # Expected bad value. For the moment this is ok. | |
b5c0bfa2 | 437 | set finish_value_known 0 |
e53890ae AC |
438 | pass "${test}" |
439 | } | |
e53890ae AC |
440 | } |
441 | ||
442 | # Re-print the last (return-value) using the more robust | |
443 | # "p/c". If no return value was found, the 'Z' from the previous | |
444 | # check that the variable was cleared, is printed. | |
6882279b | 445 | set test "value foo<n> finished; ${tests}" |
d422fe19 | 446 | gdb_test_multiple "p/c" "${test}" { |
e53890ae | 447 | -re "[foo ${n}]\[\r\n\]+${gdb_prompt} $" { |
b5c0bfa2 AC |
448 | if $finish_value_known { |
449 | pass "${test}" | |
450 | } else { | |
e53890ae AC |
451 | # This contradicts the above claim that GDB didn't |
452 | # know the location of the return-value. | |
453 | fail "${test}" | |
e53890ae AC |
454 | } |
455 | } | |
456 | -re "[zed ${n}]\[\r\n\]+${gdb_prompt} $" { | |
457 | # The value didn't get found. This is "expected". | |
b5c0bfa2 | 458 | if $finish_value_known { |
e53890ae AC |
459 | # This contradicts the above claim that GDB did |
460 | # know the location of the return-value. | |
461 | fail "${test}" | |
b5c0bfa2 AC |
462 | } else { |
463 | pass "${test}" | |
e53890ae AC |
464 | } |
465 | } | |
e53890ae AC |
466 | } |
467 | ||
468 | # Finally, check that "return" and finish" have consistent | |
469 | # behavior. | |
470 | ||
b5c0bfa2 AC |
471 | # Since "finish" works in more cases than "return" (see |
472 | # RETURN_VALUE_ABI_RETURNS_ADDRESS and | |
473 | # RETURN_VALUE_ABI_PRESERVES_ADDRESS), the "return" value being | |
474 | # known implies that the "finish" value is known (but not the | |
475 | # reverse). | |
e53890ae | 476 | |
b5c0bfa2 AC |
477 | set test "return value known implies finish value known; ${tests}" |
478 | if {$return_value_known && ! $finish_value_known} { | |
e53890ae | 479 | kfail gdb/1444 "${test}" |
b5c0bfa2 AC |
480 | } else { |
481 | pass "${test}" | |
e53890ae | 482 | } |
b4967060 | 483 | } |
853d6e5b | 484 | |
e53890ae AC |
485 | # ABIs pass anything >8 or >16 bytes in memory but below that things |
486 | # randomly use register and/and structure conventions. Check all | |
487 | # possible sized char structs in that range. But only a restricted | |
488 | # range of the other types. | |
489 | ||
490 | # NetBSD/PPC returns "unnatural" (3, 5, 6, 7) sized structs in memory. | |
491 | ||
492 | # d10v is weird. 5/6 byte structs go in memory. 2 or more char | |
493 | # structs go in memory. Everything else is in a register! | |
494 | ||
495 | # Test every single char struct from 1..17 in size. This is what the | |
496 | # original "structs" test was doing. | |
497 | ||
498 | start_structs_test { tc } | |
499 | test_struct_calls 1 | |
500 | test_struct_calls 2 | |
501 | test_struct_calls 3 | |
502 | test_struct_calls 4 | |
503 | test_struct_calls 5 | |
504 | test_struct_calls 6 | |
505 | test_struct_calls 7 | |
506 | test_struct_calls 8 | |
507 | test_struct_calls 9 | |
508 | test_struct_calls 10 | |
509 | test_struct_calls 11 | |
510 | test_struct_calls 12 | |
511 | test_struct_calls 13 | |
512 | test_struct_calls 14 | |
513 | test_struct_calls 15 | |
514 | test_struct_calls 16 | |
515 | test_struct_calls 17 | |
516 | test_struct_returns 1 | |
517 | test_struct_returns 2 | |
518 | test_struct_returns 3 | |
519 | test_struct_returns 4 | |
520 | test_struct_returns 5 | |
521 | test_struct_returns 6 | |
522 | test_struct_returns 7 | |
523 | test_struct_returns 8 | |
524 | ||
525 | ||
526 | # Let the fun begin. | |
527 | ||
528 | # Assuming that any integer struct larger than 8 bytes goes in memory, | |
529 | # come up with many and varied combinations of a return struct. For | |
530 | # "struct calls" test just beyond that 8 byte boundary, for "struct | |
531 | # returns" test up to that boundary. | |
532 | ||
533 | # For floats, assumed that up to two struct elements can be stored in | |
534 | # floating point registers, regardless of their size. | |
535 | ||
536 | # The approx size of each structure it is computed assumed that tc=1, | |
537 | # ts=2, ti=4, tl=4, tll=8, tf=4, td=8, tld=16, and that all fields are | |
538 | # naturally aligned. Padding being added where needed. Note that | |
539 | # these numbers are just approx, the d10v has ti=2, a 64-bit has has | |
540 | # tl=8. | |
541 | ||
542 | # Approx size: 2, 4, ... | |
543 | start_structs_test { ts } | |
544 | test_struct_calls 1 | |
545 | test_struct_calls 2 | |
546 | test_struct_calls 3 | |
547 | test_struct_calls 4 | |
548 | test_struct_calls 5 | |
549 | test_struct_returns 1 | |
550 | test_struct_returns 2 | |
551 | test_struct_returns 3 | |
552 | test_struct_returns 4 | |
553 | ||
554 | # Approx size: 4, 8, ... | |
555 | start_structs_test { ti } | |
556 | test_struct_calls 1 | |
557 | test_struct_calls 2 | |
558 | test_struct_calls 3 | |
559 | test_struct_returns 1 | |
560 | test_struct_returns 2 | |
561 | ||
562 | # Approx size: 4, 8, ... | |
563 | start_structs_test { tl } | |
564 | test_struct_calls 1 | |
565 | test_struct_calls 2 | |
566 | test_struct_calls 3 | |
567 | test_struct_returns 1 | |
568 | test_struct_returns 2 | |
569 | ||
570 | # Approx size: 8, 16, ... | |
571 | start_structs_test { tll } | |
572 | test_struct_calls 1 | |
573 | test_struct_calls 2 | |
574 | test_struct_returns 1 | |
575 | ||
576 | # Approx size: 4, 8, ... | |
577 | start_structs_test { tf } | |
578 | test_struct_calls 1 | |
579 | test_struct_calls 2 | |
580 | test_struct_calls 3 | |
581 | test_struct_returns 1 | |
582 | test_struct_returns 2 | |
583 | ||
584 | # Approx size: 8, 16, ... | |
585 | start_structs_test { td } | |
586 | test_struct_calls 1 | |
587 | test_struct_calls 2 | |
588 | test_struct_returns 1 | |
589 | ||
590 | # Approx size: 16, 32, ... | |
591 | start_structs_test { tld } | |
592 | test_struct_calls 1 | |
593 | test_struct_calls 2 | |
594 | test_struct_returns 1 | |
595 | ||
596 | # Approx size: 2+1=3, 4, ... | |
597 | start_structs_test { ts tc } | |
598 | test_struct_calls 2 | |
599 | test_struct_calls 3 | |
600 | test_struct_calls 4 | |
601 | test_struct_calls 5 | |
602 | test_struct_calls 6 | |
603 | test_struct_calls 7 | |
604 | test_struct_calls 8 | |
605 | test_struct_returns 2 | |
606 | ||
607 | # Approx size: 4+1=5, 6, ... | |
608 | start_structs_test { ti tc } | |
609 | test_struct_calls 2 | |
610 | test_struct_calls 3 | |
611 | test_struct_calls 4 | |
612 | test_struct_calls 5 | |
613 | test_struct_calls 6 | |
614 | test_struct_returns 2 | |
615 | ||
616 | # Approx size: 4+1=5, 6, ... | |
617 | start_structs_test { tl tc } | |
618 | test_struct_calls 2 | |
619 | test_struct_calls 3 | |
620 | test_struct_calls 4 | |
621 | test_struct_calls 5 | |
622 | test_struct_calls 6 | |
623 | test_struct_returns 2 | |
624 | ||
625 | # Approx size: 8+1=9, 10, ... | |
626 | start_structs_test { tll tc } | |
627 | test_struct_calls 2 | |
628 | ||
629 | # Approx size: 4+1=5, 6, ... | |
630 | start_structs_test { tf tc } | |
631 | test_struct_calls 2 | |
632 | test_struct_calls 3 | |
633 | test_struct_calls 4 | |
634 | test_struct_calls 5 | |
635 | test_struct_calls 6 | |
636 | test_struct_returns 2 | |
637 | ||
638 | # Approx size: 8+1=9, 10, ... | |
639 | start_structs_test { td tc } | |
640 | test_struct_calls 2 | |
641 | ||
642 | # Approx size: 16+1=17, 18, ... | |
643 | start_structs_test { tld tc } | |
644 | test_struct_calls 2 | |
645 | ||
646 | # Approx size: (1+1)+2=4, 6, ... | |
647 | start_structs_test { tc ts } | |
648 | test_struct_calls 2 | |
649 | test_struct_calls 3 | |
650 | test_struct_calls 4 | |
651 | test_struct_calls 5 | |
652 | test_struct_calls 6 | |
653 | test_struct_returns 2 | |
654 | ||
655 | # Approx size: (1+3)+4=8, 12, ... | |
656 | start_structs_test { tc ti } | |
657 | test_struct_calls 2 | |
658 | test_struct_calls 3 | |
659 | test_struct_calls 4 | |
660 | test_struct_returns 2 | |
661 | ||
662 | # Approx size: (1+3)+4=8, 12, ... | |
663 | start_structs_test { tc tl } | |
664 | test_struct_calls 2 | |
665 | test_struct_calls 3 | |
666 | test_struct_calls 4 | |
667 | test_struct_returns 2 | |
668 | ||
669 | # Approx size: (1+7)+8=16, 24, ... | |
670 | start_structs_test { tc tll } | |
671 | test_struct_calls 2 | |
672 | ||
673 | # Approx size: (1+3)+4=8, 12, ... | |
674 | start_structs_test { tc tf } | |
675 | test_struct_calls 2 | |
676 | test_struct_calls 3 | |
677 | test_struct_calls 4 | |
678 | ||
679 | # Approx size: (1+7)+8=16, 24, ... | |
680 | start_structs_test { tc td } | |
681 | test_struct_calls 2 | |
682 | ||
683 | # Approx size: (1+15)+16=32, 48, ... | |
684 | start_structs_test { tc tld } | |
685 | test_struct_calls 2 | |
686 | ||
687 | # Some float combinations | |
688 | ||
689 | # Approx size: 8+4=12, 16, ... | |
690 | # d10v: 4+4=8, 12, ... | |
691 | start_structs_test { td tf } | |
692 | test_struct_calls 2 | |
693 | test_struct_returns 2 | |
74cf1395 | 694 | |
e53890ae AC |
695 | # Approx size: (4+4)+8=16, 32, ... |
696 | # d10v: 4+4=8, 12, ... | |
697 | start_structs_test { tf td } | |
698 | test_struct_calls 2 | |
699 | test_struct_returns 2 | |
74cf1395 JM |
700 | |
701 | return 0 |