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