gdb/python/py-frame.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* Python interface to stack frames

  2.    Copyright (C) 2008-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. #include "defs.h"
  15. #include "charset.h"
  16. #include "block.h"
  17. #include "frame.h"
  18. #include "symtab.h"
  19. #include "stack.h"
  20. #include "value.h"
  21. #include "python-internal.h"
  22. #include "symfile.h"
  23. #include "objfiles.h"
  24. #include "user-regs.h"

  25. typedef struct {
  26.   PyObject_HEAD
  27.   struct frame_id frame_id;
  28.   struct gdbarch *gdbarch;

  29.   /* Marks that the FRAME_ID member actually holds the ID of the frame next
  30.      to this, and not this frames' ID itself.  This is a hack to permit Python
  31.      frame objects which represent invalid frames (i.e., the last frame_info
  32.      in a corrupt stack).  The problem arises from the fact that this code
  33.      relies on FRAME_ID to uniquely identify a frame, which is not always true
  34.      for the last "frame" in a corrupt stack (it can have a null ID, or the same
  35.      ID as the  previous frame).  Whenever get_prev_frame returns NULL, we
  36.      record the frame_id of the next frame and set FRAME_ID_IS_NEXT to 1.  */
  37.   int frame_id_is_next;
  38. } frame_object;

  39. /* Require a valid frame.  This must be called inside a TRY_CATCH, or
  40.    another context in which a gdb exception is allowed.  */
  41. #define FRAPY_REQUIRE_VALID(frame_obj, frame)                \
  42.     do {                                                \
  43.       frame = frame_object_to_frame_info (frame_obj);        \
  44.       if (frame == NULL)                                \
  45.         error (_("Frame is invalid."));                        \
  46.     } while (0)

  47. /* Returns the frame_info object corresponding to the given Python Frame
  48.    object.  If the frame doesn't exist anymore (the frame id doesn't
  49.    correspond to any frame in the inferior), returns NULL.  */

  50. struct frame_info *
  51. frame_object_to_frame_info (PyObject *obj)
  52. {
  53.   frame_object *frame_obj = (frame_object *) obj;
  54.   struct frame_info *frame;

  55.   frame = frame_find_by_id (frame_obj->frame_id);
  56.   if (frame == NULL)
  57.     return NULL;

  58.   if (frame_obj->frame_id_is_next)
  59.     frame = get_prev_frame (frame);

  60.   return frame;
  61. }

  62. /* Called by the Python interpreter to obtain string representation
  63.    of the object.  */

  64. static PyObject *
  65. frapy_str (PyObject *self)
  66. {
  67.   char *s;
  68.   PyObject *result;
  69.   struct ui_file *strfile;

  70.   strfile = mem_fileopen ();
  71.   fprint_frame_id (strfile, ((frame_object *) self)->frame_id);
  72.   s = ui_file_xstrdup (strfile, NULL);
  73.   result = PyString_FromString (s);
  74.   xfree (s);

  75.   return result;
  76. }

  77. /* Implementation of gdb.Frame.is_valid (self) -> Boolean.
  78.    Returns True if the frame corresponding to the frame_id of this
  79.    object still exists in the inferior.  */

  80. static PyObject *
  81. frapy_is_valid (PyObject *self, PyObject *args)
  82. {
  83.   struct frame_info *frame = NULL;
  84.   volatile struct gdb_exception except;

  85.   TRY_CATCH (except, RETURN_MASK_ALL)
  86.     {
  87.       frame = frame_object_to_frame_info (self);
  88.     }
  89.   GDB_PY_HANDLE_EXCEPTION (except);

  90.   if (frame == NULL)
  91.     Py_RETURN_FALSE;

  92.   Py_RETURN_TRUE;
  93. }

  94. /* Implementation of gdb.Frame.name (self) -> String.
  95.    Returns the name of the function corresponding to this frame.  */

  96. static PyObject *
  97. frapy_name (PyObject *self, PyObject *args)
  98. {
  99.   struct frame_info *frame;
  100.   char *name = NULL;
  101.   enum language lang;
  102.   PyObject *result;
  103.   volatile struct gdb_exception except;

  104.   TRY_CATCH (except, RETURN_MASK_ALL)
  105.     {
  106.       FRAPY_REQUIRE_VALID (self, frame);

  107.       find_frame_funname (frame, &name, &lang, NULL);
  108.     }

  109.   if (except.reason < 0)
  110.     xfree (name);

  111.   GDB_PY_HANDLE_EXCEPTION (except);

  112.   if (name)
  113.     {
  114.       result = PyUnicode_Decode (name, strlen (name), host_charset (), NULL);
  115.       xfree (name);
  116.     }
  117.   else
  118.     {
  119.       result = Py_None;
  120.       Py_INCREF (Py_None);
  121.     }

  122.   return result;
  123. }

  124. /* Implementation of gdb.Frame.type (self) -> Integer.
  125.    Returns the frame type, namely one of the gdb.*_FRAME constants.  */

  126. static PyObject *
  127. frapy_type (PyObject *self, PyObject *args)
  128. {
  129.   struct frame_info *frame;
  130.   enum frame_type type = NORMAL_FRAME;/* Initialize to appease gcc warning.  */
  131.   volatile struct gdb_exception except;

  132.   TRY_CATCH (except, RETURN_MASK_ALL)
  133.     {
  134.       FRAPY_REQUIRE_VALID (self, frame);

  135.       type = get_frame_type (frame);
  136.     }
  137.   GDB_PY_HANDLE_EXCEPTION (except);

  138.   return PyInt_FromLong (type);
  139. }

  140. /* Implementation of gdb.Frame.architecture (self) -> gdb.Architecture.
  141.    Returns the frame's architecture as a gdb.Architecture object.  */

  142. static PyObject *
  143. frapy_arch (PyObject *self, PyObject *args)
  144. {
  145.   struct frame_info *frame = NULL;    /* Initialize to appease gcc warning.  */
  146.   frame_object *obj = (frame_object *) self;
  147.   volatile struct gdb_exception except;

  148.   TRY_CATCH (except, RETURN_MASK_ALL)
  149.     {
  150.       FRAPY_REQUIRE_VALID (self, frame);
  151.     }
  152.   GDB_PY_HANDLE_EXCEPTION (except);

  153.   return gdbarch_to_arch_object (obj->gdbarch);
  154. }

  155. /* Implementation of gdb.Frame.unwind_stop_reason (self) -> Integer.
  156.    Returns one of the gdb.FRAME_UNWIND_* constants.  */

  157. static PyObject *
  158. frapy_unwind_stop_reason (PyObject *self, PyObject *args)
  159. {
  160.   struct frame_info *frame = NULL;    /* Initialize to appease gcc warning.  */
  161.   volatile struct gdb_exception except;
  162.   enum unwind_stop_reason stop_reason;

  163.   TRY_CATCH (except, RETURN_MASK_ALL)
  164.     {
  165.       FRAPY_REQUIRE_VALID (self, frame);
  166.     }
  167.   GDB_PY_HANDLE_EXCEPTION (except);

  168.   stop_reason = get_frame_unwind_stop_reason (frame);

  169.   return PyInt_FromLong (stop_reason);
  170. }

  171. /* Implementation of gdb.Frame.pc (self) -> Long.
  172.    Returns the frame's resume address.  */

  173. static PyObject *
  174. frapy_pc (PyObject *self, PyObject *args)
  175. {
  176.   CORE_ADDR pc = 0;              /* Initialize to appease gcc warning.  */
  177.   struct frame_info *frame;
  178.   volatile struct gdb_exception except;

  179.   TRY_CATCH (except, RETURN_MASK_ALL)
  180.     {
  181.       FRAPY_REQUIRE_VALID (self, frame);

  182.       pc = get_frame_pc (frame);
  183.     }
  184.   GDB_PY_HANDLE_EXCEPTION (except);

  185.   return gdb_py_long_from_ulongest (pc);
  186. }

  187. /* Implementation of gdb.Frame.read_register (self, register) -> gdb.Value.
  188.    Returns the value of a register in this frame.  */

  189. static PyObject *
  190. frapy_read_register (PyObject *self, PyObject *args)
  191. {
  192.   volatile struct gdb_exception except;
  193.   const char *regnum_str;
  194.   struct value *val = NULL;

  195.   if (!PyArg_ParseTuple (args, "s", &regnum_str))
  196.     return NULL;

  197.   TRY_CATCH (except, RETURN_MASK_ALL)
  198.     {
  199.       struct frame_info *frame;
  200.       int regnum;

  201.       FRAPY_REQUIRE_VALID (self, frame);

  202.       regnum = user_reg_map_name_to_regnum (get_frame_arch (frame),
  203.                                             regnum_str,
  204.                                             strlen (regnum_str));
  205.       if (regnum >= 0)
  206.         val = value_of_register (regnum, frame);

  207.       if (val == NULL)
  208.         PyErr_SetString (PyExc_ValueError, _("Unknown register."));
  209.     }
  210.   GDB_PY_HANDLE_EXCEPTION (except);

  211.   return val == NULL ? NULL : value_to_value_object (val);
  212. }

  213. /* Implementation of gdb.Frame.block (self) -> gdb.Block.
  214.    Returns the frame's code block.  */

  215. static PyObject *
  216. frapy_block (PyObject *self, PyObject *args)
  217. {
  218.   struct frame_info *frame;
  219.   const struct block *block = NULL, *fn_block;
  220.   volatile struct gdb_exception except;

  221.   TRY_CATCH (except, RETURN_MASK_ALL)
  222.     {
  223.       FRAPY_REQUIRE_VALID (self, frame);
  224.       block = get_frame_block (frame, NULL);
  225.     }
  226.   GDB_PY_HANDLE_EXCEPTION (except);

  227.   for (fn_block = block;
  228.        fn_block != NULL && BLOCK_FUNCTION (fn_block) == NULL;
  229.        fn_block = BLOCK_SUPERBLOCK (fn_block))
  230.     ;

  231.   if (block == NULL || fn_block == NULL || BLOCK_FUNCTION (fn_block) == NULL)
  232.     {
  233.       PyErr_SetString (PyExc_RuntimeError,
  234.                        _("Cannot locate block for frame."));
  235.       return NULL;
  236.     }

  237.   if (block)
  238.     {
  239.       return block_to_block_object
  240.         (block, symbol_objfile (BLOCK_FUNCTION (fn_block)));
  241.     }

  242.   Py_RETURN_NONE;
  243. }


  244. /* Implementation of gdb.Frame.function (self) -> gdb.Symbol.
  245.    Returns the symbol for the function corresponding to this frame.  */

  246. static PyObject *
  247. frapy_function (PyObject *self, PyObject *args)
  248. {
  249.   struct symbol *sym = NULL;
  250.   struct frame_info *frame;
  251.   volatile struct gdb_exception except;

  252.   TRY_CATCH (except, RETURN_MASK_ALL)
  253.     {
  254.       FRAPY_REQUIRE_VALID (self, frame);

  255.       sym = find_pc_function (get_frame_address_in_block (frame));
  256.     }
  257.   GDB_PY_HANDLE_EXCEPTION (except);

  258.   if (sym)
  259.     return symbol_to_symbol_object (sym);

  260.   Py_RETURN_NONE;
  261. }

  262. /* Convert a frame_info struct to a Python Frame object.
  263.    Sets a Python exception and returns NULL on error.  */

  264. PyObject *
  265. frame_info_to_frame_object (struct frame_info *frame)
  266. {
  267.   frame_object *frame_obj;
  268.   volatile struct gdb_exception except;

  269.   frame_obj = PyObject_New (frame_object, &frame_object_type);
  270.   if (frame_obj == NULL)
  271.     return NULL;

  272.   TRY_CATCH (except, RETURN_MASK_ALL)
  273.     {

  274.       /* Try to get the previous frame, to determine if this is the last frame
  275.          in a corrupt stack.  If so, we need to store the frame_id of the next
  276.          frame and not of this one (which is possibly invalid).  */
  277.       if (get_prev_frame (frame) == NULL
  278.           && get_frame_unwind_stop_reason (frame) != UNWIND_NO_REASON
  279.           && get_next_frame (frame) != NULL)
  280.         {
  281.           frame_obj->frame_id = get_frame_id (get_next_frame (frame));
  282.           frame_obj->frame_id_is_next = 1;
  283.         }
  284.       else
  285.         {
  286.           frame_obj->frame_id = get_frame_id (frame);
  287.           frame_obj->frame_id_is_next = 0;
  288.         }
  289.       frame_obj->gdbarch = get_frame_arch (frame);
  290.     }
  291.   if (except.reason < 0)
  292.     {
  293.       Py_DECREF (frame_obj);
  294.       gdbpy_convert_exception (except);
  295.       return NULL;
  296.     }
  297.   return (PyObject *) frame_obj;
  298. }

  299. /* Implementation of gdb.Frame.older (self) -> gdb.Frame.
  300.    Returns the frame immediately older (outer) to this frame, or None if
  301.    there isn't one.  */

  302. static PyObject *
  303. frapy_older (PyObject *self, PyObject *args)
  304. {
  305.   struct frame_info *frame, *prev = NULL;
  306.   volatile struct gdb_exception except;
  307.   PyObject *prev_obj = NULL;   /* Initialize to appease gcc warning.  */

  308.   TRY_CATCH (except, RETURN_MASK_ALL)
  309.     {
  310.       FRAPY_REQUIRE_VALID (self, frame);

  311.       prev = get_prev_frame (frame);
  312.     }
  313.   GDB_PY_HANDLE_EXCEPTION (except);

  314.   if (prev)
  315.     prev_obj = (PyObject *) frame_info_to_frame_object (prev);
  316.   else
  317.     {
  318.       Py_INCREF (Py_None);
  319.       prev_obj = Py_None;
  320.     }

  321.   return prev_obj;
  322. }

  323. /* Implementation of gdb.Frame.newer (self) -> gdb.Frame.
  324.    Returns the frame immediately newer (inner) to this frame, or None if
  325.    there isn't one.  */

  326. static PyObject *
  327. frapy_newer (PyObject *self, PyObject *args)
  328. {
  329.   struct frame_info *frame, *next = NULL;
  330.   volatile struct gdb_exception except;
  331.   PyObject *next_obj = NULL;   /* Initialize to appease gcc warning.  */

  332.   TRY_CATCH (except, RETURN_MASK_ALL)
  333.     {
  334.       FRAPY_REQUIRE_VALID (self, frame);

  335.       next = get_next_frame (frame);
  336.     }
  337.   GDB_PY_HANDLE_EXCEPTION (except);

  338.   if (next)
  339.     next_obj = (PyObject *) frame_info_to_frame_object (next);
  340.   else
  341.     {
  342.       Py_INCREF (Py_None);
  343.       next_obj = Py_None;
  344.     }

  345.   return next_obj;
  346. }

  347. /* Implementation of gdb.Frame.find_sal (self) -> gdb.Symtab_and_line.
  348.    Returns the frame's symtab and line.  */

  349. static PyObject *
  350. frapy_find_sal (PyObject *self, PyObject *args)
  351. {
  352.   struct frame_info *frame;
  353.   struct symtab_and_line sal;
  354.   volatile struct gdb_exception except;
  355.   PyObject *sal_obj = NULL;   /* Initialize to appease gcc warning.  */

  356.   TRY_CATCH (except, RETURN_MASK_ALL)
  357.     {
  358.       FRAPY_REQUIRE_VALID (self, frame);

  359.       find_frame_sal (frame, &sal);
  360.       sal_obj = symtab_and_line_to_sal_object (sal);
  361.     }
  362.   GDB_PY_HANDLE_EXCEPTION (except);

  363.   return sal_obj;
  364. }

  365. /* Implementation of gdb.Frame.read_var_value (self, variable,
  366.    [block]) -> gdb.Value.  If the optional block argument is provided
  367.    start the search from that block, otherwise search from the frame's
  368.    current block (determined by examining the resume address of the
  369.    frame).  The variable argument must be a string or an instance of a
  370.    gdb.Symbol.  The block argument must be an instance of gdb.Block.  Returns
  371.    NULL on error, with a python exception set.  */
  372. static PyObject *
  373. frapy_read_var (PyObject *self, PyObject *args)
  374. {
  375.   struct frame_info *frame;
  376.   PyObject *sym_obj, *block_obj = NULL;
  377.   struct symbol *var = NULL;        /* gcc-4.3.2 false warning.  */
  378.   struct value *val = NULL;
  379.   volatile struct gdb_exception except;

  380.   if (!PyArg_ParseTuple (args, "O|O", &sym_obj, &block_obj))
  381.     return NULL;

  382.   if (PyObject_TypeCheck (sym_obj, &symbol_object_type))
  383.     var = symbol_object_to_symbol (sym_obj);
  384.   else if (gdbpy_is_string (sym_obj))
  385.     {
  386.       char *var_name;
  387.       const struct block *block = NULL;
  388.       struct cleanup *cleanup;
  389.       volatile struct gdb_exception except;

  390.       var_name = python_string_to_target_string (sym_obj);
  391.       if (!var_name)
  392.         return NULL;
  393.       cleanup = make_cleanup (xfree, var_name);

  394.       if (block_obj)
  395.         {
  396.           block = block_object_to_block (block_obj);
  397.           if (!block)
  398.             {
  399.               PyErr_SetString (PyExc_RuntimeError,
  400.                                _("Second argument must be block."));
  401.               do_cleanups (cleanup);
  402.               return NULL;
  403.             }
  404.         }

  405.       TRY_CATCH (except, RETURN_MASK_ALL)
  406.         {
  407.           FRAPY_REQUIRE_VALID (self, frame);

  408.           if (!block)
  409.             block = get_frame_block (frame, NULL);
  410.           var = lookup_symbol (var_name, block, VAR_DOMAIN, NULL);
  411.         }
  412.       if (except.reason < 0)
  413.         {
  414.           do_cleanups (cleanup);
  415.           gdbpy_convert_exception (except);
  416.           return NULL;
  417.         }

  418.       if (!var)
  419.         {
  420.           PyErr_Format (PyExc_ValueError,
  421.                         _("Variable '%s' not found."), var_name);
  422.           do_cleanups (cleanup);

  423.           return NULL;
  424.         }

  425.       do_cleanups (cleanup);
  426.     }
  427.   else
  428.     {
  429.       PyErr_SetString (PyExc_TypeError,
  430.                        _("Argument must be a symbol or string."));
  431.       return NULL;
  432.     }

  433.   TRY_CATCH (except, RETURN_MASK_ALL)
  434.     {
  435.       FRAPY_REQUIRE_VALID (self, frame);

  436.       val = read_var_value (var, frame);
  437.     }
  438.   GDB_PY_HANDLE_EXCEPTION (except);

  439.   return value_to_value_object (val);
  440. }

  441. /* Select this frame.  */

  442. static PyObject *
  443. frapy_select (PyObject *self, PyObject *args)
  444. {
  445.   struct frame_info *fi;
  446.   volatile struct gdb_exception except;

  447.   TRY_CATCH (except, RETURN_MASK_ALL)
  448.     {
  449.       FRAPY_REQUIRE_VALID (self, fi);

  450.       select_frame (fi);
  451.     }
  452.   GDB_PY_HANDLE_EXCEPTION (except);

  453.   Py_RETURN_NONE;
  454. }

  455. /* Implementation of gdb.newest_frame () -> gdb.Frame.
  456.    Returns the newest frame object.  */

  457. PyObject *
  458. gdbpy_newest_frame (PyObject *self, PyObject *args)
  459. {
  460.   struct frame_info *frame = NULL;
  461.   volatile struct gdb_exception except;

  462.   TRY_CATCH (except, RETURN_MASK_ALL)
  463.     {
  464.       frame = get_current_frame ();
  465.     }
  466.   GDB_PY_HANDLE_EXCEPTION (except);

  467.   return frame_info_to_frame_object (frame);
  468. }

  469. /* Implementation of gdb.selected_frame () -> gdb.Frame.
  470.    Returns the selected frame object.  */

  471. PyObject *
  472. gdbpy_selected_frame (PyObject *self, PyObject *args)
  473. {
  474.   struct frame_info *frame = NULL;
  475.   volatile struct gdb_exception except;

  476.   TRY_CATCH (except, RETURN_MASK_ALL)
  477.     {
  478.       frame = get_selected_frame ("No frame is currently selected.");
  479.     }
  480.   GDB_PY_HANDLE_EXCEPTION (except);

  481.   return frame_info_to_frame_object (frame);
  482. }

  483. /* Implementation of gdb.stop_reason_string (Integer) -> String.
  484.    Return a string explaining the unwind stop reason.  */

  485. PyObject *
  486. gdbpy_frame_stop_reason_string (PyObject *self, PyObject *args)
  487. {
  488.   int reason;
  489.   const char *str;

  490.   if (!PyArg_ParseTuple (args, "i", &reason))
  491.     return NULL;

  492.   if (reason < UNWIND_FIRST || reason > UNWIND_LAST)
  493.     {
  494.       PyErr_SetString (PyExc_ValueError,
  495.                        _("Invalid frame stop reason."));
  496.       return NULL;
  497.     }

  498.   str = unwind_stop_reason_to_string (reason);
  499.   return PyUnicode_Decode (str, strlen (str), host_charset (), NULL);
  500. }

  501. /* Implements the equality comparison for Frame objects.
  502.    All other comparison operators will throw a TypeError Python exception,
  503.    as they aren't valid for frames.  */

  504. static PyObject *
  505. frapy_richcompare (PyObject *self, PyObject *other, int op)
  506. {
  507.   int result;

  508.   if (!PyObject_TypeCheck (other, &frame_object_type)
  509.       || (op != Py_EQ && op != Py_NE))
  510.     {
  511.       Py_INCREF (Py_NotImplemented);
  512.       return Py_NotImplemented;
  513.     }

  514.   if (frame_id_eq (((frame_object *) self)->frame_id,
  515.                    ((frame_object *) other)->frame_id))
  516.     result = Py_EQ;
  517.   else
  518.     result = Py_NE;

  519.   if (op == result)
  520.     Py_RETURN_TRUE;
  521.   Py_RETURN_FALSE;
  522. }

  523. /* Sets up the Frame API in the gdb module.  */

  524. int
  525. gdbpy_initialize_frames (void)
  526. {
  527.   frame_object_type.tp_new = PyType_GenericNew;
  528.   if (PyType_Ready (&frame_object_type) < 0)
  529.     return -1;

  530.   /* Note: These would probably be best exposed as class attributes of
  531.      Frame, but I don't know how to do it except by messing with the
  532.      type's dictionary.  That seems too messy.  */
  533.   if (PyModule_AddIntConstant (gdb_module, "NORMAL_FRAME", NORMAL_FRAME) < 0
  534.       || PyModule_AddIntConstant (gdb_module, "DUMMY_FRAME", DUMMY_FRAME) < 0
  535.       || PyModule_AddIntConstant (gdb_module, "INLINE_FRAME", INLINE_FRAME) < 0
  536.       || PyModule_AddIntConstant (gdb_module, "TAILCALL_FRAME",
  537.                                   TAILCALL_FRAME) < 0
  538.       || PyModule_AddIntConstant (gdb_module, "SIGTRAMP_FRAME",
  539.                                   SIGTRAMP_FRAME) < 0
  540.       || PyModule_AddIntConstant (gdb_module, "ARCH_FRAME", ARCH_FRAME) < 0
  541.       || PyModule_AddIntConstant (gdb_module, "SENTINEL_FRAME",
  542.                                   SENTINEL_FRAME) < 0)
  543.     return -1;

  544. #define SET(name, description) \
  545.   if (PyModule_AddIntConstant (gdb_module, "FRAME_"#name, name) < 0) \
  546.     return -1;
  547. #include "unwind_stop_reasons.def"
  548. #undef SET

  549.   return gdb_pymodule_addobject (gdb_module, "Frame",
  550.                                  (PyObject *) &frame_object_type);
  551. }



  552. static PyMethodDef frame_object_methods[] = {
  553.   { "is_valid", frapy_is_valid, METH_NOARGS,
  554.     "is_valid () -> Boolean.\n\
  555. Return true if this frame is valid, false if not." },
  556.   { "name", frapy_name, METH_NOARGS,
  557.     "name () -> String.\n\
  558. Return the function name of the frame, or None if it can't be determined." },
  559.   { "type", frapy_type, METH_NOARGS,
  560.     "type () -> Integer.\n\
  561. Return the type of the frame." },
  562.   { "architecture", frapy_arch, METH_NOARGS,
  563.     "architecture () -> gdb.Architecture.\n\
  564. Return the architecture of the frame." },
  565.   { "unwind_stop_reason", frapy_unwind_stop_reason, METH_NOARGS,
  566.     "unwind_stop_reason () -> Integer.\n\
  567. Return the reason why it's not possible to find frames older than this." },
  568.   { "pc", frapy_pc, METH_NOARGS,
  569.     "pc () -> Long.\n\
  570. Return the frame's resume address." },
  571.   { "read_register", frapy_read_register, METH_VARARGS,
  572.     "read_register (register_name) -> gdb.Value\n\
  573. Return the value of the register in the frame." },
  574.   { "block", frapy_block, METH_NOARGS,
  575.     "block () -> gdb.Block.\n\
  576. Return the frame's code block." },
  577.   { "function", frapy_function, METH_NOARGS,
  578.     "function () -> gdb.Symbol.\n\
  579. Returns the symbol for the function corresponding to this frame." },
  580.   { "older", frapy_older, METH_NOARGS,
  581.     "older () -> gdb.Frame.\n\
  582. Return the frame that called this frame." },
  583.   { "newer", frapy_newer, METH_NOARGS,
  584.     "newer () -> gdb.Frame.\n\
  585. Return the frame called by this frame." },
  586.   { "find_sal", frapy_find_sal, METH_NOARGS,
  587.     "find_sal () -> gdb.Symtab_and_line.\n\
  588. Return the frame's symtab and line." },
  589.   { "read_var", frapy_read_var, METH_VARARGS,
  590.     "read_var (variable) -> gdb.Value.\n\
  591. Return the value of the variable in this frame." },
  592.   { "select", frapy_select, METH_NOARGS,
  593.     "Select this frame as the user's current frame." },
  594.   {NULL/* Sentinel */
  595. };

  596. PyTypeObject frame_object_type = {
  597.   PyVarObject_HEAD_INIT (NULL, 0)
  598.   "gdb.Frame",                          /* tp_name */
  599.   sizeof (frame_object),          /* tp_basicsize */
  600.   0,                                  /* tp_itemsize */
  601.   0,                                  /* tp_dealloc */
  602.   0,                                  /* tp_print */
  603.   0,                                  /* tp_getattr */
  604.   0,                                  /* tp_setattr */
  605.   0,                                  /* tp_compare */
  606.   0,                                  /* tp_repr */
  607.   0,                                  /* tp_as_number */
  608.   0,                                  /* tp_as_sequence */
  609.   0,                                  /* tp_as_mapping */
  610.   0,                                  /* tp_hash  */
  611.   0,                                  /* tp_call */
  612.   frapy_str,                          /* tp_str */
  613.   0,                                  /* tp_getattro */
  614.   0,                                  /* tp_setattro */
  615.   0,                                  /* tp_as_buffer */
  616.   Py_TPFLAGS_DEFAULT,                  /* tp_flags */
  617.   "GDB frame object",                  /* tp_doc */
  618.   0,                                  /* tp_traverse */
  619.   0,                                  /* tp_clear */
  620.   frapy_richcompare,                  /* tp_richcompare */
  621.   0,                                  /* tp_weaklistoffset */
  622.   0,                                  /* tp_iter */
  623.   0,                                  /* tp_iternext */
  624.   frame_object_methods,                  /* tp_methods */
  625.   0,                                  /* tp_members */
  626.   0,                                  /* tp_getset */
  627.   0,                                  /* tp_base */
  628.   0,                                  /* tp_dict */
  629.   0,                                  /* tp_descr_get */
  630.   0,                                  /* tp_descr_set */
  631.   0,                                  /* tp_dictoffset */
  632.   0,                                  /* tp_init */
  633.   0,                                  /* tp_alloc */
  634. };