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