gdb/
[deliverable/binutils-gdb.git] / gdb / frame-unwind.h
1 /* Definitions for a frame unwinder, for GDB, the GNU debugger.
2
3 Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
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.
12
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.
17
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/>. */
20
21 #if !defined (FRAME_UNWIND_H)
22 #define FRAME_UNWIND_H 1
23
24 struct frame_data;
25 struct frame_info;
26 struct frame_id;
27 struct frame_unwind;
28 struct gdbarch;
29 struct regcache;
30 struct value;
31
32 #include "frame.h" /* For enum frame_type. */
33
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 this frame's `struct frame_info' and
37 prologue cache.
38
39 THIS frame's register values can be obtained by unwinding NEXT
40 frame's registers (a recursive operation).
41
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
44 registers. */
45
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. */
49
50 typedef int (frame_sniffer_ftype) (const struct frame_unwind *self,
51 struct frame_info *this_frame,
52 void **this_prologue_cache);
53
54 /* A default frame sniffer which always accepts the frame. Used by
55 fallback prologue unwinders. */
56
57 int default_frame_sniffer (const struct frame_unwind *self,
58 struct frame_info *this_frame,
59 void **this_prologue_cache);
60
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.
64
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.
68
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.
72
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
78 frame's SP.
79
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(). */
83
84 typedef void (frame_this_id_ftype) (struct frame_info *this_frame,
85 void **this_prologue_cache,
86 struct frame_id *this_id);
87
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).
92
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.
96
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.
102
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).
107
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.
111
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(). */
115
116 typedef struct value * (frame_prev_register_ftype)
117 (struct frame_info *this_frame, void **this_prologue_cache,
118 int regnum);
119
120 /* Deallocate extra memory associated with the frame cache if any. */
121
122 typedef void (frame_dealloc_cache_ftype) (struct frame_info *self,
123 void *this_cache);
124
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. */
128
129 typedef struct gdbarch *(frame_prev_arch_ftype) (struct frame_info *this_frame,
130 void **this_prologue_cache);
131
132 struct frame_unwind
133 {
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
138 here? */
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;
145 };
146
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 *);
155
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
158 frame sniffer. */
159
160 extern void frame_unwind_append_unwinder (struct gdbarch *gdbarch,
161 const struct frame_unwind *unwinder);
162
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. */
166
167 extern void frame_unwind_find_by_frame (struct frame_info *this_frame,
168 void **this_cache);
169
170 /* Helper functions for value-based register unwinding. These return
171 a (possibly lazy) value of the appropriate type. */
172
173 /* Return a value which indicates that FRAME did not save REGNUM. */
174
175 struct value *frame_unwind_got_optimized (struct frame_info *frame,
176 int regnum);
177
178 /* Return a value which indicates that FRAME copied REGNUM into
179 register NEW_REGNUM. */
180
181 struct value *frame_unwind_got_register (struct frame_info *frame, int regnum,
182 int new_regnum);
183
184 /* Return a value which indicates that FRAME saved REGNUM in memory at
185 ADDR. */
186
187 struct value *frame_unwind_got_memory (struct frame_info *frame, int regnum,
188 CORE_ADDR addr);
189
190 /* Return a value which indicates that FRAME's saved version of
191 REGNUM has a known constant (computed) value of VAL. */
192
193 struct value *frame_unwind_got_constant (struct frame_info *frame, int regnum,
194 ULONGEST val);
195
196 /* Return a value which indicates that FRAME's saved version of
197 REGNUM has a known constant (computed) value which is stored
198 inside BUF. */
199
200 struct value *frame_unwind_got_bytes (struct frame_info *frame, int regnum,
201 gdb_byte *buf);
202
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. */
206
207 struct value *frame_unwind_got_address (struct frame_info *frame, int regnum,
208 CORE_ADDR addr);
209
210 #endif
This page took 0.076101 seconds and 5 git commands to generate.