2003-07-15 Andrew Cagney <cagney@redhat.com>
[external/binutils.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 /* For compatibility with the old frame code.  See end of header for
34    new methods.  */
35 typedef const struct frame_unwind *(frame_unwind_p_ftype) (CORE_ADDR pc);
36 extern void frame_unwind_append_predicate (struct gdbarch *gdbarch,
37                                            frame_unwind_p_ftype *p);
38
39 /* The following unwind functions assume a chain of frames forming the
40    sequence: (outer) prev <-> this <-> next (inner).  All the
41    functions are called with called with the next frame's `struct
42    frame_info' and and this frame's prologue cache.
43
44    THIS frame's register values can be obtained by unwinding NEXT
45    frame's registers (a recursive operation).
46
47    THIS frame's prologue cache can be used to cache information such
48    as where this frame's prologue stores the previous frame's
49    registers.  */
50
51 /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
52    use the NEXT frame, and its register unwind method, to determine
53    the frame ID of THIS frame.
54
55    A frame ID provides an invariant that can be used to re-identify an
56    instance of a frame.  It is a combination of the frame's `base' and
57    the frame's function's code address.
58
59    Traditionally, THIS frame's ID was determined by examining THIS
60    frame's function's prologue, and identifying the register/offset
61    used as THIS frame's base.
62
63    Example: An examination of THIS frame's prologue reveals that, on
64    entry, it saves the PC(+12), SP(+8), and R1(+4) registers
65    (decrementing the SP by 12).  Consequently, the frame ID's base can
66    be determined by adding 12 to the THIS frame's stack-pointer, and
67    the value of THIS frame's SP can be obtained by unwinding the NEXT
68    frame's SP.
69
70    THIS_PROLOGUE_CACHE can be used to share any prolog analysis data
71    with the other unwind methods.  Memory for that cache should be
72    allocated using frame_obstack_zalloc().  */
73
74 typedef void (frame_this_id_ftype) (struct frame_info *next_frame,
75                                     void **this_prologue_cache,
76                                     struct frame_id *this_id);
77
78 /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
79    use the NEXT frame, and its register unwind method, to unwind THIS
80    frame's registers (returning the value of the specified register
81    REGNUM in the previous frame).
82
83    Traditionally, THIS frame's registers were unwound by examining
84    THIS frame's function's prologue and identifying which registers
85    that prolog code saved on the stack.
86
87    Example: An examination of THIS frame's prologue reveals that, on
88    entry, it saves the PC(+12), SP(+8), and R1(+4) registers
89    (decrementing the SP by 12).  Consequently, the value of the PC
90    register in the previous frame is found in memory at SP+12, and
91    THIS frame's SP can be obtained by unwinding the NEXT frame's SP.
92
93    Why not pass in THIS_FRAME?  By passing in NEXT frame and THIS
94    cache, the supplied parameters are consistent with the sibling
95    function THIS_ID.
96
97    Can the code call ``frame_register (get_prev_frame (NEXT_FRAME))''?
98    Won't the call frame_register (THIS_FRAME) be faster?  Well,
99    ignoring the possability that the previous frame does not yet
100    exist, the ``frame_register (FRAME)'' function is expanded to
101    ``frame_register_unwind (get_next_frame (FRAME)'' and hence that
102    call will expand to ``frame_register_unwind (get_next_frame
103    (get_prev_frame (NEXT_FRAME)))''.  Might as well call
104    ``frame_register_unwind (NEXT_FRAME)'' directly.
105
106    THIS_PROLOGUE_CACHE can be used to share any prolog analysis data
107    with the other unwind methods.  Memory for that cache should be
108    allocated using frame_obstack_zalloc().  */
109
110 typedef void (frame_prev_register_ftype) (struct frame_info *next_frame,
111                                           void **this_prologue_cache,
112                                           int prev_regnum,
113                                           int *optimized,
114                                           enum lval_type * lvalp,
115                                           CORE_ADDR *addrp,
116                                           int *realnump, void *valuep);
117
118 struct frame_unwind
119 {
120   /* The frame's type.  Should this instead be a collection of
121      predicates that test the frame for various attributes?  */
122   enum frame_type type;
123   /* Should an attribute indicating the frame's address-in-block go
124      here?  */
125   frame_this_id_ftype *this_id;
126   frame_prev_register_ftype *prev_register;
127 };
128
129 /* Given the NEXT frame, take a wiff of THIS frame's registers (namely
130    the PC and attributes) and if it is the applicable unwinder return
131    the unwind methods, or NULL if it is not.  */
132
133 typedef const struct frame_unwind *(frame_unwind_sniffer_ftype) (struct frame_info *next_frame);
134
135 /* Add a frame sniffer to the list.  The predicates are polled in the
136    order that they are appended.  The initial list contains the dummy
137    frame sniffer.  */
138
139 extern void frame_unwind_append_sniffer (struct gdbarch *gdbarch,
140                                          frame_unwind_sniffer_ftype *sniffer);
141
142 /* Iterate through the next frame's sniffers until one returns with an
143    unwinder implementation.  */
144
145 extern const struct frame_unwind *frame_unwind_find_by_frame (struct frame_info *next_frame);
146
147 #endif