]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/structs.exp
* gdb.base/structs.exp: New tests for passing and returning
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / structs.exp
1 # Copyright (C) 1996 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file was written by Jeff Law. (law@cygnus.com)
21
22 if $tracelevel then {
23 strace $tracelevel
24 }
25
26 set prms_id 0
27 set bug_id 0
28
29 set prototypes 0
30 set testfile "structs"
31 set srcfile ${testfile}.c
32 set binfile ${objdir}/${subdir}/${testfile}
33
34 # build the first test case
35 execute_anywhere "rm -f ${binfile}.ci"
36 execute_anywhere "echo set prototypes 1 > ${binfile}.ci"
37 if { [compile "-g ${srcdir}/${subdir}/${srcfile} -o ${binfile} "] != "" } {
38 execute_anywhere "rm -f ${binfile}.ci"
39 # built the second test case since we can't use prototypes
40 warning "Prototypes not supported, rebuilding with -DNO_PROTOTYPES"
41 execute_anywhere "echo set prototypes 0 > ${binfile}.ci"
42 if { [compile "-g -DNO_PROTOTYPES ${srcdir}/${subdir}/${srcfile} -o ${binfile} "] != "" } {
43 perror "Couldn't compile ${testfile}.c"
44 return -1
45 }
46 }
47
48 # Create and source the file that provides information about the compiler
49 # used to compile the test case.
50 if { [compile "-E ${srcdir}/${subdir}/compiler.c >> ${binfile}.ci"] != "" } {
51 perror "Couldn't make ${binfile}.ci"
52 return -1
53 }
54 source ${binfile}.ci
55
56 # The a29k can't call functions, so don't even bother with this test.
57 if [istarget "a29k-*-udi"] then {
58 setup_xfail "a29k-*-udi" 2416
59 fail "a29k-*-udi can not call functions"
60 continue
61 }
62
63 # The h8300 simulator can't call functions, so don't even bother with this test.
64 if [istarget "h8300*-*-*"] then {
65 setup_xfail "h8300*-*-*"
66 fail "h8300*-*-* simulator can not call functions"
67 continue
68 }
69
70 # FIXME: Before calling this proc, we should probably verify that
71 # we can call inferior functions and get a valid integral value
72 # returned.
73 # Note that it is OK to check for 0 or 1 as the returned values, because C
74 # specifies that the numeric value of a relational or logical expression
75 # (computed in the inferior) is 1 for true and 0 for false.
76
77 proc do_function_calls {} {
78 global prototypes
79 global gcc_compiled
80 global prompt
81
82 # First, call the "fun" functions and examine the value they return.
83 gdb_test "p fun1()" " = {a = 49 '1'}"
84 gdb_test "p fun2()" " = {a = 97 'a', b = 98 'b'}"
85 gdb_test "p fun3()" " = {a = 65 'A', b = 66 'B', c = 67 'C'}"
86 gdb_test "p fun4()" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4'}"
87 gdb_test "p fun5()" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e'}"
88 gdb_test "p fun6()" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F'}"
89 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'}"
90 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'}"
91 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'}"
92 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'}"
93 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'}"
94 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'}"
95 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'}"
96
97 # Now call the Fun functions to set the L* variables. This
98 # tests that gdb properly passes structures to functions.
99 gdb_test "p Fun1(foo1)" " = (void|0)"
100 gdb_test "p Fun2(foo2)" " = (void|0)"
101 gdb_test "p Fun3(foo3)" " = (void|0)"
102 gdb_test "p Fun4(foo4)" " = (void|0)"
103 gdb_test "p Fun5(foo5)" " = (void|0)"
104 gdb_test "p Fun6(foo6)" " = (void|0)"
105 gdb_test "p Fun7(foo7)" " = (void|0)"
106 gdb_test "p Fun8(foo8)" " = (void|0)"
107 gdb_test "p Fun9(foo9)" " = (void|0)"
108 gdb_test "p Fun10(foo10)" " = (void|0)"
109 gdb_test "p Fun11(foo11)" " = (void|0)"
110 gdb_test "p Fun12(foo12)" " = (void|0)"
111 gdb_test "p Fun16(foo16)" " = (void|0)"
112
113 # Now print the L* variables and examine their values.
114 gdb_test "p L1" " = {a = 49 '1'}"
115 gdb_test "p L2" " = {a = 97 'a', b = 98 'b'}"
116 gdb_test "p L3" " = {a = 65 'A', b = 66 'B', c = 67 'C'}"
117 gdb_test "p L4" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4'}"
118 if {$gcc_compiled} then {
119 setup_xfail "hppa*-*-*"
120 }
121 gdb_test "p L5" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e'}"
122 if {$gcc_compiled} then {
123 setup_xfail "hppa*-*-*"
124 }
125 gdb_test "p L6" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F'}"
126 if {$gcc_compiled} then {
127 setup_xfail "hppa*-*-*"
128 }
129 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'}"
130 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'}"
131 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'}"
132 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'}"
133 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'}"
134 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'}"
135 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'}"
136 }
137 # Start with a fresh gdb.
138
139 gdb_exit
140 gdb_start
141 gdb_reinitialize_dir $srcdir/$subdir
142 gdb_load ${binfile}
143
144 send "set print sevenbit-strings\n" ; expect -re "$prompt $"
145 send "set print address off\n" ; expect -re "$prompt $"
146 send "set width 0\n" ; expect -re "$prompt $"
147
148 if [runto_main] then {
149 do_function_calls
150 } else {
151 fail "C function calling tests suppressed"
152 }
153 return 0