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