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