1b725ae77Skettenis /* Definitions for a frame unwinder, for GDB, the GNU debugger. 2b725ae77Skettenis 3*11efff7fSkettenis Copyright 2003, 2004 Free Software Foundation, Inc. 4b725ae77Skettenis 5b725ae77Skettenis This file is part of GDB. 6b725ae77Skettenis 7b725ae77Skettenis This program is free software; you can redistribute it and/or modify 8b725ae77Skettenis it under the terms of the GNU General Public License as published by 9b725ae77Skettenis the Free Software Foundation; either version 2 of the License, or 10b725ae77Skettenis (at your option) any later version. 11b725ae77Skettenis 12b725ae77Skettenis This program is distributed in the hope that it will be useful, 13b725ae77Skettenis but WITHOUT ANY WARRANTY; without even the implied warranty of 14b725ae77Skettenis MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15b725ae77Skettenis GNU General Public License for more details. 16b725ae77Skettenis 17b725ae77Skettenis You should have received a copy of the GNU General Public License 18b725ae77Skettenis along with this program; if not, write to the Free Software 19b725ae77Skettenis Foundation, Inc., 59 Temple Place - Suite 330, 20b725ae77Skettenis Boston, MA 02111-1307, USA. */ 21b725ae77Skettenis 22b725ae77Skettenis #if !defined (FRAME_UNWIND_H) 23b725ae77Skettenis #define FRAME_UNWIND_H 1 24b725ae77Skettenis 25*11efff7fSkettenis struct frame_data; 26b725ae77Skettenis struct frame_info; 27b725ae77Skettenis struct frame_id; 28b725ae77Skettenis struct frame_unwind; 29b725ae77Skettenis struct gdbarch; 30b725ae77Skettenis struct regcache; 31b725ae77Skettenis 32b725ae77Skettenis #include "frame.h" /* For enum frame_type. */ 33b725ae77Skettenis 34b725ae77Skettenis /* The following unwind functions assume a chain of frames forming the 35b725ae77Skettenis sequence: (outer) prev <-> this <-> next (inner). All the 36b725ae77Skettenis functions are called with called with the next frame's `struct 37b725ae77Skettenis frame_info' and and this frame's prologue cache. 38b725ae77Skettenis 39b725ae77Skettenis THIS frame's register values can be obtained by unwinding NEXT 40b725ae77Skettenis frame's registers (a recursive operation). 41b725ae77Skettenis 42b725ae77Skettenis THIS frame's prologue cache can be used to cache information such 43b725ae77Skettenis as where this frame's prologue stores the previous frame's 44b725ae77Skettenis registers. */ 45b725ae77Skettenis 46*11efff7fSkettenis /* Given the NEXT frame, take a wiff of THIS frame's registers (namely 47*11efff7fSkettenis the PC and attributes) and if SELF is the applicable unwinder, 48*11efff7fSkettenis return non-zero. Possibly also initialize THIS_PROLOGUE_CACHE. */ 49*11efff7fSkettenis 50*11efff7fSkettenis typedef int (frame_sniffer_ftype) (const struct frame_unwind *self, 51*11efff7fSkettenis struct frame_info *next_frame, 52*11efff7fSkettenis void **this_prologue_cache); 53*11efff7fSkettenis 54b725ae77Skettenis /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); 55b725ae77Skettenis use the NEXT frame, and its register unwind method, to determine 56b725ae77Skettenis the frame ID of THIS frame. 57b725ae77Skettenis 58b725ae77Skettenis A frame ID provides an invariant that can be used to re-identify an 59b725ae77Skettenis instance of a frame. It is a combination of the frame's `base' and 60b725ae77Skettenis the frame's function's code address. 61b725ae77Skettenis 62b725ae77Skettenis Traditionally, THIS frame's ID was determined by examining THIS 63b725ae77Skettenis frame's function's prologue, and identifying the register/offset 64b725ae77Skettenis used as THIS frame's base. 65b725ae77Skettenis 66b725ae77Skettenis Example: An examination of THIS frame's prologue reveals that, on 67b725ae77Skettenis entry, it saves the PC(+12), SP(+8), and R1(+4) registers 68b725ae77Skettenis (decrementing the SP by 12). Consequently, the frame ID's base can 69b725ae77Skettenis be determined by adding 12 to the THIS frame's stack-pointer, and 70b725ae77Skettenis the value of THIS frame's SP can be obtained by unwinding the NEXT 71b725ae77Skettenis frame's SP. 72b725ae77Skettenis 73b725ae77Skettenis THIS_PROLOGUE_CACHE can be used to share any prolog analysis data 74b725ae77Skettenis with the other unwind methods. Memory for that cache should be 75b725ae77Skettenis allocated using frame_obstack_zalloc(). */ 76b725ae77Skettenis 77b725ae77Skettenis typedef void (frame_this_id_ftype) (struct frame_info *next_frame, 78b725ae77Skettenis void **this_prologue_cache, 79b725ae77Skettenis struct frame_id *this_id); 80b725ae77Skettenis 81b725ae77Skettenis /* Assuming the frame chain: (outer) prev <-> this <-> next (inner); 82b725ae77Skettenis use the NEXT frame, and its register unwind method, to unwind THIS 83b725ae77Skettenis frame's registers (returning the value of the specified register 84b725ae77Skettenis REGNUM in the previous frame). 85b725ae77Skettenis 86b725ae77Skettenis Traditionally, THIS frame's registers were unwound by examining 87b725ae77Skettenis THIS frame's function's prologue and identifying which registers 88b725ae77Skettenis that prolog code saved on the stack. 89b725ae77Skettenis 90b725ae77Skettenis Example: An examination of THIS frame's prologue reveals that, on 91b725ae77Skettenis entry, it saves the PC(+12), SP(+8), and R1(+4) registers 92b725ae77Skettenis (decrementing the SP by 12). Consequently, the value of the PC 93b725ae77Skettenis register in the previous frame is found in memory at SP+12, and 94b725ae77Skettenis THIS frame's SP can be obtained by unwinding the NEXT frame's SP. 95b725ae77Skettenis 96b725ae77Skettenis Why not pass in THIS_FRAME? By passing in NEXT frame and THIS 97b725ae77Skettenis cache, the supplied parameters are consistent with the sibling 98b725ae77Skettenis function THIS_ID. 99b725ae77Skettenis 100b725ae77Skettenis Can the code call ``frame_register (get_prev_frame (NEXT_FRAME))''? 101b725ae77Skettenis Won't the call frame_register (THIS_FRAME) be faster? Well, 102b725ae77Skettenis ignoring the possability that the previous frame does not yet 103b725ae77Skettenis exist, the ``frame_register (FRAME)'' function is expanded to 104b725ae77Skettenis ``frame_register_unwind (get_next_frame (FRAME)'' and hence that 105b725ae77Skettenis call will expand to ``frame_register_unwind (get_next_frame 106b725ae77Skettenis (get_prev_frame (NEXT_FRAME)))''. Might as well call 107b725ae77Skettenis ``frame_register_unwind (NEXT_FRAME)'' directly. 108b725ae77Skettenis 109b725ae77Skettenis THIS_PROLOGUE_CACHE can be used to share any prolog analysis data 110b725ae77Skettenis with the other unwind methods. Memory for that cache should be 111b725ae77Skettenis allocated using frame_obstack_zalloc(). */ 112b725ae77Skettenis 113b725ae77Skettenis typedef void (frame_prev_register_ftype) (struct frame_info *next_frame, 114b725ae77Skettenis void **this_prologue_cache, 115b725ae77Skettenis int prev_regnum, 116b725ae77Skettenis int *optimized, 117b725ae77Skettenis enum lval_type * lvalp, 118b725ae77Skettenis CORE_ADDR *addrp, 119b725ae77Skettenis int *realnump, void *valuep); 120b725ae77Skettenis 121b725ae77Skettenis struct frame_unwind 122b725ae77Skettenis { 123b725ae77Skettenis /* The frame's type. Should this instead be a collection of 124b725ae77Skettenis predicates that test the frame for various attributes? */ 125b725ae77Skettenis enum frame_type type; 126b725ae77Skettenis /* Should an attribute indicating the frame's address-in-block go 127b725ae77Skettenis here? */ 128b725ae77Skettenis frame_this_id_ftype *this_id; 129b725ae77Skettenis frame_prev_register_ftype *prev_register; 130*11efff7fSkettenis const struct frame_data *unwind_data; 131*11efff7fSkettenis frame_sniffer_ftype *sniffer; 132b725ae77Skettenis }; 133b725ae77Skettenis 134*11efff7fSkettenis /* Register a frame unwinder, _prepending_ it to the front of the 135*11efff7fSkettenis search list (so it is sniffed before previously registered 136*11efff7fSkettenis unwinders). By using a prepend, later calls can install unwinders 137*11efff7fSkettenis that override earlier calls. This allows, for instance, an OSABI 138*11efff7fSkettenis to install a a more specific sigtramp unwinder that overrides the 139*11efff7fSkettenis traditional brute-force unwinder. */ 140*11efff7fSkettenis extern void frame_unwind_prepend_unwinder (struct gdbarch *gdbarch, 141*11efff7fSkettenis const struct frame_unwind *unwinder); 142*11efff7fSkettenis 143b725ae77Skettenis /* Given the NEXT frame, take a wiff of THIS frame's registers (namely 144b725ae77Skettenis the PC and attributes) and if it is the applicable unwinder return 145b725ae77Skettenis the unwind methods, or NULL if it is not. */ 146b725ae77Skettenis 147b725ae77Skettenis typedef const struct frame_unwind *(frame_unwind_sniffer_ftype) (struct frame_info *next_frame); 148b725ae77Skettenis 149b725ae77Skettenis /* Add a frame sniffer to the list. The predicates are polled in the 150b725ae77Skettenis order that they are appended. The initial list contains the dummy 151b725ae77Skettenis frame sniffer. */ 152b725ae77Skettenis 153b725ae77Skettenis extern void frame_unwind_append_sniffer (struct gdbarch *gdbarch, 154b725ae77Skettenis frame_unwind_sniffer_ftype *sniffer); 155b725ae77Skettenis 156b725ae77Skettenis /* Iterate through the next frame's sniffers until one returns with an 157*11efff7fSkettenis unwinder implementation. Possibly initialize THIS_CACHE. */ 158b725ae77Skettenis 159*11efff7fSkettenis extern const struct frame_unwind *frame_unwind_find_by_frame (struct frame_info *next_frame, 160*11efff7fSkettenis void **this_cache); 161b725ae77Skettenis 162b725ae77Skettenis #endif 163