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