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