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