]>
Commit | Line | Data |
---|---|---|
494cca16 AC |
1 | /* Definitions for a frame unwinder, for GDB, the GNU debugger. |
2 | ||
9b254dd1 | 3 | Copyright (C) 2003, 2004, 2007, 2008 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; | |
29 | ||
7df05f2b AC |
30 | #include "frame.h" /* For enum frame_type. */ |
31 | ||
6dc42492 AC |
32 | /* The following unwind functions assume a chain of frames forming the |
33 | sequence: (outer) prev <-> this <-> next (inner). All the | |
34 | functions are called with called with the next frame's `struct | |
35 | frame_info' and and this frame's prologue cache. | |
36 | ||
37 | THIS frame's register values can be obtained by unwinding NEXT | |
38 | frame's registers (a recursive operation). | |
39 | ||
40 | THIS frame's prologue cache can be used to cache information such | |
41 | as where this frame's prologue stores the previous frame's | |
42 | registers. */ | |
43 | ||
82417da5 AC |
44 | /* Given the NEXT frame, take a wiff of THIS frame's registers (namely |
45 | the PC and attributes) and if SELF is the applicable unwinder, | |
46 | return non-zero. Possibly also initialize THIS_PROLOGUE_CACHE. */ | |
47 | ||
48 | typedef int (frame_sniffer_ftype) (const struct frame_unwind *self, | |
49 | struct frame_info *next_frame, | |
50 | void **this_prologue_cache); | |
51 | ||
6dc42492 AC |
52 | /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); |
53 | use the NEXT frame, and its register unwind method, to determine | |
54 | the frame ID of THIS frame. | |
55 | ||
56 | A frame ID provides an invariant that can be used to re-identify an | |
57 | instance of a frame. It is a combination of the frame's `base' and | |
58 | the frame's function's code address. | |
59 | ||
60 | Traditionally, THIS frame's ID was determined by examining THIS | |
61 | frame's function's prologue, and identifying the register/offset | |
62 | used as THIS frame's base. | |
63 | ||
64 | Example: An examination of THIS frame's prologue reveals that, on | |
65 | entry, it saves the PC(+12), SP(+8), and R1(+4) registers | |
66 | (decrementing the SP by 12). Consequently, the frame ID's base can | |
67 | be determined by adding 12 to the THIS frame's stack-pointer, and | |
68 | the value of THIS frame's SP can be obtained by unwinding the NEXT | |
69 | frame's SP. | |
70 | ||
71 | THIS_PROLOGUE_CACHE can be used to share any prolog analysis data | |
72 | with the other unwind methods. Memory for that cache should be | |
35d5d4ee | 73 | allocated using FRAME_OBSTACK_ZALLOC(). */ |
6dc42492 AC |
74 | |
75 | typedef void (frame_this_id_ftype) (struct frame_info *next_frame, | |
76 | void **this_prologue_cache, | |
77 | struct frame_id *this_id); | |
78 | ||
79 | /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); | |
80 | use the NEXT frame, and its register unwind method, to unwind THIS | |
81 | frame's registers (returning the value of the specified register | |
82 | REGNUM in the previous frame). | |
83 | ||
84 | Traditionally, THIS frame's registers were unwound by examining | |
85 | THIS frame's function's prologue and identifying which registers | |
86 | that prolog code saved on the stack. | |
87 | ||
88 | Example: An examination of THIS frame's prologue reveals that, on | |
89 | entry, it saves the PC(+12), SP(+8), and R1(+4) registers | |
90 | (decrementing the SP by 12). Consequently, the value of the PC | |
91 | register in the previous frame is found in memory at SP+12, and | |
92 | THIS frame's SP can be obtained by unwinding the NEXT frame's SP. | |
93 | ||
94 | Why not pass in THIS_FRAME? By passing in NEXT frame and THIS | |
95 | cache, the supplied parameters are consistent with the sibling | |
96 | function THIS_ID. | |
97 | ||
98 | Can the code call ``frame_register (get_prev_frame (NEXT_FRAME))''? | |
99 | Won't the call frame_register (THIS_FRAME) be faster? Well, | |
100 | ignoring the possability that the previous frame does not yet | |
101 | exist, the ``frame_register (FRAME)'' function is expanded to | |
102 | ``frame_register_unwind (get_next_frame (FRAME)'' and hence that | |
103 | call will expand to ``frame_register_unwind (get_next_frame | |
104 | (get_prev_frame (NEXT_FRAME)))''. Might as well call | |
105 | ``frame_register_unwind (NEXT_FRAME)'' directly. | |
106 | ||
107 | THIS_PROLOGUE_CACHE can be used to share any prolog analysis data | |
108 | with the other unwind methods. Memory for that cache should be | |
35d5d4ee | 109 | allocated using FRAME_OBSTACK_ZALLOC(). */ |
6dc42492 AC |
110 | |
111 | typedef void (frame_prev_register_ftype) (struct frame_info *next_frame, | |
112 | void **this_prologue_cache, | |
113 | int prev_regnum, | |
114 | int *optimized, | |
115 | enum lval_type * lvalp, | |
116 | CORE_ADDR *addrp, | |
10c42a71 | 117 | int *realnump, gdb_byte *valuep); |
494cca16 | 118 | |
cbafadeb AC |
119 | /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); |
120 | use the NEXT frame, and its register unwind method, to return the PREV | |
121 | frame's program-counter. */ | |
122 | ||
123 | typedef CORE_ADDR (frame_prev_pc_ftype) (struct frame_info *next_frame, | |
124 | void **this_prologue_cache); | |
125 | ||
272dfcfd AS |
126 | /* Deallocate extra memory associated with the frame cache if any. */ |
127 | ||
128 | typedef void (frame_dealloc_cache_ftype) (struct frame_info *self, | |
129 | void *this_cache); | |
cbafadeb | 130 | |
494cca16 AC |
131 | struct frame_unwind |
132 | { | |
7df05f2b AC |
133 | /* The frame's type. Should this instead be a collection of |
134 | predicates that test the frame for various attributes? */ | |
135 | enum frame_type type; | |
494cca16 AC |
136 | /* Should an attribute indicating the frame's address-in-block go |
137 | here? */ | |
6dc42492 AC |
138 | frame_this_id_ftype *this_id; |
139 | frame_prev_register_ftype *prev_register; | |
82417da5 AC |
140 | const struct frame_data *unwind_data; |
141 | frame_sniffer_ftype *sniffer; | |
cbafadeb | 142 | frame_prev_pc_ftype *prev_pc; |
272dfcfd | 143 | frame_dealloc_cache_ftype *dealloc_cache; |
494cca16 AC |
144 | }; |
145 | ||
fb2be677 AC |
146 | /* Register a frame unwinder, _prepending_ it to the front of the |
147 | search list (so it is sniffed before previously registered | |
148 | unwinders). By using a prepend, later calls can install unwinders | |
149 | that override earlier calls. This allows, for instance, an OSABI | |
150 | to install a a more specific sigtramp unwinder that overrides the | |
151 | traditional brute-force unwinder. */ | |
152 | extern void frame_unwind_prepend_unwinder (struct gdbarch *gdbarch, | |
153 | const struct frame_unwind *unwinder); | |
82417da5 | 154 | |
e8a89fe2 AC |
155 | /* Given the NEXT frame, take a wiff of THIS frame's registers (namely |
156 | the PC and attributes) and if it is the applicable unwinder return | |
157 | the unwind methods, or NULL if it is not. */ | |
158 | ||
159 | typedef const struct frame_unwind *(frame_unwind_sniffer_ftype) (struct frame_info *next_frame); | |
160 | ||
161 | /* Add a frame sniffer to the list. The predicates are polled in the | |
162 | order that they are appended. The initial list contains the dummy | |
163 | frame sniffer. */ | |
164 | ||
165 | extern void frame_unwind_append_sniffer (struct gdbarch *gdbarch, | |
166 | frame_unwind_sniffer_ftype *sniffer); | |
167 | ||
168 | /* Iterate through the next frame's sniffers until one returns with an | |
82417da5 | 169 | unwinder implementation. Possibly initialize THIS_CACHE. */ |
e8a89fe2 | 170 | |
82417da5 AC |
171 | extern const struct frame_unwind *frame_unwind_find_by_frame (struct frame_info *next_frame, |
172 | void **this_cache); | |
e8a89fe2 | 173 | |
494cca16 | 174 | #endif |