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