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 | |
a0b3c4fd JM |
97 | global gdb_prompt |
98 | ||
c906108c SS |
99 | # We need to up this because this can be really slow on some boards. |
100 | set timeout 60; | |
101 | ||
102 | gdb_test "p t_char_values(0,0)" " = 0" | |
103 | gdb_test "p t_char_values('a','b')" " = 1" | |
104 | gdb_test "p t_char_values(char_val1,char_val2)" " = 1" | |
105 | gdb_test "p t_char_values('a',char_val2)" " = 1" | |
106 | gdb_test "p t_char_values(char_val1,'b')" " = 1" | |
107 | ||
108 | gdb_test "p t_short_values(0,0)" " = 0" | |
109 | gdb_test "p t_short_values(10,-23)" " = 1" | |
110 | gdb_test "p t_short_values(short_val1,short_val2)" " = 1" | |
111 | gdb_test "p t_short_values(10,short_val2)" " = 1" | |
112 | gdb_test "p t_short_values(short_val1,-23)" " = 1" | |
113 | ||
114 | gdb_test "p t_int_values(0,0)" " = 0" | |
115 | gdb_test "p t_int_values(87,-26)" " = 1" | |
116 | gdb_test "p t_int_values(int_val1,int_val2)" " = 1" | |
117 | gdb_test "p t_int_values(87,int_val2)" " = 1" | |
118 | gdb_test "p t_int_values(int_val1,-26)" " = 1" | |
119 | ||
120 | gdb_test "p t_long_values(0,0)" " = 0" | |
121 | gdb_test "p t_long_values(789,-321)" " = 1" | |
122 | gdb_test "p t_long_values(long_val1,long_val2)" " = 1" | |
123 | gdb_test "p t_long_values(789,long_val2)" " = 1" | |
124 | gdb_test "p t_long_values(long_val1,-321)" " = 1" | |
125 | ||
126 | if ![target_info exists gdb,skip_float_tests] { | |
127 | gdb_test "p t_float_values(0.0,0.0)" " = 0" | |
128 | ||
129 | # These next four tests fail on the mn10300. | |
130 | # The first value is passed in regs, the other in memory. | |
131 | # Gcc emits different stabs for the two parameters; the first is | |
132 | # claimed to be a float, the second a double. | |
133 | # dbxout.c in gcc claims this is the desired behavior. | |
a0b3c4fd | 134 | setup_xfail "mn10300-*-*" |
c906108c | 135 | gdb_test "p t_float_values(3.14159,-2.3765)" " = 1" |
a0b3c4fd | 136 | setup_xfail "mn10300-*-*" |
c906108c | 137 | gdb_test "p t_float_values(float_val1,float_val2)" " = 1" |
a0b3c4fd | 138 | setup_xfail "mn10300-*-*" |
c906108c | 139 | gdb_test "p t_float_values(3.14159,float_val2)" " = 1" |
a0b3c4fd | 140 | setup_xfail "mn10300-*-*" |
c906108c SS |
141 | gdb_test "p t_float_values(float_val1,-2.3765)" " = 1" |
142 | ||
143 | # Test passing of arguments which might not be widened. | |
144 | gdb_test "p t_float_values2(0.0,0.0)" " = 0" | |
145 | ||
146 | # Although PR 5318 mentions SunOS specifically, this seems | |
147 | # to be a generic problem on quite a few platforms. | |
148 | if $prototypes then { | |
085dd6e6 | 149 | setup_xfail "sparc-*-*" "mips*-*-*" 5318 |
c906108c SS |
150 | if {!$gcc_compiled} then { |
151 | setup_xfail "alpha-dec-osf2*" "i*86-*-sysv4*" 5318 | |
152 | } | |
153 | } | |
154 | gdb_test "p t_float_values2(3.14159,float_val2)" " = 1" | |
155 | gdb_test "p t_small_values(1,2,3,4,5,6,7,8,9,10)" " = 55" | |
156 | ||
157 | gdb_test "p t_double_values(0.0,0.0)" " = 0" | |
158 | gdb_test "p t_double_values(45.654,-67.66)" " = 1" | |
159 | gdb_test "p t_double_values(double_val1,double_val2)" " = 1" | |
160 | gdb_test "p t_double_values(45.654,double_val2)" " = 1" | |
161 | gdb_test "p t_double_values(double_val1,-67.66)" " = 1" | |
162 | } | |
163 | ||
164 | gdb_test "p t_string_values(string_val2,string_val1)" " = 0" | |
165 | gdb_test "p t_string_values(string_val1,string_val2)" " = 1" | |
166 | gdb_test "p t_string_values(\"string 1\",\"string 2\")" " = 1" | |
167 | gdb_test "p t_string_values(\"string 1\",string_val2)" " = 1" | |
168 | gdb_test "p t_string_values(string_val1,\"string 2\")" " = 1" | |
169 | ||
170 | gdb_test "p t_char_array_values(char_array_val2,char_array_val1)" " = 0" | |
171 | gdb_test "p t_char_array_values(char_array_val1,char_array_val2)" " = 1" | |
172 | gdb_test "p t_char_array_values(\"carray 1\",\"carray 2\")" " = 1" | |
173 | gdb_test "p t_char_array_values(\"carray 1\",char_array_val2)" " = 1" | |
174 | gdb_test "p t_char_array_values(char_array_val1,\"carray 2\")" " = 1" | |
175 | ||
176 | gdb_test "p doubleit(4)" " = 8" | |
177 | gdb_test "p add(4,5)" " = 9" | |
178 | gdb_test "p t_func_values(func_val2,func_val1)" " = 0" | |
179 | gdb_test "p t_func_values(func_val1,func_val2)" " = 1" | |
180 | ||
181 | # On the rs6000, we need to pass the address of the trampoline routine, | |
182 | # not the address of add itself. I don't know how to go from add to | |
183 | # the address of the trampoline. Similar problems exist on the HPPA, | |
184 | # and in fact can present an unsolvable problem as the stubs may not | |
185 | # even exist in the user's program. We've slightly recoded t_func_values | |
186 | # to avoid such problems in the common case. This may or may not help | |
187 | # the RS6000. | |
188 | setup_xfail "rs6000*-*-*" | |
189 | setup_xfail "powerpc*-*-*" | |
a0b3c4fd | 190 | if {![istarget hppa*-*-hpux*]} then { |
c906108c SS |
191 | gdb_test "p t_func_values(add,func_val2)" " = 1" |
192 | } | |
193 | ||
194 | setup_xfail "rs6000*-*-*" | |
195 | setup_xfail "powerpc*-*-*" | |
a0b3c4fd | 196 | if {![istarget hppa*-*-hpux*]} then { |
c906108c SS |
197 | gdb_test "p t_func_values(func_val1,doubleit)" " = 1" |
198 | } | |
199 | ||
c906108c SS |
200 | setup_xfail "rs6000*-*-*" |
201 | setup_xfail "powerpc*-*-*" | |
a0b3c4fd | 202 | if {![istarget hppa*-*-hpux*]} then { |
c906108c SS |
203 | gdb_test "p t_call_add(add,3,4)" " = 7" |
204 | } | |
a0b3c4fd | 205 | gdb_test "p t_call_add(func_val1,3,4)" " = 7" |
c906108c SS |
206 | |
207 | gdb_test "p t_enum_value1(enumval1)" " = 1" | |
208 | gdb_test "p t_enum_value1(enum_val1)" " = 1" | |
209 | gdb_test "p t_enum_value1(enum_val2)" " = 0" | |
210 | ||
211 | gdb_test "p t_enum_value2(enumval2)" " = 1" | |
212 | gdb_test "p t_enum_value2(enum_val2)" " = 1" | |
213 | gdb_test "p t_enum_value2(enum_val1)" " = 0" | |
214 | ||
215 | gdb_test "p sum_args(1,{2})" " = 2" | |
216 | gdb_test "p sum_args(2,{2,3})" " = 5" | |
217 | gdb_test "p sum_args(3,{2,3,4})" " = 9" | |
218 | gdb_test "p sum_args(4,{2,3,4,5})" " = 14" | |
219 | ||
220 | gdb_test "p sum10 (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)" " = 55" | |
221 | ||
222 | gdb_test "p cmp10 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)" " = 1" | |
223 | ||
224 | gdb_test "p t_structs_c(struct_val1)" "= 120 'x'" \ | |
225 | "call inferior func with struct - returns char" | |
226 | gdb_test "p t_structs_s(struct_val1)" "= 87" \ | |
227 | "call inferior func with struct - returns short" | |
228 | gdb_test "p t_structs_i(struct_val1)" "= 76" \ | |
229 | "call inferior func with struct - returns int" | |
230 | gdb_test "p t_structs_l(struct_val1)" "= 51" \ | |
231 | "call inferior func with struct - returns long" | |
c906108c SS |
232 | gdb_test "p t_structs_f(struct_val1)" "= 2.12.*" \ |
233 | "call inferior func with struct - returns float" | |
c906108c SS |
234 | gdb_test "p t_structs_d(struct_val1)" "= 9.87.*" \ |
235 | "call inferior func with struct - returns double" | |
236 | gdb_test "p t_structs_a(struct_val1)" "= (.unsigned char .. )?\"foo\"" \ | |
237 | "call inferior func with struct - returns char *" | |
238 | } | |
239 | ||
c7db355b PS |
240 | # Procedure to get current content of all registers. |
241 | global all_registers_content | |
242 | set all_registers_content "" | |
243 | proc do_get_all_registers { } { | |
244 | global gdb_prompt | |
245 | global expect_out | |
246 | global all_registers_content | |
247 | ||
248 | set all_registers_content "" | |
249 | send_gdb "info all-registers\n" | |
250 | gdb_expect { | |
251 | -re "info all-registers\r\n(.*)$gdb_prompt $" { | |
252 | set all_registers_content $expect_out(1,string) | |
253 | } | |
254 | default {} | |
255 | } | |
256 | } | |
257 | ||
c906108c SS |
258 | # Start with a fresh gdb. |
259 | ||
260 | gdb_exit | |
261 | gdb_start | |
262 | gdb_reinitialize_dir $srcdir/$subdir | |
263 | gdb_load ${binfile} | |
264 | ||
265 | gdb_test "set print sevenbit-strings" "" | |
266 | gdb_test "set print address off" "" | |
267 | gdb_test "set width 0" "" | |
268 | ||
085dd6e6 JM |
269 | if { $hp_aCC_compiler } { |
270 | # Do not set language explicitly to 'C'. This will cause aCC | |
271 | # tests to fail because promotion rules are different. Just let | |
272 | # the language be set to the default. | |
273 | ||
c906108c SS |
274 | if { ![runto_main] } { |
275 | gdb_suppress_tests; | |
276 | } | |
085dd6e6 JM |
277 | |
278 | # However, turn off overload-resolution for aCC. Having it on causes | |
279 | # a lot of failures. | |
280 | ||
281 | gdb_test "set overload-resolution 0" ".*" | |
282 | } else { | |
283 | if { ![set_lang_c] } { | |
284 | gdb_suppress_tests; | |
285 | } else { | |
286 | if { ![runto_main] } { | |
287 | gdb_suppress_tests; | |
288 | } | |
289 | } | |
c906108c SS |
290 | } |
291 | ||
c7db355b PS |
292 | # Make sure that malloc gets called and that the floating point unit |
293 | # is initialized via a call to t_double_values. | |
294 | gdb_test "next" "t_double_values\\(double_val1, double_val2\\);.*" | |
c3f6f71d | 295 | gdb_test "next" "t_structs_c\\(struct_val1\\);.*" |
c7db355b PS |
296 | |
297 | # Save all register contents. | |
298 | do_get_all_registers | |
299 | set old_reg_content $all_registers_content | |
300 | ||
301 | # Perform function calls. | |
c906108c SS |
302 | do_function_calls |
303 | ||
c7db355b PS |
304 | # Check if all registers still have the same value. |
305 | do_get_all_registers | |
306 | set new_reg_content $all_registers_content | |
307 | if ![string compare $old_reg_content $new_reg_content] then { | |
308 | pass "gdb function calls preserve register contents" | |
309 | } else { | |
310 | set old_reg_content $all_registers_content | |
311 | fail "gdb function calls preserve register contents" | |
312 | } | |
313 | ||
314 | # Set breakpoint at a function we will call from gdb. | |
315 | gdb_breakpoint add | |
316 | ||
317 | # Call function (causing a breakpoint hit in the call dummy) and do a continue, | |
318 | # make sure we are back at main and still have the same register contents. | |
319 | gdb_test "print add(4,5)" "The program being debugged stopped while.*" "" | |
320 | gdb_test "continue" "Continuing.*" "continue from call dummy breakpoint" | |
321 | if ![gdb_test "bt 2" \ | |
322 | "#0 main.*" \ | |
323 | "bt after continuing from call dummy breakpoint"] then { | |
324 | do_get_all_registers | |
325 | set new_reg_content $all_registers_content | |
326 | if ![string compare $old_reg_content $new_reg_content] then { | |
327 | pass "continue after stop in call dummy preserves register contents" | |
328 | } else { | |
329 | fail "continue after stop in call dummy preserves register contents" | |
330 | } | |
331 | } | |
332 | ||
333 | # Call function (causing a breakpoint hit in the call dummy) and do a finish, | |
334 | # make sure we are back at main and still have the same register contents. | |
335 | gdb_test "print add(4,5)" "The program being debugged stopped while.*" "" | |
336 | gdb_test "finish" \ | |
337 | "Value returned is.* = 9" \ | |
338 | "finish from call dummy breakpoint returns correct value" | |
339 | if ![gdb_test "bt 2" \ | |
340 | "#0 main.*" \ | |
341 | "bt after finishing from call dummy breakpoint"] then { | |
342 | do_get_all_registers | |
343 | set new_reg_content $all_registers_content | |
344 | if ![string compare $old_reg_content $new_reg_content] then { | |
345 | pass "finish after stop in call dummy preserves register contents" | |
346 | } else { | |
347 | fail "finish after stop in call dummy preserves register contents" | |
348 | } | |
349 | } | |
350 | ||
351 | # Call function (causing a breakpoint hit in the call dummy) and do a return | |
352 | # with a value, make sure we are back at main with the same register contents. | |
353 | gdb_test "print add(4,5)" "The program being debugged stopped while.*" "" | |
354 | if ![gdb_test "return 7" \ | |
355 | "#0 main.*" \ | |
356 | "back at main after return from call dummy breakpoint" \ | |
357 | "Make add return now. .y or n.*" \ | |
358 | "y"] then { | |
359 | do_get_all_registers | |
360 | set new_reg_content $all_registers_content | |
361 | if ![string compare $old_reg_content $new_reg_content] then { | |
362 | pass "return after stop in call dummy preserves register contents" | |
363 | } else { | |
364 | fail "return after stop in call dummy preserves register contents" | |
365 | } | |
366 | } | |
367 | ||
c906108c | 368 | return 0 |