1 /* Perform an inferior function call, for GDB, the GNU debugger.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
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., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
25 #include "breakpoint.h"
29 #include "gdb_assert.h"
36 #include "gdb_string.h"
38 /* NOTE: cagney/2003-04-16: What's the future of this code?
40 GDB needs an asynchronous expression evaluator, that means an
41 asynchronous inferior function call implementation, and that in
42 turn means restructuring the code so that it is event driven. */
44 /* How you should pass arguments to a function depends on whether it
45 was defined in K&R style or prototype style. If you define a
46 function using the K&R syntax that takes a `float' argument, then
47 callers must pass that argument as a `double'. If you define the
48 function using the prototype syntax, then you must pass the
49 argument as a `float', with no promotion.
51 Unfortunately, on certain older platforms, the debug info doesn't
52 indicate reliably how each function was defined. A function type's
53 TYPE_FLAG_PROTOTYPED flag may be clear, even if the function was
54 defined in prototype style. When calling a function whose
55 TYPE_FLAG_PROTOTYPED flag is clear, GDB consults this flag to
58 For modern targets, it is proper to assume that, if the prototype
59 flag is clear, that can be trusted: `float' arguments should be
60 promoted to `double'. For some older targets, if the prototype
61 flag is clear, that doesn't tell us anything. The default is to
62 trust the debug information; the user can override this behavior
63 with "set coerce-float-to-double 0". */
65 static int coerce_float_to_double_p
= 1;
67 /* This boolean tells what gdb should do if a signal is received while
68 in a function called from gdb (call dummy). If set, gdb unwinds
69 the stack and restore the context to what as it was before the
72 The default is to stop in the frame where the signal was received. */
74 int unwind_on_signal_p
= 0;
76 /* Perform the standard coercions that are specified
77 for arguments to be passed to C functions.
79 If PARAM_TYPE is non-NULL, it is the expected parameter type.
80 IS_PROTOTYPED is non-zero if the function declaration is prototyped. */
83 value_arg_coerce (struct value
*arg
, struct type
*param_type
,
86 register struct type
*arg_type
= check_typedef (VALUE_TYPE (arg
));
87 register struct type
*type
88 = param_type
? check_typedef (param_type
) : arg_type
;
90 switch (TYPE_CODE (type
))
93 if (TYPE_CODE (arg_type
) != TYPE_CODE_REF
94 && TYPE_CODE (arg_type
) != TYPE_CODE_PTR
)
96 arg
= value_addr (arg
);
97 VALUE_TYPE (arg
) = param_type
;
105 /* If we don't have a prototype, coerce to integer type if necessary. */
108 if (TYPE_LENGTH (type
) < TYPE_LENGTH (builtin_type_int
))
109 type
= builtin_type_int
;
111 /* Currently all target ABIs require at least the width of an integer
112 type for an argument. We may have to conditionalize the following
113 type coercion for future targets. */
114 if (TYPE_LENGTH (type
) < TYPE_LENGTH (builtin_type_int
))
115 type
= builtin_type_int
;
118 if (!is_prototyped
&& coerce_float_to_double_p
)
120 if (TYPE_LENGTH (type
) < TYPE_LENGTH (builtin_type_double
))
121 type
= builtin_type_double
;
122 else if (TYPE_LENGTH (type
) > TYPE_LENGTH (builtin_type_double
))
123 type
= builtin_type_long_double
;
127 type
= lookup_pointer_type (type
);
129 case TYPE_CODE_ARRAY
:
130 /* Arrays are coerced to pointers to their first element, unless
131 they are vectors, in which case we want to leave them alone,
132 because they are passed by value. */
133 if (current_language
->c_style_arrays
)
134 if (!TYPE_VECTOR (type
))
135 type
= lookup_pointer_type (TYPE_TARGET_TYPE (type
));
137 case TYPE_CODE_UNDEF
:
139 case TYPE_CODE_STRUCT
:
140 case TYPE_CODE_UNION
:
143 case TYPE_CODE_RANGE
:
144 case TYPE_CODE_STRING
:
145 case TYPE_CODE_BITSTRING
:
146 case TYPE_CODE_ERROR
:
147 case TYPE_CODE_MEMBER
:
148 case TYPE_CODE_METHOD
:
149 case TYPE_CODE_COMPLEX
:
154 return value_cast (type
, arg
);
157 /* Determine a function's address and its return type from its value.
158 Calls error() if the function is not valid for calling. */
161 find_function_addr (struct value
*function
, struct type
**retval_type
)
163 register struct type
*ftype
= check_typedef (VALUE_TYPE (function
));
164 register enum type_code code
= TYPE_CODE (ftype
);
165 struct type
*value_type
;
168 /* If it's a member function, just look at the function
171 /* Determine address to call. */
172 if (code
== TYPE_CODE_FUNC
|| code
== TYPE_CODE_METHOD
)
174 funaddr
= VALUE_ADDRESS (function
);
175 value_type
= TYPE_TARGET_TYPE (ftype
);
177 else if (code
== TYPE_CODE_PTR
)
179 funaddr
= value_as_address (function
);
180 ftype
= check_typedef (TYPE_TARGET_TYPE (ftype
));
181 if (TYPE_CODE (ftype
) == TYPE_CODE_FUNC
182 || TYPE_CODE (ftype
) == TYPE_CODE_METHOD
)
184 funaddr
= CONVERT_FROM_FUNC_PTR_ADDR (funaddr
);
185 value_type
= TYPE_TARGET_TYPE (ftype
);
188 value_type
= builtin_type_int
;
190 else if (code
== TYPE_CODE_INT
)
192 /* Handle the case of functions lacking debugging info.
193 Their values are characters since their addresses are char */
194 if (TYPE_LENGTH (ftype
) == 1)
195 funaddr
= value_as_address (value_addr (function
));
197 /* Handle integer used as address of a function. */
198 funaddr
= (CORE_ADDR
) value_as_long (function
);
200 value_type
= builtin_type_int
;
203 error ("Invalid data type for function to be called.");
205 *retval_type
= value_type
;
209 /* Call breakpoint_auto_delete on the current contents of the bpstat
210 pointed to by arg (which is really a bpstat *). */
213 breakpoint_auto_delete_contents (void *arg
)
215 breakpoint_auto_delete (*(bpstat
*) arg
);
218 /* All this stuff with a dummy frame may seem unnecessarily complicated
219 (why not just save registers in GDB?). The purpose of pushing a dummy
220 frame which looks just like a real frame is so that if you call a
221 function and then hit a breakpoint (get a signal, etc), "backtrace"
222 will look right. Whether the backtrace needs to actually show the
223 stack at the time the inferior function was called is debatable, but
224 it certainly needs to not display garbage. So if you are contemplating
225 making dummy frames be different from normal frames, consider that. */
227 /* Perform a function call in the inferior.
228 ARGS is a vector of values of arguments (NARGS of them).
229 FUNCTION is a value, the function to be called.
230 Returns a value representing what the function returned.
231 May fail to return, if a breakpoint or signal is hit
232 during the execution of the function.
234 ARGS is modified to contain coerced values. */
237 call_function_by_hand (struct value
*function
, int nargs
, struct value
**args
)
239 register CORE_ADDR sp
;
240 CORE_ADDR dummy_addr
;
241 struct type
*value_type
;
242 unsigned char struct_return
;
243 CORE_ADDR struct_addr
= 0;
244 struct regcache
*retbuf
;
245 struct cleanup
*retbuf_cleanup
;
246 struct inferior_status
*inf_status
;
247 struct cleanup
*inf_status_cleanup
;
249 int using_gcc
; /* Set to version of gcc in use, or zero if not gcc */
251 struct type
*ftype
= check_typedef (SYMBOL_TYPE (function
));
254 if (!target_has_execution
)
257 /* Create a cleanup chain that contains the retbuf (buffer
258 containing the register values). This chain is create BEFORE the
259 inf_status chain so that the inferior status can cleaned up
260 (restored or discarded) without having the retbuf freed. */
261 retbuf
= regcache_xmalloc (current_gdbarch
);
262 retbuf_cleanup
= make_cleanup_regcache_xfree (retbuf
);
264 /* A cleanup for the inferior status. Create this AFTER the retbuf
265 so that this can be discarded or applied without interfering with
267 inf_status
= save_inferior_status (1);
268 inf_status_cleanup
= make_cleanup_restore_inferior_status (inf_status
);
270 if (DEPRECATED_PUSH_DUMMY_FRAME_P ())
272 /* DEPRECATED_PUSH_DUMMY_FRAME is responsible for saving the
273 inferior registers (and frame_pop() for restoring them). (At
274 least on most machines) they are saved on the stack in the
276 DEPRECATED_PUSH_DUMMY_FRAME
;
280 /* FIXME: cagney/2003-02-26: Step zero of this little tinker is
281 to extract the generic dummy frame code from the architecture
282 vector. Hence this direct call.
284 A follow-on change is to modify this interface so that it takes
285 thread OR frame OR tpid as a parameter, and returns a dummy
286 frame handle. The handle can then be used further down as a
287 parameter SAVE_DUMMY_FRAME_TOS. Hmm, thinking about it, since
288 everything is ment to be using generic dummy frames, why not
289 even use some of the dummy frame code to here - do a regcache
290 dup and then pass the duped regcache, along with all the other
291 stuff, at one single point.
293 In fact, you can even save the structure's return address in the
294 dummy frame and fix one of those nasty lost struct return edge
296 generic_push_dummy_frame ();
299 /* Ensure that the initial SP is correctly aligned. */
301 CORE_ADDR old_sp
= read_sp ();
302 if (gdbarch_frame_align_p (current_gdbarch
))
304 /* NOTE: cagney/2002-09-18:
306 On a RISC architecture, a void parameterless generic dummy
307 frame (i.e., no parameters, no result) typically does not
308 need to push anything the stack and hence can leave SP and
309 FP. Similarly, a framelss (possibly leaf) function does
310 not push anything on the stack and, hence, that too can
311 leave FP and SP unchanged. As a consequence, a sequence of
312 void parameterless generic dummy frame calls to frameless
313 functions will create a sequence of effectively identical
314 frames (SP, FP and TOS and PC the same). This, not
315 suprisingly, results in what appears to be a stack in an
316 infinite loop --- when GDB tries to find a generic dummy
317 frame on the internal dummy frame stack, it will always
320 To avoid this problem, the code below always grows the
321 stack. That way, two dummy frames can never be identical.
322 It does burn a few bytes of stack but that is a small price
324 sp
= gdbarch_frame_align (current_gdbarch
, old_sp
);
327 if (INNER_THAN (1, 2))
328 /* Stack grows down. */
329 sp
= gdbarch_frame_align (current_gdbarch
, old_sp
- 1);
331 /* Stack grows up. */
332 sp
= gdbarch_frame_align (current_gdbarch
, old_sp
+ 1);
334 gdb_assert ((INNER_THAN (1, 2) && sp
<= old_sp
)
335 || (INNER_THAN (2, 1) && sp
>= old_sp
));
338 /* FIXME: cagney/2002-09-18: Hey, you loose! Who knows how
339 badly aligned the SP is! Further, per comment above, if the
340 generic dummy frame ends up empty (because nothing is pushed)
341 GDB won't be able to correctly perform back traces. If a
342 target is having trouble with backtraces, first thing to do
343 is add FRAME_ALIGN() to its architecture vector. After that,
344 try adding SAVE_DUMMY_FRAME_TOS() and modifying
345 DEPRECATED_FRAME_CHAIN so that when the next outer frame is a
346 generic dummy, it returns the current frame's base. */
350 funaddr
= find_function_addr (function
, &value_type
);
351 CHECK_TYPEDEF (value_type
);
354 struct block
*b
= block_for_pc (funaddr
);
355 /* If compiled without -g, assume GCC 2. */
356 using_gcc
= (b
== NULL
? 2 : BLOCK_GCC_COMPILED (b
));
359 /* Are we returning a value using a structure return or a normal
362 struct_return
= using_struct_return (function
, funaddr
, value_type
,
365 switch (CALL_DUMMY_LOCATION
)
369 /* CALL_DUMMY is an array of words (REGISTER_SIZE), but each
370 word is in host byte order. Before calling FIX_CALL_DUMMY,
371 we byteswap it and remove any extra bytes which might exist
372 because ULONGEST is bigger than REGISTER_SIZE. */
373 /* NOTE: This is pretty wierd, as the call dummy is actually a
374 sequence of instructions. But CISC machines will have to
375 pack the instructions into REGISTER_SIZE units (and so will
376 RISC machines for which INSTRUCTION_SIZE is not
378 /* NOTE: This is pretty stupid. CALL_DUMMY should be in
379 strict target byte order. */
381 ULONGEST
*dummy
= alloca (SIZEOF_CALL_DUMMY_WORDS
);
382 int sizeof_dummy1
= (REGISTER_SIZE
* SIZEOF_CALL_DUMMY_WORDS
383 / sizeof (ULONGEST
));
384 char *dummy1
= alloca (sizeof_dummy1
);
385 memcpy (dummy
, CALL_DUMMY_WORDS
, SIZEOF_CALL_DUMMY_WORDS
);
386 if (INNER_THAN (1, 2))
388 /* Stack grows down */
398 /* NOTE: cagney/2002-09-10: Don't bother re-adjusting the
399 stack after allocating space for the call dummy. A target
400 can specify a SIZEOF_DUMMY1 (via SIZEOF_CALL_DUMMY_WORDS)
401 such that all local alignment requirements are met. */
402 /* Create a call sequence customized for this function and the
403 number of arguments for it. */
406 for (i
= 0; i
< (int) (SIZEOF_CALL_DUMMY_WORDS
/ sizeof (dummy
[0]));
408 store_unsigned_integer (&dummy1
[i
* REGISTER_SIZE
],
410 (ULONGEST
) dummy
[i
]);
412 /* NOTE: cagney/2003-04-22: This computation of REAL_PC,
413 BP_ADDR and DUMMY_ADDR is pretty messed up. It comes from
414 constant tinkering with the values. Instead a
415 FIX_CALL_DUMMY replacement (PUSH_DUMMY_BREAKPOINT?) should
416 just do everything. */
417 #ifdef GDB_TARGET_IS_HPPA
418 real_pc
= FIX_CALL_DUMMY (dummy1
, start_sp
, funaddr
, nargs
, args
,
419 value_type
, using_gcc
);
421 if (FIX_CALL_DUMMY_P ())
423 /* gdb_assert (CALL_DUMMY_LOCATION == ON_STACK) true? */
424 FIX_CALL_DUMMY (dummy1
, start_sp
, funaddr
, nargs
, args
, value_type
,
429 dummy_addr
= start_sp
;
430 /* Yes, the offset is applied to the real_pc and not the dummy
431 addr. Ulgh! Blame the HP/UX target. */
432 bp_addr
= real_pc
+ CALL_DUMMY_BREAKPOINT_OFFSET
;
433 /* Yes, the offset is applied to the real_pc and not the
434 dummy_addr. Ulgh! Blame the HP/UX target. */
435 real_pc
+= CALL_DUMMY_START_OFFSET
;
436 write_memory (start_sp
, (char *) dummy1
, sizeof_dummy1
);
437 if (DEPRECATED_USE_GENERIC_DUMMY_FRAMES
)
438 generic_save_call_dummy_addr (start_sp
, start_sp
+ sizeof_dummy1
);
443 dummy_addr
= CALL_DUMMY_ADDRESS ();
444 /* A call dummy always consists of just a single breakpoint, so
445 it's address is the same as the address of the dummy. */
446 bp_addr
= dummy_addr
;
447 if (DEPRECATED_USE_GENERIC_DUMMY_FRAMES
)
448 /* NOTE: cagney/2002-04-13: The entry point is going to be
449 modified with a single breakpoint. */
450 generic_save_call_dummy_addr (CALL_DUMMY_ADDRESS (),
451 CALL_DUMMY_ADDRESS () + 1);
454 internal_error (__FILE__
, __LINE__
, "bad switch");
457 if (nargs
< TYPE_NFIELDS (ftype
))
458 error ("too few arguments in function call");
462 for (i
= nargs
- 1; i
>= 0; i
--)
465 struct type
*param_type
;
467 /* FIXME drow/2002-05-31: Should just always mark methods as
468 prototyped. Can we respect TYPE_VARARGS? Probably not. */
469 if (TYPE_CODE (ftype
) == TYPE_CODE_METHOD
)
471 else if (i
< TYPE_NFIELDS (ftype
))
472 prototyped
= TYPE_PROTOTYPED (ftype
);
476 if (i
< TYPE_NFIELDS (ftype
))
477 param_type
= TYPE_FIELD_TYPE (ftype
, i
);
481 args
[i
] = value_arg_coerce (args
[i
], param_type
, prototyped
);
483 /* elz: this code is to handle the case in which the function
484 to be called has a pointer to function as parameter and the
485 corresponding actual argument is the address of a function
486 and not a pointer to function variable. In aCC compiled
487 code, the calls through pointers to functions (in the body
488 of the function called by hand) are made via
489 $$dyncall_external which requires some registers setting,
490 this is taken care of if we call via a function pointer
491 variable, but not via a function address. In cc this is
496 if (param_type
!= NULL
&& TYPE_CODE (ftype
) != TYPE_CODE_METHOD
)
498 /* if this parameter is a pointer to function. */
499 if (TYPE_CODE (param_type
) == TYPE_CODE_PTR
)
500 if (TYPE_CODE (TYPE_TARGET_TYPE (param_type
)) == TYPE_CODE_FUNC
)
501 /* elz: FIXME here should go the test about the
502 compiler used to compile the target. We want to
503 issue the error message only if the compiler
504 used was HP's aCC. If we used HP's cc, then
505 there is no problem and no need to return at
507 /* Go see if the actual parameter is a variable of
508 type pointer to function or just a function. */
509 if (args
[i
]->lval
== not_lval
)
512 if (find_pc_partial_function ((CORE_ADDR
) args
[i
]->aligner
.contents
[0], &arg_name
, NULL
, NULL
))
514 You cannot use function <%s> as argument. \n\
515 You must use a pointer to function type variable. Command ignored.", arg_name
);
522 if (REG_STRUCT_HAS_ADDR_P ())
525 /* This is a machine like the sparc, where we may need to pass a
526 pointer to the structure, not the structure itself. */
527 for (i
= nargs
- 1; i
>= 0; i
--)
529 struct type
*arg_type
= check_typedef (VALUE_TYPE (args
[i
]));
530 if ((TYPE_CODE (arg_type
) == TYPE_CODE_STRUCT
531 || TYPE_CODE (arg_type
) == TYPE_CODE_UNION
532 || TYPE_CODE (arg_type
) == TYPE_CODE_ARRAY
533 || TYPE_CODE (arg_type
) == TYPE_CODE_STRING
534 || TYPE_CODE (arg_type
) == TYPE_CODE_BITSTRING
535 || TYPE_CODE (arg_type
) == TYPE_CODE_SET
536 || (TYPE_CODE (arg_type
) == TYPE_CODE_FLT
537 && TYPE_LENGTH (arg_type
) > 8)
539 && REG_STRUCT_HAS_ADDR (using_gcc
, arg_type
))
542 int len
; /* = TYPE_LENGTH (arg_type); */
544 arg_type
= check_typedef (VALUE_ENCLOSING_TYPE (args
[i
]));
545 len
= TYPE_LENGTH (arg_type
);
547 if (STACK_ALIGN_P ())
548 /* MVS 11/22/96: I think at least some of this
549 stack_align code is really broken. Better to let
550 PUSH_ARGUMENTS adjust the stack in a target-defined
552 aligned_len
= STACK_ALIGN (len
);
555 if (INNER_THAN (1, 2))
557 /* stack grows downward */
559 /* ... so the address of the thing we push is the
560 stack pointer after we push it. */
565 /* The stack grows up, so the address of the thing
566 we push is the stack pointer before we push it. */
570 /* Push the structure. */
571 write_memory (addr
, VALUE_CONTENTS_ALL (args
[i
]), len
);
572 /* The value we're going to pass is the address of the
573 thing we just pushed. */
574 /*args[i] = value_from_longest (lookup_pointer_type (value_type),
576 args
[i
] = value_from_pointer (lookup_pointer_type (arg_type
),
583 /* Reserve space for the return structure to be written on the
584 stack, if necessary. Make certain that the value is correctly
589 int len
= TYPE_LENGTH (value_type
);
590 if (STACK_ALIGN_P ())
591 /* NOTE: cagney/2003-03-22: Should rely on frame align, rather
592 than stack align to force the alignment of the stack. */
593 len
= STACK_ALIGN (len
);
594 if (INNER_THAN (1, 2))
596 /* Stack grows downward. Align STRUCT_ADDR and SP after
597 making space for the return value. */
599 if (gdbarch_frame_align_p (current_gdbarch
))
600 sp
= gdbarch_frame_align (current_gdbarch
, sp
);
605 /* Stack grows upward. Align the frame, allocate space, and
606 then again, re-align the frame??? */
607 if (gdbarch_frame_align_p (current_gdbarch
))
608 sp
= gdbarch_frame_align (current_gdbarch
, sp
);
611 if (gdbarch_frame_align_p (current_gdbarch
))
612 sp
= gdbarch_frame_align (current_gdbarch
, sp
);
616 /* elz: on HPPA no need for this extra alignment, maybe it is needed
617 on other architectures. This is because all the alignment is
618 taken care of in the above code (ifdef REG_STRUCT_HAS_ADDR) and
619 in hppa_push_arguments */
620 /* NOTE: cagney/2003-03-24: The below code is very broken. Given an
621 odd sized parameter the below will mis-align the stack. As was
622 suggested back in '96, better to let PUSH_ARGUMENTS handle it. */
623 if (DEPRECATED_EXTRA_STACK_ALIGNMENT_NEEDED
)
625 /* MVS 11/22/96: I think at least some of this stack_align code
626 is really broken. Better to let push_dummy_call() adjust the
627 stack in a target-defined manner. */
628 if (STACK_ALIGN_P () && INNER_THAN (1, 2))
630 /* If stack grows down, we must leave a hole at the top. */
633 for (i
= nargs
- 1; i
>= 0; i
--)
634 len
+= TYPE_LENGTH (VALUE_ENCLOSING_TYPE (args
[i
]));
635 if (DEPRECATED_CALL_DUMMY_STACK_ADJUST_P ())
636 len
+= DEPRECATED_CALL_DUMMY_STACK_ADJUST
;
637 sp
-= STACK_ALIGN (len
) - len
;
641 /* Create the dummy stack frame. Pass in the call dummy address as,
642 presumably, the ABI code knows where, in the call dummy, the
643 return address should be pointed. */
644 if (gdbarch_push_dummy_call_p (current_gdbarch
))
645 /* When there is no push_dummy_call method, should this code
646 simply error out. That would the implementation of this method
647 for all ABIs (which is probably a good thing). */
648 sp
= gdbarch_push_dummy_call (current_gdbarch
, current_regcache
,
649 dummy_addr
, nargs
, args
, sp
, struct_return
,
651 else if (DEPRECATED_PUSH_ARGUMENTS_P ())
652 /* Keep old targets working. */
653 sp
= DEPRECATED_PUSH_ARGUMENTS (nargs
, args
, sp
, struct_return
,
656 sp
= legacy_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
);
658 if (DEPRECATED_PUSH_RETURN_ADDRESS_P ())
659 /* for targets that use no CALL_DUMMY */
660 /* There are a number of targets now which actually don't write
661 any CALL_DUMMY instructions into the target, but instead just
662 save the machine state, push the arguments, and jump directly
663 to the callee function. Since this doesn't actually involve
664 executing a JSR/BSR instruction, the return address must be set
665 up by hand, either by pushing onto the stack or copying into a
666 return-address register as appropriate. Formerly this has been
667 done in PUSH_ARGUMENTS, but that's overloading its
668 functionality a bit, so I'm making it explicit to do it here. */
669 /* NOTE: cagney/2003-04-22: The first parameter ("real_pc") has
670 been replaced with zero, it turns out that no implementation
671 used that parameter. This occured because the value being
672 supplied - the address of the called function's entry point
673 instead of the address of the breakpoint that the called
674 function should return to - wasn't useful. */
675 sp
= DEPRECATED_PUSH_RETURN_ADDRESS (0, sp
);
677 /* NOTE: cagney/2003-03-23: Diable this code when there is a
678 push_dummy_call() method. Since that method will have already
679 handled any alignment issues, the code below is entirely
681 if (!gdbarch_push_dummy_call_p (current_gdbarch
)
682 && STACK_ALIGN_P () && !INNER_THAN (1, 2))
684 /* If stack grows up, we must leave a hole at the bottom, note
685 that sp already has been advanced for the arguments! */
686 if (DEPRECATED_CALL_DUMMY_STACK_ADJUST_P ())
687 sp
+= DEPRECATED_CALL_DUMMY_STACK_ADJUST
;
688 sp
= STACK_ALIGN (sp
);
691 /* XXX This seems wrong. For stacks that grow down we shouldn't do
693 /* MVS 11/22/96: I think at least some of this stack_align code is
694 really broken. Better to let PUSH_ARGUMENTS adjust the stack in
695 a target-defined manner. */
696 if (DEPRECATED_CALL_DUMMY_STACK_ADJUST_P ())
697 if (INNER_THAN (1, 2))
699 /* stack grows downward */
700 sp
-= DEPRECATED_CALL_DUMMY_STACK_ADJUST
;
703 /* Store the address at which the structure is supposed to be
705 /* NOTE: 2003-03-24: Since PUSH_ARGUMENTS can (and typically does)
706 store the struct return address, this call is entirely redundant. */
707 if (struct_return
&& DEPRECATED_STORE_STRUCT_RETURN_P ())
708 DEPRECATED_STORE_STRUCT_RETURN (struct_addr
, sp
);
710 /* Write the stack pointer. This is here because the statements above
711 might fool with it. On SPARC, this write also stores the register
712 window into the right place in the new stack frame, which otherwise
713 wouldn't happen. (See store_inferior_registers in sparc-nat.c.) */
714 /* NOTE: cagney/2003-03-23: Disable this code when there is a
715 push_dummy_call() method. Since that method will have already
716 stored the stack pointer (as part of creating the fake call
717 frame), and none of the code following that code adjusts the
718 stack-pointer value, the below call is entirely redundant. */
719 if (DEPRECATED_DUMMY_WRITE_SP_P ())
720 DEPRECATED_DUMMY_WRITE_SP (sp
);
722 if (SAVE_DUMMY_FRAME_TOS_P ())
723 SAVE_DUMMY_FRAME_TOS (sp
);
725 /* Now proceed, having reached the desired place. */
726 clear_proceed_status ();
728 /* Create a momentary breakpoint at the return address of the
729 inferior. That way it breaks when it returns. */
732 struct breakpoint
*bpt
;
733 struct symtab_and_line sal
;
734 struct frame_id frame
;
735 init_sal (&sal
); /* initialize to zeroes */
737 sal
.section
= find_pc_overlay (sal
.pc
);
738 /* Set up a frame ID for the dummy frame so we can pass it to
739 set_momentary_breakpoint. We need to give the breakpoint a
740 frame ID so that the breakpoint code can correctly re-identify
741 the dummy breakpoint. */
742 /* The assumption here is that push_dummy_call() returned the
743 stack part of the frame ID. Unfortunatly, many older
744 architectures were, via a convoluted mess, relying on the
745 poorly defined and greatly overloaded DEPRECATED_TARGET_READ_FP
746 or DEPRECATED_FP_REGNUM to supply the value. */
747 if (DEPRECATED_TARGET_READ_FP_P ())
748 frame
= frame_id_build (DEPRECATED_TARGET_READ_FP (), sal
.pc
);
749 else if (DEPRECATED_FP_REGNUM
>= 0)
750 frame
= frame_id_build (read_register (DEPRECATED_FP_REGNUM
), sal
.pc
);
752 frame
= frame_id_build (sp
, sal
.pc
);
753 bpt
= set_momentary_breakpoint (sal
, frame
, bp_call_dummy
);
754 bpt
->disposition
= disp_del
;
757 /* Execute a "stack dummy", a piece of code stored in the stack by
758 the debugger to be executed in the inferior.
760 The dummy's frame is automatically popped whenever that break is
761 hit. If that is the first time the program stops,
762 call_function_by_hand returns to its caller with that frame
763 already gone and sets RC to 0.
765 Otherwise, set RC to a non-zero value. If the called function
766 receives a random signal, we do not allow the user to continue
767 executing it as this may not work. The dummy frame is poped and
768 we return 1. If we hit a breakpoint, we leave the frame in place
769 and return 2 (the frame will eventually be popped when we do hit
770 the dummy end breakpoint). */
773 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, 0);
776 /* If all error()s out of proceed ended up calling normal_stop
777 (and perhaps they should; it already does in the special case
778 of error out of resume()), then we wouldn't need this. */
779 make_cleanup (breakpoint_auto_delete_contents
, &stop_bpstat
);
781 disable_watchpoints_before_interactive_call_start ();
782 proceed_to_finish
= 1; /* We want stop_registers, please... */
784 if (target_can_async_p ())
785 saved_async
= target_async_mask (0);
787 proceed (real_pc
, TARGET_SIGNAL_0
, 0);
790 target_async_mask (saved_async
);
792 enable_watchpoints_after_interactive_call_stop ();
794 discard_cleanups (old_cleanups
);
797 if (stopped_by_random_signal
|| !stop_stack_dummy
)
799 /* Find the name of the function we're about to complain about. */
802 struct symbol
*symbol
= find_pc_function (funaddr
);
804 name
= SYMBOL_PRINT_NAME (symbol
);
807 /* Try the minimal symbols. */
808 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (funaddr
);
810 name
= SYMBOL_PRINT_NAME (msymbol
);
815 /* NOTE: cagney/2003-04-23: Don't blame me. This code dates
816 back to 1993-07-08, I simply moved it. */
818 sprintf (format
, "at %s", local_hex_format ());
820 /* FIXME-32x64: assumes funaddr fits in a long. */
821 sprintf (name
, format
, (unsigned long) funaddr
);
823 if (stopped_by_random_signal
)
825 /* We stopped inside the FUNCTION because of a random
826 signal. Further execution of the FUNCTION is not
829 if (unwind_on_signal_p
)
831 /* The user wants the context restored. */
833 /* We must get back to the frame we were before the
835 frame_pop (get_current_frame ());
837 /* FIXME: Insert a bunch of wrap_here; name can be very
838 long if it's a C++ name with arguments and stuff. */
840 The program being debugged was signaled while in a function called from GDB.\n\
841 GDB has restored the context to what it was before the call.\n\
842 To change this behavior use \"set unwindonsignal off\"\n\
843 Evaluation of the expression containing the function (%s) will be abandoned.",
848 /* The user wants to stay in the frame where we stopped
850 /* If we restored the inferior status (via the cleanup),
851 we would print a spurious error message (Unable to
852 restore previously selected frame), would write the
853 registers from the inf_status (which is wrong), and
854 would do other wrong things. */
855 discard_cleanups (inf_status_cleanup
);
856 discard_inferior_status (inf_status
);
857 /* FIXME: Insert a bunch of wrap_here; name can be very
858 long if it's a C++ name with arguments and stuff. */
860 The program being debugged was signaled while in a function called from GDB.\n\
861 GDB remains in the frame where the signal was received.\n\
862 To change this behavior use \"set unwindonsignal on\"\n\
863 Evaluation of the expression containing the function (%s) will be abandoned.",
868 if (!stop_stack_dummy
)
870 /* We hit a breakpoint inside the FUNCTION. */
871 /* If we restored the inferior status (via the cleanup), we
872 would print a spurious error message (Unable to restore
873 previously selected frame), would write the registers
874 from the inf_status (which is wrong), and would do other
876 discard_cleanups (inf_status_cleanup
);
877 discard_inferior_status (inf_status
);
878 /* The following error message used to say "The expression
879 which contained the function call has been discarded."
880 It is a hard concept to explain in a few words. Ideally,
881 GDB would be able to resume evaluation of the expression
882 when the function finally is done executing. Perhaps
883 someday this will be implemented (it would not be easy). */
884 /* FIXME: Insert a bunch of wrap_here; name can be very long if it's
885 a C++ name with arguments and stuff. */
887 The program being debugged stopped while in a function called from GDB.\n\
888 When the function (%s) is done executing, GDB will silently\n\
889 stop (instead of continuing to evaluate the expression containing\n\
890 the function call).", name
);
893 /* The above code errors out, so ... */
894 internal_error (__FILE__
, __LINE__
, "... should not be here");
897 /* If we get here the called FUNCTION run to completion. */
899 /* On normal return, the stack dummy has been popped already. */
900 regcache_cpy_no_passthrough (retbuf
, stop_registers
);
902 /* Restore the inferior status, via its cleanup. At this stage,
903 leave the RETBUF alone. */
904 do_cleanups (inf_status_cleanup
);
906 /* Figure out the value returned by the function. */
907 /* elz: I defined this new macro for the hppa architecture only.
908 this gives us a way to get the value returned by the function
909 from the stack, at the same address we told the function to put
910 it. We cannot assume on the pa that r28 still contains the
911 address of the returned structure. Usually this will be
912 overwritten by the callee. I don't know about other
913 architectures, so I defined this macro */
914 #ifdef VALUE_RETURNED_FROM_STACK
917 do_cleanups (retbuf_cleanup
);
918 return VALUE_RETURNED_FROM_STACK (value_type
, struct_addr
);
921 /* NOTE: cagney/2002-09-10: Only when the stack has been correctly
922 aligned (using frame_align()) do we can trust STRUCT_ADDR and
923 fetch the return value direct from the stack. This lack of trust
924 comes about because legacy targets have a nasty habit of
925 silently, and local to PUSH_ARGUMENTS(), moving STRUCT_ADDR. For
926 such targets, just hope that value_being_returned() can find the
928 if (struct_return
&& gdbarch_frame_align_p (current_gdbarch
))
930 struct value
*retval
= value_at (value_type
, struct_addr
, NULL
);
931 do_cleanups (retbuf_cleanup
);
936 struct value
*retval
= value_being_returned (value_type
, retbuf
,
938 do_cleanups (retbuf_cleanup
);
943 void _initialize_infcall (void);
946 _initialize_infcall (void)
948 add_setshow_boolean_cmd ("coerce-float-to-double", class_obscure
,
949 &coerce_float_to_double_p
, "\
950 Set coercion of floats to doubles when calling functions\n\
951 Variables of type float should generally be converted to doubles before\n\
952 calling an unprototyped function, and left alone when calling a prototyped\n\
953 function. However, some older debug info formats do not provide enough\n\
954 information to determine that a function is prototyped. If this flag is\n\
955 set, GDB will perform the conversion for a function it considers\n\
957 The default is to perform the conversion.\n", "\
958 Show coercion of floats to doubles when calling functions\n\
959 Variables of type float should generally be converted to doubles before\n\
960 calling an unprototyped function, and left alone when calling a prototyped\n\
961 function. However, some older debug info formats do not provide enough\n\
962 information to determine that a function is prototyped. If this flag is\n\
963 set, GDB will perform the conversion for a function it considers\n\
965 The default is to perform the conversion.\n",
966 NULL
, NULL
, &setlist
, &showlist
);
968 add_setshow_boolean_cmd ("unwindonsignal", no_class
,
969 &unwind_on_signal_p
, "\
970 Set unwinding of stack if a signal is received while in a call dummy.\n\
971 The unwindonsignal lets the user determine what gdb should do if a signal\n\
972 is received while in a function called from gdb (call dummy). If set, gdb\n\
973 unwinds the stack and restore the context to what as it was before the call.\n\
974 The default is to stop in the frame where the signal was received.", "\
975 Set unwinding of stack if a signal is received while in a call dummy.\n\
976 The unwindonsignal lets the user determine what gdb should do if a signal\n\
977 is received while in a function called from gdb (call dummy). If set, gdb\n\
978 unwinds the stack and restore the context to what as it was before the call.\n\
979 The default is to stop in the frame where the signal was received.",
980 NULL
, NULL
, &setlist
, &showlist
);