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