Home | History | Annotate | Line # | Download | only in python
py-block.c revision 1.5
      1  1.1  christos /* Python interface to blocks.
      2  1.1  christos 
      3  1.3  christos    Copyright (C) 2008-2015 Free Software Foundation, Inc.
      4  1.1  christos 
      5  1.1  christos    This file is part of GDB.
      6  1.1  christos 
      7  1.1  christos    This program is free software; you can redistribute it and/or modify
      8  1.1  christos    it under the terms of the GNU General Public License as published by
      9  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10  1.1  christos    (at your option) any later version.
     11  1.1  christos 
     12  1.1  christos    This program is distributed in the hope that it will be useful,
     13  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  1.1  christos    GNU General Public License for more details.
     16  1.1  christos 
     17  1.1  christos    You should have received a copy of the GNU General Public License
     18  1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19  1.1  christos 
     20  1.1  christos #include "defs.h"
     21  1.1  christos #include "block.h"
     22  1.1  christos #include "dictionary.h"
     23  1.1  christos #include "symtab.h"
     24  1.1  christos #include "python-internal.h"
     25  1.1  christos #include "objfiles.h"
     26  1.1  christos #include "symtab.h"
     27  1.1  christos 
     28  1.1  christos typedef struct blpy_block_object {
     29  1.1  christos   PyObject_HEAD
     30  1.1  christos   /* The GDB block structure that represents a frame's code block.  */
     31  1.1  christos   const struct block *block;
     32  1.1  christos   /* The backing object file.  There is no direct relationship in GDB
     33  1.1  christos      between a block and an object file.  When a block is created also
     34  1.1  christos      store a pointer to the object file for later use.  */
     35  1.1  christos   struct objfile *objfile;
     36  1.1  christos   /* Keep track of all blocks with a doubly-linked list.  Needed for
     37  1.1  christos      block invalidation if the source object file has been freed.  */
     38  1.1  christos   struct blpy_block_object *prev;
     39  1.1  christos   struct blpy_block_object *next;
     40  1.1  christos } block_object;
     41  1.1  christos 
     42  1.1  christos typedef struct {
     43  1.1  christos   PyObject_HEAD
     44  1.1  christos   /* The block.  */
     45  1.1  christos   const struct block *block;
     46  1.1  christos   /* The iterator for that block.  */
     47  1.1  christos   struct block_iterator iter;
     48  1.1  christos   /* Has the iterator been initialized flag.  */
     49  1.1  christos   int initialized_p;
     50  1.1  christos   /* Pointer back to the original source block object.  Needed to
     51  1.1  christos      check if the block is still valid, and has not been invalidated
     52  1.1  christos      when an object file has been freed.  */
     53  1.1  christos   struct blpy_block_object *source;
     54  1.1  christos } block_syms_iterator_object;
     55  1.1  christos 
     56  1.1  christos /* Require a valid block.  All access to block_object->block should be
     57  1.1  christos    gated by this call.  */
     58  1.1  christos #define BLPY_REQUIRE_VALID(block_obj, block)		\
     59  1.1  christos   do {							\
     60  1.1  christos     block = block_object_to_block (block_obj);		\
     61  1.1  christos     if (block == NULL)					\
     62  1.1  christos       {							\
     63  1.1  christos 	PyErr_SetString (PyExc_RuntimeError,		\
     64  1.1  christos 			 _("Block is invalid."));	\
     65  1.1  christos 	return NULL;					\
     66  1.1  christos       }							\
     67  1.1  christos   } while (0)
     68  1.1  christos 
     69  1.1  christos /* Require a valid block.  This macro is called during block iterator
     70  1.1  christos    creation, and at each next call.  */
     71  1.1  christos #define BLPY_ITER_REQUIRE_VALID(block_obj)				\
     72  1.1  christos   do {									\
     73  1.1  christos     if (block_obj->block == NULL)					\
     74  1.1  christos       {									\
     75  1.1  christos 	PyErr_SetString (PyExc_RuntimeError,				\
     76  1.1  christos 			 _("Source block for iterator is invalid."));	\
     77  1.1  christos 	return NULL;							\
     78  1.1  christos       }									\
     79  1.1  christos   } while (0)
     80  1.1  christos 
     81  1.5  christos extern PyTypeObject block_syms_iterator_object_type
     82  1.1  christos     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("block_syms_iterator_object");
     83  1.1  christos static const struct objfile_data *blpy_objfile_data_key;
     84  1.1  christos 
     85  1.1  christos static PyObject *
     86  1.1  christos blpy_iter (PyObject *self)
     87  1.1  christos {
     88  1.1  christos   block_syms_iterator_object *block_iter_obj;
     89  1.1  christos   const struct block *block = NULL;
     90  1.1  christos 
     91  1.1  christos   BLPY_REQUIRE_VALID (self, block);
     92  1.1  christos 
     93  1.1  christos   block_iter_obj = PyObject_New (block_syms_iterator_object,
     94  1.1  christos 				 &block_syms_iterator_object_type);
     95  1.1  christos   if (block_iter_obj == NULL)
     96  1.1  christos       return NULL;
     97  1.1  christos 
     98  1.1  christos   block_iter_obj->block = block;
     99  1.1  christos   block_iter_obj->initialized_p = 0;
    100  1.1  christos   Py_INCREF (self);
    101  1.1  christos   block_iter_obj->source = (block_object *) self;
    102  1.1  christos 
    103  1.1  christos   return (PyObject *) block_iter_obj;
    104  1.1  christos }
    105  1.1  christos 
    106  1.1  christos static PyObject *
    107  1.1  christos blpy_get_start (PyObject *self, void *closure)
    108  1.1  christos {
    109  1.1  christos   const struct block *block = NULL;
    110  1.1  christos 
    111  1.1  christos   BLPY_REQUIRE_VALID (self, block);
    112  1.1  christos 
    113  1.1  christos   return gdb_py_object_from_ulongest (BLOCK_START (block));
    114  1.1  christos }
    115  1.1  christos 
    116  1.1  christos static PyObject *
    117  1.1  christos blpy_get_end (PyObject *self, void *closure)
    118  1.1  christos {
    119  1.1  christos   const struct block *block = NULL;
    120  1.1  christos 
    121  1.1  christos   BLPY_REQUIRE_VALID (self, block);
    122  1.1  christos 
    123  1.1  christos   return gdb_py_object_from_ulongest (BLOCK_END (block));
    124  1.1  christos }
    125  1.1  christos 
    126  1.1  christos static PyObject *
    127  1.1  christos blpy_get_function (PyObject *self, void *closure)
    128  1.1  christos {
    129  1.1  christos   struct symbol *sym;
    130  1.1  christos   const struct block *block;
    131  1.1  christos 
    132  1.1  christos   BLPY_REQUIRE_VALID (self, block);
    133  1.1  christos 
    134  1.1  christos   sym = BLOCK_FUNCTION (block);
    135  1.1  christos   if (sym)
    136  1.1  christos     return symbol_to_symbol_object (sym);
    137  1.1  christos 
    138  1.1  christos   Py_RETURN_NONE;
    139  1.1  christos }
    140  1.1  christos 
    141  1.1  christos static PyObject *
    142  1.1  christos blpy_get_superblock (PyObject *self, void *closure)
    143  1.1  christos {
    144  1.1  christos   const struct block *block;
    145  1.1  christos   const struct block *super_block;
    146  1.1  christos   block_object *self_obj  = (block_object *) self;
    147  1.1  christos 
    148  1.1  christos   BLPY_REQUIRE_VALID (self, block);
    149  1.1  christos 
    150  1.1  christos   super_block = BLOCK_SUPERBLOCK (block);
    151  1.1  christos   if (super_block)
    152  1.1  christos     return block_to_block_object (super_block, self_obj->objfile);
    153  1.1  christos 
    154  1.1  christos   Py_RETURN_NONE;
    155  1.1  christos }
    156  1.1  christos 
    157  1.1  christos /* Return the global block associated to this block.  */
    158  1.1  christos 
    159  1.1  christos static PyObject *
    160  1.1  christos blpy_get_global_block (PyObject *self, void *closure)
    161  1.1  christos {
    162  1.1  christos   const struct block *block;
    163  1.1  christos   const struct block *global_block;
    164  1.1  christos   block_object *self_obj  = (block_object *) self;
    165  1.1  christos 
    166  1.1  christos   BLPY_REQUIRE_VALID (self, block);
    167  1.1  christos 
    168  1.1  christos   global_block = block_global_block (block);
    169  1.1  christos 
    170  1.1  christos   return block_to_block_object (global_block,
    171  1.1  christos 				self_obj->objfile);
    172  1.1  christos 
    173  1.1  christos }
    174  1.1  christos 
    175  1.1  christos /* Return the static block associated to this block.  Return None
    176  1.1  christos    if we cannot get the static block (this is the global block).  */
    177  1.1  christos 
    178  1.1  christos static PyObject *
    179  1.1  christos blpy_get_static_block (PyObject *self, void *closure)
    180  1.1  christos {
    181  1.1  christos   const struct block *block;
    182  1.1  christos   const struct block *static_block;
    183  1.1  christos   block_object *self_obj  = (block_object *) self;
    184  1.1  christos 
    185  1.1  christos   BLPY_REQUIRE_VALID (self, block);
    186  1.1  christos 
    187  1.1  christos   if (BLOCK_SUPERBLOCK (block) == NULL)
    188  1.1  christos     Py_RETURN_NONE;
    189  1.1  christos 
    190  1.1  christos   static_block = block_static_block (block);
    191  1.1  christos 
    192  1.1  christos   return block_to_block_object (static_block, self_obj->objfile);
    193  1.1  christos }
    194  1.1  christos 
    195  1.1  christos /* Implementation of gdb.Block.is_global (self) -> Boolean.
    196  1.1  christos    Returns True if this block object is a global block.  */
    197  1.1  christos 
    198  1.1  christos static PyObject *
    199  1.1  christos blpy_is_global (PyObject *self, void *closure)
    200  1.1  christos {
    201  1.1  christos   const struct block *block;
    202  1.1  christos 
    203  1.1  christos   BLPY_REQUIRE_VALID (self, block);
    204  1.1  christos 
    205  1.1  christos   if (BLOCK_SUPERBLOCK (block))
    206  1.1  christos     Py_RETURN_FALSE;
    207  1.1  christos 
    208  1.1  christos   Py_RETURN_TRUE;
    209  1.1  christos }
    210  1.1  christos 
    211  1.1  christos /* Implementation of gdb.Block.is_static (self) -> Boolean.
    212  1.1  christos    Returns True if this block object is a static block.  */
    213  1.1  christos 
    214  1.1  christos static PyObject *
    215  1.1  christos blpy_is_static (PyObject *self, void *closure)
    216  1.1  christos {
    217  1.1  christos   const struct block *block;
    218  1.1  christos 
    219  1.1  christos   BLPY_REQUIRE_VALID (self, block);
    220  1.1  christos 
    221  1.1  christos   if (BLOCK_SUPERBLOCK (block) != NULL
    222  1.1  christos      && BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL)
    223  1.1  christos     Py_RETURN_TRUE;
    224  1.1  christos 
    225  1.1  christos   Py_RETURN_FALSE;
    226  1.1  christos }
    227  1.1  christos 
    228  1.1  christos static void
    229  1.1  christos blpy_dealloc (PyObject *obj)
    230  1.1  christos {
    231  1.1  christos   block_object *block = (block_object *) obj;
    232  1.1  christos 
    233  1.1  christos   if (block->prev)
    234  1.1  christos     block->prev->next = block->next;
    235  1.1  christos   else if (block->objfile)
    236  1.1  christos     {
    237  1.1  christos       set_objfile_data (block->objfile, blpy_objfile_data_key,
    238  1.1  christos 			block->next);
    239  1.1  christos     }
    240  1.1  christos   if (block->next)
    241  1.1  christos     block->next->prev = block->prev;
    242  1.1  christos   block->block = NULL;
    243  1.1  christos }
    244  1.1  christos 
    245  1.1  christos /* Given a block, and a block_object that has previously been
    246  1.1  christos    allocated and initialized, populate the block_object with the
    247  1.1  christos    struct block data.  Also, register the block_object life-cycle
    248  1.1  christos    with the life-cycle of the object file associated with this
    249  1.1  christos    block, if needed.  */
    250  1.1  christos static void
    251  1.1  christos set_block (block_object *obj, const struct block *block,
    252  1.1  christos 	   struct objfile *objfile)
    253  1.1  christos {
    254  1.1  christos   obj->block = block;
    255  1.1  christos   obj->prev = NULL;
    256  1.1  christos   if (objfile)
    257  1.1  christos     {
    258  1.1  christos       obj->objfile = objfile;
    259  1.1  christos       obj->next = objfile_data (objfile, blpy_objfile_data_key);
    260  1.1  christos       if (obj->next)
    261  1.1  christos 	obj->next->prev = obj;
    262  1.1  christos       set_objfile_data (objfile, blpy_objfile_data_key, obj);
    263  1.1  christos     }
    264  1.1  christos   else
    265  1.1  christos     obj->next = NULL;
    266  1.1  christos }
    267  1.1  christos 
    268  1.1  christos /* Create a new block object (gdb.Block) that encapsulates the struct
    269  1.1  christos    block object from GDB.  */
    270  1.1  christos PyObject *
    271  1.1  christos block_to_block_object (const struct block *block, struct objfile *objfile)
    272  1.1  christos {
    273  1.1  christos   block_object *block_obj;
    274  1.1  christos 
    275  1.1  christos   block_obj = PyObject_New (block_object, &block_object_type);
    276  1.1  christos   if (block_obj)
    277  1.1  christos     set_block (block_obj, block, objfile);
    278  1.1  christos 
    279  1.1  christos   return (PyObject *) block_obj;
    280  1.1  christos }
    281  1.1  christos 
    282  1.1  christos /* Return struct block reference that is wrapped by this object.  */
    283  1.1  christos const struct block *
    284  1.1  christos block_object_to_block (PyObject *obj)
    285  1.1  christos {
    286  1.1  christos   if (! PyObject_TypeCheck (obj, &block_object_type))
    287  1.1  christos     return NULL;
    288  1.1  christos   return ((block_object *) obj)->block;
    289  1.1  christos }
    290  1.1  christos 
    291  1.1  christos /* Return a reference to the block iterator.  */
    292  1.1  christos static PyObject *
    293  1.1  christos blpy_block_syms_iter (PyObject *self)
    294  1.1  christos {
    295  1.1  christos   block_syms_iterator_object *iter_obj = (block_syms_iterator_object *) self;
    296  1.1  christos 
    297  1.1  christos   BLPY_ITER_REQUIRE_VALID (iter_obj->source);
    298  1.1  christos 
    299  1.1  christos   Py_INCREF (self);
    300  1.1  christos   return self;
    301  1.1  christos }
    302  1.1  christos 
    303  1.1  christos /* Return the next symbol in the iteration through the block's
    304  1.1  christos    dictionary.  */
    305  1.1  christos static PyObject *
    306  1.1  christos blpy_block_syms_iternext (PyObject *self)
    307  1.1  christos {
    308  1.1  christos   block_syms_iterator_object *iter_obj = (block_syms_iterator_object *) self;
    309  1.1  christos   struct symbol *sym;
    310  1.1  christos 
    311  1.1  christos   BLPY_ITER_REQUIRE_VALID (iter_obj->source);
    312  1.1  christos 
    313  1.1  christos   if (!iter_obj->initialized_p)
    314  1.1  christos     {
    315  1.1  christos       sym = block_iterator_first (iter_obj->block,  &(iter_obj->iter));
    316  1.1  christos       iter_obj->initialized_p = 1;
    317  1.1  christos     }
    318  1.1  christos   else
    319  1.1  christos     sym = block_iterator_next (&(iter_obj->iter));
    320  1.1  christos 
    321  1.1  christos   if (sym == NULL)
    322  1.1  christos     {
    323  1.1  christos       PyErr_SetString (PyExc_StopIteration, _("Symbol is null."));
    324  1.1  christos       return NULL;
    325  1.1  christos     }
    326  1.1  christos 
    327  1.1  christos   return symbol_to_symbol_object (sym);
    328  1.1  christos }
    329  1.1  christos 
    330  1.1  christos static void
    331  1.1  christos blpy_block_syms_dealloc (PyObject *obj)
    332  1.1  christos {
    333  1.1  christos   block_syms_iterator_object *iter_obj = (block_syms_iterator_object *) obj;
    334  1.1  christos 
    335  1.1  christos   Py_XDECREF (iter_obj->source);
    336  1.1  christos }
    337  1.1  christos 
    338  1.1  christos /* Implementation of gdb.Block.is_valid (self) -> Boolean.
    339  1.1  christos    Returns True if this block object still exists in GDB.  */
    340  1.1  christos 
    341  1.1  christos static PyObject *
    342  1.1  christos blpy_is_valid (PyObject *self, PyObject *args)
    343  1.1  christos {
    344  1.1  christos   const struct block *block;
    345  1.1  christos 
    346  1.1  christos   block = block_object_to_block (self);
    347  1.1  christos   if (block == NULL)
    348  1.1  christos     Py_RETURN_FALSE;
    349  1.1  christos 
    350  1.1  christos   Py_RETURN_TRUE;
    351  1.1  christos }
    352  1.1  christos 
    353  1.1  christos /* Implementation of gdb.BlockIterator.is_valid (self) -> Boolean.
    354  1.1  christos    Returns True if this block iterator object still exists in GDB  */
    355  1.1  christos 
    356  1.1  christos static PyObject *
    357  1.1  christos blpy_iter_is_valid (PyObject *self, PyObject *args)
    358  1.1  christos {
    359  1.1  christos   block_syms_iterator_object *iter_obj =
    360  1.1  christos     (block_syms_iterator_object *) self;
    361  1.1  christos 
    362  1.1  christos   if (iter_obj->source->block == NULL)
    363  1.1  christos     Py_RETURN_FALSE;
    364  1.1  christos 
    365  1.1  christos   Py_RETURN_TRUE;
    366  1.1  christos }
    367  1.1  christos 
    368  1.1  christos /* Return the innermost lexical block containing the specified pc value,
    369  1.1  christos    or 0 if there is none.  */
    370  1.1  christos PyObject *
    371  1.1  christos gdbpy_block_for_pc (PyObject *self, PyObject *args)
    372  1.1  christos {
    373  1.1  christos   gdb_py_ulongest pc;
    374  1.3  christos   const struct block *block = NULL;
    375  1.3  christos   struct compunit_symtab *cust = NULL;
    376  1.1  christos 
    377  1.1  christos   if (!PyArg_ParseTuple (args, GDB_PY_LLU_ARG, &pc))
    378  1.1  christos     return NULL;
    379  1.1  christos 
    380  1.5  christos   TRY
    381  1.1  christos     {
    382  1.3  christos       cust = find_pc_compunit_symtab (pc);
    383  1.1  christos 
    384  1.3  christos       if (cust != NULL && COMPUNIT_OBJFILE (cust) != NULL)
    385  1.1  christos 	block = block_for_pc (pc);
    386  1.1  christos     }
    387  1.5  christos   CATCH (except, RETURN_MASK_ALL)
    388  1.5  christos     {
    389  1.5  christos       GDB_PY_HANDLE_EXCEPTION (except);
    390  1.5  christos     }
    391  1.5  christos   END_CATCH
    392  1.1  christos 
    393  1.3  christos   if (cust == NULL || COMPUNIT_OBJFILE (cust) == NULL)
    394  1.1  christos     {
    395  1.1  christos       PyErr_SetString (PyExc_RuntimeError,
    396  1.1  christos 		       _("Cannot locate object file for block."));
    397  1.1  christos       return NULL;
    398  1.1  christos     }
    399  1.1  christos 
    400  1.1  christos   if (block)
    401  1.3  christos     return block_to_block_object (block, COMPUNIT_OBJFILE (cust));
    402  1.1  christos 
    403  1.1  christos   Py_RETURN_NONE;
    404  1.1  christos }
    405  1.1  christos 
    406  1.1  christos /* This function is called when an objfile is about to be freed.
    407  1.1  christos    Invalidate the block as further actions on the block would result
    408  1.1  christos    in bad data.  All access to obj->symbol should be gated by
    409  1.1  christos    BLPY_REQUIRE_VALID which will raise an exception on invalid
    410  1.1  christos    blocks.  */
    411  1.1  christos static void
    412  1.1  christos del_objfile_blocks (struct objfile *objfile, void *datum)
    413  1.1  christos {
    414  1.1  christos   block_object *obj = datum;
    415  1.1  christos 
    416  1.1  christos   while (obj)
    417  1.1  christos     {
    418  1.1  christos       block_object *next = obj->next;
    419  1.1  christos 
    420  1.1  christos       obj->block = NULL;
    421  1.1  christos       obj->objfile = NULL;
    422  1.1  christos       obj->next = NULL;
    423  1.1  christos       obj->prev = NULL;
    424  1.1  christos 
    425  1.1  christos       obj = next;
    426  1.1  christos     }
    427  1.1  christos }
    428  1.1  christos 
    429  1.1  christos int
    430  1.1  christos gdbpy_initialize_blocks (void)
    431  1.1  christos {
    432  1.1  christos   block_object_type.tp_new = PyType_GenericNew;
    433  1.1  christos   if (PyType_Ready (&block_object_type) < 0)
    434  1.1  christos     return -1;
    435  1.1  christos 
    436  1.1  christos   block_syms_iterator_object_type.tp_new = PyType_GenericNew;
    437  1.1  christos   if (PyType_Ready (&block_syms_iterator_object_type) < 0)
    438  1.1  christos     return -1;
    439  1.1  christos 
    440  1.1  christos   /* Register an objfile "free" callback so we can properly
    441  1.1  christos      invalidate blocks when an object file is about to be
    442  1.1  christos      deleted.  */
    443  1.1  christos   blpy_objfile_data_key
    444  1.1  christos     = register_objfile_data_with_cleanup (NULL, del_objfile_blocks);
    445  1.1  christos 
    446  1.1  christos   if (gdb_pymodule_addobject (gdb_module, "Block",
    447  1.1  christos 			      (PyObject *) &block_object_type) < 0)
    448  1.1  christos     return -1;
    449  1.1  christos 
    450  1.1  christos   return gdb_pymodule_addobject (gdb_module, "BlockIterator",
    451  1.1  christos 				 (PyObject *) &block_syms_iterator_object_type);
    452  1.1  christos }
    453  1.1  christos 
    454  1.1  christos 
    455  1.1  christos 
    457  1.1  christos static PyMethodDef block_object_methods[] = {
    458  1.1  christos   { "is_valid", blpy_is_valid, METH_NOARGS,
    459  1.1  christos     "is_valid () -> Boolean.\n\
    460  1.1  christos Return true if this block is valid, false if not." },
    461  1.1  christos   {NULL}  /* Sentinel */
    462  1.1  christos };
    463  1.1  christos 
    464  1.1  christos static PyGetSetDef block_object_getset[] = {
    465  1.1  christos   { "start", blpy_get_start, NULL, "Start address of the block.", NULL },
    466  1.1  christos   { "end", blpy_get_end, NULL, "End address of the block.", NULL },
    467  1.1  christos   { "function", blpy_get_function, NULL,
    468  1.1  christos     "Symbol that names the block, or None.", NULL },
    469  1.1  christos   { "superblock", blpy_get_superblock, NULL,
    470  1.1  christos     "Block containing the block, or None.", NULL },
    471  1.1  christos   { "global_block", blpy_get_global_block, NULL,
    472  1.1  christos     "Block containing the global block.", NULL },
    473  1.1  christos   { "static_block", blpy_get_static_block, NULL,
    474  1.1  christos     "Block containing the static block.", NULL },
    475  1.1  christos   { "is_static", blpy_is_static, NULL,
    476  1.1  christos     "Whether this block is a static block.", NULL },
    477  1.1  christos   { "is_global", blpy_is_global, NULL,
    478  1.1  christos     "Whether this block is a global block.", NULL },
    479  1.1  christos   { NULL }  /* Sentinel */
    480  1.1  christos };
    481  1.1  christos 
    482  1.1  christos PyTypeObject block_object_type = {
    483  1.1  christos   PyVarObject_HEAD_INIT (NULL, 0)
    484  1.1  christos   "gdb.Block",			  /*tp_name*/
    485  1.1  christos   sizeof (block_object),	  /*tp_basicsize*/
    486  1.1  christos   0,				  /*tp_itemsize*/
    487  1.1  christos   blpy_dealloc,                   /*tp_dealloc*/
    488  1.1  christos   0,				  /*tp_print*/
    489  1.1  christos   0,				  /*tp_getattr*/
    490  1.1  christos   0,				  /*tp_setattr*/
    491  1.1  christos   0,				  /*tp_compare*/
    492  1.1  christos   0,				  /*tp_repr*/
    493  1.1  christos   0,				  /*tp_as_number*/
    494  1.1  christos   0,				  /*tp_as_sequence*/
    495  1.1  christos   0,				  /*tp_as_mapping*/
    496  1.1  christos   0,				  /*tp_hash */
    497  1.1  christos   0,				  /*tp_call*/
    498  1.1  christos   0,				  /*tp_str*/
    499  1.1  christos   0,				  /*tp_getattro*/
    500  1.1  christos   0,				  /*tp_setattro*/
    501  1.1  christos   0,				  /*tp_as_buffer*/
    502  1.1  christos   Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,  /*tp_flags*/
    503  1.1  christos   "GDB block object",		  /* tp_doc */
    504  1.1  christos   0,				  /* tp_traverse */
    505  1.1  christos   0,				  /* tp_clear */
    506  1.1  christos   0,				  /* tp_richcompare */
    507  1.1  christos   0,				  /* tp_weaklistoffset */
    508  1.1  christos   blpy_iter,			  /* tp_iter */
    509  1.1  christos   0,				  /* tp_iternext */
    510  1.1  christos   block_object_methods,		  /* tp_methods */
    511  1.1  christos   0,				  /* tp_members */
    512  1.1  christos   block_object_getset		  /* tp_getset */
    513  1.1  christos };
    514  1.1  christos 
    515  1.1  christos static PyMethodDef block_iterator_object_methods[] = {
    516  1.1  christos   { "is_valid", blpy_iter_is_valid, METH_NOARGS,
    517  1.1  christos     "is_valid () -> Boolean.\n\
    518  1.1  christos Return true if this block iterator is valid, false if not." },
    519  1.1  christos   {NULL}  /* Sentinel */
    520  1.1  christos };
    521  1.5  christos 
    522  1.1  christos PyTypeObject block_syms_iterator_object_type = {
    523  1.1  christos   PyVarObject_HEAD_INIT (NULL, 0)
    524  1.1  christos   "gdb.BlockIterator",		  /*tp_name*/
    525  1.1  christos   sizeof (block_syms_iterator_object),	      /*tp_basicsize*/
    526  1.1  christos   0,				  /*tp_itemsize*/
    527  1.1  christos   blpy_block_syms_dealloc,	  /*tp_dealloc*/
    528  1.1  christos   0,				  /*tp_print*/
    529  1.1  christos   0,				  /*tp_getattr*/
    530  1.1  christos   0,				  /*tp_setattr*/
    531  1.1  christos   0,				  /*tp_compare*/
    532  1.1  christos   0,				  /*tp_repr*/
    533  1.1  christos   0,				  /*tp_as_number*/
    534  1.1  christos   0,				  /*tp_as_sequence*/
    535  1.1  christos   0,				  /*tp_as_mapping*/
    536  1.1  christos   0,				  /*tp_hash */
    537  1.1  christos   0,				  /*tp_call*/
    538  1.1  christos   0,				  /*tp_str*/
    539  1.1  christos   0,				  /*tp_getattro*/
    540  1.1  christos   0,				  /*tp_setattro*/
    541  1.1  christos   0,				  /*tp_as_buffer*/
    542  1.1  christos   Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,  /*tp_flags*/
    543  1.1  christos   "GDB block syms iterator object",	      /*tp_doc */
    544  1.1  christos   0,				  /*tp_traverse */
    545  1.1  christos   0,				  /*tp_clear */
    546  1.1  christos   0,				  /*tp_richcompare */
    547  1.1  christos   0,				  /*tp_weaklistoffset */
    548  1.1  christos   blpy_block_syms_iter,           /*tp_iter */
    549  1.1  christos   blpy_block_syms_iternext,	  /*tp_iternext */
    550  1.1  christos   block_iterator_object_methods   /*tp_methods */
    551                };
    552