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