1 /* Definitions for a frame unwinder, for GDB, the GNU debugger. 2 3 Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010, 2011 4 Free Software Foundation, Inc. 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 10 the Free Software Foundation; either version 3 of the License, or 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 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20 21 #if !defined (FRAME_UNWIND_H) 22 #define FRAME_UNWIND_H 1 23 24 struct frame_data; 25 struct frame_info; 26 struct frame_id; 27 struct frame_unwind; 28 struct gdbarch; 29 struct regcache; 30 struct value; 31 32 #include "frame.h" /* For enum frame_type. */ 33 34 /* The following unwind functions assume a chain of frames forming the 35 sequence: (outer) prev <-> this <-> next (inner). All the 36 functions are called with this frame's `struct frame_info' and 37 prologue cache. 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 46 /* Given THIS frame, take a whiff of its registers (namely 47 the PC and attributes) and if SELF is the applicable unwinder, 48 return non-zero. Possibly also initialize THIS_PROLOGUE_CACHE. */ 49 50 typedef int (frame_sniffer_ftype) (const struct frame_unwind *self, 51 struct frame_info *this_frame, 52 void **this_prologue_cache); 53 54 typedef enum unwind_stop_reason (frame_unwind_stop_reason_ftype) 55 (struct frame_info *this_frame, void **this_prologue_cache); 56 57 /* A default frame sniffer which always accepts the frame. Used by 58 fallback prologue unwinders. */ 59 60 int default_frame_sniffer (const struct frame_unwind *self, 61 struct frame_info *this_frame, 62 void **this_prologue_cache); 63 64 /* A default stop_reason callback which always claims the frame is 65 unwindable. */ 66 67 enum unwind_stop_reason 68 default_frame_unwind_stop_reason (struct frame_info *this_frame, 69 void **this_cache); 70 71 /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); 72 use THIS frame, and through it the NEXT frame's register unwind 73 method, to determine the frame ID of THIS frame. 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 92 allocated using FRAME_OBSTACK_ZALLOC(). */ 93 94 typedef void (frame_this_id_ftype) (struct frame_info *this_frame, 95 void **this_prologue_cache, 96 struct frame_id *this_id); 97 98 /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); 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). 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 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). 117 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. 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 124 allocated using FRAME_OBSTACK_ZALLOC(). */ 125 126 typedef struct value * (frame_prev_register_ftype) 127 (struct frame_info *this_frame, void **this_prologue_cache, 128 int regnum); 129 130 /* Deallocate extra memory associated with the frame cache if any. */ 131 132 typedef void (frame_dealloc_cache_ftype) (struct frame_info *self, 133 void *this_cache); 134 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 139 typedef struct gdbarch *(frame_prev_arch_ftype) (struct frame_info *this_frame, 140 void **this_prologue_cache); 141 142 struct frame_unwind 143 { 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; 147 /* Should an attribute indicating the frame's address-in-block go 148 here? */ 149 frame_unwind_stop_reason_ftype *stop_reason; 150 frame_this_id_ftype *this_id; 151 frame_prev_register_ftype *prev_register; 152 const struct frame_data *unwind_data; 153 frame_sniffer_ftype *sniffer; 154 frame_dealloc_cache_ftype *dealloc_cache; 155 frame_prev_arch_ftype *prev_arch; 156 }; 157 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 162 to install a more specific sigtramp unwinder that overrides the 163 traditional brute-force unwinder. */ 164 extern void frame_unwind_prepend_unwinder (struct gdbarch *, 165 const struct frame_unwind *); 166 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 171 extern void frame_unwind_append_unwinder (struct gdbarch *gdbarch, 172 const struct frame_unwind *unwinder); 173 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. */ 177 178 extern void frame_unwind_find_by_frame (struct frame_info *this_frame, 179 void **this_cache); 180 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 186 struct 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 192 struct 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 198 struct 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 204 struct value *frame_unwind_got_constant (struct frame_info *frame, int regnum, 205 ULONGEST val); 206 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 211 struct value *frame_unwind_got_bytes (struct frame_info *frame, int regnum, 212 gdb_byte *buf); 213 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 218 struct value *frame_unwind_got_address (struct frame_info *frame, int regnum, 219 CORE_ADDR addr); 220 221 #endif 222