GDB (API)
/home/stan/gdb/src/gdb/frame-unwind.h
Go to the documentation of this file.
00001 /* Definitions for a frame unwinder, for GDB, the GNU debugger.
00002 
00003    Copyright (C) 2003-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #if !defined (FRAME_UNWIND_H)
00021 #define FRAME_UNWIND_H 1
00022 
00023 struct frame_data;
00024 struct frame_info;
00025 struct frame_id;
00026 struct frame_unwind;
00027 struct gdbarch;
00028 struct regcache;
00029 struct value;
00030 
00031 #include "frame.h"              /* For enum frame_type.  */
00032 
00033 /* The following unwind functions assume a chain of frames forming the
00034    sequence: (outer) prev <-> this <-> next (inner).  All the
00035    functions are called with this frame's `struct frame_info' and
00036    prologue cache.
00037 
00038    THIS frame's register values can be obtained by unwinding NEXT
00039    frame's registers (a recursive operation).
00040 
00041    THIS frame's prologue cache can be used to cache information such
00042    as where this frame's prologue stores the previous frame's
00043    registers.  */
00044 
00045 /* Given THIS frame, take a whiff of its registers (namely
00046    the PC and attributes) and if SELF is the applicable unwinder,
00047    return non-zero.  Possibly also initialize THIS_PROLOGUE_CACHE; but
00048    only if returning 1.  Initializing THIS_PROLOGUE_CACHE in other
00049    cases (0 return, or exception) is invalid.  */
00050 
00051 typedef int (frame_sniffer_ftype) (const struct frame_unwind *self,
00052                                    struct frame_info *this_frame,
00053                                    void **this_prologue_cache);
00054 
00055 typedef enum unwind_stop_reason (frame_unwind_stop_reason_ftype)
00056   (struct frame_info *this_frame, void **this_prologue_cache);
00057 
00058 /* A default frame sniffer which always accepts the frame.  Used by
00059    fallback prologue unwinders.  */
00060 
00061 int default_frame_sniffer (const struct frame_unwind *self,
00062                            struct frame_info *this_frame,
00063                            void **this_prologue_cache);
00064 
00065 /* A default stop_reason callback which always claims the frame is
00066    unwindable.  */
00067 
00068 enum unwind_stop_reason
00069   default_frame_unwind_stop_reason (struct frame_info *this_frame,
00070                                     void **this_cache);
00071 
00072 /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
00073    use THIS frame, and through it the NEXT frame's register unwind
00074    method, to determine the frame ID of THIS frame.
00075 
00076    A frame ID provides an invariant that can be used to re-identify an
00077    instance of a frame.  It is a combination of the frame's `base' and
00078    the frame's function's code address.
00079 
00080    Traditionally, THIS frame's ID was determined by examining THIS
00081    frame's function's prologue, and identifying the register/offset
00082    used as THIS frame's base.
00083 
00084    Example: An examination of THIS frame's prologue reveals that, on
00085    entry, it saves the PC(+12), SP(+8), and R1(+4) registers
00086    (decrementing the SP by 12).  Consequently, the frame ID's base can
00087    be determined by adding 12 to the THIS frame's stack-pointer, and
00088    the value of THIS frame's SP can be obtained by unwinding the NEXT
00089    frame's SP.
00090 
00091    THIS_PROLOGUE_CACHE can be used to share any prolog analysis data
00092    with the other unwind methods.  Memory for that cache should be
00093    allocated using FRAME_OBSTACK_ZALLOC().  */
00094 
00095 typedef void (frame_this_id_ftype) (struct frame_info *this_frame,
00096                                     void **this_prologue_cache,
00097                                     struct frame_id *this_id);
00098 
00099 /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
00100    use THIS frame, and implicitly the NEXT frame's register unwind
00101    method, to unwind THIS frame's registers (returning the value of
00102    the specified register REGNUM in the previous frame).
00103 
00104    Traditionally, THIS frame's registers were unwound by examining
00105    THIS frame's function's prologue and identifying which registers
00106    that prolog code saved on the stack.
00107 
00108    Example: An examination of THIS frame's prologue reveals that, on
00109    entry, it saves the PC(+12), SP(+8), and R1(+4) registers
00110    (decrementing the SP by 12).  Consequently, the value of the PC
00111    register in the previous frame is found in memory at SP+12, and
00112    THIS frame's SP can be obtained by unwinding the NEXT frame's SP.
00113 
00114    This function takes THIS_FRAME as an argument.  It can find the
00115    values of registers in THIS frame by calling get_frame_register
00116    (THIS_FRAME), and reinvoke itself to find other registers in the
00117    PREVIOUS frame by calling frame_unwind_register (THIS_FRAME).
00118 
00119    The result is a GDB value object describing the register value.  It
00120    may be a lazy reference to memory, a lazy reference to the value of
00121    a register in THIS frame, or a non-lvalue.
00122 
00123    THIS_PROLOGUE_CACHE can be used to share any prolog analysis data
00124    with the other unwind methods.  Memory for that cache should be
00125    allocated using FRAME_OBSTACK_ZALLOC().  */
00126 
00127 typedef struct value * (frame_prev_register_ftype)
00128   (struct frame_info *this_frame, void **this_prologue_cache,
00129    int regnum);
00130 
00131 /* Deallocate extra memory associated with the frame cache if any.  */
00132 
00133 typedef void (frame_dealloc_cache_ftype) (struct frame_info *self,
00134                                           void *this_cache);
00135 
00136 /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
00137    use THIS frame, and implicitly the NEXT frame's register unwind
00138    method, return PREV frame's architecture.  */
00139 
00140 typedef struct gdbarch *(frame_prev_arch_ftype) (struct frame_info *this_frame,
00141                                                  void **this_prologue_cache);
00142 
00143 struct frame_unwind
00144 {
00145   /* The frame's type.  Should this instead be a collection of
00146      predicates that test the frame for various attributes?  */
00147   enum frame_type type;
00148   /* Should an attribute indicating the frame's address-in-block go
00149      here?  */
00150   frame_unwind_stop_reason_ftype *stop_reason;
00151   frame_this_id_ftype *this_id;
00152   frame_prev_register_ftype *prev_register;
00153   const struct frame_data *unwind_data;
00154   frame_sniffer_ftype *sniffer;
00155   frame_dealloc_cache_ftype *dealloc_cache;
00156   frame_prev_arch_ftype *prev_arch;
00157 };
00158 
00159 /* Register a frame unwinder, _prepending_ it to the front of the
00160    search list (so it is sniffed before previously registered
00161    unwinders).  By using a prepend, later calls can install unwinders
00162    that override earlier calls.  This allows, for instance, an OSABI
00163    to install a more specific sigtramp unwinder that overrides the
00164    traditional brute-force unwinder.  */
00165 extern void frame_unwind_prepend_unwinder (struct gdbarch *,
00166                                            const struct frame_unwind *);
00167 
00168 /* Add a frame sniffer to the list.  The predicates are polled in the
00169    order that they are appended.  The initial list contains the dummy
00170    frame sniffer.  */
00171 
00172 extern void frame_unwind_append_unwinder (struct gdbarch *gdbarch,
00173                                           const struct frame_unwind *unwinder);
00174 
00175 /* Iterate through sniffers for THIS_FRAME frame until one returns with an
00176    unwinder implementation.  THIS_FRAME->UNWIND must be NULL, it will get set
00177    by this function.  Possibly initialize THIS_CACHE.  */
00178 
00179 extern void frame_unwind_find_by_frame (struct frame_info *this_frame,
00180                                         void **this_cache);
00181 
00182 /* Helper functions for value-based register unwinding.  These return
00183    a (possibly lazy) value of the appropriate type.  */
00184 
00185 /* Return a value which indicates that FRAME did not save REGNUM.  */
00186 
00187 struct value *frame_unwind_got_optimized (struct frame_info *frame,
00188                                           int regnum);
00189 
00190 /* Return a value which indicates that FRAME copied REGNUM into
00191    register NEW_REGNUM.  */
00192 
00193 struct value *frame_unwind_got_register (struct frame_info *frame, int regnum,
00194                                          int new_regnum);
00195 
00196 /* Return a value which indicates that FRAME saved REGNUM in memory at
00197    ADDR.  */
00198 
00199 struct value *frame_unwind_got_memory (struct frame_info *frame, int regnum,
00200                                        CORE_ADDR addr);
00201 
00202 /* Return a value which indicates that FRAME's saved version of
00203    REGNUM has a known constant (computed) value of VAL.  */
00204 
00205 struct value *frame_unwind_got_constant (struct frame_info *frame, int regnum,
00206                                          ULONGEST val);
00207 
00208 /* Return a value which indicates that FRAME's saved version of
00209    REGNUM has a known constant (computed) value which is stored
00210    inside BUF.  */
00211 
00212 struct value *frame_unwind_got_bytes (struct frame_info *frame, int regnum,
00213                                       gdb_byte *buf);
00214 
00215 /* Return a value which indicates that FRAME's saved version of REGNUM
00216    has a known constant (computed) value of ADDR.  Convert the
00217    CORE_ADDR to a target address if necessary.  */
00218 
00219 struct value *frame_unwind_got_address (struct frame_info *frame, int regnum,
00220                                         CORE_ADDR addr);
00221 
00222 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines