gdb/frame-unwind.h - gdb

Data types defined

Macros defined

Source code

  1. /* Definitions for a frame unwinder, for GDB, the GNU debugger.

  2.    Copyright (C) 2003-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #if !defined (FRAME_UNWIND_H)
  15. #define FRAME_UNWIND_H 1

  16. struct frame_data;
  17. struct frame_info;
  18. struct frame_id;
  19. struct frame_unwind;
  20. struct gdbarch;
  21. struct regcache;
  22. struct value;

  23. #include "frame.h"                /* For enum frame_type.  */

  24. /* The following unwind functions assume a chain of frames forming the
  25.    sequence: (outer) prev <-> this <-> next (inner).  All the
  26.    functions are called with this frame's `struct frame_info' and
  27.    prologue cache.

  28.    THIS frame's register values can be obtained by unwinding NEXT
  29.    frame's registers (a recursive operation).

  30.    THIS frame's prologue cache can be used to cache information such
  31.    as where this frame's prologue stores the previous frame's
  32.    registers.  */

  33. /* Given THIS frame, take a whiff of its registers (namely
  34.    the PC and attributes) and if SELF is the applicable unwinder,
  35.    return non-zero.  Possibly also initialize THIS_PROLOGUE_CACHE; but
  36.    only if returning 1.  Initializing THIS_PROLOGUE_CACHE in other
  37.    cases (0 return, or exception) is invalid.  */

  38. typedef int (frame_sniffer_ftype) (const struct frame_unwind *self,
  39.                                    struct frame_info *this_frame,
  40.                                    void **this_prologue_cache);

  41. typedef enum unwind_stop_reason (frame_unwind_stop_reason_ftype)
  42.   (struct frame_info *this_frame, void **this_prologue_cache);

  43. /* A default frame sniffer which always accepts the frame.  Used by
  44.    fallback prologue unwinders.  */

  45. int default_frame_sniffer (const struct frame_unwind *self,
  46.                            struct frame_info *this_frame,
  47.                            void **this_prologue_cache);

  48. /* A default stop_reason callback which always claims the frame is
  49.    unwindable.  */

  50. enum unwind_stop_reason
  51.   default_frame_unwind_stop_reason (struct frame_info *this_frame,
  52.                                     void **this_cache);

  53. /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
  54.    use THIS frame, and through it the NEXT frame's register unwind
  55.    method, to determine the frame ID of THIS frame.

  56.    A frame ID provides an invariant that can be used to re-identify an
  57.    instance of a frame.  It is a combination of the frame's `base' and
  58.    the frame's function's code address.

  59.    Traditionally, THIS frame's ID was determined by examining THIS
  60.    frame's function's prologue, and identifying the register/offset
  61.    used as THIS frame's base.

  62.    Example: An examination of THIS frame's prologue reveals that, on
  63.    entry, it saves the PC(+12), SP(+8), and R1(+4) registers
  64.    (decrementing the SP by 12).  Consequently, the frame ID's base can
  65.    be determined by adding 12 to the THIS frame's stack-pointer, and
  66.    the value of THIS frame's SP can be obtained by unwinding the NEXT
  67.    frame's SP.

  68.    THIS_PROLOGUE_CACHE can be used to share any prolog analysis data
  69.    with the other unwind methods.  Memory for that cache should be
  70.    allocated using FRAME_OBSTACK_ZALLOC().  */

  71. typedef void (frame_this_id_ftype) (struct frame_info *this_frame,
  72.                                     void **this_prologue_cache,
  73.                                     struct frame_id *this_id);

  74. /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
  75.    use THIS frame, and implicitly the NEXT frame's register unwind
  76.    method, to unwind THIS frame's registers (returning the value of
  77.    the specified register REGNUM in the previous frame).

  78.    Traditionally, THIS frame's registers were unwound by examining
  79.    THIS frame's function's prologue and identifying which registers
  80.    that prolog code saved on the stack.

  81.    Example: An examination of THIS frame's prologue reveals that, on
  82.    entry, it saves the PC(+12), SP(+8), and R1(+4) registers
  83.    (decrementing the SP by 12).  Consequently, the value of the PC
  84.    register in the previous frame is found in memory at SP+12, and
  85.    THIS frame's SP can be obtained by unwinding the NEXT frame's SP.

  86.    This function takes THIS_FRAME as an argument.  It can find the
  87.    values of registers in THIS frame by calling get_frame_register
  88.    (THIS_FRAME), and reinvoke itself to find other registers in the
  89.    PREVIOUS frame by calling frame_unwind_register (THIS_FRAME).

  90.    The result is a GDB value object describing the register value.  It
  91.    may be a lazy reference to memory, a lazy reference to the value of
  92.    a register in THIS frame, or a non-lvalue.

  93.    THIS_PROLOGUE_CACHE can be used to share any prolog analysis data
  94.    with the other unwind methods.  Memory for that cache should be
  95.    allocated using FRAME_OBSTACK_ZALLOC().  */

  96. typedef struct value * (frame_prev_register_ftype)
  97.   (struct frame_info *this_frame, void **this_prologue_cache,
  98.    int regnum);

  99. /* Deallocate extra memory associated with the frame cache if any.  */

  100. typedef void (frame_dealloc_cache_ftype) (struct frame_info *self,
  101.                                           void *this_cache);

  102. /* Assuming the frame chain: (outer) prev <-> this <-> next (inner);
  103.    use THIS frame, and implicitly the NEXT frame's register unwind
  104.    method, return PREV frame's architecture.  */

  105. typedef struct gdbarch *(frame_prev_arch_ftype) (struct frame_info *this_frame,
  106.                                                  void **this_prologue_cache);

  107. struct frame_unwind
  108. {
  109.   /* The frame's type.  Should this instead be a collection of
  110.      predicates that test the frame for various attributes?  */
  111.   enum frame_type type;
  112.   /* Should an attribute indicating the frame's address-in-block go
  113.      here?  */
  114.   frame_unwind_stop_reason_ftype *stop_reason;
  115.   frame_this_id_ftype *this_id;
  116.   frame_prev_register_ftype *prev_register;
  117.   const struct frame_data *unwind_data;
  118.   frame_sniffer_ftype *sniffer;
  119.   frame_dealloc_cache_ftype *dealloc_cache;
  120.   frame_prev_arch_ftype *prev_arch;
  121. };

  122. /* Register a frame unwinder, _prepending_ it to the front of the
  123.    search list (so it is sniffed before previously registered
  124.    unwinders).  By using a prepend, later calls can install unwinders
  125.    that override earlier calls.  This allows, for instance, an OSABI
  126.    to install a more specific sigtramp unwinder that overrides the
  127.    traditional brute-force unwinder.  */
  128. extern void frame_unwind_prepend_unwinder (struct gdbarch *,
  129.                                            const struct frame_unwind *);

  130. /* Add a frame sniffer to the list.  The predicates are polled in the
  131.    order that they are appended.  The initial list contains the dummy
  132.    frame sniffer.  */

  133. extern void frame_unwind_append_unwinder (struct gdbarch *gdbarch,
  134.                                           const struct frame_unwind *unwinder);

  135. /* Iterate through sniffers for THIS_FRAME frame until one returns with an
  136.    unwinder implementation.  THIS_FRAME->UNWIND must be NULL, it will get set
  137.    by this function.  Possibly initialize THIS_CACHE.  */

  138. extern void frame_unwind_find_by_frame (struct frame_info *this_frame,
  139.                                         void **this_cache);

  140. /* Helper functions for value-based register unwinding.  These return
  141.    a (possibly lazy) value of the appropriate type.  */

  142. /* Return a value which indicates that FRAME did not save REGNUM.  */

  143. struct value *frame_unwind_got_optimized (struct frame_info *frame,
  144.                                           int regnum);

  145. /* Return a value which indicates that FRAME copied REGNUM into
  146.    register NEW_REGNUM.  */

  147. struct value *frame_unwind_got_register (struct frame_info *frame, int regnum,
  148.                                          int new_regnum);

  149. /* Return a value which indicates that FRAME saved REGNUM in memory at
  150.    ADDR.  */

  151. struct value *frame_unwind_got_memory (struct frame_info *frame, int regnum,
  152.                                        CORE_ADDR addr);

  153. /* Return a value which indicates that FRAME's saved version of
  154.    REGNUM has a known constant (computed) value of VAL.  */

  155. struct value *frame_unwind_got_constant (struct frame_info *frame, int regnum,
  156.                                          ULONGEST val);

  157. /* Return a value which indicates that FRAME's saved version of
  158.    REGNUM has a known constant (computed) value which is stored
  159.    inside BUF.  */

  160. struct value *frame_unwind_got_bytes (struct frame_info *frame, int regnum,
  161.                                       gdb_byte *buf);

  162. /* Return a value which indicates that FRAME's saved version of REGNUM
  163.    has a known constant (computed) value of ADDR.  Convert the
  164.    CORE_ADDR to a target address if necessary.  */

  165. struct value *frame_unwind_got_address (struct frame_info *frame, int regnum,
  166.                                         CORE_ADDR addr);

  167. #endif