diff options
author | Jeff Law <law@redhat.com> | 1996-08-09 16:38:19 +0000 |
---|---|---|
committer | Jeff Law <law@redhat.com> | 1996-08-09 16:38:19 +0000 |
commit | bd3bab1eed665fb2d8053a8d3043824959cb599f (patch) | |
tree | 4530fb7d11c63052d097d24e6bbfc0b803fca184 | |
parent | 46b6fdbd1166730455bff6b74718bbee8793c9c6 (diff) | |
download | fsf-binutils-gdb-bd3bab1eed665fb2d8053a8d3043824959cb599f.zip fsf-binutils-gdb-bd3bab1eed665fb2d8053a8d3043824959cb599f.tar.gz fsf-binutils-gdb-bd3bab1eed665fb2d8053a8d3043824959cb599f.tar.bz2 |
* gdb.base/structs.exp: New tests for passing and returning
structures.
* gdb.base/structs.c: C source for test.
Sanitized away until we've got a valid copyright assignment from
Michael Snyder.
Only tested on the PA. I assume other ports will needs some xfails
and other possible testsuite tweakage.
-rw-r--r-- | gdb/testsuite/gdb.base/.Sanitize | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/structs.c | 207 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/structs.exp | 153 |
3 files changed, 362 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.base/.Sanitize b/gdb/testsuite/gdb.base/.Sanitize index ba0503c..0cb57ec 100644 --- a/gdb/testsuite/gdb.base/.Sanitize +++ b/gdb/testsuite/gdb.base/.Sanitize @@ -104,6 +104,8 @@ whatis.c whatis.exp Things-to-lose: +structs.c +structs.exp # The lines between the "Do-last:" line and the end of the file # are executed as a /bin/sh shell script after everything else is diff --git a/gdb/testsuite/gdb.base/structs.c b/gdb/testsuite/gdb.base/structs.c new file mode 100644 index 0000000..fcb9d72 --- /dev/null +++ b/gdb/testsuite/gdb.base/structs.c @@ -0,0 +1,207 @@ +/* Copyright (C) 1996 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Please email any bugs, comments, and/or additions to this file to: + bug-gdb@prep.ai.mit.edu */ + +struct struct1 { char a;}; +struct struct2 { char a, b;}; +struct struct3 { char a, b, c; }; +struct struct4 { char a, b, c, d; }; +struct struct5 { char a, b, c, d, e; }; +struct struct6 { char a, b, c, d, e, f; }; +struct struct7 { char a, b, c, d, e, f, g; }; +struct struct8 { char a, b, c, d, e, f, g, h; }; +struct struct9 { char a, b, c, d, e, f, g, h, i; }; +struct struct10 { char a, b, c, d, e, f, g, h, i, j; }; +struct struct11 { char a, b, c, d, e, f, g, h, i, j, k; }; +struct struct12 { char a, b, c, d, e, f, g, h, i, j, k, l; }; +struct struct16 { char a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p; }; + +struct struct1 foo1 = {'1'}, L1; +struct struct2 foo2 = { 'a', 'b'}, L2; +struct struct3 foo3 = { 'A', 'B', 'C'}, L3; +struct struct4 foo4 = {'1', '2', '3', '4'}, L4; +struct struct5 foo5 = {'a', 'b', 'c', 'd', 'e'}, L5; +struct struct6 foo6 = {'A', 'B', 'C', 'D', 'E', 'F'}, L6; +struct struct7 foo7 = {'1', '2', '3', '4', '5', '6', '7'}, L7; +struct struct8 foo8 = {'1', '2', '3', '4', '5', '6', '7', '8'}, L8; +struct struct9 foo9 = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'}, L9; +struct struct10 foo10 = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'}, L10; +struct struct11 foo11 = { + '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B'}, L11; +struct struct12 foo12 = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'}, L12; +struct struct16 foo16 = { + 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'}, L16; + +struct struct1 fun1() +{ + return foo1; +} +struct struct2 fun2() +{ + return foo2; +} +struct struct3 fun3() +{ + return foo3; +} +struct struct4 fun4() +{ + return foo4; +} +struct struct5 fun5() +{ + return foo5; +} +struct struct6 fun6() +{ + return foo6; +} +struct struct7 fun7() +{ + return foo7; +} +struct struct8 fun8() +{ + return foo8; +} +struct struct9 fun9() +{ + return foo9; +} +struct struct10 fun10() +{ + return foo10; +} +struct struct11 fun11() +{ + return foo11; +} +struct struct12 fun12() +{ + return foo12; +} +struct struct16 fun16() +{ + return foo16; +} + +void Fun1(foo1) + struct struct1 foo1; +{ + L1 = foo1; +} +void Fun2(foo2) + struct struct2 foo2; +{ + L2 = foo2; +} +void Fun3(foo3) + struct struct3 foo3; +{ + L3 = foo3; +} +void Fun4(foo4) + struct struct4 foo4; +{ + L4 = foo4; +} +void Fun5(foo5) + struct struct5 foo5; +{ + L5 = foo5; +} +void Fun6(foo6) + struct struct6 foo6; +{ + L6 = foo6; +} +void Fun7(foo7) + struct struct7 foo7; +{ + L7 = foo7; +} +void Fun8(foo8) + struct struct8 foo8; +{ + L8 = foo8; +} +void Fun9(foo9) + struct struct9 foo9; +{ + L9 = foo9; +} +void Fun10(foo10) + struct struct10 foo10; +{ + L10 = foo10; +} +void Fun11(foo11) + struct struct11 foo11; +{ + L11 = foo11; +} +void Fun12(foo12) + struct struct12 foo12; +{ + L12 = foo12; +} +void Fun16(foo16) + struct struct16 foo16; +{ + L16 = foo16; +} + +int main() +{ + + /* TEST C FUNCTIONS */ + L1 = fun1(); + L2 = fun2(); + L3 = fun3(); + L4 = fun4(); + L5 = fun5(); + L6 = fun6(); + L7 = fun7(); + L8 = fun8(); + L9 = fun9(); + L10 = fun10(); + L11 = fun11(); + L12 = fun12(); + L16 = fun16(); + + foo1.a = foo2.a = foo3.a = foo4.a = foo5.a = foo6.a = foo7.a = foo8.a = + foo9.a = foo10.a = foo11.a = foo12.a = foo16.a = '$'; + + Fun1(foo1); + Fun2(foo2); + Fun3(foo3); + Fun4(foo4); + Fun5(foo5); + Fun6(foo6); + Fun7(foo7); + Fun8(foo8); + Fun9(foo9); + Fun10(foo10); + Fun11(foo11); + Fun12(foo12); + Fun16(foo16); + + return 0; +} diff --git a/gdb/testsuite/gdb.base/structs.exp b/gdb/testsuite/gdb.base/structs.exp new file mode 100644 index 0000000..a3397fb --- /dev/null +++ b/gdb/testsuite/gdb.base/structs.exp @@ -0,0 +1,153 @@ +# Copyright (C) 1996 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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +# 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 +} + +set prms_id 0 +set bug_id 0 + +set prototypes 0 +set testfile "structs" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +# build the first test case +execute_anywhere "rm -f ${binfile}.ci" +execute_anywhere "echo set prototypes 1 > ${binfile}.ci" +if { [compile "-g ${srcdir}/${subdir}/${srcfile} -o ${binfile} "] != "" } { + execute_anywhere "rm -f ${binfile}.ci" + # built the second test case since we can't use prototypes + warning "Prototypes not supported, rebuilding with -DNO_PROTOTYPES" + execute_anywhere "echo set prototypes 0 > ${binfile}.ci" + if { [compile "-g -DNO_PROTOTYPES ${srcdir}/${subdir}/${srcfile} -o ${binfile} "] != "" } { + perror "Couldn't compile ${testfile}.c" + return -1 + } +} + +# Create and source the file that provides information about the compiler +# used to compile the test case. +if { [compile "-E ${srcdir}/${subdir}/compiler.c >> ${binfile}.ci"] != "" } { + perror "Couldn't make ${binfile}.ci" + return -1 +} +source ${binfile}.ci + +# The a29k can't call functions, so don't even bother with this test. +if [istarget "a29k-*-udi"] then { + setup_xfail "a29k-*-udi" 2416 + fail "a29k-*-udi can not call functions" + continue +} + +# The h8300 simulator can't call functions, so don't even bother with this test. +if [istarget "h8300*-*-*"] then { + setup_xfail "h8300*-*-*" + fail "h8300*-*-* simulator can not call functions" + continue +} + +# 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 do_function_calls {} { + global prototypes + global gcc_compiled + global prompt + + # First, call the "fun" functions and examine the value they return. + gdb_test "p fun1()" " = {a = 49 '1'}" + gdb_test "p fun2()" " = {a = 97 'a', b = 98 'b'}" + gdb_test "p fun3()" " = {a = 65 'A', b = 66 'B', c = 67 'C'}" + gdb_test "p fun4()" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4'}" + gdb_test "p fun5()" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e'}" + gdb_test "p fun6()" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F'}" + gdb_test "p fun7()" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4', e = 53 '5', f = 54 '6', g = 55 '7'}" + gdb_test "p 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'}" + gdb_test "p 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'}" + gdb_test "p 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'}" + gdb_test "p 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'}" + gdb_test "p 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'}" + gdb_test "p 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'}" + if {$gcc_compiled} then { + setup_xfail "hppa*-*-*" + } + gdb_test "p L5" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e'}" + if {$gcc_compiled} then { + setup_xfail "hppa*-*-*" + } + gdb_test "p L6" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F'}" + if {$gcc_compiled} then { + setup_xfail "hppa*-*-*" + } + 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. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +send "set print sevenbit-strings\n" ; expect -re "$prompt $" +send "set print address off\n" ; expect -re "$prompt $" +send "set width 0\n" ; expect -re "$prompt $" + +if [runto_main] then { + do_function_calls +} else { + fail "C function calling tests suppressed" +} +return 0 |