* dwarf2-frame.c (dwarf2_frame_find_quirks): Use producer_is_realview.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / callfuncs.exp
1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2 # 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 # This file was written by Fred Fish. (fnf@cygnus.com)
18 # and modified by Bob Manson. (manson@cygnus.com)
19
20 if $tracelevel then {
21 strace $tracelevel
22 }
23
24 set prms_id 0
25 set bug_id 0
26
27 set testfile "callfuncs"
28 set srcfile ${testfile}.c
29 set binfile ${objdir}/${subdir}/${testfile}
30
31 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
32 untested callfuncs.exp
33 return -1
34 }
35
36 # Create and source the file that provides information about the compiler
37 # used to compile the test case.
38
39 if [get_compiler_info ${binfile}] {
40 return -1;
41 }
42
43 if {$hp_aCC_compiler} {
44 set prototypes 1
45 } else {
46 set prototypes 0
47 }
48
49 # Some targets can't do function calls, so don't even bother with this
50 # test.
51 if [target_info exists gdb,cannot_call_functions] {
52 setup_xfail "*-*-*" 2416
53 fail "This target can not call functions"
54 continue
55 }
56
57 # Set the current language to C. This counts as a test. If it
58 # fails, then we skip the other tests.
59
60 proc set_lang_c {} {
61 global gdb_prompt
62
63 send_gdb "set language c\n"
64 gdb_expect {
65 -re ".*$gdb_prompt $" {}
66 timeout { fail "set language c (timeout)" ; return 0; }
67 }
68
69 send_gdb "show language\n"
70 gdb_expect {
71 -re ".* source language is \"c\".*$gdb_prompt $" {
72 pass "set language to \"c\""
73 return 1
74 }
75 -re ".*$gdb_prompt $" {
76 fail "setting language to \"c\""
77 return 0
78 }
79 timeout {
80 fail "can't show language (timeout)"
81 return 0
82 }
83 }
84 }
85
86 # FIXME: Before calling this proc, we should probably verify that
87 # we can call inferior functions and get a valid integral value
88 # returned.
89 # Note that it is OK to check for 0 or 1 as the returned values, because C
90 # specifies that the numeric value of a relational or logical expression
91 # (computed in the inferior) is 1 for true and 0 for false.
92
93 proc do_function_calls {} {
94 global prototypes
95 global gdb_prompt
96
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.
132 # These tests also fail for RealView, because GDB can not tell that
133 # the function is unprototyped.
134 setup_xfail "mn10300-*-*"
135 if { [test_compiler_info "armcc-*"] } { setup_xfail "*-*-*" }
136 gdb_test "p t_float_values(3.14159,-2.3765)" " = 1"
137 setup_xfail "mn10300-*-*"
138 if { [test_compiler_info "armcc-*"] } { setup_xfail "*-*-*" }
139 gdb_test "p t_float_values(float_val1,float_val2)" " = 1"
140 setup_xfail "mn10300-*-*"
141 if { [test_compiler_info "armcc-*"] } { setup_xfail "*-*-*" }
142 gdb_test "p t_float_values(3.14159,float_val2)" " = 1"
143 setup_xfail "mn10300-*-*"
144 if { [test_compiler_info "armcc-*"] } { setup_xfail "*-*-*" }
145 gdb_test "p t_float_values(float_val1,-2.3765)" " = 1"
146
147 # Test passing of arguments which might not be widened.
148 gdb_test "p t_float_values2(0.0,0.0)" " = 0"
149
150 # Although PR 5318 mentions SunOS specifically, this seems
151 # to be a generic problem on quite a few platforms.
152 if $prototypes then {
153 setup_xfail "sparc-*-*" "mips*-*-*" 5318
154 if { ! [test_compiler_info gcc-*-*] } then {
155 setup_xfail "alpha-dec-osf2*" "i*86-*-sysv4*" 5318
156 }
157 }
158
159 gdb_test "p t_float_values2(3.14159,float_val2)" " = 1"
160
161 gdb_test "p t_float_many_args (float_val1, float_val2, float_val3, float_val4, float_val5, float_val6, float_val7, float_val8, float_val9, float_val10, float_val11, float_val12, float_val13, float_val14, float_val15)" " = 1" "Call function with many float arguments."
162
163 gdb_test "p t_small_values(1,2,3,4,5,6,7,8,9,10)" " = 55"
164
165 gdb_test "p t_double_values(0.0,0.0)" " = 0"
166 gdb_test "p t_double_values(45.654,-67.66)" " = 1"
167 gdb_test "p t_double_values(double_val1,double_val2)" " = 1"
168 gdb_test "p t_double_values(45.654,double_val2)" " = 1"
169 gdb_test "p t_double_values(double_val1,-67.66)" " = 1"
170
171 gdb_test "p t_double_many_args (double_val1, double_val2, double_val3, double_val4, double_val5, double_val6, double_val7, double_val8, double_val9, double_val10, double_val11, double_val12, double_val13, double_val14, double_val15)" " = 1" "Call function with many double arguments."
172
173 gdb_test "p t_double_int(99.0, 1)" " = 0"
174 gdb_test "p t_double_int(99.0, 99)" " = 1"
175 gdb_test "p t_int_double(99, 1.0)" " = 0"
176 gdb_test "p t_int_double(99, 99.0)" " = 1"
177 }
178
179 gdb_test "p t_string_values(string_val2,string_val1)" " = 0"
180 gdb_test "p t_string_values(string_val1,string_val2)" " = 1"
181 gdb_test "p t_string_values(\"string 1\",\"string 2\")" " = 1"
182 gdb_test "p t_string_values(\"string 1\",string_val2)" " = 1"
183 gdb_test "p t_string_values(string_val1,\"string 2\")" " = 1"
184
185 gdb_test "p t_char_array_values(char_array_val2,char_array_val1)" " = 0"
186 gdb_test "p t_char_array_values(char_array_val1,char_array_val2)" " = 1"
187 gdb_test "p t_char_array_values(\"carray 1\",\"carray 2\")" " = 1"
188 gdb_test "p t_char_array_values(\"carray 1\",char_array_val2)" " = 1"
189 gdb_test "p t_char_array_values(char_array_val1,\"carray 2\")" " = 1"
190
191 gdb_test "p doubleit(4)" " = 8"
192 gdb_test "p add(4,5)" " = 9"
193 gdb_test "p t_func_values(func_val2,func_val1)" " = 0"
194 gdb_test "p t_func_values(func_val1,func_val2)" " = 1"
195
196 gdb_test "p function_struct.func(5)" " = 10"
197 gdb_test "p function_struct_ptr->func(10)" " = 20"
198
199 # GDB currently screws up the passing of function parameters for
200 # ABIs that use function descriptors. Instead of passing the
201 # address of te function descriptor, GDB passes the address of the
202 # function body. This results in the called function treating the
203 # first few instructions of the function proper as a descriptor
204 # and attempting a jump through that (a totally random address).
205 setup_kfail "rs6000*-*-aix*" gdb/1457
206 setup_kfail "powerpc*-*-aix*" gdb/1457
207 setup_kfail hppa*-*-hpux* gdb/1457
208 gdb_test "p t_func_values(add,func_val2)" " = 1"
209 setup_kfail "rs6000*-*-aix*" gdb/1457
210 setup_kfail "powerpc*-*-aix*" gdb/1457
211 setup_kfail hppa*-*-hpux* gdb/1457
212 gdb_test "p t_func_values(func_val1,doubleit)" " = 1"
213 setup_kfail "rs6000*-*-aix*" gdb/1457
214 setup_kfail "powerpc*-*-aix*" gdb/1457
215 setup_kfail hppa*-*-hpux* gdb/1457
216 gdb_test "p t_call_add(add,3,4)" " = 7"
217 gdb_test "p t_call_add(func_val1,3,4)" " = 7"
218
219 gdb_test "p t_enum_value1(enumval1)" " = 1"
220 gdb_test "p t_enum_value1(enum_val1)" " = 1"
221 gdb_test "p t_enum_value1(enum_val2)" " = 0"
222
223 gdb_test "p t_enum_value2(enumval2)" " = 1"
224 gdb_test "p t_enum_value2(enum_val2)" " = 1"
225 gdb_test "p t_enum_value2(enum_val1)" " = 0"
226
227 gdb_test "p sum_args(1,{2})" " = 2"
228 gdb_test "p sum_args(2,{2,3})" " = 5"
229 gdb_test "p sum_args(3,{2,3,4})" " = 9"
230 gdb_test "p sum_args(4,{2,3,4,5})" " = 14"
231
232 gdb_test "p sum10 (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)" " = 55"
233
234 gdb_test "p cmp10 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)" " = 1"
235
236 gdb_test "p t_structs_c(struct_val1)" "= 120 'x'" \
237 "call inferior func with struct - returns char"
238 gdb_test "p t_structs_s(struct_val1)" "= 87" \
239 "call inferior func with struct - returns short"
240 gdb_test "p t_structs_i(struct_val1)" "= 76" \
241 "call inferior func with struct - returns int"
242 gdb_test "p t_structs_l(struct_val1)" "= 51" \
243 "call inferior func with struct - returns long"
244 gdb_test "p t_structs_f(struct_val1)" "= 2.12.*" \
245 "call inferior func with struct - returns float"
246 gdb_test "p t_structs_d(struct_val1)" "= 9.87.*" \
247 "call inferior func with struct - returns double"
248 gdb_test "p t_structs_a(struct_val1)" "= (.unsigned char .. )?\"foo\"" \
249 "call inferior func with struct - returns char *"
250 }
251
252 # Procedure to get current content of all registers.
253 proc fetch_all_registers {test} {
254 global gdb_prompt
255
256 set all_registers_lines {}
257 set bad -1
258 # Former trailing `\[\r\n\]+' may eat just \r leaving \n in the buffer
259 # corrupting the next matches.
260 if {[gdb_test_multiple "info all-registers" $test {
261 -re "info all-registers\r\n" {
262 exp_continue
263 }
264 -ex "The program has no registers now" {
265 set bad 1
266 exp_continue
267 }
268 -re "^bspstore\[ \t\]+\[^\r\n\]+\r\n" {
269 if [istarget "ia64-*-*"] {
270 # Filter out bspstore which is specially tied to bsp,
271 # giving spurious differences.
272 } else {
273 lappend all_registers_lines $expect_out(0,string)
274 }
275 exp_continue
276 }
277 -re "^\[^ \t\]+\[ \t\]+\[^\r\n\]+\r\n" {
278 lappend all_registers_lines $expect_out(0,string)
279 exp_continue
280 }
281 -re "$gdb_prompt $" {
282 incr bad
283 }
284 -re "^\[^\r\n\]+\r\n" {
285 if {!$bad} {
286 warning "Unrecognized output: $expect_out(0,string)"
287 set bad 1
288 }
289 exp_continue
290 }
291 }] != 0} {
292 return {}
293 }
294
295 if {$bad} {
296 fail $test
297 return {}
298 }
299
300 pass $test
301 return $all_registers_lines
302 }
303
304
305 # Start with a fresh gdb.
306
307 gdb_exit
308 gdb_start
309 gdb_reinitialize_dir $srcdir/$subdir
310 gdb_load ${binfile}
311
312 gdb_test "set print sevenbit-strings" ""
313 gdb_test "set print address off" ""
314 gdb_test "set width 0" ""
315
316 if { $hp_aCC_compiler } {
317 # Do not set language explicitly to 'C'. This will cause aCC
318 # tests to fail because promotion rules are different. Just let
319 # the language be set to the default.
320
321 if { ![runto_main] } {
322 gdb_suppress_tests;
323 }
324
325 # However, turn off overload-resolution for aCC. Having it on causes
326 # a lot of failures.
327
328 gdb_test "set overload-resolution 0" ".*"
329 } else {
330 if { ![set_lang_c] } {
331 gdb_suppress_tests;
332 } else {
333 if { ![runto_main] } {
334 gdb_suppress_tests;
335 }
336 }
337 }
338
339 get_debug_format
340
341 # Make sure that malloc gets called and that the floating point unit
342 # is initialized via a call to t_double_values.
343 gdb_test "next" "t_double_values\\(double_val1, double_val2\\);.*" \
344 "next to t_double_values"
345 gdb_test "next" "t_structs_c\\(struct_val1\\);.*" \
346 "next to t_structs_c"
347
348 # Save all register contents.
349 set old_reg_content [fetch_all_registers "retrieve original register contents"]
350
351 # Perform function calls.
352 do_function_calls
353
354 # Check if all registers still have the same value.
355 set new_reg_content [fetch_all_registers \
356 "register contents after gdb function calls"]
357 if {$old_reg_content == $new_reg_content} then {
358 pass "gdb function calls preserve register contents"
359 } else {
360 set old_reg_content $new_reg_content
361 fail "gdb function calls preserve register contents"
362 }
363
364 # Set breakpoint at a function we will call from gdb.
365 gdb_breakpoint add
366
367 # Call function (causing a breakpoint hit in the call dummy) and do a continue,
368 # make sure we are back at main and still have the same register contents.
369 gdb_test "print add(4,5)" \
370 "The program being debugged stopped while.*" \
371 "stop at breakpoint in call dummy function"
372 gdb_test "continue" "Continuing.*" "continue from call dummy breakpoint"
373 if ![gdb_test "bt 2" \
374 "#0 main.*" \
375 "bt after continuing from call dummy breakpoint"] then {
376 set new_reg_content [fetch_all_registers \
377 "register contents after stop in call dummy"]
378 if {$old_reg_content == $new_reg_content} then {
379 pass "continue after stop in call dummy preserves register contents"
380 } else {
381 fail "continue after stop in call dummy preserves register contents"
382 }
383 }
384
385 # Call function (causing a breakpoint hit in the call dummy) and do a finish,
386 # make sure we are back at main and still have the same register contents.
387 gdb_test "print add(4,5)" "The program being debugged stopped while.*" \
388 "call function causing a breakpoint then do a finish"
389 gdb_test "finish" \
390 "Value returned is .* = 9" \
391 "finish from call dummy breakpoint returns correct value"
392 if ![gdb_test "bt 2" \
393 "#0 main.*" \
394 "bt after finishing from call dummy breakpoint"] then {
395 set new_reg_content [fetch_all_registers \
396 "register contents after finish in call dummy"]
397 if {$old_reg_content == $new_reg_content} then {
398 pass "finish after stop in call dummy preserves register contents"
399 } else {
400 fail "finish after stop in call dummy preserves register contents"
401 }
402 }
403
404 # Call function (causing a breakpoint hit in the call dummy) and do a return
405 # with a value, make sure we are back at main with the same register contents.
406 gdb_test "print add(4,5)" "The program being debugged stopped while.*" \
407 "call function causing a breakpoint and then do a return"
408 if ![gdb_test "return 7" \
409 "#0 main.*" \
410 "back at main after return from call dummy breakpoint" \
411 "Make add return now. .y or n.*" \
412 "y"] then {
413 set new_reg_content [fetch_all_registers \
414 "register contents after return in call dummy"]
415 if {$old_reg_content == $new_reg_content} then {
416 pass "return after stop in call dummy preserves register contents"
417 } else {
418 fail "return after stop in call dummy preserves register contents"
419 }
420 }
421
422 # Call function (causing a breakpoint hit in the call dummy), and
423 # call another function from the call dummy frame (thereby setting up
424 # several nested call dummy frames). Test that backtrace and finish
425 # work when several call dummies are nested.
426 gdb_breakpoint sum10
427 gdb_breakpoint t_small_values
428 gdb_test "print add(2,3)" "The program being debugged stopped while.*" \
429 "stop at nested call level 1"
430 gdb_test "backtrace" \
431 "\#0 add \\(a=2, b=3\\).*\#1 <function called from gdb>.*\#2 main.*" \
432 "backtrace at nested call level 1"
433 gdb_test "print add(4,5)" "The program being debugged stopped while.*" \
434 "stop at nested call level 2"
435 gdb_test "backtrace" \
436 "\#0 add \\(a=4, b=5\\).*\#1 <function called from gdb>.*\#2 add \\(a=2, b=3\\).*\#3 <function called from gdb>.*\#4 main.*" \
437 "backtrace at nested call level 2"
438 gdb_test "print sum10(2,4,6,8,10,12,14,16,18,20)" \
439 "The program being debugged stopped while.*" \
440 "stop at nested call level 3"
441 gdb_test "backtrace" \
442 "\#0 sum10 \\(i0=2, i1=4, i2=6, i3=8, i4=10, i5=12, i6=14, i7=16, i8=18, i9=20\\).*\#1 <function called from gdb>.*\#2 add \\(a=4, b=5\\).*\#3 <function called from gdb>.*\#4 add \\(a=2, b=3\\).*\#5 <function called from gdb>.*\#6 main.*" \
443 "backtrace at nested call level 3"
444 gdb_test "print t_small_values(1,3,5,7,9,11,13,15,17,19)" \
445 "The program being debugged stopped while.*" \
446 "stop at nested call level 4"
447 gdb_test "backtrace" \
448 "\#0 t_small_values \\(arg1=1 '.001', arg2=3, arg3=5, arg4=7 '.a', arg5=9, arg6=11 '.v', arg7=13, arg8=15, arg9=17, arg10=19\\).*\#2 sum10 \\(i0=2, i1=4, i2=6, i3=8, i4=10, i5=12, i6=14, i7=16, i8=18, i9=20\\).*\#3 <function called from gdb>.*\#4 add \\(a=4, b=5\\).*\#5 <function called from gdb>.*\#6 add \\(a=2, b=3\\).*\#7 <function called from gdb>.*\#8 main.*" \
449 "backtrace at nested call level 4"
450 gdb_test "finish" "Value returned is .* = 100" \
451 "Finish from nested call level 4"
452 gdb_test "backtrace" \
453 "\#0 sum10 \\(i0=2, i1=4, i2=6, i3=8, i4=10, i5=12, i6=14, i7=16, i8=18, i9=20\\).*\#1 <function called from gdb>.*\#2 add \\(a=4, b=5\\).*\#3 <function called from gdb>.*\#4 add \\(a=2, b=3\\).*\#5 <function called from gdb>.*\#6 main.*" \
454 "backtrace after finish from nested call level 4"
455 gdb_test "finish" "Value returned is .* = 110" \
456 "Finish from nested call level 3"
457 gdb_test "backtrace" \
458 "\#0 add \\(a=4, b=5\\).*\#1 <function called from gdb>.*\#2 add \\(a=2, b=3\\).*\#3 <function called from gdb>.*\#4 main.*" \
459 "backtrace after finish from nested call level 3"
460 gdb_test "finish" "Value returned is .* = 9" \
461 "Finish from nested call level 2"
462 gdb_test "backtrace" \
463 "\#0 add \\(a=2, b=3\\).*\#1 <function called from gdb>.*\#2 main.*" \
464 "backtrace after finish from nested call level 2"
465 gdb_test "finish" "Value returned is .* = 5" \
466 "Finish from nested call level 1"
467 gdb_test "backtrace" "\#0 main .*" \
468 "backtrace after finish from nested call level 1"
469
470 set new_reg_content [fetch_all_registers \
471 "register contents after nested call dummies"]
472 if {$old_reg_content == $new_reg_content} then {
473 pass "nested call dummies preserve register contents"
474 } else {
475 fail "nested call dummies preserve register contents"
476 }
477
478 # GDB should not crash by internal error on $sp underflow during the inferior
479 # call. It is OK it will stop on some: Cannot access memory at address 0x$hex.
480
481 if {![target_info exists gdb,nosignals] && ![istarget "*-*-uclinux*"]} {
482 gdb_test {set $old_sp = $sp}
483
484 gdb_test {set $sp = 0}
485 gdb_test "call doubleit (1)" "" "sp == 0: call doubleit (1)"
486
487 gdb_test {set $sp = -1}
488 gdb_test "call doubleit (1)" "" "sp == -1: call doubleit (1)"
489
490 gdb_test {set $sp = $old_sp}
491 }
This page took 0.040255 seconds and 5 git commands to generate.