1*5796c8dcSSimon Schubert /* Definitions for a frame unwinder, for GDB, the GNU debugger. 2*5796c8dcSSimon Schubert 3*5796c8dcSSimon Schubert Copyright (C) 2003, 2004, 2007, 2008, 2009 Free Software Foundation, Inc. 4*5796c8dcSSimon Schubert 5*5796c8dcSSimon Schubert This file is part of GDB. 6*5796c8dcSSimon Schubert 7*5796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 8*5796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 9*5796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 10*5796c8dcSSimon Schubert (at your option) any later version. 11*5796c8dcSSimon Schubert 12*5796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 13*5796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 14*5796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*5796c8dcSSimon Schubert GNU General Public License for more details. 16*5796c8dcSSimon Schubert 17*5796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 18*5796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19*5796c8dcSSimon Schubert 20*5796c8dcSSimon Schubert #if !defined (FRAME_UNWIND_H) 21*5796c8dcSSimon Schubert #define FRAME_UNWIND_H 1 22*5796c8dcSSimon Schubert 23*5796c8dcSSimon Schubert struct frame_data; 24*5796c8dcSSimon Schubert struct frame_info; 25*5796c8dcSSimon Schubert struct frame_id; 26*5796c8dcSSimon Schubert struct frame_unwind; 27*5796c8dcSSimon Schubert struct gdbarch; 28*5796c8dcSSimon Schubert struct regcache; 29*5796c8dcSSimon Schubert struct value; 30*5796c8dcSSimon Schubert 31*5796c8dcSSimon Schubert #include "frame.h" /* For enum frame_type. */ 32*5796c8dcSSimon Schubert 33*5796c8dcSSimon Schubert /* The following unwind functions assume a chain of frames forming the 34*5796c8dcSSimon Schubert sequence: (outer) prev <-> this <-> next (inner). All the 35*5796c8dcSSimon Schubert functions are called with the next frame's `struct frame_info' 36*5796c8dcSSimon Schubert and this frame's prologue cache. 37*5796c8dcSSimon Schubert 38*5796c8dcSSimon Schubert THIS frame's register values can be obtained by unwinding NEXT 39*5796c8dcSSimon Schubert frame's registers (a recursive operation). 40*5796c8dcSSimon Schubert 41*5796c8dcSSimon Schubert THIS frame's prologue cache can be used to cache information such 42*5796c8dcSSimon Schubert as where this frame's prologue stores the previous frame's 43*5796c8dcSSimon Schubert registers. */ 44*5796c8dcSSimon Schubert 45*5796c8dcSSimon Schubert /* Given THIS frame, take a whiff of its registers (namely 46*5796c8dcSSimon Schubert the PC and attributes) and if SELF is the applicable unwinder, 47*5796c8dcSSimon Schubert return non-zero. Possibly also initialize THIS_PROLOGUE_CACHE. */ 48*5796c8dcSSimon Schubert 49*5796c8dcSSimon Schubert typedef int (frame_sniffer_ftype) (const struct frame_unwind *self, 50*5796c8dcSSimon Schubert struct frame_info *this_frame, 51*5796c8dcSSimon Schubert void **this_prologue_cache); 52*5796c8dcSSimon Schubert 53*5796c8dcSSimon Schubert /* A default frame sniffer which always accepts the frame. Used by 54*5796c8dcSSimon Schubert fallback prologue unwinders. */ 55*5796c8dcSSimon Schubert 56*5796c8dcSSimon Schubert int default_frame_sniffer (const struct frame_unwind *self, 57*5796c8dcSSimon Schubert struct frame_info *this_frame, 58*5796c8dcSSimon Schubert void **this_prologue_cache); 59*5796c8dcSSimon Schubert 60*5796c8dcSSimon Schubert /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); 61*5796c8dcSSimon Schubert use THIS frame, and through it the NEXT frame's register unwind 62*5796c8dcSSimon Schubert method, to determine the frame ID of THIS frame. 63*5796c8dcSSimon Schubert 64*5796c8dcSSimon Schubert A frame ID provides an invariant that can be used to re-identify an 65*5796c8dcSSimon Schubert instance of a frame. It is a combination of the frame's `base' and 66*5796c8dcSSimon Schubert the frame's function's code address. 67*5796c8dcSSimon Schubert 68*5796c8dcSSimon Schubert Traditionally, THIS frame's ID was determined by examining THIS 69*5796c8dcSSimon Schubert frame's function's prologue, and identifying the register/offset 70*5796c8dcSSimon Schubert used as THIS frame's base. 71*5796c8dcSSimon Schubert 72*5796c8dcSSimon Schubert Example: An examination of THIS frame's prologue reveals that, on 73*5796c8dcSSimon Schubert entry, it saves the PC(+12), SP(+8), and R1(+4) registers 74*5796c8dcSSimon Schubert (decrementing the SP by 12). Consequently, the frame ID's base can 75*5796c8dcSSimon Schubert be determined by adding 12 to the THIS frame's stack-pointer, and 76*5796c8dcSSimon Schubert the value of THIS frame's SP can be obtained by unwinding the NEXT 77*5796c8dcSSimon Schubert frame's SP. 78*5796c8dcSSimon Schubert 79*5796c8dcSSimon Schubert THIS_PROLOGUE_CACHE can be used to share any prolog analysis data 80*5796c8dcSSimon Schubert with the other unwind methods. Memory for that cache should be 81*5796c8dcSSimon Schubert allocated using FRAME_OBSTACK_ZALLOC(). */ 82*5796c8dcSSimon Schubert 83*5796c8dcSSimon Schubert typedef void (frame_this_id_ftype) (struct frame_info *this_frame, 84*5796c8dcSSimon Schubert void **this_prologue_cache, 85*5796c8dcSSimon Schubert struct frame_id *this_id); 86*5796c8dcSSimon Schubert 87*5796c8dcSSimon Schubert /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); 88*5796c8dcSSimon Schubert use THIS frame, and implicitly the NEXT frame's register unwind 89*5796c8dcSSimon Schubert method, to unwind THIS frame's registers (returning the value of 90*5796c8dcSSimon Schubert the specified register REGNUM in the previous frame). 91*5796c8dcSSimon Schubert 92*5796c8dcSSimon Schubert Traditionally, THIS frame's registers were unwound by examining 93*5796c8dcSSimon Schubert THIS frame's function's prologue and identifying which registers 94*5796c8dcSSimon Schubert that prolog code saved on the stack. 95*5796c8dcSSimon Schubert 96*5796c8dcSSimon Schubert Example: An examination of THIS frame's prologue reveals that, on 97*5796c8dcSSimon Schubert entry, it saves the PC(+12), SP(+8), and R1(+4) registers 98*5796c8dcSSimon Schubert (decrementing the SP by 12). Consequently, the value of the PC 99*5796c8dcSSimon Schubert register in the previous frame is found in memory at SP+12, and 100*5796c8dcSSimon Schubert THIS frame's SP can be obtained by unwinding the NEXT frame's SP. 101*5796c8dcSSimon Schubert 102*5796c8dcSSimon Schubert This function takes THIS_FRAME as an argument. It can find the 103*5796c8dcSSimon Schubert values of registers in THIS frame by calling get_frame_register 104*5796c8dcSSimon Schubert (THIS_FRAME), and reinvoke itself to find other registers in the 105*5796c8dcSSimon Schubert PREVIOUS frame by calling frame_unwind_register (THIS_FRAME). 106*5796c8dcSSimon Schubert 107*5796c8dcSSimon Schubert The result is a GDB value object describing the register value. It 108*5796c8dcSSimon Schubert may be a lazy reference to memory, a lazy reference to the value of 109*5796c8dcSSimon Schubert a register in THIS frame, or a non-lvalue. 110*5796c8dcSSimon Schubert 111*5796c8dcSSimon Schubert THIS_PROLOGUE_CACHE can be used to share any prolog analysis data 112*5796c8dcSSimon Schubert with the other unwind methods. Memory for that cache should be 113*5796c8dcSSimon Schubert allocated using FRAME_OBSTACK_ZALLOC(). */ 114*5796c8dcSSimon Schubert 115*5796c8dcSSimon Schubert typedef struct value * (frame_prev_register_ftype) 116*5796c8dcSSimon Schubert (struct frame_info *this_frame, void **this_prologue_cache, 117*5796c8dcSSimon Schubert int regnum); 118*5796c8dcSSimon Schubert 119*5796c8dcSSimon Schubert /* Deallocate extra memory associated with the frame cache if any. */ 120*5796c8dcSSimon Schubert 121*5796c8dcSSimon Schubert typedef void (frame_dealloc_cache_ftype) (struct frame_info *self, 122*5796c8dcSSimon Schubert void *this_cache); 123*5796c8dcSSimon Schubert 124*5796c8dcSSimon Schubert /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); 125*5796c8dcSSimon Schubert use THIS frame, and implicitly the NEXT frame's register unwind 126*5796c8dcSSimon Schubert method, return PREV frame's architecture. */ 127*5796c8dcSSimon Schubert 128*5796c8dcSSimon Schubert typedef struct gdbarch *(frame_prev_arch_ftype) (struct frame_info *this_frame, 129*5796c8dcSSimon Schubert void **this_prologue_cache); 130*5796c8dcSSimon Schubert 131*5796c8dcSSimon Schubert struct frame_unwind 132*5796c8dcSSimon Schubert { 133*5796c8dcSSimon Schubert /* The frame's type. Should this instead be a collection of 134*5796c8dcSSimon Schubert predicates that test the frame for various attributes? */ 135*5796c8dcSSimon Schubert enum frame_type type; 136*5796c8dcSSimon Schubert /* Should an attribute indicating the frame's address-in-block go 137*5796c8dcSSimon Schubert here? */ 138*5796c8dcSSimon Schubert frame_this_id_ftype *this_id; 139*5796c8dcSSimon Schubert frame_prev_register_ftype *prev_register; 140*5796c8dcSSimon Schubert const struct frame_data *unwind_data; 141*5796c8dcSSimon Schubert frame_sniffer_ftype *sniffer; 142*5796c8dcSSimon Schubert frame_dealloc_cache_ftype *dealloc_cache; 143*5796c8dcSSimon Schubert frame_prev_arch_ftype *prev_arch; 144*5796c8dcSSimon Schubert }; 145*5796c8dcSSimon Schubert 146*5796c8dcSSimon Schubert /* Register a frame unwinder, _prepending_ it to the front of the 147*5796c8dcSSimon Schubert search list (so it is sniffed before previously registered 148*5796c8dcSSimon Schubert unwinders). By using a prepend, later calls can install unwinders 149*5796c8dcSSimon Schubert that override earlier calls. This allows, for instance, an OSABI 150*5796c8dcSSimon Schubert to install a a more specific sigtramp unwinder that overrides the 151*5796c8dcSSimon Schubert traditional brute-force unwinder. */ 152*5796c8dcSSimon Schubert extern void frame_unwind_prepend_unwinder (struct gdbarch *gdbarch, 153*5796c8dcSSimon Schubert const struct frame_unwind *unwinder); 154*5796c8dcSSimon Schubert 155*5796c8dcSSimon Schubert /* Add a frame sniffer to the list. The predicates are polled in the 156*5796c8dcSSimon Schubert order that they are appended. The initial list contains the dummy 157*5796c8dcSSimon Schubert frame sniffer. */ 158*5796c8dcSSimon Schubert 159*5796c8dcSSimon Schubert extern void frame_unwind_append_unwinder (struct gdbarch *gdbarch, 160*5796c8dcSSimon Schubert const struct frame_unwind *unwinder); 161*5796c8dcSSimon Schubert 162*5796c8dcSSimon Schubert /* Iterate through sniffers for THIS frame until one returns with an 163*5796c8dcSSimon Schubert unwinder implementation. Possibly initialize THIS_CACHE. */ 164*5796c8dcSSimon Schubert 165*5796c8dcSSimon Schubert extern const struct frame_unwind *frame_unwind_find_by_frame (struct frame_info *this_frame, 166*5796c8dcSSimon Schubert void **this_cache); 167*5796c8dcSSimon Schubert 168*5796c8dcSSimon Schubert /* Helper functions for value-based register unwinding. These return 169*5796c8dcSSimon Schubert a (possibly lazy) value of the appropriate type. */ 170*5796c8dcSSimon Schubert 171*5796c8dcSSimon Schubert /* Return a value which indicates that FRAME did not save REGNUM. */ 172*5796c8dcSSimon Schubert 173*5796c8dcSSimon Schubert struct value *frame_unwind_got_optimized (struct frame_info *frame, 174*5796c8dcSSimon Schubert int regnum); 175*5796c8dcSSimon Schubert 176*5796c8dcSSimon Schubert /* Return a value which indicates that FRAME copied REGNUM into 177*5796c8dcSSimon Schubert register NEW_REGNUM. */ 178*5796c8dcSSimon Schubert 179*5796c8dcSSimon Schubert struct value *frame_unwind_got_register (struct frame_info *frame, int regnum, 180*5796c8dcSSimon Schubert int new_regnum); 181*5796c8dcSSimon Schubert 182*5796c8dcSSimon Schubert /* Return a value which indicates that FRAME saved REGNUM in memory at 183*5796c8dcSSimon Schubert ADDR. */ 184*5796c8dcSSimon Schubert 185*5796c8dcSSimon Schubert struct value *frame_unwind_got_memory (struct frame_info *frame, int regnum, 186*5796c8dcSSimon Schubert CORE_ADDR addr); 187*5796c8dcSSimon Schubert 188*5796c8dcSSimon Schubert /* Return a value which indicates that FRAME's saved version of 189*5796c8dcSSimon Schubert REGNUM has a known constant (computed) value of VAL. */ 190*5796c8dcSSimon Schubert 191*5796c8dcSSimon Schubert struct value *frame_unwind_got_constant (struct frame_info *frame, int regnum, 192*5796c8dcSSimon Schubert ULONGEST val); 193*5796c8dcSSimon Schubert 194*5796c8dcSSimon Schubert /* Return a value which indicates that FRAME's saved version of 195*5796c8dcSSimon Schubert REGNUM has a known constant (computed) value which is stored 196*5796c8dcSSimon Schubert inside BUF. */ 197*5796c8dcSSimon Schubert 198*5796c8dcSSimon Schubert struct value *frame_unwind_got_bytes (struct frame_info *frame, int regnum, 199*5796c8dcSSimon Schubert gdb_byte *buf); 200*5796c8dcSSimon Schubert 201*5796c8dcSSimon Schubert /* Return a value which indicates that FRAME's saved version of REGNUM 202*5796c8dcSSimon Schubert has a known constant (computed) value of ADDR. Convert the 203*5796c8dcSSimon Schubert CORE_ADDR to a target address if necessary. */ 204*5796c8dcSSimon Schubert 205*5796c8dcSSimon Schubert struct value *frame_unwind_got_address (struct frame_info *frame, int regnum, 206*5796c8dcSSimon Schubert CORE_ADDR addr); 207*5796c8dcSSimon Schubert 208*5796c8dcSSimon Schubert #endif 209