ad1efdf353b3d548f44d4e8e44d1de3d95fc2f2c
[deliverable/binutils-gdb.git] / gdb / frame-unwind.h
1 /* Definitions for a frame unwinder, for GDB, the GNU debugger.
2
3 Copyright 2003 Free Software Foundation, Inc.
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
9 the Free Software Foundation; either version 2 of the License, or
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
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #if !defined (FRAME_UNWIND_H)
23 #define FRAME_UNWIND_H 1
24
25 struct frame_info;
26 struct frame_id;
27 struct frame_unwind;
28 struct gdbarch;
29 struct regcache;
30
31 #include "frame.h" /* For enum frame_type. */
32
33 /* Return the frame unwind methods for the function that contains PC,
34 or NULL if this this unwinder can't handle this frame. */
35
36 typedef const struct frame_unwind *(frame_unwind_p_ftype) (CORE_ADDR pc);
37
38 /* Add a frame unwinder to the list. The predicates are polled in the
39 order that they are appended. The initial list contains the dummy
40 frame's predicate. */
41
42 extern void frame_unwind_append_predicate (struct gdbarch *gdbarch,
43 frame_unwind_p_ftype *p);
44
45 /* Iterate through the list of frame unwinders until one returns an
46 implementation. */
47
48 extern const struct frame_unwind *frame_unwind_find_by_pc (struct gdbarch
49 *gdbarch,
50 CORE_ADDR pc);
51
52 /* The following unwind functions assume a chain of frames forming the
53 sequence: (outer) prev <-> this <-> next (inner). All the
54 functions are called with called with the next frame's `struct
55 frame_info' and and this frame's prologue cache.
56
57 THIS frame's register values can be obtained by unwinding NEXT
58 frame's registers (a recursive operation).
59
60 THIS frame's prologue cache can be used to cache information such
61 as where this frame's prologue stores the previous frame's
62 registers. */
63
64 /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
65 use the NEXT frame, and its register unwind method, to determine
66 the frame ID of THIS frame.
67
68 A frame ID provides an invariant that can be used to re-identify an
69 instance of a frame. It is a combination of the frame's `base' and
70 the frame's function's code address.
71
72 Traditionally, THIS frame's ID was determined by examining THIS
73 frame's function's prologue, and identifying the register/offset
74 used as THIS frame's base.
75
76 Example: An examination of THIS frame's prologue reveals that, on
77 entry, it saves the PC(+12), SP(+8), and R1(+4) registers
78 (decrementing the SP by 12). Consequently, the frame ID's base can
79 be determined by adding 12 to the THIS frame's stack-pointer, and
80 the value of THIS frame's SP can be obtained by unwinding the NEXT
81 frame's SP.
82
83 THIS_PROLOGUE_CACHE can be used to share any prolog analysis data
84 with the other unwind methods. Memory for that cache should be
85 allocated using frame_obstack_zalloc(). */
86
87 typedef void (frame_this_id_ftype) (struct frame_info *next_frame,
88 void **this_prologue_cache,
89 struct frame_id *this_id);
90
91 /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
92 use the NEXT frame, and its register unwind method, to unwind THIS
93 frame's registers (returning the value of the specified register
94 REGNUM in the previous frame).
95
96 Traditionally, THIS frame's registers were unwound by examining
97 THIS frame's function's prologue and identifying which registers
98 that prolog code saved on the stack.
99
100 Example: An examination of THIS frame's prologue reveals that, on
101 entry, it saves the PC(+12), SP(+8), and R1(+4) registers
102 (decrementing the SP by 12). Consequently, the value of the PC
103 register in the previous frame is found in memory at SP+12, and
104 THIS frame's SP can be obtained by unwinding the NEXT frame's SP.
105
106 Why not pass in THIS_FRAME? By passing in NEXT frame and THIS
107 cache, the supplied parameters are consistent with the sibling
108 function THIS_ID.
109
110 Can the code call ``frame_register (get_prev_frame (NEXT_FRAME))''?
111 Won't the call frame_register (THIS_FRAME) be faster? Well,
112 ignoring the possability that the previous frame does not yet
113 exist, the ``frame_register (FRAME)'' function is expanded to
114 ``frame_register_unwind (get_next_frame (FRAME)'' and hence that
115 call will expand to ``frame_register_unwind (get_next_frame
116 (get_prev_frame (NEXT_FRAME)))''. Might as well call
117 ``frame_register_unwind (NEXT_FRAME)'' directly.
118
119 THIS_PROLOGUE_CACHE can be used to share any prolog analysis data
120 with the other unwind methods. Memory for that cache should be
121 allocated using frame_obstack_zalloc(). */
122
123 typedef void (frame_prev_register_ftype) (struct frame_info *next_frame,
124 void **this_prologue_cache,
125 int prev_regnum,
126 int *optimized,
127 enum lval_type * lvalp,
128 CORE_ADDR *addrp,
129 int *realnump, void *valuep);
130
131 struct frame_unwind
132 {
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;
136 /* Should an attribute indicating the frame's address-in-block go
137 here? */
138 frame_this_id_ftype *this_id;
139 frame_prev_register_ftype *prev_register;
140 };
141
142 #endif
This page took 0.037452 seconds and 3 git commands to generate.