]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/frame-unwind.h
2011-01-05 Michael Snyder <msnyder@vmware.com>
[thirdparty/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
938f5214
TJB
36 functions are called with the next frame's `struct frame_info'
37 and this frame's 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
669fac23
DJ
54/* A default frame sniffer which always accepts the frame. Used by
55 fallback prologue unwinders. */
56
57int default_frame_sniffer (const struct frame_unwind *self,
58 struct frame_info *this_frame,
59 void **this_prologue_cache);
60
6dc42492 61/* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
669fac23
DJ
62 use THIS frame, and through it the NEXT frame's register unwind
63 method, to determine the frame ID of THIS frame.
6dc42492
AC
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
35d5d4ee 82 allocated using FRAME_OBSTACK_ZALLOC(). */
6dc42492 83
669fac23 84typedef void (frame_this_id_ftype) (struct frame_info *this_frame,
6dc42492
AC
85 void **this_prologue_cache,
86 struct frame_id *this_id);
87
88/* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
669fac23
DJ
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).
6dc42492
AC
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
669fac23
DJ
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).
6dc42492 107
669fac23
DJ
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.
6dc42492
AC
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
35d5d4ee 114 allocated using FRAME_OBSTACK_ZALLOC(). */
6dc42492 115
669fac23
DJ
116typedef struct value * (frame_prev_register_ftype)
117 (struct frame_info *this_frame, void **this_prologue_cache,
118 int regnum);
cbafadeb 119
272dfcfd
AS
120/* Deallocate extra memory associated with the frame cache if any. */
121
122typedef void (frame_dealloc_cache_ftype) (struct frame_info *self,
123 void *this_cache);
cbafadeb 124
36f15f55
UW
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
129typedef struct gdbarch *(frame_prev_arch_ftype) (struct frame_info *this_frame,
130 void **this_prologue_cache);
131
494cca16
AC
132struct frame_unwind
133{
7df05f2b
AC
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;
494cca16
AC
137 /* Should an attribute indicating the frame's address-in-block go
138 here? */
6dc42492
AC
139 frame_this_id_ftype *this_id;
140 frame_prev_register_ftype *prev_register;
82417da5
AC
141 const struct frame_data *unwind_data;
142 frame_sniffer_ftype *sniffer;
272dfcfd 143 frame_dealloc_cache_ftype *dealloc_cache;
36f15f55 144 frame_prev_arch_ftype *prev_arch;
494cca16
AC
145};
146
fb2be677
AC
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. */
3e43a32a
MS
153extern void frame_unwind_prepend_unwinder (struct gdbarch *,
154 const struct frame_unwind *);
82417da5 155
e8a89fe2
AC
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
669fac23
DJ
160extern void frame_unwind_append_unwinder (struct gdbarch *gdbarch,
161 const struct frame_unwind *unwinder);
e8a89fe2 162
9f9a8002
JK
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. */
e8a89fe2 166
9f9a8002
JK
167extern void frame_unwind_find_by_frame (struct frame_info *this_frame,
168 void **this_cache);
e8a89fe2 169
669fac23
DJ
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
175struct 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
181struct 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
187struct 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
193struct value *frame_unwind_got_constant (struct frame_info *frame, int regnum,
194 ULONGEST val);
195
15c1e57f
JB
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
200struct value *frame_unwind_got_bytes (struct frame_info *frame, int regnum,
201 gdb_byte *buf);
202
669fac23
DJ
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
207struct value *frame_unwind_got_address (struct frame_info *frame, int regnum,
208 CORE_ADDR addr);
209
494cca16 210#endif