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