1 /* Perform an inferior function call, for GDB, the GNU debugger.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
25 #include "breakpoint.h"
29 #include "gdb_assert.h"
36 #include "gdb_string.h"
38 #include "dummy-frame.h"
40 /* NOTE: cagney/2003-04-16: What's the future of this code?
42 GDB needs an asynchronous expression evaluator, that means an
43 asynchronous inferior function call implementation, and that in
44 turn means restructuring the code so that it is event driven. */
46 /* How you should pass arguments to a function depends on whether it
47 was defined in K&R style or prototype style. If you define a
48 function using the K&R syntax that takes a `float' argument, then
49 callers must pass that argument as a `double'. If you define the
50 function using the prototype syntax, then you must pass the
51 argument as a `float', with no promotion.
53 Unfortunately, on certain older platforms, the debug info doesn't
54 indicate reliably how each function was defined. A function type's
55 TYPE_FLAG_PROTOTYPED flag may be clear, even if the function was
56 defined in prototype style. When calling a function whose
57 TYPE_FLAG_PROTOTYPED flag is clear, GDB consults this flag to
60 For modern targets, it is proper to assume that, if the prototype
61 flag is clear, that can be trusted: `float' arguments should be
62 promoted to `double'. For some older targets, if the prototype
63 flag is clear, that doesn't tell us anything. The default is to
64 trust the debug information; the user can override this behavior
65 with "set coerce-float-to-double 0". */
67 static int coerce_float_to_double_p
= 1;
69 show_coerce_float_to_double_p (struct ui_file
*file
, int from_tty
,
70 struct cmd_list_element
*c
, const char *value
)
72 fprintf_filtered (file
, _("\
73 Coercion of floats to doubles when calling functions is %s.\n"),
77 /* This boolean tells what gdb should do if a signal is received while
78 in a function called from gdb (call dummy). If set, gdb unwinds
79 the stack and restore the context to what as it was before the
82 The default is to stop in the frame where the signal was received. */
84 int unwind_on_signal_p
= 0;
86 show_unwind_on_signal_p (struct ui_file
*file
, int from_tty
,
87 struct cmd_list_element
*c
, const char *value
)
89 fprintf_filtered (file
, _("\
90 Unwinding of stack if a signal is received while in a call dummy is %s.\n"),
95 /* Perform the standard coercions that are specified
96 for arguments to be passed to C functions.
98 If PARAM_TYPE is non-NULL, it is the expected parameter type.
99 IS_PROTOTYPED is non-zero if the function declaration is prototyped. */
101 static struct value
*
102 value_arg_coerce (struct value
*arg
, struct type
*param_type
,
105 struct type
*arg_type
= check_typedef (value_type (arg
));
107 = param_type
? check_typedef (param_type
) : arg_type
;
109 switch (TYPE_CODE (type
))
113 struct value
*new_value
;
115 if (TYPE_CODE (arg_type
) == TYPE_CODE_REF
)
116 return value_cast_pointers (type
, arg
);
118 /* Cast the value to the reference's target type, and then
119 convert it back to a reference. This will issue an error
120 if the value was not previously in memory - in some cases
121 we should clearly be allowing this, but how? */
122 new_value
= value_cast (TYPE_TARGET_TYPE (type
), arg
);
123 new_value
= value_ref (new_value
);
130 /* If we don't have a prototype, coerce to integer type if necessary. */
133 if (TYPE_LENGTH (type
) < TYPE_LENGTH (builtin_type_int
))
134 type
= builtin_type_int
;
136 /* Currently all target ABIs require at least the width of an integer
137 type for an argument. We may have to conditionalize the following
138 type coercion for future targets. */
139 if (TYPE_LENGTH (type
) < TYPE_LENGTH (builtin_type_int
))
140 type
= builtin_type_int
;
143 if (!is_prototyped
&& coerce_float_to_double_p
)
145 if (TYPE_LENGTH (type
) < TYPE_LENGTH (builtin_type_double
))
146 type
= builtin_type_double
;
147 else if (TYPE_LENGTH (type
) > TYPE_LENGTH (builtin_type_double
))
148 type
= builtin_type_long_double
;
152 type
= lookup_pointer_type (type
);
154 case TYPE_CODE_ARRAY
:
155 /* Arrays are coerced to pointers to their first element, unless
156 they are vectors, in which case we want to leave them alone,
157 because they are passed by value. */
158 if (current_language
->c_style_arrays
)
159 if (!TYPE_VECTOR (type
))
160 type
= lookup_pointer_type (TYPE_TARGET_TYPE (type
));
162 case TYPE_CODE_UNDEF
:
164 case TYPE_CODE_STRUCT
:
165 case TYPE_CODE_UNION
:
168 case TYPE_CODE_RANGE
:
169 case TYPE_CODE_STRING
:
170 case TYPE_CODE_BITSTRING
:
171 case TYPE_CODE_ERROR
:
172 case TYPE_CODE_MEMBERPTR
:
173 case TYPE_CODE_METHODPTR
:
174 case TYPE_CODE_METHOD
:
175 case TYPE_CODE_COMPLEX
:
180 return value_cast (type
, arg
);
183 /* Determine a function's address and its return type from its value.
184 Calls error() if the function is not valid for calling. */
187 find_function_addr (struct value
*function
, struct type
**retval_type
)
189 struct type
*ftype
= check_typedef (value_type (function
));
190 enum type_code code
= TYPE_CODE (ftype
);
191 struct type
*value_type
;
194 /* If it's a member function, just look at the function
197 /* Determine address to call. */
198 if (code
== TYPE_CODE_FUNC
|| code
== TYPE_CODE_METHOD
)
200 funaddr
= VALUE_ADDRESS (function
);
201 value_type
= TYPE_TARGET_TYPE (ftype
);
203 else if (code
== TYPE_CODE_PTR
)
205 funaddr
= value_as_address (function
);
206 ftype
= check_typedef (TYPE_TARGET_TYPE (ftype
));
207 if (TYPE_CODE (ftype
) == TYPE_CODE_FUNC
208 || TYPE_CODE (ftype
) == TYPE_CODE_METHOD
)
210 funaddr
= gdbarch_convert_from_func_ptr_addr (current_gdbarch
,
213 value_type
= TYPE_TARGET_TYPE (ftype
);
216 value_type
= builtin_type_int
;
218 else if (code
== TYPE_CODE_INT
)
220 /* Handle the case of functions lacking debugging info.
221 Their values are characters since their addresses are char */
222 if (TYPE_LENGTH (ftype
) == 1)
223 funaddr
= value_as_address (value_addr (function
));
225 /* Handle integer used as address of a function. */
226 funaddr
= (CORE_ADDR
) value_as_long (function
);
228 value_type
= builtin_type_int
;
231 error (_("Invalid data type for function to be called."));
233 if (retval_type
!= NULL
)
234 *retval_type
= value_type
;
235 return funaddr
+ DEPRECATED_FUNCTION_START_OFFSET
;
238 /* Call breakpoint_auto_delete on the current contents of the bpstat
239 pointed to by arg (which is really a bpstat *). */
242 breakpoint_auto_delete_contents (void *arg
)
244 breakpoint_auto_delete (*(bpstat
*) arg
);
248 generic_push_dummy_code (struct gdbarch
*gdbarch
,
249 CORE_ADDR sp
, CORE_ADDR funaddr
, int using_gcc
,
250 struct value
**args
, int nargs
,
251 struct type
*value_type
,
252 CORE_ADDR
*real_pc
, CORE_ADDR
*bp_addr
)
254 /* Something here to findout the size of a breakpoint and then
255 allocate space for it on the stack. */
257 /* This code assumes frame align. */
258 gdb_assert (gdbarch_frame_align_p (gdbarch
));
259 /* Force the stack's alignment. The intent is to ensure that the SP
260 is aligned to at least a breakpoint instruction's boundary. */
261 sp
= gdbarch_frame_align (gdbarch
, sp
);
262 /* Allocate space for, and then position the breakpoint on the
264 if (gdbarch_inner_than (gdbarch
, 1, 2))
267 gdbarch_breakpoint_from_pc (gdbarch
, &bppc
, &bplen
);
268 sp
= gdbarch_frame_align (gdbarch
, sp
- bplen
);
270 /* Should the breakpoint size/location be re-computed here? */
275 gdbarch_breakpoint_from_pc (gdbarch
, bp_addr
, &bplen
);
276 sp
= gdbarch_frame_align (gdbarch
, sp
+ bplen
);
278 /* Inferior resumes at the function entry point. */
279 (*real_pc
) = funaddr
;
283 /* For CALL_DUMMY_ON_STACK, push a breakpoint sequence that the called
284 function returns to. */
287 push_dummy_code (struct gdbarch
*gdbarch
,
288 CORE_ADDR sp
, CORE_ADDR funaddr
, int using_gcc
,
289 struct value
**args
, int nargs
,
290 struct type
*value_type
,
291 CORE_ADDR
*real_pc
, CORE_ADDR
*bp_addr
)
293 if (gdbarch_push_dummy_code_p (gdbarch
))
294 return gdbarch_push_dummy_code (gdbarch
, sp
, funaddr
, using_gcc
,
295 args
, nargs
, value_type
, real_pc
, bp_addr
);
297 return generic_push_dummy_code (gdbarch
, sp
, funaddr
, using_gcc
,
298 args
, nargs
, value_type
, real_pc
, bp_addr
);
301 /* All this stuff with a dummy frame may seem unnecessarily complicated
302 (why not just save registers in GDB?). The purpose of pushing a dummy
303 frame which looks just like a real frame is so that if you call a
304 function and then hit a breakpoint (get a signal, etc), "backtrace"
305 will look right. Whether the backtrace needs to actually show the
306 stack at the time the inferior function was called is debatable, but
307 it certainly needs to not display garbage. So if you are contemplating
308 making dummy frames be different from normal frames, consider that. */
310 /* Perform a function call in the inferior.
311 ARGS is a vector of values of arguments (NARGS of them).
312 FUNCTION is a value, the function to be called.
313 Returns a value representing what the function returned.
314 May fail to return, if a breakpoint or signal is hit
315 during the execution of the function.
317 ARGS is modified to contain coerced values. */
320 call_function_by_hand (struct value
*function
, int nargs
, struct value
**args
)
323 CORE_ADDR dummy_addr
;
324 struct type
*values_type
;
325 unsigned char struct_return
;
326 CORE_ADDR struct_addr
= 0;
327 struct regcache
*retbuf
;
328 struct cleanup
*retbuf_cleanup
;
329 struct inferior_status
*inf_status
;
330 struct cleanup
*inf_status_cleanup
;
332 int using_gcc
; /* Set to version of gcc in use, or zero if not gcc */
334 struct type
*ftype
= check_typedef (value_type (function
));
336 struct regcache
*caller_regcache
;
337 struct cleanup
*caller_regcache_cleanup
;
338 struct frame_id dummy_id
;
340 if (TYPE_CODE (ftype
) == TYPE_CODE_PTR
)
341 ftype
= check_typedef (TYPE_TARGET_TYPE (ftype
));
343 if (!target_has_execution
)
346 if (!gdbarch_push_dummy_call_p (current_gdbarch
))
347 error (_("This target does not support function calls"));
349 /* Create a cleanup chain that contains the retbuf (buffer
350 containing the register values). This chain is create BEFORE the
351 inf_status chain so that the inferior status can cleaned up
352 (restored or discarded) without having the retbuf freed. */
353 retbuf
= regcache_xmalloc (current_gdbarch
);
354 retbuf_cleanup
= make_cleanup_regcache_xfree (retbuf
);
356 /* A cleanup for the inferior status. Create this AFTER the retbuf
357 so that this can be discarded or applied without interfering with
359 inf_status
= save_inferior_status (1);
360 inf_status_cleanup
= make_cleanup_restore_inferior_status (inf_status
);
362 /* Save the caller's registers so that they can be restored once the
363 callee returns. To allow nested calls the registers are (further
364 down) pushed onto a dummy frame stack. Include a cleanup (which
365 is tossed once the regcache has been pushed). */
366 caller_regcache
= frame_save_as_regcache (get_current_frame ());
367 caller_regcache_cleanup
= make_cleanup_regcache_xfree (caller_regcache
);
369 /* Ensure that the initial SP is correctly aligned. */
371 CORE_ADDR old_sp
= get_frame_sp (get_current_frame ());
372 if (gdbarch_frame_align_p (current_gdbarch
))
374 sp
= gdbarch_frame_align (current_gdbarch
, old_sp
);
375 /* NOTE: cagney/2003-08-13: Skip the "red zone". For some
376 ABIs, a function can use memory beyond the inner most stack
377 address. AMD64 called that region the "red zone". Skip at
378 least the "red zone" size before allocating any space on
380 if (INNER_THAN (1, 2))
381 sp
-= gdbarch_frame_red_zone_size (current_gdbarch
);
383 sp
+= gdbarch_frame_red_zone_size (current_gdbarch
);
385 gdb_assert (sp
== gdbarch_frame_align (current_gdbarch
, sp
));
386 /* NOTE: cagney/2002-09-18:
388 On a RISC architecture, a void parameterless generic dummy
389 frame (i.e., no parameters, no result) typically does not
390 need to push anything the stack and hence can leave SP and
391 FP. Similarly, a frameless (possibly leaf) function does
392 not push anything on the stack and, hence, that too can
393 leave FP and SP unchanged. As a consequence, a sequence of
394 void parameterless generic dummy frame calls to frameless
395 functions will create a sequence of effectively identical
396 frames (SP, FP and TOS and PC the same). This, not
397 suprisingly, results in what appears to be a stack in an
398 infinite loop --- when GDB tries to find a generic dummy
399 frame on the internal dummy frame stack, it will always
402 To avoid this problem, the code below always grows the
403 stack. That way, two dummy frames can never be identical.
404 It does burn a few bytes of stack but that is a small price
408 if (INNER_THAN (1, 2))
409 /* Stack grows down. */
410 sp
= gdbarch_frame_align (current_gdbarch
, old_sp
- 1);
412 /* Stack grows up. */
413 sp
= gdbarch_frame_align (current_gdbarch
, old_sp
+ 1);
415 gdb_assert ((INNER_THAN (1, 2) && sp
<= old_sp
)
416 || (INNER_THAN (2, 1) && sp
>= old_sp
));
419 /* FIXME: cagney/2002-09-18: Hey, you loose!
421 Who knows how badly aligned the SP is!
423 If the generic dummy frame ends up empty (because nothing is
424 pushed) GDB won't be able to correctly perform back traces.
425 If a target is having trouble with backtraces, first thing to
426 do is add FRAME_ALIGN() to the architecture vector. If that
427 fails, try unwind_dummy_id().
429 If the ABI specifies a "Red Zone" (see the doco) the code
430 below will quietly trash it. */
434 funaddr
= find_function_addr (function
, &values_type
);
435 CHECK_TYPEDEF (values_type
);
438 struct block
*b
= block_for_pc (funaddr
);
439 /* If compiled without -g, assume GCC 2. */
440 using_gcc
= (b
== NULL
? 2 : BLOCK_GCC_COMPILED (b
));
443 /* Are we returning a value using a structure return or a normal
446 struct_return
= using_struct_return (values_type
, using_gcc
);
448 /* Determine the location of the breakpoint (and possibly other
449 stuff) that the called function will return to. The SPARC, for a
450 function returning a structure or union, needs to make space for
451 not just the breakpoint but also an extra word containing the
452 size (?) of the structure being passed. */
454 /* The actual breakpoint (at BP_ADDR) is inserted separatly so there
455 is no need to write that out. */
457 switch (gdbarch_call_dummy_location (current_gdbarch
))
460 /* "dummy_addr" is here just to keep old targets happy. New
461 targets return that same information via "sp" and "bp_addr". */
462 if (INNER_THAN (1, 2))
464 sp
= push_dummy_code (current_gdbarch
, sp
, funaddr
,
465 using_gcc
, args
, nargs
, values_type
,
472 sp
= push_dummy_code (current_gdbarch
, sp
, funaddr
,
473 using_gcc
, args
, nargs
, values_type
,
479 dummy_addr
= entry_point_address ();
480 /* Make certain that the address points at real code, and not a
481 function descriptor. */
482 dummy_addr
= gdbarch_convert_from_func_ptr_addr (current_gdbarch
,
485 /* A call dummy always consists of just a single breakpoint, so
486 it's address is the same as the address of the dummy. */
487 bp_addr
= dummy_addr
;
490 /* Some executables define a symbol __CALL_DUMMY_ADDRESS whose
491 address is the location where the breakpoint should be
492 placed. Once all targets are using the overhauled frame code
493 this can be deleted - ON_STACK is a better option. */
495 struct minimal_symbol
*sym
;
497 sym
= lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL
, NULL
);
500 dummy_addr
= SYMBOL_VALUE_ADDRESS (sym
);
502 dummy_addr
= entry_point_address ();
503 /* Make certain that the address points at real code, and not
504 a function descriptor. */
505 dummy_addr
= gdbarch_convert_from_func_ptr_addr (current_gdbarch
,
508 /* A call dummy always consists of just a single breakpoint,
509 so it's address is the same as the address of the dummy. */
510 bp_addr
= dummy_addr
;
514 internal_error (__FILE__
, __LINE__
, _("bad switch"));
517 if (nargs
< TYPE_NFIELDS (ftype
))
518 error (_("too few arguments in function call"));
522 for (i
= nargs
- 1; i
>= 0; i
--)
525 struct type
*param_type
;
527 /* FIXME drow/2002-05-31: Should just always mark methods as
528 prototyped. Can we respect TYPE_VARARGS? Probably not. */
529 if (TYPE_CODE (ftype
) == TYPE_CODE_METHOD
)
531 else if (i
< TYPE_NFIELDS (ftype
))
532 prototyped
= TYPE_PROTOTYPED (ftype
);
536 if (i
< TYPE_NFIELDS (ftype
))
537 param_type
= TYPE_FIELD_TYPE (ftype
, i
);
541 args
[i
] = value_arg_coerce (args
[i
], param_type
, prototyped
);
543 /* elz: this code is to handle the case in which the function
544 to be called has a pointer to function as parameter and the
545 corresponding actual argument is the address of a function
546 and not a pointer to function variable. In aCC compiled
547 code, the calls through pointers to functions (in the body
548 of the function called by hand) are made via
549 $$dyncall_external which requires some registers setting,
550 this is taken care of if we call via a function pointer
551 variable, but not via a function address. In cc this is
556 if (param_type
!= NULL
&& TYPE_CODE (ftype
) != TYPE_CODE_METHOD
)
558 /* if this parameter is a pointer to function. */
559 if (TYPE_CODE (param_type
) == TYPE_CODE_PTR
)
560 if (TYPE_CODE (TYPE_TARGET_TYPE (param_type
)) == TYPE_CODE_FUNC
)
561 /* elz: FIXME here should go the test about the
562 compiler used to compile the target. We want to
563 issue the error message only if the compiler
564 used was HP's aCC. If we used HP's cc, then
565 there is no problem and no need to return at
567 /* Go see if the actual parameter is a variable of
568 type pointer to function or just a function. */
569 if (VALUE_LVAL (args
[i
]) == not_lval
)
572 /* NOTE: cagney/2005-01-02: THIS IS BOGUS. */
573 if (find_pc_partial_function ((CORE_ADDR
) value_contents (args
[i
])[0], &arg_name
, NULL
, NULL
))
575 You cannot use function <%s> as argument. \n\
576 You must use a pointer to function type variable. Command ignored."), arg_name
);
583 if (DEPRECATED_REG_STRUCT_HAS_ADDR_P ())
586 /* This is a machine like the sparc, where we may need to pass a
587 pointer to the structure, not the structure itself. */
588 for (i
= nargs
- 1; i
>= 0; i
--)
590 struct type
*arg_type
= check_typedef (value_type (args
[i
]));
591 if ((TYPE_CODE (arg_type
) == TYPE_CODE_STRUCT
592 || TYPE_CODE (arg_type
) == TYPE_CODE_UNION
593 || TYPE_CODE (arg_type
) == TYPE_CODE_ARRAY
594 || TYPE_CODE (arg_type
) == TYPE_CODE_STRING
595 || TYPE_CODE (arg_type
) == TYPE_CODE_BITSTRING
596 || TYPE_CODE (arg_type
) == TYPE_CODE_SET
597 || (TYPE_CODE (arg_type
) == TYPE_CODE_FLT
598 && TYPE_LENGTH (arg_type
) > 8)
600 && DEPRECATED_REG_STRUCT_HAS_ADDR (using_gcc
, arg_type
))
603 int len
; /* = TYPE_LENGTH (arg_type); */
605 arg_type
= check_typedef (value_enclosing_type (args
[i
]));
606 len
= TYPE_LENGTH (arg_type
);
609 if (INNER_THAN (1, 2))
611 /* stack grows downward */
613 /* ... so the address of the thing we push is the
614 stack pointer after we push it. */
619 /* The stack grows up, so the address of the thing
620 we push is the stack pointer before we push it. */
624 /* Push the structure. */
625 write_memory (addr
, value_contents_all (args
[i
]), len
);
626 /* The value we're going to pass is the address of the
627 thing we just pushed. */
628 /*args[i] = value_from_longest (lookup_pointer_type (values_type),
630 args
[i
] = value_from_pointer (lookup_pointer_type (arg_type
),
637 /* Reserve space for the return structure to be written on the
638 stack, if necessary. Make certain that the value is correctly
643 int len
= TYPE_LENGTH (values_type
);
644 if (INNER_THAN (1, 2))
646 /* Stack grows downward. Align STRUCT_ADDR and SP after
647 making space for the return value. */
649 if (gdbarch_frame_align_p (current_gdbarch
))
650 sp
= gdbarch_frame_align (current_gdbarch
, sp
);
655 /* Stack grows upward. Align the frame, allocate space, and
656 then again, re-align the frame??? */
657 if (gdbarch_frame_align_p (current_gdbarch
))
658 sp
= gdbarch_frame_align (current_gdbarch
, sp
);
661 if (gdbarch_frame_align_p (current_gdbarch
))
662 sp
= gdbarch_frame_align (current_gdbarch
, sp
);
666 /* Create the dummy stack frame. Pass in the call dummy address as,
667 presumably, the ABI code knows where, in the call dummy, the
668 return address should be pointed. */
669 sp
= gdbarch_push_dummy_call (current_gdbarch
, function
, current_regcache
,
670 bp_addr
, nargs
, args
, sp
, struct_return
,
673 /* Set up a frame ID for the dummy frame so we can pass it to
674 set_momentary_breakpoint. We need to give the breakpoint a frame
675 ID so that the breakpoint code can correctly re-identify the
677 /* Sanity. The exact same SP value is returned by PUSH_DUMMY_CALL,
678 saved as the dummy-frame TOS, and used by unwind_dummy_id to form
679 the frame ID's stack address. */
680 dummy_id
= frame_id_build (sp
, bp_addr
);
682 /* Create a momentary breakpoint at the return address of the
683 inferior. That way it breaks when it returns. */
686 struct breakpoint
*bpt
;
687 struct symtab_and_line sal
;
688 init_sal (&sal
); /* initialize to zeroes */
690 sal
.section
= find_pc_overlay (sal
.pc
);
691 /* Sanity. The exact same SP value is returned by
692 PUSH_DUMMY_CALL, saved as the dummy-frame TOS, and used by
693 unwind_dummy_id to form the frame ID's stack address. */
694 bpt
= set_momentary_breakpoint (sal
, dummy_id
, bp_call_dummy
);
695 bpt
->disposition
= disp_del
;
698 /* Everything's ready, push all the info needed to restore the
699 caller (and identify the dummy-frame) onto the dummy-frame
701 dummy_frame_push (caller_regcache
, &dummy_id
);
702 discard_cleanups (caller_regcache_cleanup
);
704 /* - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP -
705 If you're looking to implement asynchronous dummy-frames, then
706 just below is the place to chop this function in two.. */
708 /* Now proceed, having reached the desired place. */
709 clear_proceed_status ();
711 /* Execute a "stack dummy", a piece of code stored in the stack by
712 the debugger to be executed in the inferior.
714 The dummy's frame is automatically popped whenever that break is
715 hit. If that is the first time the program stops,
716 call_function_by_hand returns to its caller with that frame
717 already gone and sets RC to 0.
719 Otherwise, set RC to a non-zero value. If the called function
720 receives a random signal, we do not allow the user to continue
721 executing it as this may not work. The dummy frame is poped and
722 we return 1. If we hit a breakpoint, we leave the frame in place
723 and return 2 (the frame will eventually be popped when we do hit
724 the dummy end breakpoint). */
727 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, 0);
730 /* If all error()s out of proceed ended up calling normal_stop
731 (and perhaps they should; it already does in the special case
732 of error out of resume()), then we wouldn't need this. */
733 make_cleanup (breakpoint_auto_delete_contents
, &stop_bpstat
);
735 disable_watchpoints_before_interactive_call_start ();
736 proceed_to_finish
= 1; /* We want stop_registers, please... */
738 if (target_can_async_p ())
739 saved_async
= target_async_mask (0);
741 proceed (real_pc
, TARGET_SIGNAL_0
, 0);
744 target_async_mask (saved_async
);
746 enable_watchpoints_after_interactive_call_stop ();
748 discard_cleanups (old_cleanups
);
751 if (stopped_by_random_signal
|| !stop_stack_dummy
)
753 /* Find the name of the function we're about to complain about. */
754 const char *name
= NULL
;
756 struct symbol
*symbol
= find_pc_function (funaddr
);
758 name
= SYMBOL_PRINT_NAME (symbol
);
761 /* Try the minimal symbols. */
762 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (funaddr
);
764 name
= SYMBOL_PRINT_NAME (msymbol
);
768 /* Can't use a cleanup here. It is discarded, instead use
770 char *tmp
= xstrprintf ("at %s", hex_string (funaddr
));
771 char *a
= alloca (strlen (tmp
) + 1);
777 if (stopped_by_random_signal
)
779 /* We stopped inside the FUNCTION because of a random
780 signal. Further execution of the FUNCTION is not
783 if (unwind_on_signal_p
)
785 /* The user wants the context restored. */
787 /* We must get back to the frame we were before the
789 frame_pop (get_current_frame ());
791 /* FIXME: Insert a bunch of wrap_here; name can be very
792 long if it's a C++ name with arguments and stuff. */
794 The program being debugged was signaled while in a function called from GDB.\n\
795 GDB has restored the context to what it was before the call.\n\
796 To change this behavior use \"set unwindonsignal off\"\n\
797 Evaluation of the expression containing the function (%s) will be abandoned."),
802 /* The user wants to stay in the frame where we stopped
804 /* If we restored the inferior status (via the cleanup),
805 we would print a spurious error message (Unable to
806 restore previously selected frame), would write the
807 registers from the inf_status (which is wrong), and
808 would do other wrong things. */
809 discard_cleanups (inf_status_cleanup
);
810 discard_inferior_status (inf_status
);
811 /* FIXME: Insert a bunch of wrap_here; name can be very
812 long if it's a C++ name with arguments and stuff. */
814 The program being debugged was signaled while in a function called from GDB.\n\
815 GDB remains in the frame where the signal was received.\n\
816 To change this behavior use \"set unwindonsignal on\"\n\
817 Evaluation of the expression containing the function (%s) will be abandoned."),
822 if (!stop_stack_dummy
)
824 /* We hit a breakpoint inside the FUNCTION. */
825 /* If we restored the inferior status (via the cleanup), we
826 would print a spurious error message (Unable to restore
827 previously selected frame), would write the registers
828 from the inf_status (which is wrong), and would do other
830 discard_cleanups (inf_status_cleanup
);
831 discard_inferior_status (inf_status
);
832 /* The following error message used to say "The expression
833 which contained the function call has been discarded."
834 It is a hard concept to explain in a few words. Ideally,
835 GDB would be able to resume evaluation of the expression
836 when the function finally is done executing. Perhaps
837 someday this will be implemented (it would not be easy). */
838 /* FIXME: Insert a bunch of wrap_here; name can be very long if it's
839 a C++ name with arguments and stuff. */
841 The program being debugged stopped while in a function called from GDB.\n\
842 When the function (%s) is done executing, GDB will silently\n\
843 stop (instead of continuing to evaluate the expression containing\n\
844 the function call)."), name
);
847 /* The above code errors out, so ... */
848 internal_error (__FILE__
, __LINE__
, _("... should not be here"));
851 /* If we get here the called FUNCTION run to completion. */
853 /* On normal return, the stack dummy has been popped already. */
854 regcache_cpy_no_passthrough (retbuf
, stop_registers
);
856 /* Restore the inferior status, via its cleanup. At this stage,
857 leave the RETBUF alone. */
858 do_cleanups (inf_status_cleanup
);
860 /* Figure out the value returned by the function. */
862 struct value
*retval
= NULL
;
864 if (TYPE_CODE (values_type
) == TYPE_CODE_VOID
)
866 /* If the function returns void, don't bother fetching the
868 retval
= allocate_value (values_type
);
872 struct gdbarch
*arch
= current_gdbarch
;
874 switch (gdbarch_return_value (arch
, values_type
, NULL
, NULL
, NULL
))
876 case RETURN_VALUE_REGISTER_CONVENTION
:
877 case RETURN_VALUE_ABI_RETURNS_ADDRESS
:
878 case RETURN_VALUE_ABI_PRESERVES_ADDRESS
:
879 retval
= allocate_value (values_type
);
880 gdbarch_return_value (current_gdbarch
, values_type
, retbuf
,
881 value_contents_raw (retval
), NULL
);
883 case RETURN_VALUE_STRUCT_CONVENTION
:
884 retval
= value_at (values_type
, struct_addr
);
889 do_cleanups (retbuf_cleanup
);
897 /* Provide a prototype to silence -Wmissing-prototypes. */
898 void _initialize_infcall (void);
901 _initialize_infcall (void)
903 add_setshow_boolean_cmd ("coerce-float-to-double", class_obscure
,
904 &coerce_float_to_double_p
, _("\
905 Set coercion of floats to doubles when calling functions."), _("\
906 Show coercion of floats to doubles when calling functions"), _("\
907 Variables of type float should generally be converted to doubles before\n\
908 calling an unprototyped function, and left alone when calling a prototyped\n\
909 function. However, some older debug info formats do not provide enough\n\
910 information to determine that a function is prototyped. If this flag is\n\
911 set, GDB will perform the conversion for a function it considers\n\
913 The default is to perform the conversion.\n"),
915 show_coerce_float_to_double_p
,
916 &setlist
, &showlist
);
918 add_setshow_boolean_cmd ("unwindonsignal", no_class
,
919 &unwind_on_signal_p
, _("\
920 Set unwinding of stack if a signal is received while in a call dummy."), _("\
921 Show unwinding of stack if a signal is received while in a call dummy."), _("\
922 The unwindonsignal lets the user determine what gdb should do if a signal\n\
923 is received while in a function called from gdb (call dummy). If set, gdb\n\
924 unwinds the stack and restore the context to what as it was before the call.\n\
925 The default is to stop in the frame where the signal was received."),
927 show_unwind_on_signal_p
,
928 &setlist
, &showlist
);