1b725ae77Skettenis /* Perform an inferior function call, for GDB, the GNU debugger.
2b725ae77Skettenis
3b725ae77Skettenis Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4b725ae77Skettenis 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
5b725ae77Skettenis Free Software Foundation, Inc.
6b725ae77Skettenis
7b725ae77Skettenis This file is part of GDB.
8b725ae77Skettenis
9b725ae77Skettenis This program is free software; you can redistribute it and/or modify
10b725ae77Skettenis it under the terms of the GNU General Public License as published by
11b725ae77Skettenis the Free Software Foundation; either version 2 of the License, or
12b725ae77Skettenis (at your option) any later version.
13b725ae77Skettenis
14b725ae77Skettenis This program is distributed in the hope that it will be useful,
15b725ae77Skettenis but WITHOUT ANY WARRANTY; without even the implied warranty of
16b725ae77Skettenis MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17b725ae77Skettenis GNU General Public License for more details.
18b725ae77Skettenis
19b725ae77Skettenis You should have received a copy of the GNU General Public License
20b725ae77Skettenis along with this program; if not, write to the Free Software
21b725ae77Skettenis Foundation, Inc., 59 Temple Place - Suite 330,
22b725ae77Skettenis Boston, MA 02111-1307, USA. */
23b725ae77Skettenis
24b725ae77Skettenis #include "defs.h"
25b725ae77Skettenis #include "breakpoint.h"
26b725ae77Skettenis #include "target.h"
27b725ae77Skettenis #include "regcache.h"
28b725ae77Skettenis #include "inferior.h"
29b725ae77Skettenis #include "gdb_assert.h"
30b725ae77Skettenis #include "block.h"
31b725ae77Skettenis #include "gdbcore.h"
32b725ae77Skettenis #include "language.h"
33b725ae77Skettenis #include "objfiles.h"
34b725ae77Skettenis #include "gdbcmd.h"
35b725ae77Skettenis #include "command.h"
36b725ae77Skettenis #include "gdb_string.h"
37b725ae77Skettenis #include "infcall.h"
38*63addd46Skettenis #include "dummy-frame.h"
39b725ae77Skettenis
40b725ae77Skettenis /* NOTE: cagney/2003-04-16: What's the future of this code?
41b725ae77Skettenis
42b725ae77Skettenis GDB needs an asynchronous expression evaluator, that means an
43b725ae77Skettenis asynchronous inferior function call implementation, and that in
44b725ae77Skettenis turn means restructuring the code so that it is event driven. */
45b725ae77Skettenis
46b725ae77Skettenis /* How you should pass arguments to a function depends on whether it
47b725ae77Skettenis was defined in K&R style or prototype style. If you define a
48b725ae77Skettenis function using the K&R syntax that takes a `float' argument, then
49b725ae77Skettenis callers must pass that argument as a `double'. If you define the
50b725ae77Skettenis function using the prototype syntax, then you must pass the
51b725ae77Skettenis argument as a `float', with no promotion.
52b725ae77Skettenis
53b725ae77Skettenis Unfortunately, on certain older platforms, the debug info doesn't
54b725ae77Skettenis indicate reliably how each function was defined. A function type's
55b725ae77Skettenis TYPE_FLAG_PROTOTYPED flag may be clear, even if the function was
56b725ae77Skettenis defined in prototype style. When calling a function whose
57b725ae77Skettenis TYPE_FLAG_PROTOTYPED flag is clear, GDB consults this flag to
58b725ae77Skettenis decide what to do.
59b725ae77Skettenis
60b725ae77Skettenis For modern targets, it is proper to assume that, if the prototype
61b725ae77Skettenis flag is clear, that can be trusted: `float' arguments should be
62b725ae77Skettenis promoted to `double'. For some older targets, if the prototype
63b725ae77Skettenis flag is clear, that doesn't tell us anything. The default is to
64b725ae77Skettenis trust the debug information; the user can override this behavior
65b725ae77Skettenis with "set coerce-float-to-double 0". */
66b725ae77Skettenis
67b725ae77Skettenis static int coerce_float_to_double_p = 1;
68b725ae77Skettenis
69b725ae77Skettenis /* This boolean tells what gdb should do if a signal is received while
70b725ae77Skettenis in a function called from gdb (call dummy). If set, gdb unwinds
71b725ae77Skettenis the stack and restore the context to what as it was before the
72b725ae77Skettenis call.
73b725ae77Skettenis
74b725ae77Skettenis The default is to stop in the frame where the signal was received. */
75b725ae77Skettenis
76b725ae77Skettenis int unwind_on_signal_p = 0;
77b725ae77Skettenis
78b725ae77Skettenis /* Perform the standard coercions that are specified
79b725ae77Skettenis for arguments to be passed to C functions.
80b725ae77Skettenis
81b725ae77Skettenis If PARAM_TYPE is non-NULL, it is the expected parameter type.
82b725ae77Skettenis IS_PROTOTYPED is non-zero if the function declaration is prototyped. */
83b725ae77Skettenis
84b725ae77Skettenis static struct value *
value_arg_coerce(struct value * arg,struct type * param_type,int is_prototyped)85b725ae77Skettenis value_arg_coerce (struct value *arg, struct type *param_type,
86b725ae77Skettenis int is_prototyped)
87b725ae77Skettenis {
88b725ae77Skettenis struct type *arg_type = check_typedef (VALUE_TYPE (arg));
89b725ae77Skettenis struct type *type
90b725ae77Skettenis = param_type ? check_typedef (param_type) : arg_type;
91b725ae77Skettenis
92b725ae77Skettenis switch (TYPE_CODE (type))
93b725ae77Skettenis {
94b725ae77Skettenis case TYPE_CODE_REF:
95b725ae77Skettenis if (TYPE_CODE (arg_type) != TYPE_CODE_REF
96b725ae77Skettenis && TYPE_CODE (arg_type) != TYPE_CODE_PTR)
97b725ae77Skettenis {
98b725ae77Skettenis arg = value_addr (arg);
99b725ae77Skettenis VALUE_TYPE (arg) = param_type;
100b725ae77Skettenis return arg;
101b725ae77Skettenis }
102b725ae77Skettenis break;
103b725ae77Skettenis case TYPE_CODE_INT:
104b725ae77Skettenis case TYPE_CODE_CHAR:
105b725ae77Skettenis case TYPE_CODE_BOOL:
106b725ae77Skettenis case TYPE_CODE_ENUM:
107b725ae77Skettenis /* If we don't have a prototype, coerce to integer type if necessary. */
108b725ae77Skettenis if (!is_prototyped)
109b725ae77Skettenis {
110b725ae77Skettenis if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_int))
111b725ae77Skettenis type = builtin_type_int;
112b725ae77Skettenis }
113b725ae77Skettenis /* Currently all target ABIs require at least the width of an integer
114b725ae77Skettenis type for an argument. We may have to conditionalize the following
115b725ae77Skettenis type coercion for future targets. */
116b725ae77Skettenis if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_int))
117b725ae77Skettenis type = builtin_type_int;
118b725ae77Skettenis break;
119b725ae77Skettenis case TYPE_CODE_FLT:
120b725ae77Skettenis if (!is_prototyped && coerce_float_to_double_p)
121b725ae77Skettenis {
122b725ae77Skettenis if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_double))
123b725ae77Skettenis type = builtin_type_double;
124b725ae77Skettenis else if (TYPE_LENGTH (type) > TYPE_LENGTH (builtin_type_double))
125b725ae77Skettenis type = builtin_type_long_double;
126b725ae77Skettenis }
127b725ae77Skettenis break;
128b725ae77Skettenis case TYPE_CODE_FUNC:
129b725ae77Skettenis type = lookup_pointer_type (type);
130b725ae77Skettenis break;
131b725ae77Skettenis case TYPE_CODE_ARRAY:
132b725ae77Skettenis /* Arrays are coerced to pointers to their first element, unless
133b725ae77Skettenis they are vectors, in which case we want to leave them alone,
134b725ae77Skettenis because they are passed by value. */
135b725ae77Skettenis if (current_language->c_style_arrays)
136b725ae77Skettenis if (!TYPE_VECTOR (type))
137b725ae77Skettenis type = lookup_pointer_type (TYPE_TARGET_TYPE (type));
138b725ae77Skettenis break;
139b725ae77Skettenis case TYPE_CODE_UNDEF:
140b725ae77Skettenis case TYPE_CODE_PTR:
141b725ae77Skettenis case TYPE_CODE_STRUCT:
142b725ae77Skettenis case TYPE_CODE_UNION:
143b725ae77Skettenis case TYPE_CODE_VOID:
144b725ae77Skettenis case TYPE_CODE_SET:
145b725ae77Skettenis case TYPE_CODE_RANGE:
146b725ae77Skettenis case TYPE_CODE_STRING:
147b725ae77Skettenis case TYPE_CODE_BITSTRING:
148b725ae77Skettenis case TYPE_CODE_ERROR:
149b725ae77Skettenis case TYPE_CODE_MEMBER:
150b725ae77Skettenis case TYPE_CODE_METHOD:
151b725ae77Skettenis case TYPE_CODE_COMPLEX:
152b725ae77Skettenis default:
153b725ae77Skettenis break;
154b725ae77Skettenis }
155b725ae77Skettenis
156b725ae77Skettenis return value_cast (type, arg);
157b725ae77Skettenis }
158b725ae77Skettenis
159b725ae77Skettenis /* Determine a function's address and its return type from its value.
160b725ae77Skettenis Calls error() if the function is not valid for calling. */
161b725ae77Skettenis
162b725ae77Skettenis CORE_ADDR
find_function_addr(struct value * function,struct type ** retval_type)163b725ae77Skettenis find_function_addr (struct value *function, struct type **retval_type)
164b725ae77Skettenis {
165b725ae77Skettenis struct type *ftype = check_typedef (VALUE_TYPE (function));
166b725ae77Skettenis enum type_code code = TYPE_CODE (ftype);
167b725ae77Skettenis struct type *value_type;
168b725ae77Skettenis CORE_ADDR funaddr;
169b725ae77Skettenis
170b725ae77Skettenis /* If it's a member function, just look at the function
171b725ae77Skettenis part of it. */
172b725ae77Skettenis
173b725ae77Skettenis /* Determine address to call. */
174b725ae77Skettenis if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD)
175b725ae77Skettenis {
176b725ae77Skettenis funaddr = VALUE_ADDRESS (function);
177b725ae77Skettenis value_type = TYPE_TARGET_TYPE (ftype);
178b725ae77Skettenis }
179b725ae77Skettenis else if (code == TYPE_CODE_PTR)
180b725ae77Skettenis {
181b725ae77Skettenis funaddr = value_as_address (function);
182b725ae77Skettenis ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
183b725ae77Skettenis if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
184b725ae77Skettenis || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
185b725ae77Skettenis {
186b725ae77Skettenis funaddr = gdbarch_convert_from_func_ptr_addr (current_gdbarch,
187b725ae77Skettenis funaddr,
188b725ae77Skettenis ¤t_target);
189b725ae77Skettenis value_type = TYPE_TARGET_TYPE (ftype);
190b725ae77Skettenis }
191b725ae77Skettenis else
192b725ae77Skettenis value_type = builtin_type_int;
193b725ae77Skettenis }
194b725ae77Skettenis else if (code == TYPE_CODE_INT)
195b725ae77Skettenis {
196b725ae77Skettenis /* Handle the case of functions lacking debugging info.
197b725ae77Skettenis Their values are characters since their addresses are char */
198b725ae77Skettenis if (TYPE_LENGTH (ftype) == 1)
199b725ae77Skettenis funaddr = value_as_address (value_addr (function));
200b725ae77Skettenis else
201b725ae77Skettenis /* Handle integer used as address of a function. */
202b725ae77Skettenis funaddr = (CORE_ADDR) value_as_long (function);
203b725ae77Skettenis
204b725ae77Skettenis value_type = builtin_type_int;
205b725ae77Skettenis }
206b725ae77Skettenis else
207b725ae77Skettenis error ("Invalid data type for function to be called.");
208b725ae77Skettenis
209*63addd46Skettenis if (retval_type != NULL)
210b725ae77Skettenis *retval_type = value_type;
211*63addd46Skettenis return funaddr + DEPRECATED_FUNCTION_START_OFFSET;
212b725ae77Skettenis }
213b725ae77Skettenis
214b725ae77Skettenis /* Call breakpoint_auto_delete on the current contents of the bpstat
215b725ae77Skettenis pointed to by arg (which is really a bpstat *). */
216b725ae77Skettenis
217b725ae77Skettenis static void
breakpoint_auto_delete_contents(void * arg)218b725ae77Skettenis breakpoint_auto_delete_contents (void *arg)
219b725ae77Skettenis {
220b725ae77Skettenis breakpoint_auto_delete (*(bpstat *) arg);
221b725ae77Skettenis }
222b725ae77Skettenis
223b725ae77Skettenis static CORE_ADDR
generic_push_dummy_code(struct gdbarch * gdbarch,CORE_ADDR sp,CORE_ADDR funaddr,int using_gcc,struct value ** args,int nargs,struct type * value_type,CORE_ADDR * real_pc,CORE_ADDR * bp_addr)224b725ae77Skettenis generic_push_dummy_code (struct gdbarch *gdbarch,
225b725ae77Skettenis CORE_ADDR sp, CORE_ADDR funaddr, int using_gcc,
226b725ae77Skettenis struct value **args, int nargs,
227b725ae77Skettenis struct type *value_type,
228b725ae77Skettenis CORE_ADDR *real_pc, CORE_ADDR *bp_addr)
229b725ae77Skettenis {
230b725ae77Skettenis /* Something here to findout the size of a breakpoint and then
231b725ae77Skettenis allocate space for it on the stack. */
232b725ae77Skettenis int bplen;
233b725ae77Skettenis /* This code assumes frame align. */
234b725ae77Skettenis gdb_assert (gdbarch_frame_align_p (gdbarch));
235b725ae77Skettenis /* Force the stack's alignment. The intent is to ensure that the SP
236b725ae77Skettenis is aligned to at least a breakpoint instruction's boundary. */
237b725ae77Skettenis sp = gdbarch_frame_align (gdbarch, sp);
238b725ae77Skettenis /* Allocate space for, and then position the breakpoint on the
239b725ae77Skettenis stack. */
240b725ae77Skettenis if (gdbarch_inner_than (gdbarch, 1, 2))
241b725ae77Skettenis {
242b725ae77Skettenis CORE_ADDR bppc = sp;
243b725ae77Skettenis gdbarch_breakpoint_from_pc (gdbarch, &bppc, &bplen);
244b725ae77Skettenis sp = gdbarch_frame_align (gdbarch, sp - bplen);
245b725ae77Skettenis (*bp_addr) = sp;
246b725ae77Skettenis /* Should the breakpoint size/location be re-computed here? */
247b725ae77Skettenis }
248b725ae77Skettenis else
249b725ae77Skettenis {
250b725ae77Skettenis (*bp_addr) = sp;
251b725ae77Skettenis gdbarch_breakpoint_from_pc (gdbarch, bp_addr, &bplen);
252b725ae77Skettenis sp = gdbarch_frame_align (gdbarch, sp + bplen);
253b725ae77Skettenis }
254b725ae77Skettenis /* Inferior resumes at the function entry point. */
255b725ae77Skettenis (*real_pc) = funaddr;
256b725ae77Skettenis return sp;
257b725ae77Skettenis }
258b725ae77Skettenis
259*63addd46Skettenis /* For CALL_DUMMY_ON_STACK, push a breakpoint sequence that the called
260*63addd46Skettenis function returns to. */
261b725ae77Skettenis
262b725ae77Skettenis static CORE_ADDR
push_dummy_code(struct gdbarch * gdbarch,CORE_ADDR sp,CORE_ADDR funaddr,int using_gcc,struct value ** args,int nargs,struct type * value_type,CORE_ADDR * real_pc,CORE_ADDR * bp_addr)263b725ae77Skettenis push_dummy_code (struct gdbarch *gdbarch,
264b725ae77Skettenis CORE_ADDR sp, CORE_ADDR funaddr, int using_gcc,
265b725ae77Skettenis struct value **args, int nargs,
266b725ae77Skettenis struct type *value_type,
267b725ae77Skettenis CORE_ADDR *real_pc, CORE_ADDR *bp_addr)
268b725ae77Skettenis {
269b725ae77Skettenis if (gdbarch_push_dummy_code_p (gdbarch))
270b725ae77Skettenis return gdbarch_push_dummy_code (gdbarch, sp, funaddr, using_gcc,
271b725ae77Skettenis args, nargs, value_type, real_pc, bp_addr);
272b725ae77Skettenis else
273b725ae77Skettenis return generic_push_dummy_code (gdbarch, sp, funaddr, using_gcc,
274b725ae77Skettenis args, nargs, value_type, real_pc, bp_addr);
275b725ae77Skettenis }
276b725ae77Skettenis
277b725ae77Skettenis /* All this stuff with a dummy frame may seem unnecessarily complicated
278b725ae77Skettenis (why not just save registers in GDB?). The purpose of pushing a dummy
279b725ae77Skettenis frame which looks just like a real frame is so that if you call a
280b725ae77Skettenis function and then hit a breakpoint (get a signal, etc), "backtrace"
281b725ae77Skettenis will look right. Whether the backtrace needs to actually show the
282b725ae77Skettenis stack at the time the inferior function was called is debatable, but
283b725ae77Skettenis it certainly needs to not display garbage. So if you are contemplating
284b725ae77Skettenis making dummy frames be different from normal frames, consider that. */
285b725ae77Skettenis
286b725ae77Skettenis /* Perform a function call in the inferior.
287b725ae77Skettenis ARGS is a vector of values of arguments (NARGS of them).
288b725ae77Skettenis FUNCTION is a value, the function to be called.
289b725ae77Skettenis Returns a value representing what the function returned.
290b725ae77Skettenis May fail to return, if a breakpoint or signal is hit
291b725ae77Skettenis during the execution of the function.
292b725ae77Skettenis
293b725ae77Skettenis ARGS is modified to contain coerced values. */
294b725ae77Skettenis
295b725ae77Skettenis struct value *
call_function_by_hand(struct value * function,int nargs,struct value ** args)296b725ae77Skettenis call_function_by_hand (struct value *function, int nargs, struct value **args)
297b725ae77Skettenis {
298b725ae77Skettenis CORE_ADDR sp;
299b725ae77Skettenis CORE_ADDR dummy_addr;
300b725ae77Skettenis struct type *value_type;
301b725ae77Skettenis unsigned char struct_return;
302b725ae77Skettenis CORE_ADDR struct_addr = 0;
303b725ae77Skettenis struct regcache *retbuf;
304b725ae77Skettenis struct cleanup *retbuf_cleanup;
305b725ae77Skettenis struct inferior_status *inf_status;
306b725ae77Skettenis struct cleanup *inf_status_cleanup;
307b725ae77Skettenis CORE_ADDR funaddr;
308b725ae77Skettenis int using_gcc; /* Set to version of gcc in use, or zero if not gcc */
309b725ae77Skettenis CORE_ADDR real_pc;
310*63addd46Skettenis struct type *ftype = check_typedef (VALUE_TYPE (function));
311b725ae77Skettenis CORE_ADDR bp_addr;
312*63addd46Skettenis struct regcache *caller_regcache;
313*63addd46Skettenis struct cleanup *caller_regcache_cleanup;
314*63addd46Skettenis struct frame_id dummy_id;
315b725ae77Skettenis
316b725ae77Skettenis if (!target_has_execution)
317b725ae77Skettenis noprocess ();
318b725ae77Skettenis
319b725ae77Skettenis /* Create a cleanup chain that contains the retbuf (buffer
320b725ae77Skettenis containing the register values). This chain is create BEFORE the
321b725ae77Skettenis inf_status chain so that the inferior status can cleaned up
322b725ae77Skettenis (restored or discarded) without having the retbuf freed. */
323b725ae77Skettenis retbuf = regcache_xmalloc (current_gdbarch);
324b725ae77Skettenis retbuf_cleanup = make_cleanup_regcache_xfree (retbuf);
325b725ae77Skettenis
326b725ae77Skettenis /* A cleanup for the inferior status. Create this AFTER the retbuf
327b725ae77Skettenis so that this can be discarded or applied without interfering with
328b725ae77Skettenis the regbuf. */
329b725ae77Skettenis inf_status = save_inferior_status (1);
330b725ae77Skettenis inf_status_cleanup = make_cleanup_restore_inferior_status (inf_status);
331b725ae77Skettenis
332*63addd46Skettenis /* Save the caller's registers so that they can be restored once the
333*63addd46Skettenis callee returns. To allow nested calls the registers are (further
334*63addd46Skettenis down) pushed onto a dummy frame stack. Include a cleanup (which
335*63addd46Skettenis is tossed once the regcache has been pushed). */
336*63addd46Skettenis caller_regcache = frame_save_as_regcache (get_current_frame ());
337*63addd46Skettenis caller_regcache_cleanup = make_cleanup_regcache_xfree (caller_regcache);
338b725ae77Skettenis
339b725ae77Skettenis /* Ensure that the initial SP is correctly aligned. */
340b725ae77Skettenis {
341b725ae77Skettenis CORE_ADDR old_sp = read_sp ();
342b725ae77Skettenis if (gdbarch_frame_align_p (current_gdbarch))
343b725ae77Skettenis {
344b725ae77Skettenis sp = gdbarch_frame_align (current_gdbarch, old_sp);
345b725ae77Skettenis /* NOTE: cagney/2003-08-13: Skip the "red zone". For some
346b725ae77Skettenis ABIs, a function can use memory beyond the inner most stack
347b725ae77Skettenis address. AMD64 called that region the "red zone". Skip at
348b725ae77Skettenis least the "red zone" size before allocating any space on
349b725ae77Skettenis the stack. */
350b725ae77Skettenis if (INNER_THAN (1, 2))
351b725ae77Skettenis sp -= gdbarch_frame_red_zone_size (current_gdbarch);
352b725ae77Skettenis else
353b725ae77Skettenis sp += gdbarch_frame_red_zone_size (current_gdbarch);
354b725ae77Skettenis /* Still aligned? */
355b725ae77Skettenis gdb_assert (sp == gdbarch_frame_align (current_gdbarch, sp));
356b725ae77Skettenis /* NOTE: cagney/2002-09-18:
357b725ae77Skettenis
358b725ae77Skettenis On a RISC architecture, a void parameterless generic dummy
359b725ae77Skettenis frame (i.e., no parameters, no result) typically does not
360b725ae77Skettenis need to push anything the stack and hence can leave SP and
361b725ae77Skettenis FP. Similarly, a frameless (possibly leaf) function does
362b725ae77Skettenis not push anything on the stack and, hence, that too can
363b725ae77Skettenis leave FP and SP unchanged. As a consequence, a sequence of
364b725ae77Skettenis void parameterless generic dummy frame calls to frameless
365b725ae77Skettenis functions will create a sequence of effectively identical
366b725ae77Skettenis frames (SP, FP and TOS and PC the same). This, not
367b725ae77Skettenis suprisingly, results in what appears to be a stack in an
368b725ae77Skettenis infinite loop --- when GDB tries to find a generic dummy
369b725ae77Skettenis frame on the internal dummy frame stack, it will always
370b725ae77Skettenis find the first one.
371b725ae77Skettenis
372b725ae77Skettenis To avoid this problem, the code below always grows the
373b725ae77Skettenis stack. That way, two dummy frames can never be identical.
374b725ae77Skettenis It does burn a few bytes of stack but that is a small price
375b725ae77Skettenis to pay :-). */
376b725ae77Skettenis if (sp == old_sp)
377b725ae77Skettenis {
378b725ae77Skettenis if (INNER_THAN (1, 2))
379b725ae77Skettenis /* Stack grows down. */
380b725ae77Skettenis sp = gdbarch_frame_align (current_gdbarch, old_sp - 1);
381b725ae77Skettenis else
382b725ae77Skettenis /* Stack grows up. */
383b725ae77Skettenis sp = gdbarch_frame_align (current_gdbarch, old_sp + 1);
384b725ae77Skettenis }
385b725ae77Skettenis gdb_assert ((INNER_THAN (1, 2) && sp <= old_sp)
386b725ae77Skettenis || (INNER_THAN (2, 1) && sp >= old_sp));
387b725ae77Skettenis }
388b725ae77Skettenis else
389b725ae77Skettenis /* FIXME: cagney/2002-09-18: Hey, you loose!
390b725ae77Skettenis
391b725ae77Skettenis Who knows how badly aligned the SP is!
392b725ae77Skettenis
393b725ae77Skettenis If the generic dummy frame ends up empty (because nothing is
394b725ae77Skettenis pushed) GDB won't be able to correctly perform back traces.
395b725ae77Skettenis If a target is having trouble with backtraces, first thing to
396b725ae77Skettenis do is add FRAME_ALIGN() to the architecture vector. If that
397b725ae77Skettenis fails, try unwind_dummy_id().
398b725ae77Skettenis
399b725ae77Skettenis If the ABI specifies a "Red Zone" (see the doco) the code
400b725ae77Skettenis below will quietly trash it. */
401b725ae77Skettenis sp = old_sp;
402b725ae77Skettenis }
403b725ae77Skettenis
404b725ae77Skettenis funaddr = find_function_addr (function, &value_type);
405b725ae77Skettenis CHECK_TYPEDEF (value_type);
406b725ae77Skettenis
407b725ae77Skettenis {
408b725ae77Skettenis struct block *b = block_for_pc (funaddr);
409b725ae77Skettenis /* If compiled without -g, assume GCC 2. */
410b725ae77Skettenis using_gcc = (b == NULL ? 2 : BLOCK_GCC_COMPILED (b));
411b725ae77Skettenis }
412b725ae77Skettenis
413b725ae77Skettenis /* Are we returning a value using a structure return or a normal
414b725ae77Skettenis value return? */
415b725ae77Skettenis
416b725ae77Skettenis struct_return = using_struct_return (value_type, using_gcc);
417b725ae77Skettenis
418b725ae77Skettenis /* Determine the location of the breakpoint (and possibly other
419b725ae77Skettenis stuff) that the called function will return to. The SPARC, for a
420b725ae77Skettenis function returning a structure or union, needs to make space for
421b725ae77Skettenis not just the breakpoint but also an extra word containing the
422b725ae77Skettenis size (?) of the structure being passed. */
423b725ae77Skettenis
424b725ae77Skettenis /* The actual breakpoint (at BP_ADDR) is inserted separatly so there
425b725ae77Skettenis is no need to write that out. */
426b725ae77Skettenis
427b725ae77Skettenis switch (CALL_DUMMY_LOCATION)
428b725ae77Skettenis {
429b725ae77Skettenis case ON_STACK:
430b725ae77Skettenis /* "dummy_addr" is here just to keep old targets happy. New
431b725ae77Skettenis targets return that same information via "sp" and "bp_addr". */
432b725ae77Skettenis if (INNER_THAN (1, 2))
433b725ae77Skettenis {
434b725ae77Skettenis sp = push_dummy_code (current_gdbarch, sp, funaddr,
435b725ae77Skettenis using_gcc, args, nargs, value_type,
436b725ae77Skettenis &real_pc, &bp_addr);
437b725ae77Skettenis dummy_addr = sp;
438b725ae77Skettenis }
439b725ae77Skettenis else
440b725ae77Skettenis {
441b725ae77Skettenis dummy_addr = sp;
442b725ae77Skettenis sp = push_dummy_code (current_gdbarch, sp, funaddr,
443b725ae77Skettenis using_gcc, args, nargs, value_type,
444b725ae77Skettenis &real_pc, &bp_addr);
445b725ae77Skettenis }
446b725ae77Skettenis break;
447b725ae77Skettenis case AT_ENTRY_POINT:
448b725ae77Skettenis real_pc = funaddr;
449b725ae77Skettenis dummy_addr = entry_point_address ();
450b725ae77Skettenis /* Make certain that the address points at real code, and not a
451b725ae77Skettenis function descriptor. */
452b725ae77Skettenis dummy_addr = gdbarch_convert_from_func_ptr_addr (current_gdbarch,
453b725ae77Skettenis dummy_addr,
454b725ae77Skettenis ¤t_target);
455b725ae77Skettenis /* A call dummy always consists of just a single breakpoint, so
456b725ae77Skettenis it's address is the same as the address of the dummy. */
457b725ae77Skettenis bp_addr = dummy_addr;
458b725ae77Skettenis break;
459b725ae77Skettenis case AT_SYMBOL:
460b725ae77Skettenis /* Some executables define a symbol __CALL_DUMMY_ADDRESS whose
461b725ae77Skettenis address is the location where the breakpoint should be
462b725ae77Skettenis placed. Once all targets are using the overhauled frame code
463b725ae77Skettenis this can be deleted - ON_STACK is a better option. */
464b725ae77Skettenis {
465b725ae77Skettenis struct minimal_symbol *sym;
466b725ae77Skettenis
467b725ae77Skettenis sym = lookup_minimal_symbol ("__CALL_DUMMY_ADDRESS", NULL, NULL);
468b725ae77Skettenis real_pc = funaddr;
469b725ae77Skettenis if (sym)
470b725ae77Skettenis dummy_addr = SYMBOL_VALUE_ADDRESS (sym);
471b725ae77Skettenis else
472b725ae77Skettenis dummy_addr = entry_point_address ();
473b725ae77Skettenis /* Make certain that the address points at real code, and not
474b725ae77Skettenis a function descriptor. */
475b725ae77Skettenis dummy_addr = gdbarch_convert_from_func_ptr_addr (current_gdbarch,
476b725ae77Skettenis dummy_addr,
477b725ae77Skettenis ¤t_target);
478b725ae77Skettenis /* A call dummy always consists of just a single breakpoint,
479b725ae77Skettenis so it's address is the same as the address of the dummy. */
480b725ae77Skettenis bp_addr = dummy_addr;
481b725ae77Skettenis break;
482b725ae77Skettenis }
483b725ae77Skettenis default:
484b725ae77Skettenis internal_error (__FILE__, __LINE__, "bad switch");
485b725ae77Skettenis }
486b725ae77Skettenis
487b725ae77Skettenis if (nargs < TYPE_NFIELDS (ftype))
488b725ae77Skettenis error ("too few arguments in function call");
489b725ae77Skettenis
490b725ae77Skettenis {
491b725ae77Skettenis int i;
492b725ae77Skettenis for (i = nargs - 1; i >= 0; i--)
493b725ae77Skettenis {
494b725ae77Skettenis int prototyped;
495b725ae77Skettenis struct type *param_type;
496b725ae77Skettenis
497b725ae77Skettenis /* FIXME drow/2002-05-31: Should just always mark methods as
498b725ae77Skettenis prototyped. Can we respect TYPE_VARARGS? Probably not. */
499b725ae77Skettenis if (TYPE_CODE (ftype) == TYPE_CODE_METHOD)
500b725ae77Skettenis prototyped = 1;
501b725ae77Skettenis else if (i < TYPE_NFIELDS (ftype))
502b725ae77Skettenis prototyped = TYPE_PROTOTYPED (ftype);
503b725ae77Skettenis else
504b725ae77Skettenis prototyped = 0;
505b725ae77Skettenis
506b725ae77Skettenis if (i < TYPE_NFIELDS (ftype))
507b725ae77Skettenis param_type = TYPE_FIELD_TYPE (ftype, i);
508b725ae77Skettenis else
509b725ae77Skettenis param_type = NULL;
510b725ae77Skettenis
511b725ae77Skettenis args[i] = value_arg_coerce (args[i], param_type, prototyped);
512b725ae77Skettenis
513b725ae77Skettenis /* elz: this code is to handle the case in which the function
514b725ae77Skettenis to be called has a pointer to function as parameter and the
515b725ae77Skettenis corresponding actual argument is the address of a function
516b725ae77Skettenis and not a pointer to function variable. In aCC compiled
517b725ae77Skettenis code, the calls through pointers to functions (in the body
518b725ae77Skettenis of the function called by hand) are made via
519b725ae77Skettenis $$dyncall_external which requires some registers setting,
520b725ae77Skettenis this is taken care of if we call via a function pointer
521b725ae77Skettenis variable, but not via a function address. In cc this is
522b725ae77Skettenis not a problem. */
523b725ae77Skettenis
524b725ae77Skettenis if (using_gcc == 0)
525b725ae77Skettenis {
526b725ae77Skettenis if (param_type != NULL && TYPE_CODE (ftype) != TYPE_CODE_METHOD)
527b725ae77Skettenis {
528b725ae77Skettenis /* if this parameter is a pointer to function. */
529b725ae77Skettenis if (TYPE_CODE (param_type) == TYPE_CODE_PTR)
530b725ae77Skettenis if (TYPE_CODE (TYPE_TARGET_TYPE (param_type)) == TYPE_CODE_FUNC)
531b725ae77Skettenis /* elz: FIXME here should go the test about the
532b725ae77Skettenis compiler used to compile the target. We want to
533b725ae77Skettenis issue the error message only if the compiler
534b725ae77Skettenis used was HP's aCC. If we used HP's cc, then
535b725ae77Skettenis there is no problem and no need to return at
536b725ae77Skettenis this point. */
537b725ae77Skettenis /* Go see if the actual parameter is a variable of
538b725ae77Skettenis type pointer to function or just a function. */
539b725ae77Skettenis if (args[i]->lval == not_lval)
540b725ae77Skettenis {
541b725ae77Skettenis char *arg_name;
542b725ae77Skettenis if (find_pc_partial_function ((CORE_ADDR) args[i]->aligner.contents[0], &arg_name, NULL, NULL))
543b725ae77Skettenis error ("\
544b725ae77Skettenis You cannot use function <%s> as argument. \n\
545b725ae77Skettenis You must use a pointer to function type variable. Command ignored.", arg_name);
546b725ae77Skettenis }
547b725ae77Skettenis }
548b725ae77Skettenis }
549b725ae77Skettenis }
550b725ae77Skettenis }
551b725ae77Skettenis
552b725ae77Skettenis if (DEPRECATED_REG_STRUCT_HAS_ADDR_P ())
553b725ae77Skettenis {
554b725ae77Skettenis int i;
555b725ae77Skettenis /* This is a machine like the sparc, where we may need to pass a
556b725ae77Skettenis pointer to the structure, not the structure itself. */
557b725ae77Skettenis for (i = nargs - 1; i >= 0; i--)
558b725ae77Skettenis {
559b725ae77Skettenis struct type *arg_type = check_typedef (VALUE_TYPE (args[i]));
560b725ae77Skettenis if ((TYPE_CODE (arg_type) == TYPE_CODE_STRUCT
561b725ae77Skettenis || TYPE_CODE (arg_type) == TYPE_CODE_UNION
562b725ae77Skettenis || TYPE_CODE (arg_type) == TYPE_CODE_ARRAY
563b725ae77Skettenis || TYPE_CODE (arg_type) == TYPE_CODE_STRING
564b725ae77Skettenis || TYPE_CODE (arg_type) == TYPE_CODE_BITSTRING
565b725ae77Skettenis || TYPE_CODE (arg_type) == TYPE_CODE_SET
566b725ae77Skettenis || (TYPE_CODE (arg_type) == TYPE_CODE_FLT
567b725ae77Skettenis && TYPE_LENGTH (arg_type) > 8)
568b725ae77Skettenis )
569b725ae77Skettenis && DEPRECATED_REG_STRUCT_HAS_ADDR (using_gcc, arg_type))
570b725ae77Skettenis {
571b725ae77Skettenis CORE_ADDR addr;
572b725ae77Skettenis int len; /* = TYPE_LENGTH (arg_type); */
573b725ae77Skettenis int aligned_len;
574b725ae77Skettenis arg_type = check_typedef (VALUE_ENCLOSING_TYPE (args[i]));
575b725ae77Skettenis len = TYPE_LENGTH (arg_type);
576b725ae77Skettenis
577b725ae77Skettenis aligned_len = len;
578b725ae77Skettenis if (INNER_THAN (1, 2))
579b725ae77Skettenis {
580b725ae77Skettenis /* stack grows downward */
581b725ae77Skettenis sp -= aligned_len;
582b725ae77Skettenis /* ... so the address of the thing we push is the
583b725ae77Skettenis stack pointer after we push it. */
584b725ae77Skettenis addr = sp;
585b725ae77Skettenis }
586b725ae77Skettenis else
587b725ae77Skettenis {
588b725ae77Skettenis /* The stack grows up, so the address of the thing
589b725ae77Skettenis we push is the stack pointer before we push it. */
590b725ae77Skettenis addr = sp;
591b725ae77Skettenis sp += aligned_len;
592b725ae77Skettenis }
593b725ae77Skettenis /* Push the structure. */
594b725ae77Skettenis write_memory (addr, VALUE_CONTENTS_ALL (args[i]), len);
595b725ae77Skettenis /* The value we're going to pass is the address of the
596b725ae77Skettenis thing we just pushed. */
597b725ae77Skettenis /*args[i] = value_from_longest (lookup_pointer_type (value_type),
598b725ae77Skettenis (LONGEST) addr); */
599b725ae77Skettenis args[i] = value_from_pointer (lookup_pointer_type (arg_type),
600b725ae77Skettenis addr);
601b725ae77Skettenis }
602b725ae77Skettenis }
603b725ae77Skettenis }
604b725ae77Skettenis
605b725ae77Skettenis
606b725ae77Skettenis /* Reserve space for the return structure to be written on the
607b725ae77Skettenis stack, if necessary. Make certain that the value is correctly
608b725ae77Skettenis aligned. */
609b725ae77Skettenis
610b725ae77Skettenis if (struct_return)
611b725ae77Skettenis {
612b725ae77Skettenis int len = TYPE_LENGTH (value_type);
613b725ae77Skettenis if (INNER_THAN (1, 2))
614b725ae77Skettenis {
615b725ae77Skettenis /* Stack grows downward. Align STRUCT_ADDR and SP after
616b725ae77Skettenis making space for the return value. */
617b725ae77Skettenis sp -= len;
618b725ae77Skettenis if (gdbarch_frame_align_p (current_gdbarch))
619b725ae77Skettenis sp = gdbarch_frame_align (current_gdbarch, sp);
620b725ae77Skettenis struct_addr = sp;
621b725ae77Skettenis }
622b725ae77Skettenis else
623b725ae77Skettenis {
624b725ae77Skettenis /* Stack grows upward. Align the frame, allocate space, and
625b725ae77Skettenis then again, re-align the frame??? */
626b725ae77Skettenis if (gdbarch_frame_align_p (current_gdbarch))
627b725ae77Skettenis sp = gdbarch_frame_align (current_gdbarch, sp);
628b725ae77Skettenis struct_addr = sp;
629b725ae77Skettenis sp += len;
630b725ae77Skettenis if (gdbarch_frame_align_p (current_gdbarch))
631b725ae77Skettenis sp = gdbarch_frame_align (current_gdbarch, sp);
632b725ae77Skettenis }
633b725ae77Skettenis }
634b725ae77Skettenis
635b725ae77Skettenis /* Create the dummy stack frame. Pass in the call dummy address as,
636b725ae77Skettenis presumably, the ABI code knows where, in the call dummy, the
637b725ae77Skettenis return address should be pointed. */
638b725ae77Skettenis if (gdbarch_push_dummy_call_p (current_gdbarch))
639b725ae77Skettenis /* When there is no push_dummy_call method, should this code
640b725ae77Skettenis simply error out. That would the implementation of this method
641b725ae77Skettenis for all ABIs (which is probably a good thing). */
642*63addd46Skettenis sp = gdbarch_push_dummy_call (current_gdbarch, function, current_regcache,
643b725ae77Skettenis bp_addr, nargs, args, sp, struct_return,
644b725ae77Skettenis struct_addr);
645b725ae77Skettenis else if (DEPRECATED_PUSH_ARGUMENTS_P ())
646b725ae77Skettenis /* Keep old targets working. */
647b725ae77Skettenis sp = DEPRECATED_PUSH_ARGUMENTS (nargs, args, sp, struct_return,
648b725ae77Skettenis struct_addr);
649b725ae77Skettenis else
650*63addd46Skettenis error ("This target does not support function calls");
651b725ae77Skettenis
652*63addd46Skettenis /* Set up a frame ID for the dummy frame so we can pass it to
653*63addd46Skettenis set_momentary_breakpoint. We need to give the breakpoint a frame
654*63addd46Skettenis ID so that the breakpoint code can correctly re-identify the
655*63addd46Skettenis dummy breakpoint. */
656*63addd46Skettenis /* Sanity. The exact same SP value is returned by PUSH_DUMMY_CALL,
657*63addd46Skettenis saved as the dummy-frame TOS, and used by unwind_dummy_id to form
658*63addd46Skettenis the frame ID's stack address. */
659*63addd46Skettenis dummy_id = frame_id_build (sp, bp_addr);
660b725ae77Skettenis
661b725ae77Skettenis /* Create a momentary breakpoint at the return address of the
662b725ae77Skettenis inferior. That way it breaks when it returns. */
663b725ae77Skettenis
664b725ae77Skettenis {
665b725ae77Skettenis struct breakpoint *bpt;
666b725ae77Skettenis struct symtab_and_line sal;
667b725ae77Skettenis init_sal (&sal); /* initialize to zeroes */
668b725ae77Skettenis sal.pc = bp_addr;
669b725ae77Skettenis sal.section = find_pc_overlay (sal.pc);
670b725ae77Skettenis /* Sanity. The exact same SP value is returned by
671b725ae77Skettenis PUSH_DUMMY_CALL, saved as the dummy-frame TOS, and used by
672b725ae77Skettenis unwind_dummy_id to form the frame ID's stack address. */
673*63addd46Skettenis bpt = set_momentary_breakpoint (sal, dummy_id, bp_call_dummy);
674b725ae77Skettenis bpt->disposition = disp_del;
675b725ae77Skettenis }
676b725ae77Skettenis
677*63addd46Skettenis /* Everything's ready, push all the info needed to restore the
678*63addd46Skettenis caller (and identify the dummy-frame) onto the dummy-frame
679*63addd46Skettenis stack. */
680*63addd46Skettenis dummy_frame_push (caller_regcache, &dummy_id);
681*63addd46Skettenis discard_cleanups (caller_regcache_cleanup);
682*63addd46Skettenis
683*63addd46Skettenis /* - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP - SNIP -
684*63addd46Skettenis If you're looking to implement asynchronous dummy-frames, then
685*63addd46Skettenis just below is the place to chop this function in two.. */
686*63addd46Skettenis
687*63addd46Skettenis /* Now proceed, having reached the desired place. */
688*63addd46Skettenis clear_proceed_status ();
689*63addd46Skettenis
690b725ae77Skettenis /* Execute a "stack dummy", a piece of code stored in the stack by
691b725ae77Skettenis the debugger to be executed in the inferior.
692b725ae77Skettenis
693b725ae77Skettenis The dummy's frame is automatically popped whenever that break is
694b725ae77Skettenis hit. If that is the first time the program stops,
695b725ae77Skettenis call_function_by_hand returns to its caller with that frame
696b725ae77Skettenis already gone and sets RC to 0.
697b725ae77Skettenis
698b725ae77Skettenis Otherwise, set RC to a non-zero value. If the called function
699b725ae77Skettenis receives a random signal, we do not allow the user to continue
700b725ae77Skettenis executing it as this may not work. The dummy frame is poped and
701b725ae77Skettenis we return 1. If we hit a breakpoint, we leave the frame in place
702b725ae77Skettenis and return 2 (the frame will eventually be popped when we do hit
703b725ae77Skettenis the dummy end breakpoint). */
704b725ae77Skettenis
705b725ae77Skettenis {
706b725ae77Skettenis struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0);
707b725ae77Skettenis int saved_async = 0;
708b725ae77Skettenis
709b725ae77Skettenis /* If all error()s out of proceed ended up calling normal_stop
710b725ae77Skettenis (and perhaps they should; it already does in the special case
711b725ae77Skettenis of error out of resume()), then we wouldn't need this. */
712b725ae77Skettenis make_cleanup (breakpoint_auto_delete_contents, &stop_bpstat);
713b725ae77Skettenis
714b725ae77Skettenis disable_watchpoints_before_interactive_call_start ();
715b725ae77Skettenis proceed_to_finish = 1; /* We want stop_registers, please... */
716b725ae77Skettenis
717b725ae77Skettenis if (target_can_async_p ())
718b725ae77Skettenis saved_async = target_async_mask (0);
719b725ae77Skettenis
720b725ae77Skettenis proceed (real_pc, TARGET_SIGNAL_0, 0);
721b725ae77Skettenis
722b725ae77Skettenis if (saved_async)
723b725ae77Skettenis target_async_mask (saved_async);
724b725ae77Skettenis
725b725ae77Skettenis enable_watchpoints_after_interactive_call_stop ();
726b725ae77Skettenis
727b725ae77Skettenis discard_cleanups (old_cleanups);
728b725ae77Skettenis }
729b725ae77Skettenis
730b725ae77Skettenis if (stopped_by_random_signal || !stop_stack_dummy)
731b725ae77Skettenis {
732b725ae77Skettenis /* Find the name of the function we're about to complain about. */
733b725ae77Skettenis const char *name = NULL;
734b725ae77Skettenis {
735b725ae77Skettenis struct symbol *symbol = find_pc_function (funaddr);
736b725ae77Skettenis if (symbol)
737b725ae77Skettenis name = SYMBOL_PRINT_NAME (symbol);
738b725ae77Skettenis else
739b725ae77Skettenis {
740b725ae77Skettenis /* Try the minimal symbols. */
741b725ae77Skettenis struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (funaddr);
742b725ae77Skettenis if (msymbol)
743b725ae77Skettenis name = SYMBOL_PRINT_NAME (msymbol);
744b725ae77Skettenis }
745b725ae77Skettenis if (name == NULL)
746b725ae77Skettenis {
747b725ae77Skettenis /* Can't use a cleanup here. It is discarded, instead use
748b725ae77Skettenis an alloca. */
749*63addd46Skettenis char *tmp = xstrprintf ("at %s", hex_string (funaddr));
750b725ae77Skettenis char *a = alloca (strlen (tmp) + 1);
751b725ae77Skettenis strcpy (a, tmp);
752b725ae77Skettenis xfree (tmp);
753b725ae77Skettenis name = a;
754b725ae77Skettenis }
755b725ae77Skettenis }
756b725ae77Skettenis if (stopped_by_random_signal)
757b725ae77Skettenis {
758b725ae77Skettenis /* We stopped inside the FUNCTION because of a random
759b725ae77Skettenis signal. Further execution of the FUNCTION is not
760b725ae77Skettenis allowed. */
761b725ae77Skettenis
762b725ae77Skettenis if (unwind_on_signal_p)
763b725ae77Skettenis {
764b725ae77Skettenis /* The user wants the context restored. */
765b725ae77Skettenis
766b725ae77Skettenis /* We must get back to the frame we were before the
767b725ae77Skettenis dummy call. */
768b725ae77Skettenis frame_pop (get_current_frame ());
769b725ae77Skettenis
770b725ae77Skettenis /* FIXME: Insert a bunch of wrap_here; name can be very
771b725ae77Skettenis long if it's a C++ name with arguments and stuff. */
772b725ae77Skettenis error ("\
773b725ae77Skettenis The program being debugged was signaled while in a function called from GDB.\n\
774b725ae77Skettenis GDB has restored the context to what it was before the call.\n\
775b725ae77Skettenis To change this behavior use \"set unwindonsignal off\"\n\
776b725ae77Skettenis Evaluation of the expression containing the function (%s) will be abandoned.",
777b725ae77Skettenis name);
778b725ae77Skettenis }
779b725ae77Skettenis else
780b725ae77Skettenis {
781b725ae77Skettenis /* The user wants to stay in the frame where we stopped
782b725ae77Skettenis (default).*/
783b725ae77Skettenis /* If we restored the inferior status (via the cleanup),
784b725ae77Skettenis we would print a spurious error message (Unable to
785b725ae77Skettenis restore previously selected frame), would write the
786b725ae77Skettenis registers from the inf_status (which is wrong), and
787b725ae77Skettenis would do other wrong things. */
788b725ae77Skettenis discard_cleanups (inf_status_cleanup);
789b725ae77Skettenis discard_inferior_status (inf_status);
790b725ae77Skettenis /* FIXME: Insert a bunch of wrap_here; name can be very
791b725ae77Skettenis long if it's a C++ name with arguments and stuff. */
792b725ae77Skettenis error ("\
793b725ae77Skettenis The program being debugged was signaled while in a function called from GDB.\n\
794b725ae77Skettenis GDB remains in the frame where the signal was received.\n\
795b725ae77Skettenis To change this behavior use \"set unwindonsignal on\"\n\
796b725ae77Skettenis Evaluation of the expression containing the function (%s) will be abandoned.",
797b725ae77Skettenis name);
798b725ae77Skettenis }
799b725ae77Skettenis }
800b725ae77Skettenis
801b725ae77Skettenis if (!stop_stack_dummy)
802b725ae77Skettenis {
803b725ae77Skettenis /* We hit a breakpoint inside the FUNCTION. */
804b725ae77Skettenis /* If we restored the inferior status (via the cleanup), we
805b725ae77Skettenis would print a spurious error message (Unable to restore
806b725ae77Skettenis previously selected frame), would write the registers
807b725ae77Skettenis from the inf_status (which is wrong), and would do other
808b725ae77Skettenis wrong things. */
809b725ae77Skettenis discard_cleanups (inf_status_cleanup);
810b725ae77Skettenis discard_inferior_status (inf_status);
811b725ae77Skettenis /* The following error message used to say "The expression
812b725ae77Skettenis which contained the function call has been discarded."
813b725ae77Skettenis It is a hard concept to explain in a few words. Ideally,
814b725ae77Skettenis GDB would be able to resume evaluation of the expression
815b725ae77Skettenis when the function finally is done executing. Perhaps
816b725ae77Skettenis someday this will be implemented (it would not be easy). */
817b725ae77Skettenis /* FIXME: Insert a bunch of wrap_here; name can be very long if it's
818b725ae77Skettenis a C++ name with arguments and stuff. */
819b725ae77Skettenis error ("\
820b725ae77Skettenis The program being debugged stopped while in a function called from GDB.\n\
821b725ae77Skettenis When the function (%s) is done executing, GDB will silently\n\
822b725ae77Skettenis stop (instead of continuing to evaluate the expression containing\n\
823b725ae77Skettenis the function call).", name);
824b725ae77Skettenis }
825b725ae77Skettenis
826b725ae77Skettenis /* The above code errors out, so ... */
827b725ae77Skettenis internal_error (__FILE__, __LINE__, "... should not be here");
828b725ae77Skettenis }
829b725ae77Skettenis
830b725ae77Skettenis /* If we get here the called FUNCTION run to completion. */
831b725ae77Skettenis
832b725ae77Skettenis /* On normal return, the stack dummy has been popped already. */
833b725ae77Skettenis regcache_cpy_no_passthrough (retbuf, stop_registers);
834b725ae77Skettenis
835b725ae77Skettenis /* Restore the inferior status, via its cleanup. At this stage,
836b725ae77Skettenis leave the RETBUF alone. */
837b725ae77Skettenis do_cleanups (inf_status_cleanup);
838b725ae77Skettenis
839*63addd46Skettenis /* Figure out the value returned by the function, return that. */
840b725ae77Skettenis {
841*63addd46Skettenis struct value *retval;
842*63addd46Skettenis if (TYPE_CODE (value_type) == TYPE_CODE_VOID)
843*63addd46Skettenis /* If the function returns void, don't bother fetching the
844*63addd46Skettenis return value. */
845*63addd46Skettenis retval = allocate_value (value_type);
846*63addd46Skettenis else if (struct_return)
847b725ae77Skettenis /* NOTE: cagney/2003-09-27: This assumes that PUSH_DUMMY_CALL
848b725ae77Skettenis has correctly stored STRUCT_ADDR in the target. In the past
849b725ae77Skettenis that hasn't been the case, the old MIPS PUSH_ARGUMENTS
850b725ae77Skettenis (PUSH_DUMMY_CALL precursor) would silently move the location
851b725ae77Skettenis of the struct return value making STRUCT_ADDR bogus. If
852b725ae77Skettenis you're seeing problems with values being returned using the
853b725ae77Skettenis "struct return convention", check that PUSH_DUMMY_CALL isn't
854b725ae77Skettenis playing tricks. */
855*63addd46Skettenis retval = value_at (value_type, struct_addr, NULL);
856b725ae77Skettenis else
857b725ae77Skettenis {
858*63addd46Skettenis /* This code only handles "register convention". */
859*63addd46Skettenis retval = allocate_value (value_type);
860*63addd46Skettenis gdb_assert (gdbarch_return_value (current_gdbarch, value_type,
861*63addd46Skettenis NULL, NULL, NULL)
862*63addd46Skettenis == RETURN_VALUE_REGISTER_CONVENTION);
863*63addd46Skettenis gdbarch_return_value (current_gdbarch, value_type, retbuf,
864*63addd46Skettenis VALUE_CONTENTS_RAW (retval) /*read*/,
865*63addd46Skettenis NULL /*write*/);
866*63addd46Skettenis }
867b725ae77Skettenis do_cleanups (retbuf_cleanup);
868b725ae77Skettenis return retval;
869b725ae77Skettenis }
870b725ae77Skettenis }
871b725ae77Skettenis
872b725ae77Skettenis void _initialize_infcall (void);
873b725ae77Skettenis
874b725ae77Skettenis void
_initialize_infcall(void)875b725ae77Skettenis _initialize_infcall (void)
876b725ae77Skettenis {
877b725ae77Skettenis add_setshow_boolean_cmd ("coerce-float-to-double", class_obscure,
878b725ae77Skettenis &coerce_float_to_double_p, "\
879*63addd46Skettenis Set coercion of floats to doubles when calling functions.", "\
880*63addd46Skettenis Show coercion of floats to doubles when calling functions", "\
881b725ae77Skettenis Variables of type float should generally be converted to doubles before\n\
882b725ae77Skettenis calling an unprototyped function, and left alone when calling a prototyped\n\
883b725ae77Skettenis function. However, some older debug info formats do not provide enough\n\
884b725ae77Skettenis information to determine that a function is prototyped. If this flag is\n\
885b725ae77Skettenis set, GDB will perform the conversion for a function it considers\n\
886b725ae77Skettenis unprototyped.\n\
887b725ae77Skettenis The default is to perform the conversion.\n", "\
888*63addd46Skettenis Coercion of floats to doubles when calling functions is %s.",
889b725ae77Skettenis NULL, NULL, &setlist, &showlist);
890b725ae77Skettenis
891b725ae77Skettenis add_setshow_boolean_cmd ("unwindonsignal", no_class,
892b725ae77Skettenis &unwind_on_signal_p, "\
893*63addd46Skettenis Set unwinding of stack if a signal is received while in a call dummy.", "\
894*63addd46Skettenis Show unwinding of stack if a signal is received while in a call dummy.", "\
895b725ae77Skettenis The unwindonsignal lets the user determine what gdb should do if a signal\n\
896b725ae77Skettenis is received while in a function called from gdb (call dummy). If set, gdb\n\
897b725ae77Skettenis unwinds the stack and restore the context to what as it was before the call.\n\
898b725ae77Skettenis The default is to stop in the frame where the signal was received.", "\
899*63addd46Skettenis Unwinding of stack if a signal is received while in a call dummy is %s.",
900b725ae77Skettenis NULL, NULL, &setlist, &showlist);
901b725ae77Skettenis }
902