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