]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/callfuncs.exp
Major revision to testsuites for cross-testing and DOS testing support.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / callfuncs.exp
CommitLineData
787f6220 1# Copyright (C) 92, 96, 1997 Free Software Foundation, Inc.
eed4066f
FF
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
787f6220 15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
eed4066f
FF
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 Fred Fish. (fnf@cygnus.com)
787f6220 21# and modified by Bob Manson. (manson@cygnus.com)
eed4066f
FF
22
23if $tracelevel then {
24 strace $tracelevel
25}
26
27set prms_id 0
28set bug_id 0
29
782445c7 30set testfile "callfuncs"
04d5f3d6 31set srcfile ${testfile}.c
782445c7
FF
32set binfile ${objdir}/${subdir}/${testfile}
33
787f6220
BM
34set prototypes 1
35if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
36 set prototypes 0;
782445c7
FF
37 # built the second test case since we can't use prototypes
38 warning "Prototypes not supported, rebuilding with -DNO_PROTOTYPES"
787f6220 39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DNO_PROTOTYPES}] != "" } {
782445c7
FF
40 perror "Couldn't compile ${testfile}.c"
41 return -1
42 }
43}
eed4066f 44
04d5f3d6
FF
45# Create and source the file that provides information about the compiler
46# used to compile the test case.
787f6220
BM
47
48if [get_compiler_info ${binfile}] {
49 return -1;
eed4066f 50}
782445c7 51
eed4066f 52# The a29k can't call functions, so don't even bother with this test.
787f6220
BM
53if [target_info exists gdb,cannot_call_functions] {
54 setup_xfail "*-*-*" 2416
55 fail "This target can not call functions"
eed4066f
FF
56 continue
57}
58
59# Set the current language to C. This counts as a test. If it
60# fails, then we skip the other tests.
61
62proc set_lang_c {} {
63 global prompt
64
787f6220 65 send_gdb "set language c\n"
eed4066f
FF
66 expect {
67 -re ".*$prompt $" {}
68 timeout { fail "set language c (timeout)" ; return 0 }
69 }
70
787f6220 71 send_gdb "show language\n"
eed4066f
FF
72 expect {
73 -re ".* source language is \"c\".*$prompt $" {
74 pass "set language to \"c\""
75 return 1
76 }
77 -re ".*$prompt $" {
78 fail "setting language to \"c\""
79 return 0
80 }
81 timeout {
82 fail "can't show language (timeout)"
83 return 0
84 }
85 }
86}
87
88# FIXME: Before calling this proc, we should probably verify that
89# we can call inferior functions and get a valid integral value
90# returned.
91# Note that it is OK to check for 0 or 1 as the returned values, because C
92# specifies that the numeric value of a relational or logical expression
93# (computed in the inferior) is 1 for true and 0 for false.
94
95proc do_function_calls {} {
96 global prototypes
ce102e96 97 global gcc_compiled
eed4066f
FF
98
99 gdb_test "p t_char_values(0,0)" " = 0"
100 gdb_test "p t_char_values('a','b')" " = 1"
101 gdb_test "p t_char_values(char_val1,char_val2)" " = 1"
102 gdb_test "p t_char_values('a',char_val2)" " = 1"
103 gdb_test "p t_char_values(char_val1,'b')" " = 1"
104
105 gdb_test "p t_short_values(0,0)" " = 0"
106 gdb_test "p t_short_values(10,-23)" " = 1"
107 gdb_test "p t_short_values(short_val1,short_val2)" " = 1"
108 gdb_test "p t_short_values(10,short_val2)" " = 1"
109 gdb_test "p t_short_values(short_val1,-23)" " = 1"
110
111 gdb_test "p t_int_values(0,0)" " = 0"
112 gdb_test "p t_int_values(87,-26)" " = 1"
113 gdb_test "p t_int_values(int_val1,int_val2)" " = 1"
114 gdb_test "p t_int_values(87,int_val2)" " = 1"
115 gdb_test "p t_int_values(int_val1,-26)" " = 1"
116
117 gdb_test "p t_long_values(0,0)" " = 0"
118 gdb_test "p t_long_values(789,-321)" " = 1"
119 gdb_test "p t_long_values(long_val1,long_val2)" " = 1"
120 gdb_test "p t_long_values(789,long_val2)" " = 1"
121 gdb_test "p t_long_values(long_val1,-321)" " = 1"
122
123 gdb_test "p t_float_values(0.0,0.0)" " = 0"
124 gdb_test "p t_float_values(3.14159,-2.3765)" " = 1"
125 gdb_test "p t_float_values(float_val1,float_val2)" " = 1"
126 gdb_test "p t_float_values(3.14159,float_val2)" " = 1"
127 gdb_test "p t_float_values(float_val1,-2.3765)" " = 1"
128
129 # Test passing of arguments which might not be widened.
130 gdb_test "p t_float_values2(0.0,0.0)" " = 0"
ce102e96
FF
131
132 # Although PR 5318 mentions SunOS specifically, this seems
218f9f03 133 # to be a generic problem on quite a few platforms.
ce102e96 134 if $prototypes then {
04d5f3d6
FF
135 setup_xfail "hppa*-*-*" "sparc-*-*" "mips*-*-*" 5318
136 if {!$gcc_compiled} then {
137 setup_xfail "alpha-dec-osf2*" "i*86-*-sysv4*" 5318
138 }
ce102e96 139 }
eed4066f
FF
140 gdb_test "p t_float_values2(3.14159,float_val2)" " = 1"
141 gdb_test "p t_small_values(1,2,3,4,5,6,7,8,9,10)" " = 55"
142
143 gdb_test "p t_double_values(0.0,0.0)" " = 0"
144 gdb_test "p t_double_values(45.654,-67.66)" " = 1"
145 gdb_test "p t_double_values(double_val1,double_val2)" " = 1"
146 gdb_test "p t_double_values(45.654,double_val2)" " = 1"
147 gdb_test "p t_double_values(double_val1,-67.66)" " = 1"
148
149 gdb_test "p t_string_values(string_val2,string_val1)" " = 0"
150 gdb_test "p t_string_values(string_val1,string_val2)" " = 1"
151 gdb_test "p t_string_values(\"string 1\",\"string 2\")" " = 1"
152 gdb_test "p t_string_values(\"string 1\",string_val2)" " = 1"
153 gdb_test "p t_string_values(string_val1,\"string 2\")" " = 1"
154
155 gdb_test "p t_char_array_values(char_array_val2,char_array_val1)" " = 0"
156 gdb_test "p t_char_array_values(char_array_val1,char_array_val2)" " = 1"
157 gdb_test "p t_char_array_values(\"carray 1\",\"carray 2\")" " = 1"
158 gdb_test "p t_char_array_values(\"carray 1\",char_array_val2)" " = 1"
159 gdb_test "p t_char_array_values(char_array_val1,\"carray 2\")" " = 1"
160
161 gdb_test "p doubleit(4)" " = 8"
162 gdb_test "p add(4,5)" " = 9"
163 gdb_test "p t_func_values(func_val2,func_val1)" " = 0"
164 gdb_test "p t_func_values(func_val1,func_val2)" " = 1"
165
166 # On the rs6000, we need to pass the address of the trampoline routine,
167 # not the address of add itself. I don't know how to go from add to
168 # the address of the trampoline. Similar problems exist on the HPPA,
169 # and in fact can present an unsolvable problem as the stubs may not
170 # even exist in the user's program. We've slightly recoded t_func_values
171 # to avoid such problems in the common case. This may or may not help
172 # the RS6000.
173 setup_xfail "rs6000*-*-*"
5c6f833b 174 setup_xfail "powerpc*-*-*"
eed4066f
FF
175 gdb_test "p t_func_values(add,func_val2)" " = 1"
176
177 setup_xfail "rs6000*-*-*"
5c6f833b 178 setup_xfail "powerpc*-*-*"
eed4066f
FF
179 gdb_test "p t_func_values(func_val1,doubleit)" " = 1"
180
181 gdb_test "p t_call_add(func_val1,3,4)" " = 7"
182
183 setup_xfail "rs6000*-*-*"
5c6f833b 184 setup_xfail "powerpc*-*-*"
eed4066f
FF
185 gdb_test "p t_call_add(add,3,4)" " = 7"
186
187 gdb_test "p t_enum_value1(enumval1)" " = 1"
188 gdb_test "p t_enum_value1(enum_val1)" " = 1"
189 gdb_test "p t_enum_value1(enum_val2)" " = 0"
190
191 gdb_test "p t_enum_value2(enumval2)" " = 1"
192 gdb_test "p t_enum_value2(enum_val2)" " = 1"
193 gdb_test "p t_enum_value2(enum_val1)" " = 0"
194
195 gdb_test "p sum_args(1,{2})" " = 2"
196 gdb_test "p sum_args(2,{2,3})" " = 5"
197 gdb_test "p sum_args(3,{2,3,4})" " = 9"
198 gdb_test "p sum_args(4,{2,3,4,5})" " = 14"
199 gdb_test "p sum10 (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)" " = 55"
200
201 gdb_test "p t_structs_c(struct_val1)" "= 120 'x'" \
202 "call inferior func with struct - returns char"
203 gdb_test "p t_structs_s(struct_val1)" "= 87" \
204 "call inferior func with struct - returns short"
205 gdb_test "p t_structs_i(struct_val1)" "= 76" \
206 "call inferior func with struct - returns int"
207 gdb_test "p t_structs_l(struct_val1)" "= 51" \
208 "call inferior func with struct - returns long"
06c87bef 209 setup_xfail "i*86-*-*"
eed4066f
FF
210 gdb_test "p t_structs_f(struct_val1)" "= 2.12.*" \
211 "call inferior func with struct - returns float"
06c87bef 212 setup_xfail "i*86-*-*"
eed4066f
FF
213 gdb_test "p t_structs_d(struct_val1)" "= 9.87.*" \
214 "call inferior func with struct - returns double"
218f9f03 215 gdb_test "p t_structs_a(struct_val1)" "= (.unsigned char .. )?\"foo\"" \
eed4066f
FF
216 "call inferior func with struct - returns char *"
217
218}
219
220# Start with a fresh gdb.
221
222gdb_exit
223gdb_start
224gdb_reinitialize_dir $srcdir/$subdir
782445c7 225gdb_load ${binfile}
eed4066f 226
787f6220
BM
227gdb_test "set print sevenbit-strings" ""
228gdb_test "set print address off" ""
229gdb_test "set width 0" ""
eed4066f
FF
230
231if [set_lang_c] then {
232 if [runto_main] then {
787f6220 233 gdb_test "next" ".*"
eed4066f
FF
234 do_function_calls
235 } else {
236 fail "C function calling tests suppressed"
237 }
238} else {
239 fail "C function calling tests suppressed"
240}
241return 0