1 /* Cache and manage frames for GDB, the GNU debugger.
3 Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000,
4 2001, 2002, 2003 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
27 #include "inferior.h" /* for inferior_ptid */
29 #include "gdb_assert.h"
30 #include "gdb_string.h"
31 #include "builtin-regs.h"
32 #include "gdb_obstack.h"
33 #include "dummy-frame.h"
37 #include "frame-unwind.h"
39 /* Return a frame uniq ID that can be used to, later, re-find the
43 get_frame_id (struct frame_info
*fi
)
58 const struct frame_id null_frame_id
; /* All zeros. */
61 frame_id_build (CORE_ADDR base
, CORE_ADDR func_or_pc
)
70 frame_id_p (struct frame_id l
)
72 /* The .func can be NULL but the .base cannot. */
77 frame_id_eq (struct frame_id l
, struct frame_id r
)
79 /* If .base is different, the frames are different. */
82 /* Add a test to check that the frame ID's are for the same function
88 frame_id_inner (struct frame_id l
, struct frame_id r
)
90 /* Only return non-zero when strictly inner than. Note that, per
91 comment in "frame.h", there is some fuzz here. Frameless
92 functions are not strictly inner than (same .base but different
94 return INNER_THAN (l
.base
, r
.base
);
98 frame_find_by_id (struct frame_id id
)
100 struct frame_info
*frame
;
102 /* ZERO denotes the null frame, let the caller decide what to do
103 about it. Should it instead return get_current_frame()? */
104 if (!frame_id_p (id
))
107 for (frame
= get_current_frame ();
109 frame
= get_prev_frame (frame
))
111 struct frame_id
this = get_frame_id (frame
);
112 if (frame_id_eq (id
, this))
113 /* An exact match. */
115 if (frame_id_inner (id
, this))
118 /* Either, we're not yet gone far enough out along the frame
119 chain (inner(this,id), or we're comparing frameless functions
120 (same .base, different .func, no test available). Struggle
121 on until we've definitly gone to far. */
127 frame_pc_unwind (struct frame_info
*frame
)
129 if (!frame
->pc_unwind_cache_p
)
131 frame
->pc_unwind_cache
= frame
->unwind
->pc (frame
, &frame
->unwind_cache
);
132 frame
->pc_unwind_cache_p
= 1;
134 return frame
->pc_unwind_cache
;
138 frame_id_unwind (struct frame_info
*frame
)
140 if (!frame
->id_unwind_cache_p
)
142 frame
->unwind
->id (frame
, &frame
->unwind_cache
, &frame
->id_unwind_cache
);
143 frame
->id_unwind_cache_p
= 1;
145 return frame
->id_unwind_cache
;
149 frame_pop (struct frame_info
*frame
)
151 /* FIXME: cagney/2003-01-18: There is probably a chicken-egg problem
152 with passing in current_regcache. The pop function needs to be
153 written carefully so as to not overwrite registers whose [old]
154 values are needed to restore other registers. Instead, this code
155 should pass in a scratch cache and, as a second step, restore the
156 registers using that. */
157 frame
->unwind
->pop (frame
, &frame
->unwind_cache
, current_regcache
);
158 flush_cached_frames ();
162 frame_register_unwind (struct frame_info
*frame
, int regnum
,
163 int *optimizedp
, enum lval_type
*lvalp
,
164 CORE_ADDR
*addrp
, int *realnump
, void *bufferp
)
166 struct frame_unwind_cache
*cache
;
168 /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
169 that the value proper does not need to be fetched. */
170 gdb_assert (optimizedp
!= NULL
);
171 gdb_assert (lvalp
!= NULL
);
172 gdb_assert (addrp
!= NULL
);
173 gdb_assert (realnump
!= NULL
);
174 /* gdb_assert (bufferp != NULL); */
176 /* NOTE: cagney/2002-04-14: It would be nice if, instead of a
177 special case, there was always an inner frame dedicated to the
178 hardware registers. Unfortunatly, there is too much unwind code
179 around that looks up/down the frame chain while making the
180 assumption that each frame level is using the same unwind code. */
184 /* We're in the inner-most frame, get the value direct from the
187 *lvalp
= lval_register
;
188 /* ULGH! Code uses the offset into the raw register byte array
189 as a way of identifying a register. */
190 *addrp
= REGISTER_BYTE (regnum
);
191 /* Should this code test ``register_cached (regnum) < 0'' and do
192 something like set realnum to -1 when the register isn't
196 deprecated_read_register_gen (regnum
, bufferp
);
200 /* Ask this frame to unwind its register. */
201 frame
->unwind
->reg (frame
, &frame
->unwind_cache
, regnum
,
202 optimizedp
, lvalp
, addrp
, realnump
, bufferp
);
206 frame_register (struct frame_info
*frame
, int regnum
,
207 int *optimizedp
, enum lval_type
*lvalp
,
208 CORE_ADDR
*addrp
, int *realnump
, void *bufferp
)
210 /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
211 that the value proper does not need to be fetched. */
212 gdb_assert (optimizedp
!= NULL
);
213 gdb_assert (lvalp
!= NULL
);
214 gdb_assert (addrp
!= NULL
);
215 gdb_assert (realnump
!= NULL
);
216 /* gdb_assert (bufferp != NULL); */
218 /* Ulgh! Old code that, for lval_register, sets ADDRP to the offset
219 of the register in the register cache. It should instead return
220 the REGNUM corresponding to that register. Translate the . */
221 if (GET_SAVED_REGISTER_P ())
223 GET_SAVED_REGISTER (bufferp
, optimizedp
, addrp
, frame
, regnum
, lvalp
);
224 /* Compute the REALNUM if the caller wants it. */
225 if (*lvalp
== lval_register
)
228 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
230 if (*addrp
== register_offset_hack (current_gdbarch
, regnum
))
236 internal_error (__FILE__
, __LINE__
,
237 "Failed to compute the register number corresponding"
238 " to 0x%s", paddr_d (*addrp
));
244 /* Reached the the bottom (youngest, inner most) of the frame chain
245 (youngest, inner most) frame, go direct to the hardware register
246 cache (do not pass go, do not try to cache the value, ...). The
247 unwound value would have been cached in frame->next but that
248 doesn't exist. This doesn't matter as the hardware register
249 cache is stopping any unnecessary accesses to the target. */
251 /* NOTE: cagney/2002-04-14: It would be nice if, instead of a
252 special case, there was always an inner frame dedicated to the
253 hardware registers. Unfortunatly, there is too much unwind code
254 around that looks up/down the frame chain while making the
255 assumption that each frame level is using the same unwind code. */
258 frame_register_unwind (NULL
, regnum
, optimizedp
, lvalp
, addrp
, realnump
,
261 frame_register_unwind (frame
->next
, regnum
, optimizedp
, lvalp
, addrp
,
266 frame_unwind_signed_register (struct frame_info
*frame
, int regnum
,
273 void *buf
= alloca (MAX_REGISTER_RAW_SIZE
);
274 frame_register_unwind (frame
, regnum
, &optimized
, &lval
, &addr
,
276 (*val
) = extract_signed_integer (buf
, REGISTER_VIRTUAL_SIZE (regnum
));
280 frame_unwind_unsigned_register (struct frame_info
*frame
, int regnum
,
287 void *buf
= alloca (MAX_REGISTER_RAW_SIZE
);
288 frame_register_unwind (frame
, regnum
, &optimized
, &lval
, &addr
,
290 (*val
) = extract_unsigned_integer (buf
, REGISTER_VIRTUAL_SIZE (regnum
));
294 frame_read_unsigned_register (struct frame_info
*frame
, int regnum
,
297 /* NOTE: cagney/2002-10-31: There is a bit of dogma here - there is
298 always a frame. Both this, and the equivalent
299 frame_read_signed_register() function, can only be called with a
300 valid frame. If, for some reason, this function is called
301 without a frame then the problem isn't here, but rather in the
302 caller. It should of first created a frame and then passed that
304 /* NOTE: cagney/2002-10-31: As a side bar, keep in mind that the
305 ``current_frame'' should not be treated as a special case. While
306 ``get_next_frame (current_frame) == NULL'' currently holds, it
307 should, as far as possible, not be relied upon. In the future,
308 ``get_next_frame (current_frame)'' may instead simply return a
309 normal frame object that simply always gets register values from
310 the register cache. Consequently, frame code should try to avoid
311 tests like ``if get_next_frame() == NULL'' and instead just rely
312 on recursive frame calls (like the below code) when manipulating
314 gdb_assert (frame
!= NULL
);
315 frame_unwind_unsigned_register (get_next_frame (frame
), regnum
, val
);
319 frame_read_signed_register (struct frame_info
*frame
, int regnum
,
322 /* See note in frame_read_unsigned_register(). */
323 gdb_assert (frame
!= NULL
);
324 frame_unwind_signed_register (get_next_frame (frame
), regnum
, val
);
328 generic_unwind_get_saved_register (char *raw_buffer
,
331 struct frame_info
*frame
,
333 enum lval_type
*lvalp
)
338 enum lval_type lvalx
;
340 if (!target_has_registers
)
341 error ("No registers.");
343 /* Keep things simple, ensure that all the pointers (except valuep)
345 if (optimizedp
== NULL
)
346 optimizedp
= &optimizedx
;
352 /* Reached the the bottom (youngest, inner most) of the frame chain
353 (youngest, inner most) frame, go direct to the hardware register
354 cache (do not pass go, do not try to cache the value, ...). The
355 unwound value would have been cached in frame->next but that
356 doesn't exist. This doesn't matter as the hardware register
357 cache is stopping any unnecessary accesses to the target. */
359 /* NOTE: cagney/2002-04-14: It would be nice if, instead of a
360 special case, there was always an inner frame dedicated to the
361 hardware registers. Unfortunatly, there is too much unwind code
362 around that looks up/down the frame chain while making the
363 assumption that each frame level is using the same unwind code. */
366 frame_register_unwind (NULL
, regnum
, optimizedp
, lvalp
, addrp
, &realnumx
,
369 frame_register_unwind (frame
->next
, regnum
, optimizedp
, lvalp
, addrp
,
370 &realnumx
, raw_buffer
);
374 get_saved_register (char *raw_buffer
,
377 struct frame_info
*frame
,
379 enum lval_type
*lval
)
381 if (GET_SAVED_REGISTER_P ())
383 GET_SAVED_REGISTER (raw_buffer
, optimized
, addrp
, frame
, regnum
, lval
);
386 generic_unwind_get_saved_register (raw_buffer
, optimized
, addrp
, frame
,
390 /* frame_register_read ()
392 Find and return the value of REGNUM for the specified stack frame.
393 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
395 Returns 0 if the register value could not be found. */
398 frame_register_read (struct frame_info
*frame
, int regnum
, void *myaddr
)
404 frame_register (frame
, regnum
, &optimized
, &lval
, &addr
, &realnum
, myaddr
);
406 /* FIXME: cagney/2002-05-15: This test, is just bogus.
408 It indicates that the target failed to supply a value for a
409 register because it was "not available" at this time. Problem
410 is, the target still has the register and so get saved_register()
411 may be returning a value saved on the stack. */
413 if (register_cached (regnum
) < 0)
414 return 0; /* register value not available */
420 /* Map between a frame register number and its name. A frame register
421 space is a superset of the cooked register space --- it also
422 includes builtin registers. */
425 frame_map_name_to_regnum (const char *name
, int len
)
429 /* Search register name space. */
430 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
431 if (REGISTER_NAME (i
) && len
== strlen (REGISTER_NAME (i
))
432 && strncmp (name
, REGISTER_NAME (i
), len
) == 0)
437 /* Try builtin registers. */
438 i
= builtin_reg_map_name_to_regnum (name
, len
);
441 /* A builtin register doesn't fall into the architecture's
443 gdb_assert (i
>= NUM_REGS
+ NUM_PSEUDO_REGS
);
451 frame_map_regnum_to_name (int regnum
)
455 if (regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
)
456 return REGISTER_NAME (regnum
);
457 return builtin_reg_map_regnum_to_name (regnum
);
460 /* Info about the innermost stack frame (contents of FP register) */
462 static struct frame_info
*current_frame
;
464 /* Cache for frame addresses already read by gdb. Valid only while
465 inferior is stopped. Control variables for the frame cache should
466 be local to this module. */
468 static struct obstack frame_cache_obstack
;
471 frame_obstack_zalloc (unsigned long size
)
473 void *data
= obstack_alloc (&frame_cache_obstack
, size
);
474 memset (data
, 0, size
);
479 frame_saved_regs_zalloc (struct frame_info
*fi
)
481 fi
->saved_regs
= (CORE_ADDR
*)
482 frame_obstack_zalloc (SIZEOF_FRAME_SAVED_REGS
);
483 return fi
->saved_regs
;
487 get_frame_saved_regs (struct frame_info
*fi
)
489 return fi
->saved_regs
;
492 /* Return the innermost (currently executing) stack frame. */
495 get_current_frame (void)
497 if (current_frame
== NULL
)
499 if (target_has_stack
)
500 current_frame
= create_new_frame (read_fp (), read_pc ());
504 return current_frame
;
507 /* The "selected" stack frame is used by default for local and arg
508 access. May be zero, for no selected frame. */
510 struct frame_info
*deprecated_selected_frame
;
512 /* Return the selected frame. Always non-null (unless there isn't an
513 inferior sufficient for creating a frame) in which case an error is
517 get_selected_frame (void)
519 if (deprecated_selected_frame
== NULL
)
520 /* Hey! Don't trust this. It should really be re-finding the
521 last selected frame of the currently selected thread. This,
522 though, is better than nothing. */
523 select_frame (get_current_frame ());
524 /* There is always a frame. */
525 gdb_assert (deprecated_selected_frame
!= NULL
);
526 return deprecated_selected_frame
;
529 /* Select frame FI (or NULL - to invalidate the current frame). */
532 select_frame (struct frame_info
*fi
)
534 register struct symtab
*s
;
536 deprecated_selected_frame
= fi
;
537 /* NOTE: cagney/2002-05-04: FI can be NULL. This occures when the
538 frame is being invalidated. */
539 if (selected_frame_level_changed_hook
)
540 selected_frame_level_changed_hook (frame_relative_level (fi
));
542 /* FIXME: kseitz/2002-08-28: It would be nice to call
543 selected_frame_level_changed_event right here, but due to limitations
544 in the current interfaces, we would end up flooding UIs with events
545 because select_frame is used extensively internally.
547 Once we have frame-parameterized frame (and frame-related) commands,
548 the event notification can be moved here, since this function will only
549 be called when the users selected frame is being changed. */
551 /* Ensure that symbols for this frame are read in. Also, determine the
552 source language of this frame, and switch to it if desired. */
555 s
= find_pc_symtab (fi
->pc
);
557 && s
->language
!= current_language
->la_language
558 && s
->language
!= language_unknown
559 && language_mode
== language_mode_auto
)
561 set_language (s
->language
);
566 /* Return the register saved in the simplistic ``saved_regs'' cache.
567 If the value isn't here AND a value is needed, try the next inner
571 frame_saved_regs_register_unwind (struct frame_info
*frame
, void **cache
,
572 int regnum
, int *optimizedp
,
573 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
574 int *realnump
, void *bufferp
)
576 /* There is always a frame at this point. And THIS is the frame
577 we're interested in. */
578 gdb_assert (frame
!= NULL
);
579 /* If we're using generic dummy frames, we'd better not be in a call
580 dummy. (generic_call_dummy_register_unwind ought to have been called
582 gdb_assert (!(DEPRECATED_USE_GENERIC_DUMMY_FRAMES
583 && (get_frame_type (frame
) == DUMMY_FRAME
)));
585 /* Only (older) architectures that implement the
586 FRAME_INIT_SAVED_REGS method should be using this function. */
587 gdb_assert (FRAME_INIT_SAVED_REGS_P ());
589 /* Load the saved_regs register cache. */
590 if (frame
->saved_regs
== NULL
)
591 FRAME_INIT_SAVED_REGS (frame
);
593 if (frame
->saved_regs
!= NULL
594 && frame
->saved_regs
[regnum
] != 0)
596 if (regnum
== SP_REGNUM
)
598 /* SP register treated specially. */
604 store_address (bufferp
, REGISTER_RAW_SIZE (regnum
),
605 frame
->saved_regs
[regnum
]);
609 /* Any other register is saved in memory, fetch it but cache
610 a local copy of its value. */
612 *lvalp
= lval_memory
;
613 *addrp
= frame
->saved_regs
[regnum
];
618 /* Save each register value, as it is read in, in a
619 frame based cache. */
620 void **regs
= (*cache
);
623 int sizeof_cache
= ((NUM_REGS
+ NUM_PSEUDO_REGS
)
625 regs
= frame_obstack_zalloc (sizeof_cache
);
628 if (regs
[regnum
] == NULL
)
631 = frame_obstack_zalloc (REGISTER_RAW_SIZE (regnum
));
632 read_memory (frame
->saved_regs
[regnum
], regs
[regnum
],
633 REGISTER_RAW_SIZE (regnum
));
635 memcpy (bufferp
, regs
[regnum
], REGISTER_RAW_SIZE (regnum
));
637 /* Read the value in from memory. */
638 read_memory (frame
->saved_regs
[regnum
], bufferp
,
639 REGISTER_RAW_SIZE (regnum
));
646 /* No luck, assume this and the next frame have the same register
647 value. If a value is needed, pass the request on down the chain;
648 otherwise just return an indication that the value is in the same
649 register as the next frame. */
653 *lvalp
= lval_register
;
659 frame_register_unwind (frame
->next
, regnum
, optimizedp
, lvalp
, addrp
,
665 frame_saved_regs_pc_unwind (struct frame_info
*frame
, void **cache
)
667 return FRAME_SAVED_PC (frame
);
671 frame_saved_regs_id_unwind (struct frame_info
*next_frame
, void **cache
,
678 /* Start out by assuming it's NULL. */
679 (*id
) = null_frame_id
;
681 if (next_frame
->next
== NULL
)
682 /* FIXME: 2002-11-09: Frameless functions can occure anywhere in
683 the frame chain, not just the inner most frame! The generic,
684 per-architecture, frame code should handle this and the below
685 should simply be removed. */
686 fromleaf
= FRAMELESS_FUNCTION_INVOCATION (next_frame
);
691 /* A frameless inner-most frame. The `FP' (which isn't an
692 architecture frame-pointer register!) of the caller is the same
694 /* FIXME: 2002-11-09: There isn't any reason to special case this
695 edge condition. Instead the per-architecture code should hande
697 base
= get_frame_base (next_frame
);
700 /* Two macros defined in tm.h specify the machine-dependent
701 actions to be performed here.
703 First, get the frame's chain-pointer.
705 If that is zero, the frame is the outermost frame or a leaf
706 called by the outermost frame. This means that if start
707 calls main without a frame, we'll return 0 (which is fine
710 Nope; there's a problem. This also returns when the current
711 routine is a leaf of main. This is unacceptable. We move
712 this to after the ffi test; I'd rather have backtraces from
713 start go curfluy than have an abort called from main not show
715 base
= FRAME_CHAIN (next_frame
);
717 if (!frame_chain_valid (base
, next_frame
))
723 /* FIXME: cagney/2002-06-08: This should probably return the frame's
724 function and not the PC (a.k.a. resume address). */
725 pc
= frame_pc_unwind (next_frame
);
731 frame_saved_regs_pop (struct frame_info
*fi
, void **cache
,
732 struct regcache
*regcache
)
734 gdb_assert (POP_FRAME_P ());
738 const struct frame_unwind trad_frame_unwinder
= {
739 frame_saved_regs_pop
,
740 frame_saved_regs_pc_unwind
,
741 frame_saved_regs_id_unwind
,
742 frame_saved_regs_register_unwind
744 const struct frame_unwind
*trad_frame_unwind
= &trad_frame_unwinder
;
747 /* Function: get_saved_register
748 Find register number REGNUM relative to FRAME and put its (raw,
749 target format) contents in *RAW_BUFFER.
751 Set *OPTIMIZED if the variable was optimized out (and thus can't be
752 fetched). Note that this is never set to anything other than zero
753 in this implementation.
755 Set *LVAL to lval_memory, lval_register, or not_lval, depending on
756 whether the value was fetched from memory, from a register, or in a
757 strange and non-modifiable way (e.g. a frame pointer which was
758 calculated rather than fetched). We will use not_lval for values
759 fetched from generic dummy frames.
761 Set *ADDRP to the address, either in memory or as a REGISTER_BYTE
762 offset into the registers array. If the value is stored in a dummy
763 frame, set *ADDRP to zero.
765 To use this implementation, define a function called
766 "get_saved_register" in your target code, which simply passes all
767 of its arguments to this function.
769 The argument RAW_BUFFER must point to aligned memory. */
772 deprecated_generic_get_saved_register (char *raw_buffer
, int *optimized
,
774 struct frame_info
*frame
, int regnum
,
775 enum lval_type
*lval
)
777 if (!target_has_registers
)
778 error ("No registers.");
780 gdb_assert (FRAME_INIT_SAVED_REGS_P ());
782 /* Normal systems don't optimize out things with register numbers. */
783 if (optimized
!= NULL
)
786 if (addrp
) /* default assumption: not found in memory */
789 /* Note: since the current frame's registers could only have been
790 saved by frames INTERIOR TO the current frame, we skip examining
791 the current frame itself: otherwise, we would be getting the
792 previous frame's registers which were saved by the current frame. */
794 while (frame
&& ((frame
= frame
->next
) != NULL
))
796 if (get_frame_type (frame
) == DUMMY_FRAME
)
798 if (lval
) /* found it in a CALL_DUMMY frame */
801 /* FIXME: cagney/2002-06-26: This should be via the
802 gdbarch_register_read() method so that it, on the fly,
803 constructs either a raw or pseudo register from the raw
805 regcache_raw_read (generic_find_dummy_frame (frame
->pc
,
811 FRAME_INIT_SAVED_REGS (frame
);
812 if (frame
->saved_regs
!= NULL
813 && frame
->saved_regs
[regnum
] != 0)
815 if (lval
) /* found it saved on the stack */
817 if (regnum
== SP_REGNUM
)
819 if (raw_buffer
) /* SP register treated specially */
820 store_address (raw_buffer
, REGISTER_RAW_SIZE (regnum
),
821 frame
->saved_regs
[regnum
]);
825 if (addrp
) /* any other register */
826 *addrp
= frame
->saved_regs
[regnum
];
828 read_memory (frame
->saved_regs
[regnum
], raw_buffer
,
829 REGISTER_RAW_SIZE (regnum
));
835 /* If we get thru the loop to this point, it means the register was
836 not saved in any frame. Return the actual live-register value. */
838 if (lval
) /* found it in a live register */
839 *lval
= lval_register
;
841 *addrp
= REGISTER_BYTE (regnum
);
843 deprecated_read_register_gen (regnum
, raw_buffer
);
846 /* Create an arbitrary (i.e. address specified by user) or innermost frame.
847 Always returns a non-NULL value. */
850 create_new_frame (CORE_ADDR addr
, CORE_ADDR pc
)
852 struct frame_info
*fi
;
853 enum frame_type type
;
855 fi
= frame_obstack_zalloc (sizeof (struct frame_info
));
859 /* NOTE: cagney/2002-11-18: The code segments, found in
860 create_new_frame and get_prev_frame(), that initializes the
861 frames type is subtly different. The latter only updates ->type
862 when it encounters a SIGTRAMP_FRAME or DUMMY_FRAME. This stops
863 get_prev_frame() overriding the frame's type when the INIT code
864 has previously set it. This is really somewhat bogus. The
865 initialization, as seen in create_new_frame(), should occur
866 before the INIT function has been called. */
867 if (DEPRECATED_USE_GENERIC_DUMMY_FRAMES
868 && (DEPRECATED_PC_IN_CALL_DUMMY_P ()
869 ? DEPRECATED_PC_IN_CALL_DUMMY (pc
, 0, 0)
870 : pc_in_dummy_frame (pc
)))
871 /* NOTE: cagney/2002-11-11: Does this even occure? */
876 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
877 if (PC_IN_SIGTRAMP (fi
->pc
, name
))
878 type
= SIGTRAMP_FRAME
;
884 if (INIT_EXTRA_FRAME_INFO_P ())
885 INIT_EXTRA_FRAME_INFO (0, fi
);
887 /* Select/initialize an unwind function. */
888 fi
->unwind
= frame_unwind_find_by_pc (current_gdbarch
, fi
->pc
);
893 /* Return the frame that FRAME calls (NULL if FRAME is the innermost
897 get_next_frame (struct frame_info
*frame
)
902 /* Flush the entire frame cache. */
905 flush_cached_frames (void)
907 /* Since we can't really be sure what the first object allocated was */
908 obstack_free (&frame_cache_obstack
, 0);
909 obstack_init (&frame_cache_obstack
);
911 current_frame
= NULL
; /* Invalidate cache */
913 annotate_frames_invalid ();
916 /* Flush the frame cache, and start a new one if necessary. */
919 reinit_frame_cache (void)
921 flush_cached_frames ();
923 /* FIXME: The inferior_ptid test is wrong if there is a corefile. */
924 if (PIDGET (inferior_ptid
) != 0)
926 select_frame (get_current_frame ());
930 /* Return a structure containing various interesting information
931 about the frame that called NEXT_FRAME. Returns NULL
932 if there is no such frame. */
935 get_prev_frame (struct frame_info
*next_frame
)
937 CORE_ADDR address
= 0;
938 struct frame_info
*prev
;
941 /* Return the inner-most frame, when the caller passes in NULL. */
942 /* NOTE: cagney/2002-11-09: Not sure how this would happen. The
943 caller should have previously obtained a valid frame using
944 get_selected_frame() and then called this code - only possibility
945 I can think of is code behaving badly. */
946 if (next_frame
== NULL
)
948 /* NOTE: cagney/2002-11-09: There was a code segment here that
949 would error out when CURRENT_FRAME was NULL. The comment
950 that went with it made the claim ...
952 ``This screws value_of_variable, which just wants a nice
953 clean NULL return from block_innermost_frame if there are no
954 frames. I don't think I've ever seen this message happen
955 otherwise. And returning NULL here is a perfectly legitimate
958 Per the above, this code shouldn't even be called with a NULL
960 return current_frame
;
963 /* Only try to do the unwind once. */
964 if (next_frame
->prev_p
)
965 return next_frame
->prev
;
966 next_frame
->prev_p
= 1;
968 /* On some machines it is possible to call a function without
969 setting up a stack frame for it. On these machines, we
970 define this macro to take two args; a frameinfo pointer
971 identifying a frame and a variable to set or clear if it is
972 or isn't leafless. */
974 /* Still don't want to worry about this except on the innermost
975 frame. This macro will set FROMLEAF if NEXT_FRAME is a frameless
976 function invocation. */
977 if (next_frame
->next
== NULL
)
978 /* FIXME: 2002-11-09: Frameless functions can occure anywhere in
979 the frame chain, not just the inner most frame! The generic,
980 per-architecture, frame code should handle this and the below
981 should simply be removed. */
982 fromleaf
= FRAMELESS_FUNCTION_INVOCATION (next_frame
);
987 /* A frameless inner-most frame. The `FP' (which isn't an
988 architecture frame-pointer register!) of the caller is the same
990 /* FIXME: 2002-11-09: There isn't any reason to special case this
991 edge condition. Instead the per-architecture code should hande
993 address
= get_frame_base (next_frame
);
996 /* Two macros defined in tm.h specify the machine-dependent
997 actions to be performed here.
999 First, get the frame's chain-pointer.
1001 If that is zero, the frame is the outermost frame or a leaf
1002 called by the outermost frame. This means that if start
1003 calls main without a frame, we'll return 0 (which is fine
1006 Nope; there's a problem. This also returns when the current
1007 routine is a leaf of main. This is unacceptable. We move
1008 this to after the ffi test; I'd rather have backtraces from
1009 start go curfluy than have an abort called from main not show
1011 address
= FRAME_CHAIN (next_frame
);
1013 if (!frame_chain_valid (address
, next_frame
))
1019 /* Create an initially zero previous frame. */
1020 prev
= frame_obstack_zalloc (sizeof (struct frame_info
));
1023 next_frame
->prev
= prev
;
1024 prev
->next
= next_frame
;
1025 prev
->frame
= address
;
1026 prev
->level
= next_frame
->level
+ 1;
1027 /* FIXME: cagney/2002-11-18: Should be setting the frame's type
1028 here, before anything else, and not last. Various INIT functions
1029 are full of work-arounds for the frames type not being set
1030 correctly from the word go. Ulgh! */
1031 prev
->type
= NORMAL_FRAME
;
1033 /* This change should not be needed, FIXME! We should determine
1034 whether any targets *need* DEPRECATED_INIT_FRAME_PC to happen
1035 after INIT_EXTRA_FRAME_INFO and come up with a simple way to
1036 express what goes on here.
1038 INIT_EXTRA_FRAME_INFO is called from two places: create_new_frame
1039 (where the PC is already set up) and here (where it isn't).
1040 DEPRECATED_INIT_FRAME_PC is only called from here, always after
1041 INIT_EXTRA_FRAME_INFO.
1043 The catch is the MIPS, where INIT_EXTRA_FRAME_INFO requires the
1044 PC value (which hasn't been set yet). Some other machines appear
1045 to require INIT_EXTRA_FRAME_INFO before they can do
1046 DEPRECATED_INIT_FRAME_PC. Phoo.
1048 We shouldn't need DEPRECATED_INIT_FRAME_PC_FIRST to add more
1049 complication to an already overcomplicated part of GDB.
1050 gnu@cygnus.com, 15Sep92.
1052 Assuming that some machines need DEPRECATED_INIT_FRAME_PC after
1053 INIT_EXTRA_FRAME_INFO, one possible scheme:
1055 SETUP_INNERMOST_FRAME(): Default version is just create_new_frame
1056 (read_fp ()), read_pc ()). Machines with extra frame info would
1057 do that (or the local equivalent) and then set the extra fields.
1059 SETUP_ARBITRARY_FRAME(argc, argv): Only change here is that
1060 create_new_frame would no longer init extra frame info;
1061 SETUP_ARBITRARY_FRAME would have to do that.
1063 INIT_PREV_FRAME(fromleaf, prev) Replace INIT_EXTRA_FRAME_INFO and
1064 DEPRECATED_INIT_FRAME_PC. This should also return a flag saying
1065 whether to keep the new frame, or whether to discard it, because
1066 on some machines (e.g. mips) it is really awkward to have
1067 FRAME_CHAIN_VALID called *before* INIT_EXTRA_FRAME_INFO (there is
1068 no good way to get information deduced in FRAME_CHAIN_VALID into
1069 the extra fields of the new frame). std_frame_pc(fromleaf, prev)
1071 This is the default setting for INIT_PREV_FRAME. It just does
1072 what the default DEPRECATED_INIT_FRAME_PC does. Some machines
1073 will call it from INIT_PREV_FRAME (either at the beginning, the
1074 end, or in the middle). Some machines won't use it.
1076 kingdon@cygnus.com, 13Apr93, 31Jan94, 14Dec94. */
1078 /* NOTE: cagney/2002-11-09: Just ignore the above! There is no
1079 reason for things to be this complicated.
1081 The trick is to assume that there is always a frame. Instead of
1082 special casing the inner-most frame, create fake frame
1083 (containing the hardware registers) that is inner to the
1084 user-visible inner-most frame (...) and then unwind from that.
1085 That way architecture code can use use the standard
1086 frame_XX_unwind() functions and not differentiate between the
1087 inner most and any other case.
1089 Since there is always a frame to unwind from, there is always
1090 somewhere (NEXT_FRAME) to store all the info needed to construct
1091 a new (previous) frame without having to first create it. This
1092 means that the convolution below - needing to carefully order a
1093 frame's initialization - isn't needed.
1095 The irony here though, is that FRAME_CHAIN(), at least for a more
1096 up-to-date architecture, always calls FRAME_SAVED_PC(), and
1097 FRAME_SAVED_PC() computes the PC but without first needing the
1098 frame! Instead of the convolution below, we could have simply
1099 called FRAME_SAVED_PC() and been done with it! Note that
1100 FRAME_SAVED_PC() is being superseed by frame_pc_unwind() and that
1101 function does have somewhere to cache that PC value. */
1103 if (DEPRECATED_INIT_FRAME_PC_FIRST_P ())
1104 prev
->pc
= (DEPRECATED_INIT_FRAME_PC_FIRST (fromleaf
, prev
));
1106 if (INIT_EXTRA_FRAME_INFO_P ())
1107 INIT_EXTRA_FRAME_INFO (fromleaf
, prev
);
1109 /* This entry is in the frame queue now, which is good since
1110 FRAME_SAVED_PC may use that queue to figure out its value (see
1111 tm-sparc.h). We want the pc saved in the inferior frame. */
1112 if (DEPRECATED_INIT_FRAME_PC_P ())
1113 prev
->pc
= DEPRECATED_INIT_FRAME_PC (fromleaf
, prev
);
1115 /* If ->frame and ->pc are unchanged, we are in the process of
1116 getting ourselves into an infinite backtrace. Some architectures
1117 check this in FRAME_CHAIN or thereabouts, but it seems like there
1118 is no reason this can't be an architecture-independent check. */
1119 if (prev
->frame
== next_frame
->frame
1120 && prev
->pc
== next_frame
->pc
)
1122 next_frame
->prev
= NULL
;
1123 obstack_free (&frame_cache_obstack
, prev
);
1127 /* Initialize the code used to unwind the frame PREV based on the PC
1128 (and probably other architectural information). The PC lets you
1129 check things like the debug info at that point (dwarf2cfi?) and
1130 use that to decide how the frame should be unwound. */
1131 prev
->unwind
= frame_unwind_find_by_pc (current_gdbarch
, prev
->pc
);
1133 /* NOTE: cagney/2002-11-18: The code segments, found in
1134 create_new_frame and get_prev_frame(), that initializes the
1135 frames type is subtly different. The latter only updates ->type
1136 when it encounters a SIGTRAMP_FRAME or DUMMY_FRAME. This stops
1137 get_prev_frame() overriding the frame's type when the INIT code
1138 has previously set it. This is really somewhat bogus. The
1139 initialization, as seen in create_new_frame(), should occur
1140 before the INIT function has been called. */
1141 if (DEPRECATED_USE_GENERIC_DUMMY_FRAMES
1142 && (DEPRECATED_PC_IN_CALL_DUMMY_P ()
1143 ? DEPRECATED_PC_IN_CALL_DUMMY (prev
->pc
, 0, 0)
1144 : pc_in_dummy_frame (prev
->pc
)))
1145 prev
->type
= DUMMY_FRAME
;
1148 /* FIXME: cagney/2002-11-10: This should be moved to before the
1149 INIT code above so that the INIT code knows what the frame's
1150 type is (in fact, for a [generic] dummy-frame, the type can
1151 be set and then the entire initialization can be skipped.
1152 Unforunatly, its the INIT code that sets the PC (Hmm, catch
1155 find_pc_partial_function (prev
->pc
, &name
, NULL
, NULL
);
1156 if (PC_IN_SIGTRAMP (prev
->pc
, name
))
1157 prev
->type
= SIGTRAMP_FRAME
;
1158 /* FIXME: cagney/2002-11-11: Leave prev->type alone. Some
1159 architectures are forcing the frame's type in INIT so we
1160 don't want to override it here. Remember, NORMAL_FRAME == 0,
1161 so it all works (just :-/). Once this initialization is
1162 moved to the start of this function, all this nastness will
1170 get_frame_pc (struct frame_info
*frame
)
1176 pc_notcurrent (struct frame_info
*frame
)
1178 /* If FRAME is not the innermost frame, that normally means that
1179 FRAME->pc points at the return instruction (which is *after* the
1180 call instruction), and we want to get the line containing the
1181 call (because the call is where the user thinks the program is).
1182 However, if the next frame is either a SIGTRAMP_FRAME or a
1183 DUMMY_FRAME, then the next frame will contain a saved interrupt
1184 PC and such a PC indicates the current (rather than next)
1185 instruction/line, consequently, for such cases, want to get the
1186 line containing fi->pc. */
1187 struct frame_info
*next
= get_next_frame (frame
);
1188 int notcurrent
= (next
!= NULL
&& get_frame_type (next
) == NORMAL_FRAME
);
1193 find_frame_sal (struct frame_info
*frame
, struct symtab_and_line
*sal
)
1195 (*sal
) = find_pc_line (frame
->pc
, pc_notcurrent (frame
));
1198 /* Per "frame.h", return the ``address'' of the frame. Code should
1199 really be using get_frame_id(). */
1201 get_frame_base (struct frame_info
*fi
)
1206 /* Level of the selected frame: 0 for innermost, 1 for its caller, ...
1207 or -1 for a NULL frame. */
1210 frame_relative_level (struct frame_info
*fi
)
1219 get_frame_type (struct frame_info
*frame
)
1221 /* Some targets still don't use [generic] dummy frames. Catch them
1223 if (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES
1224 && deprecated_frame_in_dummy (frame
))
1230 deprecated_set_frame_type (struct frame_info
*frame
, enum frame_type type
)
1232 /* Arrrg! See comment in "frame.h". */
1236 #ifdef FRAME_FIND_SAVED_REGS
1237 /* XXX - deprecated. This is a compatibility function for targets
1238 that do not yet implement FRAME_INIT_SAVED_REGS. */
1239 /* Find the addresses in which registers are saved in FRAME. */
1242 deprecated_get_frame_saved_regs (struct frame_info
*frame
,
1243 struct frame_saved_regs
*saved_regs_addr
)
1245 if (frame
->saved_regs
== NULL
)
1247 frame
->saved_regs
= (CORE_ADDR
*)
1248 frame_obstack_zalloc (SIZEOF_FRAME_SAVED_REGS
);
1250 if (saved_regs_addr
== NULL
)
1252 struct frame_saved_regs saved_regs
;
1253 FRAME_FIND_SAVED_REGS (frame
, saved_regs
);
1254 memcpy (frame
->saved_regs
, &saved_regs
, SIZEOF_FRAME_SAVED_REGS
);
1258 FRAME_FIND_SAVED_REGS (frame
, *saved_regs_addr
);
1259 memcpy (frame
->saved_regs
, saved_regs_addr
, SIZEOF_FRAME_SAVED_REGS
);
1264 struct frame_extra_info
*
1265 get_frame_extra_info (struct frame_info
*fi
)
1267 return fi
->extra_info
;
1270 struct frame_extra_info
*
1271 frame_extra_info_zalloc (struct frame_info
*fi
, long size
)
1273 fi
->extra_info
= frame_obstack_zalloc (size
);
1274 return fi
->extra_info
;
1278 deprecated_update_frame_pc_hack (struct frame_info
*frame
, CORE_ADDR pc
)
1280 /* See comment in "frame.h". */
1285 deprecated_update_frame_base_hack (struct frame_info
*frame
, CORE_ADDR base
)
1287 /* See comment in "frame.h". */
1288 frame
->frame
= base
;
1292 deprecated_set_frame_saved_regs_hack (struct frame_info
*frame
,
1293 CORE_ADDR
*saved_regs
)
1295 frame
->saved_regs
= saved_regs
;
1299 deprecated_set_frame_extra_info_hack (struct frame_info
*frame
,
1300 struct frame_extra_info
*extra_info
)
1302 frame
->extra_info
= extra_info
;
1306 deprecated_set_frame_next_hack (struct frame_info
*fi
,
1307 struct frame_info
*next
)
1313 deprecated_set_frame_prev_hack (struct frame_info
*fi
,
1314 struct frame_info
*prev
)
1320 deprecated_get_frame_context (struct frame_info
*fi
)
1326 deprecated_set_frame_context (struct frame_info
*fi
,
1327 struct context
*context
)
1329 fi
->context
= context
;
1333 deprecated_frame_xmalloc (void)
1335 struct frame_info
*frame
= XMALLOC (struct frame_info
);
1336 memset (frame
, 0, sizeof (struct frame_info
));
1341 deprecated_frame_xmalloc_with_cleanup (long sizeof_saved_regs
,
1342 long sizeof_extra_info
)
1344 struct frame_info
*frame
= deprecated_frame_xmalloc ();
1345 make_cleanup (xfree
, frame
);
1346 if (sizeof_saved_regs
> 0)
1348 frame
->saved_regs
= xcalloc (1, sizeof_saved_regs
);
1349 make_cleanup (xfree
, frame
->saved_regs
);
1351 if (sizeof_extra_info
> 0)
1353 frame
->extra_info
= xcalloc (1, sizeof_extra_info
);
1354 make_cleanup (xfree
, frame
->extra_info
);
1360 _initialize_frame (void)
1362 obstack_init (&frame_cache_obstack
);