From e53890ae03ca5fa04f101c032cbc9341a6cca949 Mon Sep 17 00:00:00 2001 From: Andrew Cagney Date: Thu, 20 Nov 2003 17:11:55 +0000 Subject: 2003-11-20 Andrew Cagney * gdb.base/structs.exp: Update copyright. Rewrite. * gdb.base/structs.c: Update copyright. Rewrite. --- gdb/testsuite/gdb.base/structs.exp | 748 +++++++++++++++++++++++++++++++------ 1 file changed, 635 insertions(+), 113 deletions(-) (limited to 'gdb/testsuite/gdb.base/structs.exp') diff --git a/gdb/testsuite/gdb.base/structs.exp b/gdb/testsuite/gdb.base/structs.exp index ed91c86..0e89fc6 100644 --- a/gdb/testsuite/gdb.base/structs.exp +++ b/gdb/testsuite/gdb.base/structs.exp @@ -1,4 +1,6 @@ -# Copyright 1996, 1997, 1999 Free Software Foundation, Inc. +# This testcase is part of GDB, the GNU debugger. + +# Copyright 1996, 1997, 1999, 2003 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,8 +19,6 @@ # Please email any bugs, comments, and/or additions to this file to: # bug-gdb@prep.ai.mit.edu -# This file was written by Jeff Law. (law@cygnus.com) - if $tracelevel then { strace $tracelevel } @@ -26,142 +26,664 @@ if $tracelevel then { set prms_id 0 set bug_id 0 -set prototypes 1 +# Some targets can't call functions, so don't even bother with this +# test. + +if [target_info exists gdb,cannot_call_functions] { + setup_xfail "*-*-*" + fail "This target can not call functions" + continue +} + set testfile "structs" set srcfile ${testfile}.c set binfile ${objdir}/${subdir}/${testfile} -# build the first test case -if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { - # built the second test case since we can't use prototypes - warning "Prototypes not supported, rebuilding with -DNO_PROTOTYPES" -if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DNO_PROTOTYPES}] != "" } { - gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." - } - set prototypes 0 -} +# Create and source the file that provides information about the +# compiler used to compile the test case. -# Create and source the file that provides information about the compiler -# used to compile the test case. if [get_compiler_info ${binfile}] { return -1; } +# Compile a variant of structs.c using TYPES to specify the type of +# the first N struct elements (the remaining elements take the type of +# the last TYPES field). Run the compmiled program up to "main". +# Also updates the global "testfile" to reflect the most recent build. -# Some targets can't call functions, so don't even bother with this -# test. -if [target_info exists gdb,cannot_call_functions] { - setup_xfail "*-*-*" 2416 - fail "This target can not call functions" - continue +proc start_structs_test { types } { + global testfile + global srcfile + global binfile + global objdir + global subdir + global srcdir + global gdb_prompt + + # Create the additional flags + set flags "debug" + set testfile "structs" + set n 0 + for {set n 0} {$n<[llength ${types}]} {incr n} { + set m [I2A ${n}] + set t [lindex ${types} $n] + lappend flags "additional_flags=-Dt${m}=${t}" + append testfile "-" "$t" + } + + set binfile ${objdir}/${subdir}/${testfile} + if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "${flags}"] != "" } { + # built the second test case since we can't use prototypes + warning "Prototypes not supported, rebuilding with -DNO_PROTOTYPES" + if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "${flags} additional_flags=-DNO_PROTOTYPES"] != "" } { + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." + } + } + + # Start with a fresh gdb. + gdb_start + gdb_reinitialize_dir $srcdir/$subdir + gdb_load ${binfile} + + # Make certain that the output is consistent + gdb_test "set print sevenbit-strings" "" \ + "set print sevenbit-strings; ${testfile}" + gdb_test "set print address off" "" \ + "set print address off; ${testfile}" + gdb_test "set width 0" "" \ + "set width 0; ${testfile}" + + # Advance to main + if { ![runto_main] } then { + gdb_suppress_tests; + } + + # check that at the struct containing all the relevant types is correct + set foo_t "type = struct struct[llength ${types}] \{" + for {set n 0} {$n<[llength ${types}]} {incr n} { + append foo_t "\[\r\n \]+[lindex ${types} $n] [i2a $n];" + } + append foo_t "\[\r\n \]+\}" + gdb_test "ptype foo[llength ${types}]" "${foo_t}" \ + "ptype foo[llength ${types}]; ${testfile}" } +# The expected value for fun${n}, L${n} and foo${n}. First element is +# empty to make indexing easier. "foo" returns the modified value, +# "zed" returns the invalid value. -# Call FUNC with no arguments, and expect to see the regexp RESULT in -# the output. If we get back the error message "Function return value -# unknown", call that an unsupported test; on some architectures, it's -# impossible to find structs returned by value reliably. -proc call_struct_func { func result } { - global gdb_prompt - - set command "p ${func}()" - send_gdb "${command}\n" - gdb_expect { - -re "$result\[\r\n\]+$gdb_prompt $" { - pass "$command" - } - -re "Function return value unknown.\[\r\n\]+$gdb_prompt $" { - unsupported "$command" - } - -re "$gdb_prompt $" { - fail "$command" - } - timeout { - fail "$command (timeout)" - } +proc foo { n } { + return [lindex { + "{}" + "{a = 49 '1'}" + "{a = 97 'a', b = 50 '2'}" + "{a = 49 '1', b = 98 'b', c = 51 '3'}" + "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4'}" + "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5'}" + "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4', e = 101 'e', f = 54 '6'}" + "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7'}" + "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8'}" + "{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'}" + "{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'}" + "{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'}" + "{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'}" + "{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'}" + "{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'}" + "{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'}" + "{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'}" + "{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'}" + } $n] +} + +proc zed { n } { + return [lindex { + "{}" + "{a = 90 'Z'}" + "{a = 90 'Z', b = 90 'Z'}" + "{a = 90 'Z', b = 90 'Z', c = 90 'Z'}" + "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z'}" + "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z'}" + "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z'}" + "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z'}" + "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z'}" + "{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'}" + "{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'}" + "{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'}" + "{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'}" + "{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'}" + "{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'}" + "{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'}" + "{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'}" + "{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'}" + } $n] +} + +# Given N (0..25), return the corresponding alphabetic letter in lower +# or upper case. This is ment to be i18n proof. + +proc i2a { n } { + return [string range "abcdefghijklmnopqrstuvwxyz" $n $n] +} + +proc I2A { n } { + return [string toupper [i2a $n]] +} + + +# Use the file name, compiler and tuples to set up any needed KFAILs. + +proc setup_kfails { file tuples bug } { + global testfile + if [string match $file $testfile] { + foreach f $tuples { setup_kfail $f $bug } } } -# FIXME: Before calling this proc, we should probably verify that -# we can call inferior functions and get a valid integral value -# returned. -# Note that it is OK to check for 0 or 1 as the returned values, because C -# specifies that the numeric value of a relational or logical expression -# (computed in the inferior) is 1 for true and 0 for false. +proc setup_compiler_kfails { file compiler format tuples bug } { + global testfile + if {[string match $file $testfile] && [test_compiler_info $compiler] && [test_debug_format $format]} { + foreach f $tuples { setup_kfail $f $bug } + } +} + +# Test GDB's ability to make inferior function calls to functions +# returning (or passing in a single structs. + +# N identifies the number of elements in the struct that will be used +# for the test case. FAILS is a list of target tuples that will fail +# this test. -proc do_function_calls {} { - global prototypes - global gcc_compiled +# start_structs_test() will have previously built a program with a +# specified combination of types for those elements. To ensure +# robustness of the output, "p/c" is used. + +# This tests the code paths "which return-value convention?" and +# "extract return-value from registers" called by "infcall.c". + +proc test_struct_calls { n } { + global testfile global gdb_prompt - # First, call the "fun" functions and examine the value they return. - call_struct_func "fun1" " = {a = 49 '1'}" - call_struct_func "fun2" " = {a = 97 'a', b = 98 'b'}" - call_struct_func "fun3" " = {a = 65 'A', b = 66 'B', c = 67 'C'}" - call_struct_func "fun4" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4'}" - call_struct_func "fun5" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e'}" - call_struct_func "fun6" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F'}" - call_struct_func "fun7" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4', e = 53 '5', f = 54 '6', g = 55 '7'}" - call_struct_func "fun8" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4', e = 53 '5', f = 54 '6', g = 55 '7', h = 56 '8'}" - call_struct_func "fun9" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e', f = 102 'f', g = 103 'g', h = 104 'h', i = 105 'i'}" - call_struct_func "fun10" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F', g = 71 'G', h = 72 'H', i = 73 'I', j = 74 'J'}" - call_struct_func "fun11" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4', e = 53 '5', f = 54 '6', g = 55 '7', h = 56 '8', i = 57 '9', j = 65 'A', k = 66 'B'}" - call_struct_func "fun12" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F', g = 71 'G', h = 72 'H', i = 73 'I', j = 74 'J', k = 75 'K', l = 76 'L'}" - call_struct_func "fun16" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e', f = 102 'f', g = 103 'g', h = 104 'h', i = 105 'i', j = 106 'j', k = 107 'k', l = 108 'l', m = 109 'm', n = 110 'n', o = 111 'o', p = 112 'p'}" - - # Now call the Fun functions to set the L* variables. This - # tests that gdb properly passes structures to functions. - gdb_test "p Fun1(foo1)" " = (void|0)" - gdb_test "p Fun2(foo2)" " = (void|0)" - gdb_test "p Fun3(foo3)" " = (void|0)" - gdb_test "p Fun4(foo4)" " = (void|0)" - gdb_test "p Fun5(foo5)" " = (void|0)" - gdb_test "p Fun6(foo6)" " = (void|0)" - gdb_test "p Fun7(foo7)" " = (void|0)" - gdb_test "p Fun8(foo8)" " = (void|0)" - gdb_test "p Fun9(foo9)" " = (void|0)" - gdb_test "p Fun10(foo10)" " = (void|0)" - gdb_test "p Fun11(foo11)" " = (void|0)" - gdb_test "p Fun12(foo12)" " = (void|0)" - gdb_test "p Fun16(foo16)" " = (void|0)" - - # Now print the L* variables and examine their values. - gdb_test "p L1" " = {a = 49 '1'}" - gdb_test "p L2" " = {a = 97 'a', b = 98 'b'}" - gdb_test "p L3" " = {a = 65 'A', b = 66 'B', c = 67 'C'}" - gdb_test "p L4" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4'}" - gdb_test "p L5" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e'}" - gdb_test "p L6" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F'}" - gdb_test "p L7" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4', e = 53 '5', f = 54 '6', g = 55 '7'}" - gdb_test "p L8" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4', e = 53 '5', f = 54 '6', g = 55 '7', h = 56 '8'}" - gdb_test "p L9" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e', f = 102 'f', g = 103 'g', h = 104 'h', i = 105 'i'}" - gdb_test "p L10" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F', g = 71 'G', h = 72 'H', i = 73 'I', j = 74 'J'}" - gdb_test "p L11" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4', e = 53 '5', f = 54 '6', g = 55 '7', h = 56 '8', i = 57 '9', j = 65 'A', k = 66 'B'}" - gdb_test "p L12" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F', g = 71 'G', h = 72 'H', i = 73 'I', j = 74 'J', k = 75 'K', l = 76 'L'}" - gdb_test "p L16" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e', f = 102 'f', g = 103 'g', h = 104 'h', i = 105 'i', j = 106 'j', k = 107 'k', l = 108 'l', m = 109 'm', n = 110 'n', o = 111 'o', p = 112 'p'}" -} -# Start with a fresh gdb. + # Check that GDB can always extract a struct-return value from an + # inferior function call. Since GDB always knows the location of an + # inferior function call's return value these should never fail + + # Implemented by calling the parameterless function "fun$N" and then + # examining the return value printed by GDB. -gdb_start -gdb_reinitialize_dir $srcdir/$subdir -gdb_load ${binfile} + set tests "call $n ${testfile}" -gdb_test "set print sevenbit-strings" "" -gdb_test "set print address off" "" -gdb_test "set width 0" "" + # Call fun${n}, checking the printed return-value. + setup_kfails structs-*tld* i686-*-* gdb/1447 + setup_compiler_kfails structs-tc-* gcc-3-3 "DWARF 2" i686-*-* gdb/1455 + gdb_test "p/c fun${n}()" "[foo ${n}]" "p/c fun(); ${tests}" -if [target_info exists gdb,cannot_call_functions] { - setup_xfail "*-*-*" 2416 - fail "This target can not call functions" - return 0 + # Check that GDB can always pass a structure to an inferior function. + # This test can never fail. + + # Implemented by calling the one parameter function "Fun$N" which + # stores its parameter in the global variable "L$N". GDB then + # examining that global to confirm that the value is as expected. + + gdb_test "call Fun${n}(foo${n})" "" "call Fun(foo); ${tests}" + setup_kfails structs-*tld* i686-*-* gdb/1447 + setup_compiler_kfails structs-tc-* gcc-3-3 "DWARF 2" i686-*-* gdb/1455 + gdb_test "p/c L${n}" [foo ${n}] "p/c L; ${tests}" } -if { ![runto_main] } then { - gdb_suppress_tests; +# Test GDB's ability to both return a function (with "return" or +# "finish") and correctly extract/store any corresponding +# return-value. + +# Check that GDB can consistently extract/store structure return +# values. There are two cases - returned in registers and returned in +# memory. For the latter case, the return value can't be found and a +# failure is "expected". However GDB must still both return the +# function and display the final source and line information. + +# N identifies the number of elements in the struct that will be used +# for the test case. FAILS is a list of target tuples that will fail +# this test. + +# This tests the code paths "which return-value convention?", "extract +# return-value from registers", and "store return-value in registers". +# Unlike "test struct calls", this test is expected to "fail" when the +# return-value is in memory (GDB can't find the location). The test +# is in three parts: test "return"; test "finish"; check that the two +# are consistent. GDB can sometimes work for one command and not the +# other. + +proc test_struct_returns { n } { + global gdb_prompt + global testfile + + set tests "return $n ${testfile}" + + + # Check that "return" works. + + # GDB must always force the return of a function that has + # a struct result. Dependant on the ABI, it may, or may not be + # possible to store the return value in a register. + + # The relevant code looks like "L{n} = fun{n}()". The test forces + # "fun{n}" to "return" with an explicit value. Since that code + # snippet will store the the returned value in "L{n}" the return + # is tested by examining "L{n}". This assumes that the + # compiler implemented this as fun{n}(&L{n}) and hence that when + # the value isn't stored "L{n}" remains unchanged. Also check for + # consistency between this and the "finish" case. + + # Get into a call of fun${n} + gdb_test "advance fun${n}" \ + "fun${n} .*\[\r\n\]+\[0-9\].*return foo${n}.*" \ + "advance to fun for return; ${tests}" + + # Check that the program invalidated the relevant global. + setup_kfails structs-tld i686-*-* gdb/1447 + gdb_test "p/c L${n}" " = [zed $n]" "zed L for return; ${tests} .${testfile}." + + # Force the "return". This checks that the return is always + # performed, and that GDB correctly reported this to the user. + # GDB 6.0 and earlier, when the return-value's location wasn't + # known, both failed to print a final "source and line" and misplaced + # the frame ("No frame"). + + # The test is writen so that it only reports one FAIL/PASS for the + # entire operation. The value returned is checked further down. + # "return_value_unknown", if non-empty, records why GDB realised + # that it didn't know where the return value was. + + send_gdb "return foo${n}\n" + set test "return foo; ${tests}" + set return_value_unknown 0 + gdb_expect { + -re "The location" { + # Ulgh, a struct return, remember this (still need prompt). + set return_value_unknown 1 + exp_continue + } + -re "A structure or union" { + # Ulgh, a struct return, remember this (still need prompt). + # Set it to something unique so that it won't match a + # struct return convention value. + # set return_value_unknown -1 + set return_value_unknown 1 + exp_continue + } + -re "Make fun${n} return now.*y or n. $" { + send_gdb "y\n" + gdb_expect { + -re "L${n} *= fun${n}.*${gdb_prompt} $" { + # Need to step off the function call + gdb_test "next" "L.* *= fun.*" "${test}" + } + -re "L[expr ${n} + 1] *= fun[expr ${n} + 1].*${gdb_prompt} $" { + pass "${test}" + } + timeout { + fail "${test} (timeout 2)" + } + } + } + -re "${gdb_prompt} $" { + fail "${test} (no query)" + } + timeout { + fail "${test} (timeout 1)" + } + } + + # Check that the return-value is as expected. At this stage we're + # just checking that GDB has returned a value consistent with + # "return_value_unknown" set above. + + send_gdb "p/c L${n}\n" + set test "value foo returned; ${tests}" + setup_kfails structs-*tld* i686-*-* gdb/1447 + gdb_expect { + -re " = [foo ${n}].*${gdb_prompt} $" { + if $return_value_unknown { + # This contradicts the above claim that GDB didn't + # know the location of the return-value. + fail "${test}" + } else { + pass "${test}" + } + } + -re " = [zed ${n}].*${gdb_prompt} $" { + if $return_value_unknown { + # The struct return case. Since any modification + # would be by reference, and that can't happen, the + # value should be unmodified and hence Z is expected. + # Is this a reasonable assumption? + pass "${test}" + } else { + # This contradicts the above claim that GDB knew + # the location of the return-value. + fail "${test}" + } + } + -re "${gdb_prompt} $" { + # Garbage returned, garbage printed + fail "${test}" + } + timeout { + fail "${test} (timeout)" + } + } + + # Check that a "finish" works. + + # This is almost but not quite the same as "call struct funcs". + # Architectures can have subtle differences in the two code paths. + + # The relevant code snippet is "L{n} = fun{n}()". The program is + # advanced into a call to "fun{n}" and then that function is + # finished. The returned value that GDB prints, reformatted using + # "p/c", is checked. + + # Get into "fun${n}()". + gdb_test "advance fun${n}" \ + "fun${n} .*\[\r\n\]+\[0-9\].*return foo${n}.*" \ + "advance to fun for finish; ${tests}" + + # Check that the program invalidated the relevant global. + setup_kfails structs-tld i686-*-* gdb/1447 + gdb_test "p/c L${n}" " = [zed $n]" "zed L for finish; ${tests}" + + # Finish the function, set 'finish_value_unknown" to non-empty if the + # return-value was not found. + send_gdb "finish\n" + set test "finish foo${n}; ${tests}" + set finish_value_unknown 0 + gdb_expect { + -re "Value returned is .*${gdb_prompt} $" { + pass "${test}" + } + -re "Cannot determine contents.*${gdb_prompt} $" { + # Expected bad value. For the moment this is ok. + set finish_value_unknown 1 + pass "${test}" + } + -re ".*${gdb_prompt} $" { + # Garbage returned + fail "${test}" + } + timeout { + fail "${test} (timeout)" + } + } + + # Re-print the last (return-value) using the more robust + # "p/c". If no return value was found, the 'Z' from the previous + # check that the variable was cleared, is printed. + send_gdb "p/c\n" + set test "value foo${n} finished; ${tests}" + setup_kfails structs-*tld* i686-*-* gdb/1447 + gdb_expect { + -re "[foo ${n}]\[\r\n\]+${gdb_prompt} $" { + if $finish_value_unknown { + # This contradicts the above claim that GDB didn't + # know the location of the return-value. + fail "${test}" + } else { + pass "${test}" + } + } + -re "[zed ${n}]\[\r\n\]+${gdb_prompt} $" { + # The value didn't get found. This is "expected". + if $finish_value_unknown { + pass "${test}" + } else { + # This contradicts the above claim that GDB did + # know the location of the return-value. + fail "${test}" + } + } + -re ".*${gdb_prompt} $" { + # Garbage returned + fail "${test}" + } + timeout { + fail "${test} (timeout)" + } + } + + # Finally, check that "return" and finish" have consistent + # behavior. + + # Since both "return" and "finish" use equivalent "which + # return-value convention" logic, both commands should have + # identical can/can-not find return-value messages. + + # Note that since "call" and "finish" use common code paths, a + # failure here is a strong indicator of problems with "store + # return-value" code paths. Suggest looking at "return_value" + # when investigating a fix. + + set test "return and finish use same convention; ${tests}" + if {$finish_value_unknown == $return_value_unknown} { + pass "${test}" + } else { + kfail gdb/1444 "${test}" + } } -do_function_calls; +# ABIs pass anything >8 or >16 bytes in memory but below that things +# randomly use register and/and structure conventions. Check all +# possible sized char structs in that range. But only a restricted +# range of the other types. + +# NetBSD/PPC returns "unnatural" (3, 5, 6, 7) sized structs in memory. + +# d10v is weird. 5/6 byte structs go in memory. 2 or more char +# structs go in memory. Everything else is in a register! + +# Test every single char struct from 1..17 in size. This is what the +# original "structs" test was doing. + +start_structs_test { tc } +test_struct_calls 1 +test_struct_calls 2 +test_struct_calls 3 +test_struct_calls 4 +test_struct_calls 5 +test_struct_calls 6 +test_struct_calls 7 +test_struct_calls 8 +test_struct_calls 9 +test_struct_calls 10 +test_struct_calls 11 +test_struct_calls 12 +test_struct_calls 13 +test_struct_calls 14 +test_struct_calls 15 +test_struct_calls 16 +test_struct_calls 17 +test_struct_returns 1 +test_struct_returns 2 +test_struct_returns 3 +test_struct_returns 4 +test_struct_returns 5 +test_struct_returns 6 +test_struct_returns 7 +test_struct_returns 8 + + +# Let the fun begin. + +# Assuming that any integer struct larger than 8 bytes goes in memory, +# come up with many and varied combinations of a return struct. For +# "struct calls" test just beyond that 8 byte boundary, for "struct +# returns" test up to that boundary. + +# For floats, assumed that up to two struct elements can be stored in +# floating point registers, regardless of their size. + +# The approx size of each structure it is computed assumed that tc=1, +# ts=2, ti=4, tl=4, tll=8, tf=4, td=8, tld=16, and that all fields are +# naturally aligned. Padding being added where needed. Note that +# these numbers are just approx, the d10v has ti=2, a 64-bit has has +# tl=8. + +# Approx size: 2, 4, ... +start_structs_test { ts } +test_struct_calls 1 +test_struct_calls 2 +test_struct_calls 3 +test_struct_calls 4 +test_struct_calls 5 +test_struct_returns 1 +test_struct_returns 2 +test_struct_returns 3 +test_struct_returns 4 + +# Approx size: 4, 8, ... +start_structs_test { ti } +test_struct_calls 1 +test_struct_calls 2 +test_struct_calls 3 +test_struct_returns 1 +test_struct_returns 2 + +# Approx size: 4, 8, ... +start_structs_test { tl } +test_struct_calls 1 +test_struct_calls 2 +test_struct_calls 3 +test_struct_returns 1 +test_struct_returns 2 + +# Approx size: 8, 16, ... +start_structs_test { tll } +test_struct_calls 1 +test_struct_calls 2 +test_struct_returns 1 + +# Approx size: 4, 8, ... +start_structs_test { tf } +test_struct_calls 1 +test_struct_calls 2 +test_struct_calls 3 +test_struct_returns 1 +test_struct_returns 2 + +# Approx size: 8, 16, ... +start_structs_test { td } +test_struct_calls 1 +test_struct_calls 2 +test_struct_returns 1 + +# Approx size: 16, 32, ... +start_structs_test { tld } +test_struct_calls 1 +test_struct_calls 2 +test_struct_returns 1 + +# Approx size: 2+1=3, 4, ... +start_structs_test { ts tc } +test_struct_calls 2 +test_struct_calls 3 +test_struct_calls 4 +test_struct_calls 5 +test_struct_calls 6 +test_struct_calls 7 +test_struct_calls 8 +test_struct_returns 2 + +# Approx size: 4+1=5, 6, ... +start_structs_test { ti tc } +test_struct_calls 2 +test_struct_calls 3 +test_struct_calls 4 +test_struct_calls 5 +test_struct_calls 6 +test_struct_returns 2 + +# Approx size: 4+1=5, 6, ... +start_structs_test { tl tc } +test_struct_calls 2 +test_struct_calls 3 +test_struct_calls 4 +test_struct_calls 5 +test_struct_calls 6 +test_struct_returns 2 + +# Approx size: 8+1=9, 10, ... +start_structs_test { tll tc } +test_struct_calls 2 + +# Approx size: 4+1=5, 6, ... +start_structs_test { tf tc } +test_struct_calls 2 +test_struct_calls 3 +test_struct_calls 4 +test_struct_calls 5 +test_struct_calls 6 +test_struct_returns 2 + +# Approx size: 8+1=9, 10, ... +start_structs_test { td tc } +test_struct_calls 2 + +# Approx size: 16+1=17, 18, ... +start_structs_test { tld tc } +test_struct_calls 2 + +# Approx size: (1+1)+2=4, 6, ... +start_structs_test { tc ts } +test_struct_calls 2 +test_struct_calls 3 +test_struct_calls 4 +test_struct_calls 5 +test_struct_calls 6 +test_struct_returns 2 + +# Approx size: (1+3)+4=8, 12, ... +start_structs_test { tc ti } +test_struct_calls 2 +test_struct_calls 3 +test_struct_calls 4 +test_struct_returns 2 + +# Approx size: (1+3)+4=8, 12, ... +start_structs_test { tc tl } +test_struct_calls 2 +test_struct_calls 3 +test_struct_calls 4 +test_struct_returns 2 + +# Approx size: (1+7)+8=16, 24, ... +start_structs_test { tc tll } +test_struct_calls 2 + +# Approx size: (1+3)+4=8, 12, ... +start_structs_test { tc tf } +test_struct_calls 2 +test_struct_calls 3 +test_struct_calls 4 + +# Approx size: (1+7)+8=16, 24, ... +start_structs_test { tc td } +test_struct_calls 2 + +# Approx size: (1+15)+16=32, 48, ... +start_structs_test { tc tld } +test_struct_calls 2 + +# Some float combinations + +# Approx size: 8+4=12, 16, ... +# d10v: 4+4=8, 12, ... +start_structs_test { td tf } +test_struct_calls 2 +test_struct_returns 2 -gdb_stop_suppressing_tests; +# Approx size: (4+4)+8=16, 32, ... +# d10v: 4+4=8, 12, ... +start_structs_test { tf td } +test_struct_calls 2 +test_struct_returns 2 return 0 -- cgit v1.1