]>
Commit | Line | Data |
---|---|---|
494cca16 AC |
1 | /* Definitions for a frame unwinder, for GDB, the GNU debugger. |
2 | ||
0b302171 | 3 | Copyright (C) 2003-2004, 2007-2012 Free Software Foundation, Inc. |
494cca16 AC |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
494cca16 AC |
10 | (at your option) any later version. |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
494cca16 AC |
19 | |
20 | #if !defined (FRAME_UNWIND_H) | |
21 | #define FRAME_UNWIND_H 1 | |
22 | ||
82417da5 | 23 | struct frame_data; |
494cca16 AC |
24 | struct frame_info; |
25 | struct frame_id; | |
26 | struct frame_unwind; | |
27 | struct gdbarch; | |
28 | struct regcache; | |
669fac23 | 29 | struct value; |
494cca16 | 30 | |
7df05f2b AC |
31 | #include "frame.h" /* For enum frame_type. */ |
32 | ||
6dc42492 AC |
33 | /* The following unwind functions assume a chain of frames forming the |
34 | sequence: (outer) prev <-> this <-> next (inner). All the | |
b7ea3126 PA |
35 | functions are called with this frame's `struct frame_info' and |
36 | prologue cache. | |
6dc42492 AC |
37 | |
38 | THIS frame's register values can be obtained by unwinding NEXT | |
39 | frame's registers (a recursive operation). | |
40 | ||
41 | THIS frame's prologue cache can be used to cache information such | |
42 | as where this frame's prologue stores the previous frame's | |
43 | registers. */ | |
44 | ||
669fac23 | 45 | /* Given THIS frame, take a whiff of its registers (namely |
82417da5 AC |
46 | the PC and attributes) and if SELF is the applicable unwinder, |
47 | return non-zero. Possibly also initialize THIS_PROLOGUE_CACHE. */ | |
48 | ||
49 | typedef int (frame_sniffer_ftype) (const struct frame_unwind *self, | |
669fac23 | 50 | struct frame_info *this_frame, |
82417da5 AC |
51 | void **this_prologue_cache); |
52 | ||
8fbca658 PA |
53 | typedef enum unwind_stop_reason (frame_unwind_stop_reason_ftype) |
54 | (struct frame_info *this_frame, void **this_prologue_cache); | |
55 | ||
669fac23 DJ |
56 | /* A default frame sniffer which always accepts the frame. Used by |
57 | fallback prologue unwinders. */ | |
58 | ||
59 | int default_frame_sniffer (const struct frame_unwind *self, | |
60 | struct frame_info *this_frame, | |
61 | void **this_prologue_cache); | |
62 | ||
8fbca658 PA |
63 | /* A default stop_reason callback which always claims the frame is |
64 | unwindable. */ | |
65 | ||
66 | enum unwind_stop_reason | |
67 | default_frame_unwind_stop_reason (struct frame_info *this_frame, | |
68 | void **this_cache); | |
69 | ||
6dc42492 | 70 | /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); |
669fac23 DJ |
71 | use THIS frame, and through it the NEXT frame's register unwind |
72 | method, to determine the frame ID of THIS frame. | |
6dc42492 AC |
73 | |
74 | A frame ID provides an invariant that can be used to re-identify an | |
75 | instance of a frame. It is a combination of the frame's `base' and | |
76 | the frame's function's code address. | |
77 | ||
78 | Traditionally, THIS frame's ID was determined by examining THIS | |
79 | frame's function's prologue, and identifying the register/offset | |
80 | used as THIS frame's base. | |
81 | ||
82 | Example: An examination of THIS frame's prologue reveals that, on | |
83 | entry, it saves the PC(+12), SP(+8), and R1(+4) registers | |
84 | (decrementing the SP by 12). Consequently, the frame ID's base can | |
85 | be determined by adding 12 to the THIS frame's stack-pointer, and | |
86 | the value of THIS frame's SP can be obtained by unwinding the NEXT | |
87 | frame's SP. | |
88 | ||
89 | THIS_PROLOGUE_CACHE can be used to share any prolog analysis data | |
90 | with the other unwind methods. Memory for that cache should be | |
35d5d4ee | 91 | allocated using FRAME_OBSTACK_ZALLOC(). */ |
6dc42492 | 92 | |
669fac23 | 93 | typedef void (frame_this_id_ftype) (struct frame_info *this_frame, |
6dc42492 AC |
94 | void **this_prologue_cache, |
95 | struct frame_id *this_id); | |
96 | ||
97 | /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); | |
669fac23 DJ |
98 | use THIS frame, and implicitly the NEXT frame's register unwind |
99 | method, to unwind THIS frame's registers (returning the value of | |
100 | the specified register REGNUM in the previous frame). | |
6dc42492 AC |
101 | |
102 | Traditionally, THIS frame's registers were unwound by examining | |
103 | THIS frame's function's prologue and identifying which registers | |
104 | that prolog code saved on the stack. | |
105 | ||
106 | Example: An examination of THIS frame's prologue reveals that, on | |
107 | entry, it saves the PC(+12), SP(+8), and R1(+4) registers | |
108 | (decrementing the SP by 12). Consequently, the value of the PC | |
109 | register in the previous frame is found in memory at SP+12, and | |
110 | THIS frame's SP can be obtained by unwinding the NEXT frame's SP. | |
111 | ||
669fac23 DJ |
112 | This function takes THIS_FRAME as an argument. It can find the |
113 | values of registers in THIS frame by calling get_frame_register | |
114 | (THIS_FRAME), and reinvoke itself to find other registers in the | |
115 | PREVIOUS frame by calling frame_unwind_register (THIS_FRAME). | |
6dc42492 | 116 | |
669fac23 DJ |
117 | The result is a GDB value object describing the register value. It |
118 | may be a lazy reference to memory, a lazy reference to the value of | |
119 | a register in THIS frame, or a non-lvalue. | |
6dc42492 AC |
120 | |
121 | THIS_PROLOGUE_CACHE can be used to share any prolog analysis data | |
122 | with the other unwind methods. Memory for that cache should be | |
35d5d4ee | 123 | allocated using FRAME_OBSTACK_ZALLOC(). */ |
6dc42492 | 124 | |
669fac23 DJ |
125 | typedef struct value * (frame_prev_register_ftype) |
126 | (struct frame_info *this_frame, void **this_prologue_cache, | |
127 | int regnum); | |
cbafadeb | 128 | |
272dfcfd AS |
129 | /* Deallocate extra memory associated with the frame cache if any. */ |
130 | ||
131 | typedef void (frame_dealloc_cache_ftype) (struct frame_info *self, | |
132 | void *this_cache); | |
cbafadeb | 133 | |
36f15f55 UW |
134 | /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); |
135 | use THIS frame, and implicitly the NEXT frame's register unwind | |
136 | method, return PREV frame's architecture. */ | |
137 | ||
138 | typedef struct gdbarch *(frame_prev_arch_ftype) (struct frame_info *this_frame, | |
139 | void **this_prologue_cache); | |
140 | ||
494cca16 AC |
141 | struct frame_unwind |
142 | { | |
7df05f2b AC |
143 | /* The frame's type. Should this instead be a collection of |
144 | predicates that test the frame for various attributes? */ | |
145 | enum frame_type type; | |
494cca16 AC |
146 | /* Should an attribute indicating the frame's address-in-block go |
147 | here? */ | |
8fbca658 | 148 | frame_unwind_stop_reason_ftype *stop_reason; |
6dc42492 AC |
149 | frame_this_id_ftype *this_id; |
150 | frame_prev_register_ftype *prev_register; | |
82417da5 AC |
151 | const struct frame_data *unwind_data; |
152 | frame_sniffer_ftype *sniffer; | |
272dfcfd | 153 | frame_dealloc_cache_ftype *dealloc_cache; |
36f15f55 | 154 | frame_prev_arch_ftype *prev_arch; |
494cca16 AC |
155 | }; |
156 | ||
fb2be677 AC |
157 | /* Register a frame unwinder, _prepending_ it to the front of the |
158 | search list (so it is sniffed before previously registered | |
159 | unwinders). By using a prepend, later calls can install unwinders | |
160 | that override earlier calls. This allows, for instance, an OSABI | |
766062f6 | 161 | to install a more specific sigtramp unwinder that overrides the |
fb2be677 | 162 | traditional brute-force unwinder. */ |
3e43a32a MS |
163 | extern void frame_unwind_prepend_unwinder (struct gdbarch *, |
164 | const struct frame_unwind *); | |
82417da5 | 165 | |
e8a89fe2 AC |
166 | /* Add a frame sniffer to the list. The predicates are polled in the |
167 | order that they are appended. The initial list contains the dummy | |
168 | frame sniffer. */ | |
169 | ||
669fac23 DJ |
170 | extern void frame_unwind_append_unwinder (struct gdbarch *gdbarch, |
171 | const struct frame_unwind *unwinder); | |
e8a89fe2 | 172 | |
9f9a8002 JK |
173 | /* Iterate through sniffers for THIS_FRAME frame until one returns with an |
174 | unwinder implementation. THIS_FRAME->UNWIND must be NULL, it will get set | |
175 | by this function. Possibly initialize THIS_CACHE. */ | |
e8a89fe2 | 176 | |
9f9a8002 JK |
177 | extern void frame_unwind_find_by_frame (struct frame_info *this_frame, |
178 | void **this_cache); | |
e8a89fe2 | 179 | |
669fac23 DJ |
180 | /* Helper functions for value-based register unwinding. These return |
181 | a (possibly lazy) value of the appropriate type. */ | |
182 | ||
183 | /* Return a value which indicates that FRAME did not save REGNUM. */ | |
184 | ||
185 | struct value *frame_unwind_got_optimized (struct frame_info *frame, | |
186 | int regnum); | |
187 | ||
188 | /* Return a value which indicates that FRAME copied REGNUM into | |
189 | register NEW_REGNUM. */ | |
190 | ||
191 | struct value *frame_unwind_got_register (struct frame_info *frame, int regnum, | |
192 | int new_regnum); | |
193 | ||
194 | /* Return a value which indicates that FRAME saved REGNUM in memory at | |
195 | ADDR. */ | |
196 | ||
197 | struct value *frame_unwind_got_memory (struct frame_info *frame, int regnum, | |
198 | CORE_ADDR addr); | |
199 | ||
200 | /* Return a value which indicates that FRAME's saved version of | |
201 | REGNUM has a known constant (computed) value of VAL. */ | |
202 | ||
203 | struct value *frame_unwind_got_constant (struct frame_info *frame, int regnum, | |
204 | ULONGEST val); | |
205 | ||
15c1e57f JB |
206 | /* Return a value which indicates that FRAME's saved version of |
207 | REGNUM has a known constant (computed) value which is stored | |
208 | inside BUF. */ | |
209 | ||
210 | struct value *frame_unwind_got_bytes (struct frame_info *frame, int regnum, | |
211 | gdb_byte *buf); | |
212 | ||
669fac23 DJ |
213 | /* Return a value which indicates that FRAME's saved version of REGNUM |
214 | has a known constant (computed) value of ADDR. Convert the | |
215 | CORE_ADDR to a target address if necessary. */ | |
216 | ||
217 | struct value *frame_unwind_got_address (struct frame_info *frame, int regnum, | |
218 | CORE_ADDR addr); | |
219 | ||
494cca16 | 220 | #endif |