Commit | Line | Data |
---|---|---|
04714b91 AC |
1 | /* Perform an inferior function call, for GDB, the GNU debugger. |
2 | ||
3 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, | |
4 | 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software | |
5 | Foundation, Inc. | |
6 | ||
7 | This file is part of GDB. | |
8 | ||
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. | |
13 | ||
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. | |
18 | ||
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. */ | |
23 | ||
24 | #include "defs.h" | |
25 | #include "breakpoint.h" | |
26 | #include "target.h" | |
27 | #include "regcache.h" | |
28 | #include "inferior.h" | |
29 | #include "gdb_assert.h" | |
30 | #include "block.h" | |
31 | #include "gdbcore.h" | |
32 | #include "language.h" | |
33 | #include "symfile.h" | |
34 | #include "gdbcmd.h" | |
35 | #include "command.h" | |
36 | #include "gdb_string.h" | |
b9362cc7 | 37 | #include "infcall.h" |
04714b91 AC |
38 | |
39 | /* NOTE: cagney/2003-04-16: What's the future of this code? | |
40 | ||
41 | GDB needs an asynchronous expression evaluator, that means an | |
42 | asynchronous inferior function call implementation, and that in | |
43 | turn means restructuring the code so that it is event driven. */ | |
44 | ||
45 | /* How you should pass arguments to a function depends on whether it | |
46 | was defined in K&R style or prototype style. If you define a | |
47 | function using the K&R syntax that takes a `float' argument, then | |
48 | callers must pass that argument as a `double'. If you define the | |
49 | function using the prototype syntax, then you must pass the | |
50 | argument as a `float', with no promotion. | |
51 | ||
52 | Unfortunately, on certain older platforms, the debug info doesn't | |
53 | indicate reliably how each function was defined. A function type's | |
54 | TYPE_FLAG_PROTOTYPED flag may be clear, even if the function was | |
55 | defined in prototype style. When calling a function whose | |
56 | TYPE_FLAG_PROTOTYPED flag is clear, GDB consults this flag to | |
57 | decide what to do. | |
58 | ||
59 | For modern targets, it is proper to assume that, if the prototype | |
60 | flag is clear, that can be trusted: `float' arguments should be | |
61 | promoted to `double'. For some older targets, if the prototype | |
62 | flag is clear, that doesn't tell us anything. The default is to | |
63 | trust the debug information; the user can override this behavior | |
64 | with "set coerce-float-to-double 0". */ | |
65 | ||
66 | static int coerce_float_to_double_p = 1; | |
67 | ||
68 | /* This boolean tells what gdb should do if a signal is received while | |
69 | in a function called from gdb (call dummy). If set, gdb unwinds | |
70 | the stack and restore the context to what as it was before the | |
71 | call. | |
72 | ||
73 | The default is to stop in the frame where the signal was received. */ | |
74 | ||
75 | int unwind_on_signal_p = 0; | |
76 | ||
77 | /* Perform the standard coercions that are specified | |
78 | for arguments to be passed to C functions. | |
79 | ||
80 | If PARAM_TYPE is non-NULL, it is the expected parameter type. | |
81 | IS_PROTOTYPED is non-zero if the function declaration is prototyped. */ | |
82 | ||
83 | static struct value * | |
84 | value_arg_coerce (struct value *arg, struct type *param_type, | |
85 | int is_prototyped) | |
86 | { | |
87 | register struct type *arg_type = check_typedef (VALUE_TYPE (arg)); | |
88 | register struct type *type | |
89 | = param_type ? check_typedef (param_type) : arg_type; | |
90 | ||
91 | switch (TYPE_CODE (type)) | |
92 | { | |
93 | case TYPE_CODE_REF: | |
94 | if (TYPE_CODE (arg_type) != TYPE_CODE_REF | |
95 | && TYPE_CODE (arg_type) != TYPE_CODE_PTR) | |
96 | { | |
97 | arg = value_addr (arg); | |
98 | VALUE_TYPE (arg) = param_type; | |
99 | return arg; | |
100 | } | |
101 | break; | |
102 | case TYPE_CODE_INT: | |
103 | case TYPE_CODE_CHAR: | |
104 | case TYPE_CODE_BOOL: | |
105 | case TYPE_CODE_ENUM: | |
106 | /* If we don't have a prototype, coerce to integer type if necessary. */ | |
107 | if (!is_prototyped) | |
108 | { | |
109 | if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_int)) | |
110 | type = builtin_type_int; | |
111 | } | |
112 | /* Currently all target ABIs require at least the width of an integer | |
113 | type for an argument. We may have to conditionalize the following | |
114 | type coercion for future targets. */ | |
115 | if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_int)) | |
116 | type = builtin_type_int; | |
117 | break; | |
118 | case TYPE_CODE_FLT: | |
119 | if (!is_prototyped && coerce_float_to_double_p) | |
120 | { | |
121 | if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_double)) | |
122 | type = builtin_type_double; | |
123 | else if (TYPE_LENGTH (type) > TYPE_LENGTH (builtin_type_double)) | |
124 | type = builtin_type_long_double; | |
125 | } | |
126 | break; | |
127 | case TYPE_CODE_FUNC: | |
128 | type = lookup_pointer_type (type); | |
129 | break; | |
130 | case TYPE_CODE_ARRAY: | |
131 | /* Arrays are coerced to pointers to their first element, unless | |
132 | they are vectors, in which case we want to leave them alone, | |
133 | because they are passed by value. */ | |
134 | if (current_language->c_style_arrays) | |
135 | if (!TYPE_VECTOR (type)) | |
136 | type = lookup_pointer_type (TYPE_TARGET_TYPE (type)); | |
137 | break; | |
138 | case TYPE_CODE_UNDEF: | |
139 | case TYPE_CODE_PTR: | |
140 | case TYPE_CODE_STRUCT: | |
141 | case TYPE_CODE_UNION: | |
142 | case TYPE_CODE_VOID: | |
143 | case TYPE_CODE_SET: | |
144 | case TYPE_CODE_RANGE: | |
145 | case TYPE_CODE_STRING: | |
146 | case TYPE_CODE_BITSTRING: | |
147 | case TYPE_CODE_ERROR: | |
148 | case TYPE_CODE_MEMBER: | |
149 | case TYPE_CODE_METHOD: | |
150 | case TYPE_CODE_COMPLEX: | |
151 | default: | |
152 | break; | |
153 | } | |
154 | ||
155 | return value_cast (type, arg); | |
156 | } | |
157 | ||
158 | /* Determine a function's address and its return type from its value. | |
159 | Calls error() if the function is not valid for calling. */ | |
160 | ||
a9fa03de | 161 | CORE_ADDR |
04714b91 AC |
162 | find_function_addr (struct value *function, struct type **retval_type) |
163 | { | |
164 | register struct type *ftype = check_typedef (VALUE_TYPE (function)); | |
165 | register enum type_code code = TYPE_CODE (ftype); | |
166 | struct type *value_type; | |
167 | CORE_ADDR funaddr; | |
168 | ||
169 | /* If it's a member function, just look at the function | |
170 | part of it. */ | |
171 | ||
172 | /* Determine address to call. */ | |
173 | if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD) | |
174 | { | |
175 | funaddr = VALUE_ADDRESS (function); | |
176 | value_type = TYPE_TARGET_TYPE (ftype); | |
177 | } | |
178 | else if (code == TYPE_CODE_PTR) | |
179 | { | |
180 | funaddr = value_as_address (function); | |
181 | ftype = check_typedef (TYPE_TARGET_TYPE (ftype)); | |
182 | if (TYPE_CODE (ftype) == TYPE_CODE_FUNC | |
183 | || TYPE_CODE (ftype) == TYPE_CODE_METHOD) | |
184 | { | |
185 | funaddr = CONVERT_FROM_FUNC_PTR_ADDR (funaddr); | |
186 | value_type = TYPE_TARGET_TYPE (ftype); | |
187 | } | |
188 | else | |
189 | value_type = builtin_type_int; | |
190 | } | |
191 | else if (code == TYPE_CODE_INT) | |
192 | { | |
193 | /* Handle the case of functions lacking debugging info. | |
194 | Their values are characters since their addresses are char */ | |
195 | if (TYPE_LENGTH (ftype) == 1) | |
196 | funaddr = value_as_address (value_addr (function)); | |
197 | else | |
198 | /* Handle integer used as address of a function. */ | |
199 | funaddr = (CORE_ADDR) value_as_long (function); | |
200 | ||
201 | value_type = builtin_type_int; | |
202 | } | |
203 | else | |
204 | error ("Invalid data type for function to be called."); | |
205 | ||
206 | *retval_type = value_type; | |
207 | return funaddr; | |
208 | } | |
209 | ||
210 | /* Call breakpoint_auto_delete on the current contents of the bpstat | |
211 | pointed to by arg (which is really a bpstat *). */ | |
212 | ||
213 | static void | |
214 | breakpoint_auto_delete_contents (void *arg) | |
215 | { | |
216 | breakpoint_auto_delete (*(bpstat *) arg); | |
217 | } | |
218 | ||
7043d8dc AC |
219 | static CORE_ADDR |
220 | legacy_push_dummy_code (struct gdbarch *gdbarch, | |
221 | CORE_ADDR sp, CORE_ADDR funaddr, int using_gcc, | |
222 | struct value **args, int nargs, | |
223 | struct type *value_type, | |
224 | CORE_ADDR *real_pc, CORE_ADDR *bp_addr) | |
225 | { | |
b1e29e33 AC |
226 | /* CALL_DUMMY is an array of words (DEPRECATED_REGISTER_SIZE), but |
227 | each word is in host byte order. Before calling | |
228 | DEPRECATED_FIX_CALL_DUMMY, we byteswap it and remove any extra | |
229 | bytes which might exist because ULONGEST is bigger than | |
230 | DEPRECATED_REGISTER_SIZE. */ | |
7043d8dc AC |
231 | /* NOTE: This is pretty wierd, as the call dummy is actually a |
232 | sequence of instructions. But CISC machines will have to pack | |
b1e29e33 AC |
233 | the instructions into DEPRECATED_REGISTER_SIZE units (and so will |
234 | RISC machines for which INSTRUCTION_SIZE is not | |
235 | DEPRECATED_REGISTER_SIZE). */ | |
7043d8dc AC |
236 | /* NOTE: This is pretty stupid. CALL_DUMMY should be in strict |
237 | target byte order. */ | |
238 | CORE_ADDR start_sp; | |
b1e29e33 AC |
239 | ULONGEST *dummy = alloca (DEPRECATED_SIZEOF_CALL_DUMMY_WORDS); |
240 | int sizeof_dummy1 = (DEPRECATED_REGISTER_SIZE | |
241 | * DEPRECATED_SIZEOF_CALL_DUMMY_WORDS | |
7043d8dc AC |
242 | / sizeof (ULONGEST)); |
243 | char *dummy1 = alloca (sizeof_dummy1); | |
b1e29e33 AC |
244 | memcpy (dummy, DEPRECATED_CALL_DUMMY_WORDS, |
245 | DEPRECATED_SIZEOF_CALL_DUMMY_WORDS); | |
7043d8dc AC |
246 | if (INNER_THAN (1, 2)) |
247 | { | |
248 | /* Stack grows down */ | |
249 | sp -= sizeof_dummy1; | |
250 | start_sp = sp; | |
251 | } | |
252 | else | |
253 | { | |
254 | /* Stack grows up */ | |
255 | start_sp = sp; | |
256 | sp += sizeof_dummy1; | |
257 | } | |
258 | /* NOTE: cagney/2002-09-10: Don't bother re-adjusting the stack | |
259 | after allocating space for the call dummy. A target can specify | |
b1e29e33 AC |
260 | a SIZEOF_DUMMY1 (via DEPRECATED_SIZEOF_CALL_DUMMY_WORDS) such |
261 | that all local alignment requirements are met. */ | |
7043d8dc AC |
262 | /* Create a call sequence customized for this function and the |
263 | number of arguments for it. */ | |
264 | { | |
265 | int i; | |
b1e29e33 | 266 | for (i = 0; i < (int) (DEPRECATED_SIZEOF_CALL_DUMMY_WORDS / sizeof (dummy[0])); |
7043d8dc | 267 | i++) |
b1e29e33 AC |
268 | store_unsigned_integer (&dummy1[i * DEPRECATED_REGISTER_SIZE], |
269 | DEPRECATED_REGISTER_SIZE, | |
7043d8dc AC |
270 | (ULONGEST) dummy[i]); |
271 | } | |
272 | /* NOTE: cagney/2003-04-22: This computation of REAL_PC, BP_ADDR and | |
273 | DUMMY_ADDR is pretty messed up. It comes from constant tinkering | |
b1e29e33 | 274 | with the values. Instead a DEPRECATED_FIX_CALL_DUMMY replacement |
7043d8dc AC |
275 | (PUSH_DUMMY_BREAKPOINT?) should just do everything. */ |
276 | #ifdef GDB_TARGET_IS_HPPA | |
222e5d1d AC |
277 | (*real_pc) = DEPRECATED_FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, |
278 | args, value_type, using_gcc); | |
7043d8dc | 279 | #else |
b1e29e33 | 280 | if (DEPRECATED_FIX_CALL_DUMMY_P ()) |
7043d8dc AC |
281 | { |
282 | /* gdb_assert (CALL_DUMMY_LOCATION == ON_STACK) true? */ | |
b1e29e33 AC |
283 | DEPRECATED_FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, args, |
284 | value_type, using_gcc); | |
7043d8dc AC |
285 | } |
286 | (*real_pc) = start_sp; | |
287 | #endif | |
288 | /* Yes, the offset is applied to the real_pc and not the dummy addr. | |
289 | Ulgh! Blame the HP/UX target. */ | |
b1e29e33 | 290 | (*bp_addr) = (*real_pc) + DEPRECATED_CALL_DUMMY_BREAKPOINT_OFFSET; |
7043d8dc AC |
291 | /* Yes, the offset is applied to the real_pc and not the |
292 | dummy_addr. Ulgh! Blame the HP/UX target. */ | |
b1e29e33 | 293 | (*real_pc) += DEPRECATED_CALL_DUMMY_START_OFFSET; |
7043d8dc AC |
294 | write_memory (start_sp, (char *) dummy1, sizeof_dummy1); |
295 | if (DEPRECATED_USE_GENERIC_DUMMY_FRAMES) | |
296 | generic_save_call_dummy_addr (start_sp, start_sp + sizeof_dummy1); | |
297 | return sp; | |
298 | } | |
299 | ||
300 | static CORE_ADDR | |
301 | generic_push_dummy_code (struct gdbarch *gdbarch, | |
302 | CORE_ADDR sp, CORE_ADDR funaddr, int using_gcc, | |
303 | struct value **args, int nargs, | |
304 | struct type *value_type, | |
305 | CORE_ADDR *real_pc, CORE_ADDR *bp_addr) | |
306 | { | |
307 | /* Something here to findout the size of a breakpoint and then | |
308 | allocate space for it on the stack. */ | |
309 | int bplen; | |
310 | /* This code assumes frame align. */ | |
311 | gdb_assert (gdbarch_frame_align_p (gdbarch)); | |
312 | /* Force the stack's alignment. The intent is to ensure that the SP | |
313 | is aligned to at least a breakpoint instruction's boundary. */ | |
314 | sp = gdbarch_frame_align (gdbarch, sp); | |
315 | /* Allocate space for, and then position the breakpoint on the | |
316 | stack. */ | |
317 | if (gdbarch_inner_than (gdbarch, 1, 2)) | |
318 | { | |
319 | CORE_ADDR bppc = sp; | |
320 | gdbarch_breakpoint_from_pc (gdbarch, &bppc, &bplen); | |
321 | sp = gdbarch_frame_align (gdbarch, sp - bplen); | |
322 | (*bp_addr) = sp; | |
323 | /* Should the breakpoint size/location be re-computed here? */ | |
324 | } | |
325 | else | |
326 | { | |
327 | (*bp_addr) = sp; | |
328 | gdbarch_breakpoint_from_pc (gdbarch, bp_addr, &bplen); | |
329 | sp = gdbarch_frame_align (gdbarch, sp + bplen); | |
330 | } | |
331 | /* Inferior resumes at the function entry point. */ | |
332 | (*real_pc) = funaddr; | |
333 | return sp; | |
334 | } | |
335 | ||
b1e29e33 AC |
336 | /* Provide backward compatibility. Once DEPRECATED_FIX_CALL_DUMMY is |
337 | eliminated, this can be simplified. */ | |
7043d8dc AC |
338 | |
339 | static CORE_ADDR | |
340 | push_dummy_code (struct gdbarch *gdbarch, | |
341 | CORE_ADDR sp, CORE_ADDR funaddr, int using_gcc, | |
342 | struct value **args, int nargs, | |
343 | struct type *value_type, | |
344 | CORE_ADDR *real_pc, CORE_ADDR *bp_addr) | |
345 | { | |
346 | if (gdbarch_push_dummy_code_p (gdbarch)) | |
347 | return gdbarch_push_dummy_code (gdbarch, sp, funaddr, using_gcc, | |
348 | args, nargs, value_type, real_pc, bp_addr); | |
b1e29e33 | 349 | else if (DEPRECATED_FIX_CALL_DUMMY_P ()) |
7043d8dc AC |
350 | return legacy_push_dummy_code (gdbarch, sp, funaddr, using_gcc, |
351 | args, nargs, value_type, real_pc, bp_addr); | |
352 | else | |
353 | return generic_push_dummy_code (gdbarch, sp, funaddr, using_gcc, | |
354 | args, nargs, value_type, real_pc, bp_addr); | |
355 | } | |
356 | ||
04714b91 AC |
357 | /* All this stuff with a dummy frame may seem unnecessarily complicated |
358 | (why not just save registers in GDB?). The purpose of pushing a dummy | |
359 | frame which looks just like a real frame is so that if you call a | |
360 | function and then hit a breakpoint (get a signal, etc), "backtrace" | |
361 | will look right. Whether the backtrace needs to actually show the | |
362 | stack at the time the inferior function was called is debatable, but | |
363 | it certainly needs to not display garbage. So if you are contemplating | |
364 | making dummy frames be different from normal frames, consider that. */ | |
365 | ||
366 | /* Perform a function call in the inferior. | |
367 | ARGS is a vector of values of arguments (NARGS of them). | |
368 | FUNCTION is a value, the function to be called. | |
369 | Returns a value representing what the function returned. | |
370 | May fail to return, if a breakpoint or signal is hit | |
371 | during the execution of the function. | |
372 | ||
373 | ARGS is modified to contain coerced values. */ | |
374 | ||
375 | struct value * | |
376 | call_function_by_hand (struct value *function, int nargs, struct value **args) | |
377 | { | |
378 | register CORE_ADDR sp; | |
04714b91 | 379 | CORE_ADDR dummy_addr; |
04714b91 AC |
380 | struct type *value_type; |
381 | unsigned char struct_return; | |
382 | CORE_ADDR struct_addr = 0; | |
383 | struct regcache *retbuf; | |
384 | struct cleanup *retbuf_cleanup; | |
385 | struct inferior_status *inf_status; | |
386 | struct cleanup *inf_status_cleanup; | |
387 | CORE_ADDR funaddr; | |
388 | int using_gcc; /* Set to version of gcc in use, or zero if not gcc */ | |
389 | CORE_ADDR real_pc; | |
04714b91 | 390 | struct type *ftype = check_typedef (SYMBOL_TYPE (function)); |
d585e13a | 391 | CORE_ADDR bp_addr; |
04714b91 | 392 | |
04714b91 AC |
393 | if (!target_has_execution) |
394 | noprocess (); | |
395 | ||
396 | /* Create a cleanup chain that contains the retbuf (buffer | |
397 | containing the register values). This chain is create BEFORE the | |
398 | inf_status chain so that the inferior status can cleaned up | |
399 | (restored or discarded) without having the retbuf freed. */ | |
400 | retbuf = regcache_xmalloc (current_gdbarch); | |
401 | retbuf_cleanup = make_cleanup_regcache_xfree (retbuf); | |
402 | ||
403 | /* A cleanup for the inferior status. Create this AFTER the retbuf | |
404 | so that this can be discarded or applied without interfering with | |
405 | the regbuf. */ | |
406 | inf_status = save_inferior_status (1); | |
407 | inf_status_cleanup = make_cleanup_restore_inferior_status (inf_status); | |
408 | ||
409 | if (DEPRECATED_PUSH_DUMMY_FRAME_P ()) | |
410 | { | |
411 | /* DEPRECATED_PUSH_DUMMY_FRAME is responsible for saving the | |
412 | inferior registers (and frame_pop() for restoring them). (At | |
413 | least on most machines) they are saved on the stack in the | |
414 | inferior. */ | |
415 | DEPRECATED_PUSH_DUMMY_FRAME; | |
416 | } | |
417 | else | |
418 | { | |
419 | /* FIXME: cagney/2003-02-26: Step zero of this little tinker is | |
420 | to extract the generic dummy frame code from the architecture | |
421 | vector. Hence this direct call. | |
422 | ||
423 | A follow-on change is to modify this interface so that it takes | |
c48a845b | 424 | thread OR frame OR ptid as a parameter, and returns a dummy |
04714b91 | 425 | frame handle. The handle can then be used further down as a |
a59fe496 AC |
426 | parameter to generic_save_dummy_frame_tos(). Hmm, thinking |
427 | about it, since everything is ment to be using generic dummy | |
428 | frames, why not even use some of the dummy frame code to here - | |
429 | do a regcache dup and then pass the duped regcache, along with | |
430 | all the other stuff, at one single point. | |
04714b91 AC |
431 | |
432 | In fact, you can even save the structure's return address in the | |
433 | dummy frame and fix one of those nasty lost struct return edge | |
434 | conditions. */ | |
435 | generic_push_dummy_frame (); | |
436 | } | |
437 | ||
04714b91 | 438 | /* Ensure that the initial SP is correctly aligned. */ |
ebc7896c AC |
439 | { |
440 | CORE_ADDR old_sp = read_sp (); | |
441 | if (gdbarch_frame_align_p (current_gdbarch)) | |
442 | { | |
443 | /* NOTE: cagney/2002-09-18: | |
444 | ||
445 | On a RISC architecture, a void parameterless generic dummy | |
446 | frame (i.e., no parameters, no result) typically does not | |
447 | need to push anything the stack and hence can leave SP and | |
c48a845b | 448 | FP. Similarly, a frameless (possibly leaf) function does |
ebc7896c AC |
449 | not push anything on the stack and, hence, that too can |
450 | leave FP and SP unchanged. As a consequence, a sequence of | |
451 | void parameterless generic dummy frame calls to frameless | |
452 | functions will create a sequence of effectively identical | |
453 | frames (SP, FP and TOS and PC the same). This, not | |
454 | suprisingly, results in what appears to be a stack in an | |
455 | infinite loop --- when GDB tries to find a generic dummy | |
456 | frame on the internal dummy frame stack, it will always | |
457 | find the first one. | |
458 | ||
459 | To avoid this problem, the code below always grows the | |
460 | stack. That way, two dummy frames can never be identical. | |
461 | It does burn a few bytes of stack but that is a small price | |
462 | to pay :-). */ | |
463 | sp = gdbarch_frame_align (current_gdbarch, old_sp); | |
464 | if (sp == old_sp) | |
465 | { | |
466 | if (INNER_THAN (1, 2)) | |
467 | /* Stack grows down. */ | |
468 | sp = gdbarch_frame_align (current_gdbarch, old_sp - 1); | |
469 | else | |
470 | /* Stack grows up. */ | |
471 | sp = gdbarch_frame_align (current_gdbarch, old_sp + 1); | |
472 | } | |
473 | gdb_assert ((INNER_THAN (1, 2) && sp <= old_sp) | |
474 | || (INNER_THAN (2, 1) && sp >= old_sp)); | |
475 | } | |
476 | else | |
a59fe496 AC |
477 | /* FIXME: cagney/2002-09-18: Hey, you loose! |
478 | ||
479 | Who knows how badly aligned the SP is! Further, per comment | |
480 | above, if the generic dummy frame ends up empty (because | |
481 | nothing is pushed) GDB won't be able to correctly perform | |
482 | back traces. If a target is having trouble with backtraces, | |
483 | first thing to do is add FRAME_ALIGN() to the architecture | |
484 | vector. If that fails, try unwind_dummy_id(). */ | |
ebc7896c AC |
485 | sp = old_sp; |
486 | } | |
04714b91 | 487 | |
04714b91 AC |
488 | funaddr = find_function_addr (function, &value_type); |
489 | CHECK_TYPEDEF (value_type); | |
490 | ||
491 | { | |
492 | struct block *b = block_for_pc (funaddr); | |
493 | /* If compiled without -g, assume GCC 2. */ | |
494 | using_gcc = (b == NULL ? 2 : BLOCK_GCC_COMPILED (b)); | |
495 | } | |
496 | ||
497 | /* Are we returning a value using a structure return or a normal | |
498 | value return? */ | |
499 | ||
500 | struct_return = using_struct_return (function, funaddr, value_type, | |
501 | using_gcc); | |
502 | ||
7043d8dc AC |
503 | /* Determine the location of the breakpoint (and possibly other |
504 | stuff) that the called function will return to. The SPARC, for a | |
505 | function returning a structure or union, needs to make space for | |
506 | not just the breakpoint but also an extra word containing the | |
507 | size (?) of the structure being passed. */ | |
508 | ||
509 | /* The actual breakpoint (at BP_ADDR) is inserted separatly so there | |
510 | is no need to write that out. */ | |
511 | ||
04714b91 AC |
512 | switch (CALL_DUMMY_LOCATION) |
513 | { | |
514 | case ON_STACK: | |
7043d8dc AC |
515 | /* "dummy_addr" is here just to keep old targets happy. New |
516 | targets return that same information via "sp" and "bp_addr". */ | |
517 | if (INNER_THAN (1, 2)) | |
d585e13a | 518 | { |
7043d8dc AC |
519 | sp = push_dummy_code (current_gdbarch, sp, funaddr, |
520 | using_gcc, args, nargs, value_type, | |
521 | &real_pc, &bp_addr); | |
522 | dummy_addr = sp; | |
d585e13a | 523 | } |
7043d8dc AC |
524 | else |
525 | { | |
526 | dummy_addr = sp; | |
527 | sp = push_dummy_code (current_gdbarch, sp, funaddr, | |
528 | using_gcc, args, nargs, value_type, | |
529 | &real_pc, &bp_addr); | |
530 | } | |
531 | break; | |
04714b91 | 532 | case AT_ENTRY_POINT: |
c89b70f1 AC |
533 | if (DEPRECATED_FIX_CALL_DUMMY_P ()) |
534 | { | |
535 | /* Sigh. Some targets use DEPRECATED_FIX_CALL_DUMMY to | |
536 | shove extra stuff onto the stack or into registers. That | |
537 | code should be in PUSH_DUMMY_CALL, however, in the mean | |
538 | time ... */ | |
539 | /* If the target is manipulating DUMMY1, it looses big time. */ | |
540 | void *dummy1 = NULL; | |
541 | DEPRECATED_FIX_CALL_DUMMY (dummy1, sp, funaddr, nargs, args, | |
542 | value_type, using_gcc); | |
543 | } | |
04714b91 AC |
544 | real_pc = funaddr; |
545 | dummy_addr = CALL_DUMMY_ADDRESS (); | |
d585e13a AC |
546 | /* A call dummy always consists of just a single breakpoint, so |
547 | it's address is the same as the address of the dummy. */ | |
548 | bp_addr = dummy_addr; | |
04714b91 AC |
549 | break; |
550 | default: | |
551 | internal_error (__FILE__, __LINE__, "bad switch"); | |
552 | } | |
553 | ||
7043d8dc AC |
554 | if (DEPRECATED_USE_GENERIC_DUMMY_FRAMES) |
555 | /* Save where the breakpoint is going to be inserted so that the | |
556 | dummy-frame code is later able to re-identify it. */ | |
557 | generic_save_call_dummy_addr (bp_addr, bp_addr + 1); | |
558 | ||
04714b91 AC |
559 | if (nargs < TYPE_NFIELDS (ftype)) |
560 | error ("too few arguments in function call"); | |
561 | ||
ebc7896c AC |
562 | { |
563 | int i; | |
564 | for (i = nargs - 1; i >= 0; i--) | |
565 | { | |
566 | int prototyped; | |
567 | struct type *param_type; | |
568 | ||
569 | /* FIXME drow/2002-05-31: Should just always mark methods as | |
570 | prototyped. Can we respect TYPE_VARARGS? Probably not. */ | |
571 | if (TYPE_CODE (ftype) == TYPE_CODE_METHOD) | |
572 | prototyped = 1; | |
573 | else if (i < TYPE_NFIELDS (ftype)) | |
574 | prototyped = TYPE_PROTOTYPED (ftype); | |
575 | else | |
576 | prototyped = 0; | |
577 | ||
578 | if (i < TYPE_NFIELDS (ftype)) | |
579 | param_type = TYPE_FIELD_TYPE (ftype, i); | |
580 | else | |
581 | param_type = NULL; | |
582 | ||
583 | args[i] = value_arg_coerce (args[i], param_type, prototyped); | |
584 | ||
585 | /* elz: this code is to handle the case in which the function | |
586 | to be called has a pointer to function as parameter and the | |
587 | corresponding actual argument is the address of a function | |
588 | and not a pointer to function variable. In aCC compiled | |
589 | code, the calls through pointers to functions (in the body | |
590 | of the function called by hand) are made via | |
591 | $$dyncall_external which requires some registers setting, | |
592 | this is taken care of if we call via a function pointer | |
593 | variable, but not via a function address. In cc this is | |
594 | not a problem. */ | |
595 | ||
596 | if (using_gcc == 0) | |
597 | { | |
598 | if (param_type != NULL && TYPE_CODE (ftype) != TYPE_CODE_METHOD) | |
599 | { | |
600 | /* if this parameter is a pointer to function. */ | |
601 | if (TYPE_CODE (param_type) == TYPE_CODE_PTR) | |
602 | if (TYPE_CODE (TYPE_TARGET_TYPE (param_type)) == TYPE_CODE_FUNC) | |
603 | /* elz: FIXME here should go the test about the | |
604 | compiler used to compile the target. We want to | |
605 | issue the error message only if the compiler | |
606 | used was HP's aCC. If we used HP's cc, then | |
607 | there is no problem and no need to return at | |
608 | this point. */ | |
609 | /* Go see if the actual parameter is a variable of | |
610 | type pointer to function or just a function. */ | |
611 | if (args[i]->lval == not_lval) | |
612 | { | |
613 | char *arg_name; | |
614 | if (find_pc_partial_function ((CORE_ADDR) args[i]->aligner.contents[0], &arg_name, NULL, NULL)) | |
615 | error ("\ | |
04714b91 AC |
616 | You cannot use function <%s> as argument. \n\ |
617 | You must use a pointer to function type variable. Command ignored.", arg_name); | |
ebc7896c AC |
618 | } |
619 | } | |
620 | } | |
621 | } | |
622 | } | |
04714b91 AC |
623 | |
624 | if (REG_STRUCT_HAS_ADDR_P ()) | |
625 | { | |
ebc7896c | 626 | int i; |
04714b91 AC |
627 | /* This is a machine like the sparc, where we may need to pass a |
628 | pointer to the structure, not the structure itself. */ | |
629 | for (i = nargs - 1; i >= 0; i--) | |
630 | { | |
631 | struct type *arg_type = check_typedef (VALUE_TYPE (args[i])); | |
632 | if ((TYPE_CODE (arg_type) == TYPE_CODE_STRUCT | |
633 | || TYPE_CODE (arg_type) == TYPE_CODE_UNION | |
634 | || TYPE_CODE (arg_type) == TYPE_CODE_ARRAY | |
635 | || TYPE_CODE (arg_type) == TYPE_CODE_STRING | |
636 | || TYPE_CODE (arg_type) == TYPE_CODE_BITSTRING | |
637 | || TYPE_CODE (arg_type) == TYPE_CODE_SET | |
638 | || (TYPE_CODE (arg_type) == TYPE_CODE_FLT | |
639 | && TYPE_LENGTH (arg_type) > 8) | |
640 | ) | |
641 | && REG_STRUCT_HAS_ADDR (using_gcc, arg_type)) | |
642 | { | |
643 | CORE_ADDR addr; | |
644 | int len; /* = TYPE_LENGTH (arg_type); */ | |
645 | int aligned_len; | |
646 | arg_type = check_typedef (VALUE_ENCLOSING_TYPE (args[i])); | |
647 | len = TYPE_LENGTH (arg_type); | |
648 | ||
649 | if (STACK_ALIGN_P ()) | |
650 | /* MVS 11/22/96: I think at least some of this | |
651 | stack_align code is really broken. Better to let | |
652 | PUSH_ARGUMENTS adjust the stack in a target-defined | |
653 | manner. */ | |
654 | aligned_len = STACK_ALIGN (len); | |
655 | else | |
656 | aligned_len = len; | |
657 | if (INNER_THAN (1, 2)) | |
658 | { | |
659 | /* stack grows downward */ | |
660 | sp -= aligned_len; | |
661 | /* ... so the address of the thing we push is the | |
662 | stack pointer after we push it. */ | |
663 | addr = sp; | |
664 | } | |
665 | else | |
666 | { | |
667 | /* The stack grows up, so the address of the thing | |
668 | we push is the stack pointer before we push it. */ | |
669 | addr = sp; | |
670 | sp += aligned_len; | |
671 | } | |
672 | /* Push the structure. */ | |
673 | write_memory (addr, VALUE_CONTENTS_ALL (args[i]), len); | |
674 | /* The value we're going to pass is the address of the | |
675 | thing we just pushed. */ | |
676 | /*args[i] = value_from_longest (lookup_pointer_type (value_type), | |
677 | (LONGEST) addr); */ | |
678 | args[i] = value_from_pointer (lookup_pointer_type (arg_type), | |
679 | addr); | |
680 | } | |
681 | } | |
682 | } | |
683 | ||
684 | ||
685 | /* Reserve space for the return structure to be written on the | |
686 | stack, if necessary. Make certain that the value is correctly | |
687 | aligned. */ | |
688 | ||
689 | if (struct_return) | |
690 | { | |
691 | int len = TYPE_LENGTH (value_type); | |
692 | if (STACK_ALIGN_P ()) | |
693 | /* NOTE: cagney/2003-03-22: Should rely on frame align, rather | |
694 | than stack align to force the alignment of the stack. */ | |
695 | len = STACK_ALIGN (len); | |
696 | if (INNER_THAN (1, 2)) | |
697 | { | |
698 | /* Stack grows downward. Align STRUCT_ADDR and SP after | |
699 | making space for the return value. */ | |
700 | sp -= len; | |
701 | if (gdbarch_frame_align_p (current_gdbarch)) | |
702 | sp = gdbarch_frame_align (current_gdbarch, sp); | |
703 | struct_addr = sp; | |
704 | } | |
705 | else | |
706 | { | |
707 | /* Stack grows upward. Align the frame, allocate space, and | |
708 | then again, re-align the frame??? */ | |
709 | if (gdbarch_frame_align_p (current_gdbarch)) | |
710 | sp = gdbarch_frame_align (current_gdbarch, sp); | |
711 | struct_addr = sp; | |
712 | sp += len; | |
713 | if (gdbarch_frame_align_p (current_gdbarch)) | |
714 | sp = gdbarch_frame_align (current_gdbarch, sp); | |
715 | } | |
716 | } | |
717 | ||
718 | /* elz: on HPPA no need for this extra alignment, maybe it is needed | |
719 | on other architectures. This is because all the alignment is | |
720 | taken care of in the above code (ifdef REG_STRUCT_HAS_ADDR) and | |
721 | in hppa_push_arguments */ | |
722 | /* NOTE: cagney/2003-03-24: The below code is very broken. Given an | |
723 | odd sized parameter the below will mis-align the stack. As was | |
724 | suggested back in '96, better to let PUSH_ARGUMENTS handle it. */ | |
725 | if (DEPRECATED_EXTRA_STACK_ALIGNMENT_NEEDED) | |
726 | { | |
727 | /* MVS 11/22/96: I think at least some of this stack_align code | |
728 | is really broken. Better to let push_dummy_call() adjust the | |
729 | stack in a target-defined manner. */ | |
730 | if (STACK_ALIGN_P () && INNER_THAN (1, 2)) | |
731 | { | |
732 | /* If stack grows down, we must leave a hole at the top. */ | |
733 | int len = 0; | |
ebc7896c | 734 | int i; |
04714b91 AC |
735 | for (i = nargs - 1; i >= 0; i--) |
736 | len += TYPE_LENGTH (VALUE_ENCLOSING_TYPE (args[i])); | |
737 | if (DEPRECATED_CALL_DUMMY_STACK_ADJUST_P ()) | |
738 | len += DEPRECATED_CALL_DUMMY_STACK_ADJUST; | |
739 | sp -= STACK_ALIGN (len) - len; | |
740 | } | |
741 | } | |
742 | ||
743 | /* Create the dummy stack frame. Pass in the call dummy address as, | |
744 | presumably, the ABI code knows where, in the call dummy, the | |
745 | return address should be pointed. */ | |
746 | if (gdbarch_push_dummy_call_p (current_gdbarch)) | |
747 | /* When there is no push_dummy_call method, should this code | |
748 | simply error out. That would the implementation of this method | |
749 | for all ABIs (which is probably a good thing). */ | |
6a65450a | 750 | sp = gdbarch_push_dummy_call (current_gdbarch, funaddr, current_regcache, |
7043d8dc | 751 | bp_addr, nargs, args, sp, struct_return, |
04714b91 AC |
752 | struct_addr); |
753 | else if (DEPRECATED_PUSH_ARGUMENTS_P ()) | |
754 | /* Keep old targets working. */ | |
755 | sp = DEPRECATED_PUSH_ARGUMENTS (nargs, args, sp, struct_return, | |
756 | struct_addr); | |
757 | else | |
758 | sp = legacy_push_arguments (nargs, args, sp, struct_return, struct_addr); | |
759 | ||
760 | if (DEPRECATED_PUSH_RETURN_ADDRESS_P ()) | |
761 | /* for targets that use no CALL_DUMMY */ | |
762 | /* There are a number of targets now which actually don't write | |
763 | any CALL_DUMMY instructions into the target, but instead just | |
764 | save the machine state, push the arguments, and jump directly | |
765 | to the callee function. Since this doesn't actually involve | |
766 | executing a JSR/BSR instruction, the return address must be set | |
767 | up by hand, either by pushing onto the stack or copying into a | |
768 | return-address register as appropriate. Formerly this has been | |
769 | done in PUSH_ARGUMENTS, but that's overloading its | |
770 | functionality a bit, so I'm making it explicit to do it here. */ | |
d585e13a AC |
771 | /* NOTE: cagney/2003-04-22: The first parameter ("real_pc") has |
772 | been replaced with zero, it turns out that no implementation | |
773 | used that parameter. This occured because the value being | |
774 | supplied - the address of the called function's entry point | |
775 | instead of the address of the breakpoint that the called | |
776 | function should return to - wasn't useful. */ | |
777 | sp = DEPRECATED_PUSH_RETURN_ADDRESS (0, sp); | |
04714b91 AC |
778 | |
779 | /* NOTE: cagney/2003-03-23: Diable this code when there is a | |
780 | push_dummy_call() method. Since that method will have already | |
781 | handled any alignment issues, the code below is entirely | |
782 | redundant. */ | |
783 | if (!gdbarch_push_dummy_call_p (current_gdbarch) | |
784 | && STACK_ALIGN_P () && !INNER_THAN (1, 2)) | |
785 | { | |
786 | /* If stack grows up, we must leave a hole at the bottom, note | |
787 | that sp already has been advanced for the arguments! */ | |
788 | if (DEPRECATED_CALL_DUMMY_STACK_ADJUST_P ()) | |
789 | sp += DEPRECATED_CALL_DUMMY_STACK_ADJUST; | |
790 | sp = STACK_ALIGN (sp); | |
791 | } | |
792 | ||
793 | /* XXX This seems wrong. For stacks that grow down we shouldn't do | |
794 | anything here! */ | |
795 | /* MVS 11/22/96: I think at least some of this stack_align code is | |
796 | really broken. Better to let PUSH_ARGUMENTS adjust the stack in | |
797 | a target-defined manner. */ | |
798 | if (DEPRECATED_CALL_DUMMY_STACK_ADJUST_P ()) | |
799 | if (INNER_THAN (1, 2)) | |
800 | { | |
801 | /* stack grows downward */ | |
802 | sp -= DEPRECATED_CALL_DUMMY_STACK_ADJUST; | |
803 | } | |
804 | ||
805 | /* Store the address at which the structure is supposed to be | |
806 | written. */ | |
807 | /* NOTE: 2003-03-24: Since PUSH_ARGUMENTS can (and typically does) | |
808 | store the struct return address, this call is entirely redundant. */ | |
809 | if (struct_return && DEPRECATED_STORE_STRUCT_RETURN_P ()) | |
810 | DEPRECATED_STORE_STRUCT_RETURN (struct_addr, sp); | |
811 | ||
1fd4ae22 AC |
812 | /* Write the stack pointer. This is here because the statements |
813 | above might fool with it. On SPARC, this write also stores the | |
814 | register window into the right place in the new stack frame, | |
815 | which otherwise wouldn't happen (see store_inferior_registers in | |
816 | sparc-nat.c). */ | |
817 | /* NOTE: cagney/2003-03-23: Since the architecture method | |
818 | push_dummy_call() should have already stored the stack pointer | |
819 | (as part of creating the fake call frame), and none of the code | |
820 | following that call adjusts the stack-pointer value, the below | |
821 | call is entirely redundant. */ | |
04714b91 AC |
822 | if (DEPRECATED_DUMMY_WRITE_SP_P ()) |
823 | DEPRECATED_DUMMY_WRITE_SP (sp); | |
824 | ||
3e210248 AC |
825 | if (gdbarch_unwind_dummy_id_p (current_gdbarch)) |
826 | { | |
827 | /* Sanity. The exact same SP value is returned by | |
828 | PUSH_DUMMY_CALL, saved as the dummy-frame TOS, and used by | |
829 | unwind_dummy_id to form the frame ID's stack address. */ | |
830 | gdb_assert (DEPRECATED_USE_GENERIC_DUMMY_FRAMES); | |
831 | generic_save_dummy_frame_tos (sp); | |
832 | } | |
a59fe496 AC |
833 | else if (DEPRECATED_SAVE_DUMMY_FRAME_TOS_P ()) |
834 | DEPRECATED_SAVE_DUMMY_FRAME_TOS (sp); | |
04714b91 | 835 | |
74cfe982 AC |
836 | /* Now proceed, having reached the desired place. */ |
837 | clear_proceed_status (); | |
838 | ||
839 | /* Create a momentary breakpoint at the return address of the | |
840 | inferior. That way it breaks when it returns. */ | |
04714b91 | 841 | |
74cfe982 AC |
842 | { |
843 | struct breakpoint *bpt; | |
844 | struct symtab_and_line sal; | |
845 | struct frame_id frame; | |
846 | init_sal (&sal); /* initialize to zeroes */ | |
847 | sal.pc = bp_addr; | |
848 | sal.section = find_pc_overlay (sal.pc); | |
849 | /* Set up a frame ID for the dummy frame so we can pass it to | |
850 | set_momentary_breakpoint. We need to give the breakpoint a | |
0ba6dca9 AC |
851 | frame ID so that the breakpoint code can correctly re-identify |
852 | the dummy breakpoint. */ | |
3e210248 AC |
853 | if (gdbarch_unwind_dummy_id_p (current_gdbarch)) |
854 | { | |
855 | /* Sanity. The exact same SP value is returned by | |
856 | PUSH_DUMMY_CALL, saved as the dummy-frame TOS, and used by | |
857 | unwind_dummy_id to form the frame ID's stack address. */ | |
858 | gdb_assert (DEPRECATED_USE_GENERIC_DUMMY_FRAMES); | |
859 | frame = frame_id_build (sp, sal.pc); | |
860 | } | |
0ba6dca9 | 861 | else |
3e210248 AC |
862 | { |
863 | /* The assumption here is that push_dummy_call() returned the | |
864 | stack part of the frame ID. Unfortunatly, many older | |
865 | architectures were, via a convoluted mess, relying on the | |
866 | poorly defined and greatly overloaded | |
867 | DEPRECATED_TARGET_READ_FP or DEPRECATED_FP_REGNUM to supply | |
868 | the value. */ | |
869 | if (DEPRECATED_TARGET_READ_FP_P ()) | |
870 | frame = frame_id_build (DEPRECATED_TARGET_READ_FP (), sal.pc); | |
871 | else if (DEPRECATED_FP_REGNUM >= 0) | |
872 | frame = frame_id_build (read_register (DEPRECATED_FP_REGNUM), sal.pc); | |
873 | else | |
874 | frame = frame_id_build (sp, sal.pc); | |
875 | } | |
74cfe982 AC |
876 | bpt = set_momentary_breakpoint (sal, frame, bp_call_dummy); |
877 | bpt->disposition = disp_del; | |
878 | } | |
04714b91 | 879 | |
74cfe982 AC |
880 | /* Execute a "stack dummy", a piece of code stored in the stack by |
881 | the debugger to be executed in the inferior. | |
04714b91 | 882 | |
74cfe982 AC |
883 | The dummy's frame is automatically popped whenever that break is |
884 | hit. If that is the first time the program stops, | |
885 | call_function_by_hand returns to its caller with that frame | |
886 | already gone and sets RC to 0. | |
887 | ||
888 | Otherwise, set RC to a non-zero value. If the called function | |
889 | receives a random signal, we do not allow the user to continue | |
890 | executing it as this may not work. The dummy frame is poped and | |
891 | we return 1. If we hit a breakpoint, we leave the frame in place | |
892 | and return 2 (the frame will eventually be popped when we do hit | |
893 | the dummy end breakpoint). */ | |
04714b91 | 894 | |
74cfe982 AC |
895 | { |
896 | struct cleanup *old_cleanups = make_cleanup (null_cleanup, 0); | |
897 | int saved_async = 0; | |
898 | ||
899 | /* If all error()s out of proceed ended up calling normal_stop | |
900 | (and perhaps they should; it already does in the special case | |
901 | of error out of resume()), then we wouldn't need this. */ | |
902 | make_cleanup (breakpoint_auto_delete_contents, &stop_bpstat); | |
903 | ||
904 | disable_watchpoints_before_interactive_call_start (); | |
905 | proceed_to_finish = 1; /* We want stop_registers, please... */ | |
906 | ||
907 | if (target_can_async_p ()) | |
908 | saved_async = target_async_mask (0); | |
909 | ||
910 | proceed (real_pc, TARGET_SIGNAL_0, 0); | |
911 | ||
912 | if (saved_async) | |
913 | target_async_mask (saved_async); | |
914 | ||
915 | enable_watchpoints_after_interactive_call_stop (); | |
04714b91 | 916 | |
74cfe982 | 917 | discard_cleanups (old_cleanups); |
52557533 | 918 | } |
04714b91 | 919 | |
52557533 AC |
920 | if (stopped_by_random_signal || !stop_stack_dummy) |
921 | { | |
922 | /* Find the name of the function we're about to complain about. */ | |
923 | char *name = NULL; | |
04714b91 | 924 | { |
52557533 AC |
925 | struct symbol *symbol = find_pc_function (funaddr); |
926 | if (symbol) | |
927 | name = SYMBOL_PRINT_NAME (symbol); | |
928 | else | |
04714b91 | 929 | { |
52557533 AC |
930 | /* Try the minimal symbols. */ |
931 | struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (funaddr); | |
932 | if (msymbol) | |
933 | name = SYMBOL_PRINT_NAME (msymbol); | |
934 | } | |
935 | } | |
936 | if (name == NULL) | |
937 | { | |
938 | /* NOTE: cagney/2003-04-23: Don't blame me. This code dates | |
939 | back to 1993-07-08, I simply moved it. */ | |
940 | char format[80]; | |
941 | sprintf (format, "at %s", local_hex_format ()); | |
942 | name = alloca (80); | |
943 | /* FIXME-32x64: assumes funaddr fits in a long. */ | |
944 | sprintf (name, format, (unsigned long) funaddr); | |
945 | } | |
946 | if (stopped_by_random_signal) | |
947 | { | |
948 | /* We stopped inside the FUNCTION because of a random | |
949 | signal. Further execution of the FUNCTION is not | |
950 | allowed. */ | |
04714b91 | 951 | |
52557533 AC |
952 | if (unwind_on_signal_p) |
953 | { | |
954 | /* The user wants the context restored. */ | |
955 | ||
956 | /* We must get back to the frame we were before the | |
957 | dummy call. */ | |
958 | frame_pop (get_current_frame ()); | |
04714b91 | 959 | |
52557533 AC |
960 | /* FIXME: Insert a bunch of wrap_here; name can be very |
961 | long if it's a C++ name with arguments and stuff. */ | |
962 | error ("\ | |
04714b91 AC |
963 | The program being debugged was signaled while in a function called from GDB.\n\ |
964 | GDB has restored the context to what it was before the call.\n\ | |
965 | To change this behavior use \"set unwindonsignal off\"\n\ | |
966 | Evaluation of the expression containing the function (%s) will be abandoned.", | |
52557533 AC |
967 | name); |
968 | } | |
969 | else | |
970 | { | |
971 | /* The user wants to stay in the frame where we stopped | |
972 | (default).*/ | |
973 | /* If we restored the inferior status (via the cleanup), | |
974 | we would print a spurious error message (Unable to | |
975 | restore previously selected frame), would write the | |
976 | registers from the inf_status (which is wrong), and | |
977 | would do other wrong things. */ | |
978 | discard_cleanups (inf_status_cleanup); | |
979 | discard_inferior_status (inf_status); | |
980 | /* FIXME: Insert a bunch of wrap_here; name can be very | |
981 | long if it's a C++ name with arguments and stuff. */ | |
982 | error ("\ | |
04714b91 AC |
983 | The program being debugged was signaled while in a function called from GDB.\n\ |
984 | GDB remains in the frame where the signal was received.\n\ | |
985 | To change this behavior use \"set unwindonsignal on\"\n\ | |
986 | Evaluation of the expression containing the function (%s) will be abandoned.", | |
52557533 AC |
987 | name); |
988 | } | |
989 | } | |
04714b91 | 990 | |
52557533 AC |
991 | if (!stop_stack_dummy) |
992 | { | |
993 | /* We hit a breakpoint inside the FUNCTION. */ | |
994 | /* If we restored the inferior status (via the cleanup), we | |
995 | would print a spurious error message (Unable to restore | |
996 | previously selected frame), would write the registers | |
997 | from the inf_status (which is wrong), and would do other | |
998 | wrong things. */ | |
999 | discard_cleanups (inf_status_cleanup); | |
1000 | discard_inferior_status (inf_status); | |
1001 | /* The following error message used to say "The expression | |
1002 | which contained the function call has been discarded." | |
1003 | It is a hard concept to explain in a few words. Ideally, | |
1004 | GDB would be able to resume evaluation of the expression | |
1005 | when the function finally is done executing. Perhaps | |
1006 | someday this will be implemented (it would not be easy). */ | |
1007 | /* FIXME: Insert a bunch of wrap_here; name can be very long if it's | |
1008 | a C++ name with arguments and stuff. */ | |
1009 | error ("\ | |
04714b91 AC |
1010 | The program being debugged stopped while in a function called from GDB.\n\ |
1011 | When the function (%s) is done executing, GDB will silently\n\ | |
1012 | stop (instead of continuing to evaluate the expression containing\n\ | |
1013 | the function call).", name); | |
52557533 AC |
1014 | } |
1015 | ||
1016 | /* The above code errors out, so ... */ | |
1017 | internal_error (__FILE__, __LINE__, "... should not be here"); | |
1018 | } | |
04714b91 | 1019 | |
74cfe982 AC |
1020 | /* If we get here the called FUNCTION run to completion. */ |
1021 | ||
1022 | /* On normal return, the stack dummy has been popped already. */ | |
1023 | regcache_cpy_no_passthrough (retbuf, stop_registers); | |
1024 | ||
1025 | /* Restore the inferior status, via its cleanup. At this stage, | |
1026 | leave the RETBUF alone. */ | |
1027 | do_cleanups (inf_status_cleanup); | |
1028 | ||
1029 | /* Figure out the value returned by the function. */ | |
1030 | /* elz: I defined this new macro for the hppa architecture only. | |
1031 | this gives us a way to get the value returned by the function | |
1032 | from the stack, at the same address we told the function to put | |
1033 | it. We cannot assume on the pa that r28 still contains the | |
1034 | address of the returned structure. Usually this will be | |
1035 | overwritten by the callee. I don't know about other | |
1036 | architectures, so I defined this macro */ | |
04714b91 | 1037 | #ifdef VALUE_RETURNED_FROM_STACK |
74cfe982 AC |
1038 | if (struct_return) |
1039 | { | |
1040 | do_cleanups (retbuf_cleanup); | |
1041 | return VALUE_RETURNED_FROM_STACK (value_type, struct_addr); | |
1042 | } | |
04714b91 | 1043 | #endif |
74cfe982 AC |
1044 | /* NOTE: cagney/2002-09-10: Only when the stack has been correctly |
1045 | aligned (using frame_align()) do we can trust STRUCT_ADDR and | |
1046 | fetch the return value direct from the stack. This lack of trust | |
1047 | comes about because legacy targets have a nasty habit of | |
1048 | silently, and local to PUSH_ARGUMENTS(), moving STRUCT_ADDR. For | |
1049 | such targets, just hope that value_being_returned() can find the | |
1050 | adjusted value. */ | |
1051 | if (struct_return && gdbarch_frame_align_p (current_gdbarch)) | |
1052 | { | |
1053 | struct value *retval = value_at (value_type, struct_addr, NULL); | |
1054 | do_cleanups (retbuf_cleanup); | |
1055 | return retval; | |
1056 | } | |
1057 | else | |
1058 | { | |
4e7d7511 MS |
1059 | struct value *retval = value_being_returned (value_type, retbuf, |
1060 | struct_return); | |
74cfe982 AC |
1061 | do_cleanups (retbuf_cleanup); |
1062 | return retval; | |
1063 | } | |
04714b91 AC |
1064 | } |
1065 | ||
1066 | void _initialize_infcall (void); | |
1067 | ||
1068 | void | |
1069 | _initialize_infcall (void) | |
1070 | { | |
1071 | add_setshow_boolean_cmd ("coerce-float-to-double", class_obscure, | |
1072 | &coerce_float_to_double_p, "\ | |
1073 | Set coercion of floats to doubles when calling functions\n\ | |
1074 | Variables of type float should generally be converted to doubles before\n\ | |
1075 | calling an unprototyped function, and left alone when calling a prototyped\n\ | |
1076 | function. However, some older debug info formats do not provide enough\n\ | |
1077 | information to determine that a function is prototyped. If this flag is\n\ | |
1078 | set, GDB will perform the conversion for a function it considers\n\ | |
1079 | unprototyped.\n\ | |
1080 | The default is to perform the conversion.\n", "\ | |
1081 | Show coercion of floats to doubles when calling functions\n\ | |
1082 | Variables of type float should generally be converted to doubles before\n\ | |
1083 | calling an unprototyped function, and left alone when calling a prototyped\n\ | |
1084 | function. However, some older debug info formats do not provide enough\n\ | |
1085 | information to determine that a function is prototyped. If this flag is\n\ | |
1086 | set, GDB will perform the conversion for a function it considers\n\ | |
1087 | unprototyped.\n\ | |
1088 | The default is to perform the conversion.\n", | |
1089 | NULL, NULL, &setlist, &showlist); | |
1090 | ||
1091 | add_setshow_boolean_cmd ("unwindonsignal", no_class, | |
1092 | &unwind_on_signal_p, "\ | |
1093 | Set unwinding of stack if a signal is received while in a call dummy.\n\ | |
1094 | The unwindonsignal lets the user determine what gdb should do if a signal\n\ | |
1095 | is received while in a function called from gdb (call dummy). If set, gdb\n\ | |
1096 | unwinds the stack and restore the context to what as it was before the call.\n\ | |
1097 | The default is to stop in the frame where the signal was received.", "\ | |
1098 | Set unwinding of stack if a signal is received while in a call dummy.\n\ | |
1099 | The unwindonsignal lets the user determine what gdb should do if a signal\n\ | |
1100 | is received while in a function called from gdb (call dummy). If set, gdb\n\ | |
1101 | unwinds the stack and restore the context to what as it was before the call.\n\ | |
1102 | The default is to stop in the frame where the signal was received.", | |
1103 | NULL, NULL, &setlist, &showlist); | |
1104 | } |