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