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