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