]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | # Copyright (C) 92, 96, 1997 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 | # and modified by Bob Manson. (manson@cygnus.com) | |
22 | ||
23 | if $tracelevel then { | |
24 | strace $tracelevel | |
25 | } | |
26 | ||
27 | set prms_id 0 | |
28 | set bug_id 0 | |
29 | ||
30 | set testfile "callfuncs" | |
31 | set srcfile ${testfile}.c | |
32 | set binfile ${objdir}/${subdir}/${testfile} | |
33 | ||
c906108c | 34 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
c906108c | 35 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." |
c906108c SS |
36 | } |
37 | ||
38 | # Create and source the file that provides information about the compiler | |
39 | # used to compile the test case. | |
40 | ||
41 | if [get_compiler_info ${binfile}] { | |
42 | return -1; | |
43 | } | |
44 | ||
085dd6e6 JM |
45 | if {$hp_aCC_compiler} { |
46 | set prototypes 1 | |
47 | } else { | |
48 | set prototypes 0 | |
49 | } | |
50 | ||
c906108c SS |
51 | # The a29k can't call functions, so don't even bother with this test. |
52 | if [target_info exists gdb,cannot_call_functions] { | |
53 | setup_xfail "*-*-*" 2416 | |
54 | fail "This target can not call functions" | |
55 | continue | |
56 | } | |
57 | ||
58 | # Set the current language to C. This counts as a test. If it | |
59 | # fails, then we skip the other tests. | |
60 | ||
61 | proc set_lang_c {} { | |
62 | global gdb_prompt | |
63 | ||
64 | send_gdb "set language c\n" | |
65 | gdb_expect { | |
66 | -re ".*$gdb_prompt $" {} | |
67 | timeout { fail "set language c (timeout)" ; return 0; } | |
68 | } | |
69 | ||
70 | send_gdb "show language\n" | |
71 | gdb_expect { | |
72 | -re ".* source language is \"c\".*$gdb_prompt $" { | |
73 | pass "set language to \"c\"" | |
74 | return 1 | |
75 | } | |
76 | -re ".*$gdb_prompt $" { | |
77 | fail "setting language to \"c\"" | |
78 | return 0 | |
79 | } | |
80 | timeout { | |
81 | fail "can't show language (timeout)" | |
82 | return 0 | |
83 | } | |
84 | } | |
85 | } | |
86 | ||
87 | # FIXME: Before calling this proc, we should probably verify that | |
88 | # we can call inferior functions and get a valid integral value | |
89 | # returned. | |
90 | # Note that it is OK to check for 0 or 1 as the returned values, because C | |
91 | # specifies that the numeric value of a relational or logical expression | |
92 | # (computed in the inferior) is 1 for true and 0 for false. | |
93 | ||
94 | proc do_function_calls {} { | |
95 | global prototypes | |
96 | global gcc_compiled | |
97 | # We need to up this because this can be really slow on some boards. | |
98 | set timeout 60; | |
99 | ||
100 | gdb_test "p t_char_values(0,0)" " = 0" | |
101 | gdb_test "p t_char_values('a','b')" " = 1" | |
102 | gdb_test "p t_char_values(char_val1,char_val2)" " = 1" | |
103 | gdb_test "p t_char_values('a',char_val2)" " = 1" | |
104 | gdb_test "p t_char_values(char_val1,'b')" " = 1" | |
105 | ||
106 | gdb_test "p t_short_values(0,0)" " = 0" | |
107 | gdb_test "p t_short_values(10,-23)" " = 1" | |
108 | gdb_test "p t_short_values(short_val1,short_val2)" " = 1" | |
109 | gdb_test "p t_short_values(10,short_val2)" " = 1" | |
110 | gdb_test "p t_short_values(short_val1,-23)" " = 1" | |
111 | ||
112 | gdb_test "p t_int_values(0,0)" " = 0" | |
113 | gdb_test "p t_int_values(87,-26)" " = 1" | |
114 | gdb_test "p t_int_values(int_val1,int_val2)" " = 1" | |
115 | gdb_test "p t_int_values(87,int_val2)" " = 1" | |
116 | gdb_test "p t_int_values(int_val1,-26)" " = 1" | |
117 | ||
118 | gdb_test "p t_long_values(0,0)" " = 0" | |
119 | gdb_test "p t_long_values(789,-321)" " = 1" | |
120 | gdb_test "p t_long_values(long_val1,long_val2)" " = 1" | |
121 | gdb_test "p t_long_values(789,long_val2)" " = 1" | |
122 | gdb_test "p t_long_values(long_val1,-321)" " = 1" | |
123 | ||
124 | if ![target_info exists gdb,skip_float_tests] { | |
125 | gdb_test "p t_float_values(0.0,0.0)" " = 0" | |
126 | ||
127 | # These next four tests fail on the mn10300. | |
128 | # The first value is passed in regs, the other in memory. | |
129 | # Gcc emits different stabs for the two parameters; the first is | |
130 | # claimed to be a float, the second a double. | |
131 | # dbxout.c in gcc claims this is the desired behavior. | |
085dd6e6 | 132 | setup_xfail "mn10300-*-*" "hppa*-*-*11*" |
c906108c | 133 | gdb_test "p t_float_values(3.14159,-2.3765)" " = 1" |
085dd6e6 | 134 | setup_xfail "mn10300-*-*" "hppa*-*-*11*" |
c906108c | 135 | gdb_test "p t_float_values(float_val1,float_val2)" " = 1" |
085dd6e6 | 136 | setup_xfail "mn10300-*-*" "hppa*-*-*11*" |
c906108c | 137 | gdb_test "p t_float_values(3.14159,float_val2)" " = 1" |
085dd6e6 | 138 | setup_xfail "mn10300-*-*" "hppa*-*-*11*" |
c906108c SS |
139 | gdb_test "p t_float_values(float_val1,-2.3765)" " = 1" |
140 | ||
141 | # Test passing of arguments which might not be widened. | |
142 | gdb_test "p t_float_values2(0.0,0.0)" " = 0" | |
143 | ||
144 | # Although PR 5318 mentions SunOS specifically, this seems | |
145 | # to be a generic problem on quite a few platforms. | |
146 | if $prototypes then { | |
085dd6e6 | 147 | setup_xfail "sparc-*-*" "mips*-*-*" 5318 |
c906108c SS |
148 | if {!$gcc_compiled} then { |
149 | setup_xfail "alpha-dec-osf2*" "i*86-*-sysv4*" 5318 | |
150 | } | |
151 | } | |
152 | gdb_test "p t_float_values2(3.14159,float_val2)" " = 1" | |
153 | gdb_test "p t_small_values(1,2,3,4,5,6,7,8,9,10)" " = 55" | |
154 | ||
155 | gdb_test "p t_double_values(0.0,0.0)" " = 0" | |
156 | gdb_test "p t_double_values(45.654,-67.66)" " = 1" | |
157 | gdb_test "p t_double_values(double_val1,double_val2)" " = 1" | |
158 | gdb_test "p t_double_values(45.654,double_val2)" " = 1" | |
159 | gdb_test "p t_double_values(double_val1,-67.66)" " = 1" | |
160 | } | |
161 | ||
162 | gdb_test "p t_string_values(string_val2,string_val1)" " = 0" | |
163 | gdb_test "p t_string_values(string_val1,string_val2)" " = 1" | |
164 | gdb_test "p t_string_values(\"string 1\",\"string 2\")" " = 1" | |
165 | gdb_test "p t_string_values(\"string 1\",string_val2)" " = 1" | |
166 | gdb_test "p t_string_values(string_val1,\"string 2\")" " = 1" | |
167 | ||
168 | gdb_test "p t_char_array_values(char_array_val2,char_array_val1)" " = 0" | |
169 | gdb_test "p t_char_array_values(char_array_val1,char_array_val2)" " = 1" | |
170 | gdb_test "p t_char_array_values(\"carray 1\",\"carray 2\")" " = 1" | |
171 | gdb_test "p t_char_array_values(\"carray 1\",char_array_val2)" " = 1" | |
172 | gdb_test "p t_char_array_values(char_array_val1,\"carray 2\")" " = 1" | |
173 | ||
174 | gdb_test "p doubleit(4)" " = 8" | |
175 | gdb_test "p add(4,5)" " = 9" | |
176 | gdb_test "p t_func_values(func_val2,func_val1)" " = 0" | |
177 | gdb_test "p t_func_values(func_val1,func_val2)" " = 1" | |
178 | ||
179 | # On the rs6000, we need to pass the address of the trampoline routine, | |
180 | # not the address of add itself. I don't know how to go from add to | |
181 | # the address of the trampoline. Similar problems exist on the HPPA, | |
182 | # and in fact can present an unsolvable problem as the stubs may not | |
183 | # even exist in the user's program. We've slightly recoded t_func_values | |
184 | # to avoid such problems in the common case. This may or may not help | |
185 | # the RS6000. | |
186 | setup_xfail "rs6000*-*-*" | |
187 | setup_xfail "powerpc*-*-*" | |
188 | if {!$gcc_compiled && [istarget hppa*-*-hpux*]} then { | |
085dd6e6 JM |
189 | send_gdb "p t_func_values(add,func_val2)\n" |
190 | gdb_expect { | |
191 | -re "You cannot.*ignored.*" {pass "p t_func_values(add,func_val2)"} | |
192 | -re "Program received signal SIGBUS, Bus error.*" { | |
193 | if [istarget hppa*-*-hpux*] { | |
194 | pass "p t_func_values(add,func_val2)" | |
195 | } else { | |
196 | fail "p t_func_values(add,func_val2)" | |
197 | } | |
198 | } | |
199 | } | |
c906108c SS |
200 | } else { |
201 | gdb_test "p t_func_values(add,func_val2)" " = 1" | |
202 | } | |
203 | ||
204 | setup_xfail "rs6000*-*-*" | |
205 | setup_xfail "powerpc*-*-*" | |
206 | if {!$gcc_compiled && [istarget hppa*-*-hpux*]} then { | |
085dd6e6 JM |
207 | send_gdb "p t_func_values(func_val1,doubleit)\n" |
208 | gdb_expect { | |
209 | -re "You cannot.*ignored.*" {pass "p t_func_values(func_val1,doubleit)"} | |
210 | -re "Program received signal SIGBUS, Bus error.*" { | |
211 | if [istarget hppa*-*-hpux*] { | |
212 | pass "p t_func_values(func_val1,doubleit)" | |
213 | } else { | |
214 | fail "p t_func_values(func_val1,doubleit)" | |
215 | } | |
216 | } | |
217 | } | |
c906108c SS |
218 | } else { |
219 | gdb_test "p t_func_values(func_val1,doubleit)" " = 1" | |
220 | } | |
221 | ||
222 | gdb_test "p t_call_add(func_val1,3,4)" " = 7" | |
223 | ||
224 | setup_xfail "rs6000*-*-*" | |
225 | setup_xfail "powerpc*-*-*" | |
226 | if {!$gcc_compiled && [istarget hppa*-*-hpux*]} then { | |
085dd6e6 JM |
227 | send_gdb "p t_call_add(add,3,4)\n" |
228 | gdb_expect { | |
229 | -re "You cannot.*ignored.*" {pass "p t_call_add(add,3,4)"} | |
230 | -re "Program received signal SIGBUS, Bus error.*" { | |
231 | if [istarget hppa*-*-hpux*] { | |
232 | pass "p t_call_add(add,3,4)" | |
233 | } else { | |
234 | fail "p t_call_add(add,3,4)" | |
235 | } | |
236 | } | |
237 | } | |
c906108c SS |
238 | } else { |
239 | gdb_test "p t_call_add(add,3,4)" " = 7" | |
240 | } | |
241 | ||
242 | gdb_test "p t_enum_value1(enumval1)" " = 1" | |
243 | gdb_test "p t_enum_value1(enum_val1)" " = 1" | |
244 | gdb_test "p t_enum_value1(enum_val2)" " = 0" | |
245 | ||
246 | gdb_test "p t_enum_value2(enumval2)" " = 1" | |
247 | gdb_test "p t_enum_value2(enum_val2)" " = 1" | |
248 | gdb_test "p t_enum_value2(enum_val1)" " = 0" | |
249 | ||
250 | gdb_test "p sum_args(1,{2})" " = 2" | |
251 | gdb_test "p sum_args(2,{2,3})" " = 5" | |
252 | gdb_test "p sum_args(3,{2,3,4})" " = 9" | |
253 | gdb_test "p sum_args(4,{2,3,4,5})" " = 14" | |
254 | ||
255 | gdb_test "p sum10 (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)" " = 55" | |
256 | ||
257 | gdb_test "p cmp10 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)" " = 1" | |
258 | ||
259 | gdb_test "p t_structs_c(struct_val1)" "= 120 'x'" \ | |
260 | "call inferior func with struct - returns char" | |
261 | gdb_test "p t_structs_s(struct_val1)" "= 87" \ | |
262 | "call inferior func with struct - returns short" | |
263 | gdb_test "p t_structs_i(struct_val1)" "= 76" \ | |
264 | "call inferior func with struct - returns int" | |
265 | gdb_test "p t_structs_l(struct_val1)" "= 51" \ | |
266 | "call inferior func with struct - returns long" | |
267 | setup_xfail "i*86-*-*" | |
268 | gdb_test "p t_structs_f(struct_val1)" "= 2.12.*" \ | |
269 | "call inferior func with struct - returns float" | |
270 | setup_xfail "i*86-*-*" | |
271 | gdb_test "p t_structs_d(struct_val1)" "= 9.87.*" \ | |
272 | "call inferior func with struct - returns double" | |
273 | gdb_test "p t_structs_a(struct_val1)" "= (.unsigned char .. )?\"foo\"" \ | |
274 | "call inferior func with struct - returns char *" | |
275 | } | |
276 | ||
277 | # Start with a fresh gdb. | |
278 | ||
279 | gdb_exit | |
280 | gdb_start | |
281 | gdb_reinitialize_dir $srcdir/$subdir | |
282 | gdb_load ${binfile} | |
283 | ||
284 | gdb_test "set print sevenbit-strings" "" | |
285 | gdb_test "set print address off" "" | |
286 | gdb_test "set width 0" "" | |
287 | ||
085dd6e6 JM |
288 | if { $hp_aCC_compiler } { |
289 | # Do not set language explicitly to 'C'. This will cause aCC | |
290 | # tests to fail because promotion rules are different. Just let | |
291 | # the language be set to the default. | |
292 | ||
c906108c SS |
293 | if { ![runto_main] } { |
294 | gdb_suppress_tests; | |
295 | } | |
085dd6e6 JM |
296 | |
297 | # However, turn off overload-resolution for aCC. Having it on causes | |
298 | # a lot of failures. | |
299 | ||
300 | gdb_test "set overload-resolution 0" ".*" | |
301 | } else { | |
302 | if { ![set_lang_c] } { | |
303 | gdb_suppress_tests; | |
304 | } else { | |
305 | if { ![runto_main] } { | |
306 | gdb_suppress_tests; | |
307 | } | |
308 | } | |
c906108c SS |
309 | } |
310 | ||
311 | gdb_test "next" ".*" | |
312 | do_function_calls | |
313 | ||
314 | return 0 |