xref: /dflybsd-src/contrib/gdb-7/gdb/frame-unwind.h (revision cf7f2e2d389e8012d562650bd94d7e433f449d6e)
15796c8dcSSimon Schubert /* Definitions for a frame unwinder, for GDB, the GNU debugger.
25796c8dcSSimon Schubert 
3*cf7f2e2dSJohn Marino    Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010
4*cf7f2e2dSJohn Marino    Free Software Foundation, Inc.
55796c8dcSSimon Schubert 
65796c8dcSSimon Schubert    This file is part of GDB.
75796c8dcSSimon Schubert 
85796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
95796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
105796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
115796c8dcSSimon Schubert    (at your option) any later version.
125796c8dcSSimon Schubert 
135796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
145796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
155796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
165796c8dcSSimon Schubert    GNU General Public License for more details.
175796c8dcSSimon Schubert 
185796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
195796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
205796c8dcSSimon Schubert 
215796c8dcSSimon Schubert #if !defined (FRAME_UNWIND_H)
225796c8dcSSimon Schubert #define FRAME_UNWIND_H 1
235796c8dcSSimon Schubert 
245796c8dcSSimon Schubert struct frame_data;
255796c8dcSSimon Schubert struct frame_info;
265796c8dcSSimon Schubert struct frame_id;
275796c8dcSSimon Schubert struct frame_unwind;
285796c8dcSSimon Schubert struct gdbarch;
295796c8dcSSimon Schubert struct regcache;
305796c8dcSSimon Schubert struct value;
315796c8dcSSimon Schubert 
325796c8dcSSimon Schubert #include "frame.h"		/* For enum frame_type.  */
335796c8dcSSimon Schubert 
345796c8dcSSimon Schubert /* The following unwind functions assume a chain of frames forming the
355796c8dcSSimon Schubert    sequence: (outer) prev <-> this <-> next (inner).  All the
365796c8dcSSimon Schubert    functions are called with the next frame's `struct frame_info'
375796c8dcSSimon Schubert    and this frame's prologue cache.
385796c8dcSSimon Schubert 
395796c8dcSSimon Schubert    THIS frame's register values can be obtained by unwinding NEXT
405796c8dcSSimon Schubert    frame's registers (a recursive operation).
415796c8dcSSimon Schubert 
425796c8dcSSimon Schubert    THIS frame's prologue cache can be used to cache information such
435796c8dcSSimon Schubert    as where this frame's prologue stores the previous frame's
445796c8dcSSimon Schubert    registers.  */
455796c8dcSSimon Schubert 
465796c8dcSSimon Schubert /* Given THIS frame, take a whiff of its registers (namely
475796c8dcSSimon Schubert    the PC and attributes) and if SELF is the applicable unwinder,
485796c8dcSSimon Schubert    return non-zero.  Possibly also initialize THIS_PROLOGUE_CACHE.  */
495796c8dcSSimon Schubert 
505796c8dcSSimon Schubert typedef int (frame_sniffer_ftype) (const struct frame_unwind *self,
515796c8dcSSimon Schubert 				   struct frame_info *this_frame,
525796c8dcSSimon Schubert 				   void **this_prologue_cache);
535796c8dcSSimon Schubert 
545796c8dcSSimon Schubert /* A default frame sniffer which always accepts the frame.  Used by
555796c8dcSSimon Schubert    fallback prologue unwinders.  */
565796c8dcSSimon Schubert 
575796c8dcSSimon Schubert int default_frame_sniffer (const struct frame_unwind *self,
585796c8dcSSimon Schubert 			   struct frame_info *this_frame,
595796c8dcSSimon Schubert 			   void **this_prologue_cache);
605796c8dcSSimon Schubert 
615796c8dcSSimon Schubert /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
625796c8dcSSimon Schubert    use THIS frame, and through it the NEXT frame's register unwind
635796c8dcSSimon Schubert    method, to determine the frame ID of THIS frame.
645796c8dcSSimon Schubert 
655796c8dcSSimon Schubert    A frame ID provides an invariant that can be used to re-identify an
665796c8dcSSimon Schubert    instance of a frame.  It is a combination of the frame's `base' and
675796c8dcSSimon Schubert    the frame's function's code address.
685796c8dcSSimon Schubert 
695796c8dcSSimon Schubert    Traditionally, THIS frame's ID was determined by examining THIS
705796c8dcSSimon Schubert    frame's function's prologue, and identifying the register/offset
715796c8dcSSimon Schubert    used as THIS frame's base.
725796c8dcSSimon Schubert 
735796c8dcSSimon Schubert    Example: An examination of THIS frame's prologue reveals that, on
745796c8dcSSimon Schubert    entry, it saves the PC(+12), SP(+8), and R1(+4) registers
755796c8dcSSimon Schubert    (decrementing the SP by 12).  Consequently, the frame ID's base can
765796c8dcSSimon Schubert    be determined by adding 12 to the THIS frame's stack-pointer, and
775796c8dcSSimon Schubert    the value of THIS frame's SP can be obtained by unwinding the NEXT
785796c8dcSSimon Schubert    frame's SP.
795796c8dcSSimon Schubert 
805796c8dcSSimon Schubert    THIS_PROLOGUE_CACHE can be used to share any prolog analysis data
815796c8dcSSimon Schubert    with the other unwind methods.  Memory for that cache should be
825796c8dcSSimon Schubert    allocated using FRAME_OBSTACK_ZALLOC().  */
835796c8dcSSimon Schubert 
845796c8dcSSimon Schubert typedef void (frame_this_id_ftype) (struct frame_info *this_frame,
855796c8dcSSimon Schubert 				    void **this_prologue_cache,
865796c8dcSSimon Schubert 				    struct frame_id *this_id);
875796c8dcSSimon Schubert 
885796c8dcSSimon Schubert /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
895796c8dcSSimon Schubert    use THIS frame, and implicitly the NEXT frame's register unwind
905796c8dcSSimon Schubert    method, to unwind THIS frame's registers (returning the value of
915796c8dcSSimon Schubert    the specified register REGNUM in the previous frame).
925796c8dcSSimon Schubert 
935796c8dcSSimon Schubert    Traditionally, THIS frame's registers were unwound by examining
945796c8dcSSimon Schubert    THIS frame's function's prologue and identifying which registers
955796c8dcSSimon Schubert    that prolog code saved on the stack.
965796c8dcSSimon Schubert 
975796c8dcSSimon Schubert    Example: An examination of THIS frame's prologue reveals that, on
985796c8dcSSimon Schubert    entry, it saves the PC(+12), SP(+8), and R1(+4) registers
995796c8dcSSimon Schubert    (decrementing the SP by 12).  Consequently, the value of the PC
1005796c8dcSSimon Schubert    register in the previous frame is found in memory at SP+12, and
1015796c8dcSSimon Schubert    THIS frame's SP can be obtained by unwinding the NEXT frame's SP.
1025796c8dcSSimon Schubert 
1035796c8dcSSimon Schubert    This function takes THIS_FRAME as an argument.  It can find the
1045796c8dcSSimon Schubert    values of registers in THIS frame by calling get_frame_register
1055796c8dcSSimon Schubert    (THIS_FRAME), and reinvoke itself to find other registers in the
1065796c8dcSSimon Schubert    PREVIOUS frame by calling frame_unwind_register (THIS_FRAME).
1075796c8dcSSimon Schubert 
1085796c8dcSSimon Schubert    The result is a GDB value object describing the register value.  It
1095796c8dcSSimon Schubert    may be a lazy reference to memory, a lazy reference to the value of
1105796c8dcSSimon Schubert    a register in THIS frame, or a non-lvalue.
1115796c8dcSSimon Schubert 
1125796c8dcSSimon Schubert    THIS_PROLOGUE_CACHE can be used to share any prolog analysis data
1135796c8dcSSimon Schubert    with the other unwind methods.  Memory for that cache should be
1145796c8dcSSimon Schubert    allocated using FRAME_OBSTACK_ZALLOC().  */
1155796c8dcSSimon Schubert 
1165796c8dcSSimon Schubert typedef struct value * (frame_prev_register_ftype)
1175796c8dcSSimon Schubert   (struct frame_info *this_frame, void **this_prologue_cache,
1185796c8dcSSimon Schubert    int regnum);
1195796c8dcSSimon Schubert 
1205796c8dcSSimon Schubert /* Deallocate extra memory associated with the frame cache if any.  */
1215796c8dcSSimon Schubert 
1225796c8dcSSimon Schubert typedef void (frame_dealloc_cache_ftype) (struct frame_info *self,
1235796c8dcSSimon Schubert 					  void *this_cache);
1245796c8dcSSimon Schubert 
1255796c8dcSSimon Schubert /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
1265796c8dcSSimon Schubert    use THIS frame, and implicitly the NEXT frame's register unwind
1275796c8dcSSimon Schubert    method, return PREV frame's architecture.  */
1285796c8dcSSimon Schubert 
1295796c8dcSSimon Schubert typedef struct gdbarch *(frame_prev_arch_ftype) (struct frame_info *this_frame,
1305796c8dcSSimon Schubert 						 void **this_prologue_cache);
1315796c8dcSSimon Schubert 
1325796c8dcSSimon Schubert struct frame_unwind
1335796c8dcSSimon Schubert {
1345796c8dcSSimon Schubert   /* The frame's type.  Should this instead be a collection of
1355796c8dcSSimon Schubert      predicates that test the frame for various attributes?  */
1365796c8dcSSimon Schubert   enum frame_type type;
1375796c8dcSSimon Schubert   /* Should an attribute indicating the frame's address-in-block go
1385796c8dcSSimon Schubert      here?  */
1395796c8dcSSimon Schubert   frame_this_id_ftype *this_id;
1405796c8dcSSimon Schubert   frame_prev_register_ftype *prev_register;
1415796c8dcSSimon Schubert   const struct frame_data *unwind_data;
1425796c8dcSSimon Schubert   frame_sniffer_ftype *sniffer;
1435796c8dcSSimon Schubert   frame_dealloc_cache_ftype *dealloc_cache;
1445796c8dcSSimon Schubert   frame_prev_arch_ftype *prev_arch;
1455796c8dcSSimon Schubert };
1465796c8dcSSimon Schubert 
1475796c8dcSSimon Schubert /* Register a frame unwinder, _prepending_ it to the front of the
1485796c8dcSSimon Schubert    search list (so it is sniffed before previously registered
1495796c8dcSSimon Schubert    unwinders).  By using a prepend, later calls can install unwinders
1505796c8dcSSimon Schubert    that override earlier calls.  This allows, for instance, an OSABI
1515796c8dcSSimon Schubert    to install a a more specific sigtramp unwinder that overrides the
1525796c8dcSSimon Schubert    traditional brute-force unwinder.  */
1535796c8dcSSimon Schubert extern void frame_unwind_prepend_unwinder (struct gdbarch *gdbarch,
1545796c8dcSSimon Schubert 					   const struct frame_unwind *unwinder);
1555796c8dcSSimon Schubert 
1565796c8dcSSimon Schubert /* Add a frame sniffer to the list.  The predicates are polled in the
1575796c8dcSSimon Schubert    order that they are appended.  The initial list contains the dummy
1585796c8dcSSimon Schubert    frame sniffer.  */
1595796c8dcSSimon Schubert 
1605796c8dcSSimon Schubert extern void frame_unwind_append_unwinder (struct gdbarch *gdbarch,
1615796c8dcSSimon Schubert 					  const struct frame_unwind *unwinder);
1625796c8dcSSimon Schubert 
1635796c8dcSSimon Schubert /* Iterate through sniffers for THIS frame until one returns with an
1645796c8dcSSimon Schubert    unwinder implementation.  Possibly initialize THIS_CACHE.  */
1655796c8dcSSimon Schubert 
1665796c8dcSSimon Schubert extern const struct frame_unwind *frame_unwind_find_by_frame (struct frame_info *this_frame,
1675796c8dcSSimon Schubert 							      void **this_cache);
1685796c8dcSSimon Schubert 
1695796c8dcSSimon Schubert /* Helper functions for value-based register unwinding.  These return
1705796c8dcSSimon Schubert    a (possibly lazy) value of the appropriate type.  */
1715796c8dcSSimon Schubert 
1725796c8dcSSimon Schubert /* Return a value which indicates that FRAME did not save REGNUM.  */
1735796c8dcSSimon Schubert 
1745796c8dcSSimon Schubert struct value *frame_unwind_got_optimized (struct frame_info *frame,
1755796c8dcSSimon Schubert 					  int regnum);
1765796c8dcSSimon Schubert 
1775796c8dcSSimon Schubert /* Return a value which indicates that FRAME copied REGNUM into
1785796c8dcSSimon Schubert    register NEW_REGNUM.  */
1795796c8dcSSimon Schubert 
1805796c8dcSSimon Schubert struct value *frame_unwind_got_register (struct frame_info *frame, int regnum,
1815796c8dcSSimon Schubert 					 int new_regnum);
1825796c8dcSSimon Schubert 
1835796c8dcSSimon Schubert /* Return a value which indicates that FRAME saved REGNUM in memory at
1845796c8dcSSimon Schubert    ADDR.  */
1855796c8dcSSimon Schubert 
1865796c8dcSSimon Schubert struct value *frame_unwind_got_memory (struct frame_info *frame, int regnum,
1875796c8dcSSimon Schubert 				       CORE_ADDR addr);
1885796c8dcSSimon Schubert 
1895796c8dcSSimon Schubert /* Return a value which indicates that FRAME's saved version of
1905796c8dcSSimon Schubert    REGNUM has a known constant (computed) value of VAL.  */
1915796c8dcSSimon Schubert 
1925796c8dcSSimon Schubert struct value *frame_unwind_got_constant (struct frame_info *frame, int regnum,
1935796c8dcSSimon Schubert 					 ULONGEST val);
1945796c8dcSSimon Schubert 
1955796c8dcSSimon Schubert /* Return a value which indicates that FRAME's saved version of
1965796c8dcSSimon Schubert    REGNUM has a known constant (computed) value which is stored
1975796c8dcSSimon Schubert    inside BUF.  */
1985796c8dcSSimon Schubert 
1995796c8dcSSimon Schubert struct value *frame_unwind_got_bytes (struct frame_info *frame, int regnum,
2005796c8dcSSimon Schubert                                       gdb_byte *buf);
2015796c8dcSSimon Schubert 
2025796c8dcSSimon Schubert /* Return a value which indicates that FRAME's saved version of REGNUM
2035796c8dcSSimon Schubert    has a known constant (computed) value of ADDR.  Convert the
2045796c8dcSSimon Schubert    CORE_ADDR to a target address if necessary.  */
2055796c8dcSSimon Schubert 
2065796c8dcSSimon Schubert struct value *frame_unwind_got_address (struct frame_info *frame, int regnum,
2075796c8dcSSimon Schubert 					CORE_ADDR addr);
2085796c8dcSSimon Schubert 
2095796c8dcSSimon Schubert #endif
210