1 /* Definitions for a frame unwinder, for GDB, the GNU debugger.
3 Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010, 2011
4 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 3 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, see <http://www.gnu.org/licenses/>. */
21 #if !defined (FRAME_UNWIND_H)
22 #define FRAME_UNWIND_H 1
32 #include "frame.h" /* For enum frame_type. */
34 /* The following unwind functions assume a chain of frames forming the
35 sequence: (outer) prev <-> this <-> next (inner). All the
36 functions are called with the next frame's `struct frame_info'
37 and this frame's prologue cache.
39 THIS frame's register values can be obtained by unwinding NEXT
40 frame's registers (a recursive operation).
42 THIS frame's prologue cache can be used to cache information such
43 as where this frame's prologue stores the previous frame's
46 /* Given THIS frame, take a whiff of its registers (namely
47 the PC and attributes) and if SELF is the applicable unwinder,
48 return non-zero. Possibly also initialize THIS_PROLOGUE_CACHE. */
50 typedef int (frame_sniffer_ftype) (const struct frame_unwind *self,
51 struct frame_info *this_frame,
52 void **this_prologue_cache);
54 /* A default frame sniffer which always accepts the frame. Used by
55 fallback prologue unwinders. */
57 int default_frame_sniffer (const struct frame_unwind *self,
58 struct frame_info *this_frame,
59 void **this_prologue_cache);
61 /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
62 use THIS frame, and through it the NEXT frame's register unwind
63 method, to determine the frame ID of THIS frame.
65 A frame ID provides an invariant that can be used to re-identify an
66 instance of a frame. It is a combination of the frame's `base' and
67 the frame's function's code address.
69 Traditionally, THIS frame's ID was determined by examining THIS
70 frame's function's prologue, and identifying the register/offset
71 used as THIS frame's base.
73 Example: An examination of THIS frame's prologue reveals that, on
74 entry, it saves the PC(+12), SP(+8), and R1(+4) registers
75 (decrementing the SP by 12). Consequently, the frame ID's base can
76 be determined by adding 12 to the THIS frame's stack-pointer, and
77 the value of THIS frame's SP can be obtained by unwinding the NEXT
80 THIS_PROLOGUE_CACHE can be used to share any prolog analysis data
81 with the other unwind methods. Memory for that cache should be
82 allocated using FRAME_OBSTACK_ZALLOC(). */
84 typedef void (frame_this_id_ftype) (struct frame_info *this_frame,
85 void **this_prologue_cache,
86 struct frame_id *this_id);
88 /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
89 use THIS frame, and implicitly the NEXT frame's register unwind
90 method, to unwind THIS frame's registers (returning the value of
91 the specified register REGNUM in the previous frame).
93 Traditionally, THIS frame's registers were unwound by examining
94 THIS frame's function's prologue and identifying which registers
95 that prolog code saved on the stack.
97 Example: An examination of THIS frame's prologue reveals that, on
98 entry, it saves the PC(+12), SP(+8), and R1(+4) registers
99 (decrementing the SP by 12). Consequently, the value of the PC
100 register in the previous frame is found in memory at SP+12, and
101 THIS frame's SP can be obtained by unwinding the NEXT frame's SP.
103 This function takes THIS_FRAME as an argument. It can find the
104 values of registers in THIS frame by calling get_frame_register
105 (THIS_FRAME), and reinvoke itself to find other registers in the
106 PREVIOUS frame by calling frame_unwind_register (THIS_FRAME).
108 The result is a GDB value object describing the register value. It
109 may be a lazy reference to memory, a lazy reference to the value of
110 a register in THIS frame, or a non-lvalue.
112 THIS_PROLOGUE_CACHE can be used to share any prolog analysis data
113 with the other unwind methods. Memory for that cache should be
114 allocated using FRAME_OBSTACK_ZALLOC(). */
116 typedef struct value * (frame_prev_register_ftype)
117 (struct frame_info *this_frame, void **this_prologue_cache,
120 /* Deallocate extra memory associated with the frame cache if any. */
122 typedef void (frame_dealloc_cache_ftype) (struct frame_info *self,
125 /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
126 use THIS frame, and implicitly the NEXT frame's register unwind
127 method, return PREV frame's architecture. */
129 typedef struct gdbarch *(frame_prev_arch_ftype) (struct frame_info *this_frame,
130 void **this_prologue_cache);
134 /* The frame's type. Should this instead be a collection of
135 predicates that test the frame for various attributes? */
136 enum frame_type type;
137 /* Should an attribute indicating the frame's address-in-block go
139 frame_this_id_ftype *this_id;
140 frame_prev_register_ftype *prev_register;
141 const struct frame_data *unwind_data;
142 frame_sniffer_ftype *sniffer;
143 frame_dealloc_cache_ftype *dealloc_cache;
144 frame_prev_arch_ftype *prev_arch;
147 /* Register a frame unwinder, _prepending_ it to the front of the
148 search list (so it is sniffed before previously registered
149 unwinders). By using a prepend, later calls can install unwinders
150 that override earlier calls. This allows, for instance, an OSABI
151 to install a a more specific sigtramp unwinder that overrides the
152 traditional brute-force unwinder. */
153 extern void frame_unwind_prepend_unwinder (struct gdbarch *,
154 const struct frame_unwind *);
156 /* Add a frame sniffer to the list. The predicates are polled in the
157 order that they are appended. The initial list contains the dummy
160 extern void frame_unwind_append_unwinder (struct gdbarch *gdbarch,
161 const struct frame_unwind *unwinder);
163 /* Iterate through sniffers for THIS_FRAME frame until one returns with an
164 unwinder implementation. THIS_FRAME->UNWIND must be NULL, it will get set
165 by this function. Possibly initialize THIS_CACHE. */
167 extern void frame_unwind_find_by_frame (struct frame_info *this_frame,
170 /* Helper functions for value-based register unwinding. These return
171 a (possibly lazy) value of the appropriate type. */
173 /* Return a value which indicates that FRAME did not save REGNUM. */
175 struct value *frame_unwind_got_optimized (struct frame_info *frame,
178 /* Return a value which indicates that FRAME copied REGNUM into
179 register NEW_REGNUM. */
181 struct value *frame_unwind_got_register (struct frame_info *frame, int regnum,
184 /* Return a value which indicates that FRAME saved REGNUM in memory at
187 struct value *frame_unwind_got_memory (struct frame_info *frame, int regnum,
190 /* Return a value which indicates that FRAME's saved version of
191 REGNUM has a known constant (computed) value of VAL. */
193 struct value *frame_unwind_got_constant (struct frame_info *frame, int regnum,
196 /* Return a value which indicates that FRAME's saved version of
197 REGNUM has a known constant (computed) value which is stored
200 struct value *frame_unwind_got_bytes (struct frame_info *frame, int regnum,
203 /* Return a value which indicates that FRAME's saved version of REGNUM
204 has a known constant (computed) value of ADDR. Convert the
205 CORE_ADDR to a target address if necessary. */
207 struct value *frame_unwind_got_address (struct frame_info *frame, int regnum,