Home | History | Annotate | Line # | Download | only in python
py-linetable.c revision 1.3.2.1
      1      1.1  christos /* Python interface to line tables.
      2      1.1  christos 
      3      1.3  christos    Copyright (C) 2013-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 "python-internal.h"
     22      1.1  christos 
     23      1.1  christos typedef struct {
     24      1.1  christos   PyObject_HEAD
     25      1.1  christos   /* The line table source line.  */
     26      1.1  christos   int line;
     27      1.1  christos   /* The pc associated with the source line.  */
     28      1.1  christos   CORE_ADDR pc;
     29      1.1  christos } linetable_entry_object;
     30      1.1  christos 
     31  1.3.2.1  pgoyette extern PyTypeObject linetable_entry_object_type
     32      1.1  christos     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("linetable_entry_object");
     33      1.1  christos 
     34      1.1  christos typedef struct {
     35      1.1  christos   PyObject_HEAD
     36      1.1  christos   /* The symtab python object.  We store the Python object here as the
     37      1.1  christos      underlying symtab can become invalid, and we have to run validity
     38      1.1  christos      checks on it.  */
     39      1.1  christos   PyObject *symtab;
     40      1.1  christos } linetable_object;
     41      1.1  christos 
     42  1.3.2.1  pgoyette extern PyTypeObject linetable_object_type
     43      1.1  christos     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("linetable_object");
     44      1.1  christos 
     45      1.1  christos typedef struct {
     46      1.1  christos   PyObject_HEAD
     47      1.1  christos   /* The current entry in the line table for the iterator  */
     48      1.1  christos   int current_index;
     49      1.1  christos   /* Pointer back to the original source line table object.  Needed to
     50      1.1  christos      check if the line table is still valid, and has not been invalidated
     51      1.1  christos      when an object file has been freed.  */
     52      1.1  christos   PyObject *source;
     53      1.1  christos } ltpy_iterator_object;
     54      1.1  christos 
     55  1.3.2.1  pgoyette extern PyTypeObject ltpy_iterator_object_type
     56      1.1  christos     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("ltpy_iterator_object");
     57      1.1  christos 
     58      1.1  christos /* Internal helper function to extract gdb.Symtab from a gdb.Linetable
     59      1.1  christos    object.  */
     60      1.1  christos 
     61      1.1  christos static PyObject *
     62      1.1  christos get_symtab (PyObject *linetable)
     63      1.1  christos {
     64      1.1  christos   linetable_object *lt = (linetable_object *) linetable;
     65      1.1  christos 
     66      1.1  christos   return lt->symtab;
     67      1.1  christos }
     68      1.1  christos 
     69      1.1  christos #define LTPY_REQUIRE_VALID(lt_obj, symtab)				\
     70      1.1  christos   do {									\
     71      1.1  christos     symtab = symtab_object_to_symtab (get_symtab (lt_obj));		\
     72      1.1  christos     if (symtab == NULL)							\
     73      1.1  christos       {									\
     74      1.1  christos 	  PyErr_SetString (PyExc_RuntimeError,				\
     75      1.1  christos 			   _("Symbol Table in line table is invalid."));\
     76      1.1  christos 	  return NULL;							\
     77      1.1  christos 	}								\
     78      1.1  christos   } while (0)
     79      1.1  christos 
     80      1.1  christos 
     81      1.1  christos /* Helper function to create a line table object that wraps a
     82      1.1  christos    gdb.Symtab object.  */
     83      1.1  christos 
     84      1.1  christos PyObject *
     85      1.1  christos symtab_to_linetable_object (PyObject *symtab)
     86      1.1  christos {
     87      1.1  christos   linetable_object *ltable;
     88      1.1  christos 
     89      1.1  christos   ltable = PyObject_New (linetable_object, &linetable_object_type);
     90      1.1  christos   if (ltable != NULL)
     91      1.1  christos     {
     92      1.1  christos       ltable->symtab = symtab;
     93      1.1  christos       Py_INCREF (symtab);
     94      1.1  christos     }
     95      1.1  christos   return (PyObject *) ltable;
     96      1.1  christos }
     97      1.1  christos 
     98      1.1  christos /* Internal helper function to build a line table object from a line
     99      1.1  christos    and an address.  */
    100      1.1  christos 
    101      1.1  christos static PyObject *
    102      1.1  christos build_linetable_entry (int line, CORE_ADDR address)
    103      1.1  christos {
    104      1.1  christos   linetable_entry_object *obj;
    105      1.1  christos 
    106      1.1  christos   obj = PyObject_New (linetable_entry_object,
    107      1.1  christos 		      &linetable_entry_object_type);
    108      1.1  christos   if (obj != NULL)
    109      1.1  christos     {
    110      1.1  christos       obj->line = line;
    111      1.1  christos       obj->pc = address;
    112      1.1  christos     }
    113      1.1  christos 
    114      1.1  christos   return (PyObject *) obj;
    115      1.1  christos }
    116      1.1  christos 
    117      1.1  christos /* Internal helper function to build a Python Tuple from a GDB Vector.
    118      1.1  christos    A line table entry can have multiple PCs for a given source line.
    119      1.1  christos    Construct a Tuple of all entries for the given source line, LINE
    120      1.1  christos    from the line table VEC.  Construct one line table entry object per
    121      1.1  christos    address.  */
    122      1.1  christos 
    123      1.1  christos static PyObject *
    124      1.1  christos build_line_table_tuple_from_pcs (int line, VEC (CORE_ADDR) *vec)
    125      1.1  christos {
    126      1.1  christos   int vec_len = 0;
    127      1.1  christos   PyObject *tuple;
    128      1.1  christos   CORE_ADDR pc;
    129      1.1  christos   int i;
    130      1.1  christos 
    131      1.1  christos   vec_len = VEC_length (CORE_ADDR, vec);
    132      1.1  christos   if (vec_len < 1)
    133      1.1  christos     Py_RETURN_NONE;
    134      1.1  christos 
    135      1.1  christos   tuple = PyTuple_New (vec_len);
    136      1.1  christos 
    137      1.1  christos   if (tuple == NULL)
    138      1.1  christos     return NULL;
    139      1.1  christos 
    140      1.1  christos   for (i = 0; VEC_iterate (CORE_ADDR, vec, i, pc); ++i)
    141      1.1  christos     {
    142      1.1  christos       PyObject *obj = build_linetable_entry (line, pc);
    143      1.1  christos 
    144      1.1  christos       if (obj == NULL)
    145      1.1  christos 	{
    146      1.1  christos 	  Py_DECREF (tuple);
    147      1.1  christos 	  tuple = NULL;
    148      1.1  christos 	  break;
    149      1.1  christos 	}
    150      1.1  christos       else if (PyTuple_SetItem (tuple, i, obj) != 0)
    151      1.1  christos 	{
    152      1.1  christos 	  Py_DECREF (obj);
    153      1.1  christos 	  Py_DECREF (tuple);
    154      1.1  christos 	  tuple = NULL;
    155      1.1  christos 	  break;
    156      1.1  christos 	}
    157      1.1  christos     }
    158      1.1  christos 
    159      1.1  christos   return tuple;
    160      1.1  christos }
    161      1.1  christos 
    162      1.1  christos /* Implementation of gdb.LineTable.line (self) -> Tuple.  Returns a
    163      1.1  christos    tuple of LineTableEntry objects associated with this line from the
    164      1.1  christos    in the line table.  */
    165      1.1  christos 
    166      1.1  christos static PyObject *
    167      1.1  christos ltpy_get_pcs_for_line (PyObject *self, PyObject *args)
    168      1.1  christos {
    169      1.1  christos   struct symtab *symtab;
    170      1.1  christos   gdb_py_longest py_line;
    171      1.1  christos   struct linetable_entry *best_entry = NULL;
    172      1.1  christos   linetable_entry_object *result;
    173      1.1  christos   VEC (CORE_ADDR) *pcs = NULL;
    174      1.1  christos   PyObject *tuple;
    175      1.1  christos 
    176      1.1  christos   LTPY_REQUIRE_VALID (self, symtab);
    177      1.1  christos 
    178      1.1  christos   if (! PyArg_ParseTuple (args, GDB_PY_LL_ARG, &py_line))
    179      1.1  christos     return NULL;
    180      1.1  christos 
    181  1.3.2.1  pgoyette   TRY
    182      1.1  christos     {
    183      1.1  christos       pcs = find_pcs_for_symtab_line (symtab, py_line, &best_entry);
    184      1.1  christos     }
    185  1.3.2.1  pgoyette   CATCH (except, RETURN_MASK_ALL)
    186  1.3.2.1  pgoyette     {
    187  1.3.2.1  pgoyette       GDB_PY_HANDLE_EXCEPTION (except);
    188  1.3.2.1  pgoyette     }
    189  1.3.2.1  pgoyette   END_CATCH
    190      1.1  christos 
    191      1.1  christos   tuple = build_line_table_tuple_from_pcs (py_line, pcs);
    192      1.1  christos   VEC_free (CORE_ADDR, pcs);
    193      1.1  christos 
    194      1.1  christos   return tuple;
    195      1.1  christos }
    196      1.1  christos 
    197      1.1  christos /* Implementation of gdb.LineTable.has_line (self, line) -> Boolean.
    198      1.1  christos    Returns a Python Boolean indicating whether a source line has any
    199      1.1  christos    line table entries corresponding to it.  */
    200      1.1  christos 
    201      1.1  christos static PyObject *
    202      1.1  christos ltpy_has_line (PyObject *self, PyObject *args)
    203      1.1  christos {
    204      1.1  christos   struct symtab *symtab;
    205      1.1  christos   gdb_py_longest py_line;
    206      1.1  christos   int index;
    207      1.1  christos 
    208      1.1  christos   LTPY_REQUIRE_VALID (self, symtab);
    209      1.1  christos 
    210      1.1  christos   if (! PyArg_ParseTuple (args, GDB_PY_LL_ARG, &py_line))
    211      1.1  christos     return NULL;
    212      1.1  christos 
    213      1.3  christos   if (SYMTAB_LINETABLE (symtab) == NULL)
    214      1.1  christos     {
    215      1.1  christos       PyErr_SetString (PyExc_RuntimeError,
    216      1.1  christos 		       _("Linetable information not found in symbol table"));
    217      1.1  christos       return NULL;
    218      1.1  christos     }
    219      1.1  christos 
    220      1.3  christos   for (index = 0; index < SYMTAB_LINETABLE (symtab)->nitems; index++)
    221      1.1  christos     {
    222      1.3  christos       struct linetable_entry *item = &(SYMTAB_LINETABLE (symtab)->item[index]);
    223      1.1  christos       if (item->line == py_line)
    224      1.1  christos 	  Py_RETURN_TRUE;
    225      1.1  christos     }
    226      1.1  christos 
    227      1.1  christos   Py_RETURN_FALSE;
    228      1.1  christos }
    229      1.1  christos 
    230      1.1  christos /* Implementation of gdb.LineTable.source_lines (self) -> FrozenSet.
    231      1.1  christos    Returns a Python FrozenSet that contains source line entries in the
    232      1.1  christos    line table.  This function will just return the source lines
    233      1.1  christos    without corresponding addresses.  */
    234      1.1  christos 
    235      1.1  christos static PyObject *
    236      1.1  christos ltpy_get_all_source_lines (PyObject *self, PyObject *args)
    237      1.1  christos {
    238      1.1  christos   struct symtab *symtab;
    239      1.1  christos   Py_ssize_t index;
    240      1.1  christos   PyObject *source_list, *source_dict, *line;
    241      1.1  christos   struct linetable_entry *item;
    242      1.1  christos   Py_ssize_t list_size;
    243      1.1  christos 
    244      1.1  christos   LTPY_REQUIRE_VALID (self, symtab);
    245      1.1  christos 
    246      1.3  christos   if (SYMTAB_LINETABLE (symtab) == NULL)
    247      1.1  christos     {
    248      1.1  christos       PyErr_SetString (PyExc_RuntimeError,
    249      1.1  christos 		       _("Linetable information not found in symbol table"));
    250      1.1  christos       return NULL;
    251      1.1  christos     }
    252      1.1  christos 
    253      1.1  christos   source_dict = PyDict_New ();
    254      1.1  christos   if (source_dict == NULL)
    255      1.1  christos     return NULL;
    256      1.1  christos 
    257      1.3  christos   for (index = 0; index < SYMTAB_LINETABLE (symtab)->nitems; index++)
    258      1.1  christos     {
    259      1.3  christos       item = &(SYMTAB_LINETABLE (symtab)->item[index]);
    260      1.1  christos 
    261      1.1  christos       /* 0 is used to signify end of line table information.  Do not
    262      1.1  christos 	 include in the source set. */
    263      1.1  christos       if (item->line > 0)
    264      1.1  christos 	{
    265      1.1  christos 	  line = gdb_py_object_from_longest (item->line);
    266      1.1  christos 
    267      1.1  christos 	  if (line == NULL)
    268      1.1  christos 	    {
    269      1.1  christos 	      Py_DECREF (source_dict);
    270      1.1  christos 	      return NULL;
    271      1.1  christos 	    }
    272      1.1  christos 
    273      1.1  christos 	  if (PyDict_SetItem (source_dict, line, Py_None) == -1)
    274      1.1  christos 	    {
    275      1.1  christos 	      Py_DECREF (line);
    276      1.1  christos 	      Py_DECREF (source_dict);
    277      1.1  christos 	      return NULL;
    278      1.1  christos 	    }
    279      1.1  christos 
    280      1.1  christos 	  Py_DECREF (line);
    281      1.1  christos 	}
    282      1.1  christos     }
    283      1.1  christos 
    284      1.1  christos 
    285      1.1  christos   source_list = PyDict_Keys (source_dict);
    286      1.1  christos   Py_DECREF (source_dict);
    287      1.1  christos 
    288      1.1  christos   return source_list;
    289      1.1  christos }
    290      1.1  christos 
    291      1.1  christos /* Implementation of gdb.Linetable.is_valid (self) -> Boolean.
    292      1.1  christos    Returns True if this line table object still exists in GDB.  */
    293      1.1  christos 
    294      1.1  christos static PyObject *
    295      1.1  christos ltpy_is_valid (PyObject *self, PyObject *args)
    296      1.1  christos {
    297      1.1  christos   struct symtab *symtab = NULL;
    298      1.1  christos   linetable_object *obj = (linetable_object *) self;
    299      1.1  christos 
    300      1.1  christos   symtab = symtab_object_to_symtab (get_symtab (self));
    301      1.1  christos 
    302      1.1  christos   if (symtab == NULL)
    303      1.1  christos     Py_RETURN_FALSE;
    304      1.1  christos 
    305      1.1  christos   Py_RETURN_TRUE;
    306      1.1  christos }
    307      1.1  christos 
    308      1.1  christos /* Deconstructor for the line table object.  Decrement the reference
    309      1.1  christos    to the symbol table object before calling the default free.  */
    310      1.1  christos 
    311      1.1  christos static void
    312      1.1  christos ltpy_dealloc (PyObject *self)
    313      1.1  christos {
    314      1.1  christos   linetable_object *obj = (linetable_object *) self;
    315      1.1  christos 
    316      1.1  christos   Py_DECREF (obj->symtab);
    317      1.1  christos   Py_TYPE (self)->tp_free (self);
    318      1.1  christos }
    319      1.1  christos 
    320      1.1  christos /* Initialize LineTable, LineTableEntry and LineTableIterator
    321      1.1  christos    objects.  */
    322      1.1  christos 
    323      1.1  christos int
    324      1.1  christos gdbpy_initialize_linetable (void)
    325      1.1  christos {
    326      1.1  christos   if (PyType_Ready (&linetable_object_type) < 0)
    327      1.1  christos     return -1;
    328      1.1  christos   if (PyType_Ready (&linetable_entry_object_type) < 0)
    329      1.1  christos     return -1;
    330      1.1  christos   if (PyType_Ready (&ltpy_iterator_object_type) < 0)
    331      1.1  christos     return -1;
    332      1.1  christos 
    333      1.1  christos   Py_INCREF (&linetable_object_type);
    334      1.1  christos   Py_INCREF (&linetable_entry_object_type);
    335      1.1  christos   Py_INCREF (&ltpy_iterator_object_type);
    336      1.1  christos 
    337      1.1  christos   if (gdb_pymodule_addobject (gdb_module, "LineTable",
    338      1.1  christos 			      (PyObject *) &linetable_object_type) < 0)
    339      1.1  christos     return -1;
    340      1.1  christos 
    341      1.1  christos   if (gdb_pymodule_addobject (gdb_module, "LineTableEntry",
    342      1.1  christos 			      (PyObject *) &linetable_entry_object_type) < 0)
    343      1.1  christos     return -1;
    344      1.1  christos 
    345      1.1  christos   if (gdb_pymodule_addobject (gdb_module, "LineTableIterator",
    346      1.1  christos 			      (PyObject *) &ltpy_iterator_object_type) < 0)
    347      1.1  christos     return -1;
    348      1.1  christos 
    349      1.1  christos   return 0;
    350      1.1  christos }
    351      1.1  christos 
    352      1.1  christos /* Linetable entry object get functions.  */
    353      1.1  christos 
    354      1.1  christos /* Implementation of gdb.LineTableEntry.line (self) -> Long.  Returns
    355      1.1  christos    a long integer associated with the line table entry.  */
    356      1.1  christos 
    357      1.1  christos static PyObject *
    358      1.1  christos ltpy_entry_get_line (PyObject *self, void *closure)
    359      1.1  christos {
    360      1.1  christos   linetable_entry_object *obj = (linetable_entry_object *) self;
    361      1.1  christos 
    362      1.1  christos   return gdb_py_object_from_longest (obj->line);
    363      1.1  christos }
    364      1.1  christos 
    365      1.1  christos /* Implementation of gdb.LineTableEntry.pc (self) -> Long.  Returns a
    366      1.1  christos    a long integer associated with the PC of the line table entry.  */
    367      1.1  christos 
    368      1.1  christos static PyObject *
    369      1.1  christos ltpy_entry_get_pc (PyObject *self, void *closure)
    370      1.1  christos {
    371      1.1  christos   linetable_entry_object *obj = (linetable_entry_object *) self;
    372      1.1  christos 
    373      1.1  christos   return  gdb_py_object_from_longest (obj->pc);
    374      1.1  christos }
    375      1.1  christos 
    376      1.1  christos /* Linetable iterator functions.  */
    377      1.1  christos 
    378      1.1  christos /* Return a new line table iterator.  */
    379      1.1  christos 
    380      1.1  christos static PyObject *
    381      1.1  christos ltpy_iter (PyObject *self)
    382      1.1  christos {
    383      1.1  christos   ltpy_iterator_object *ltpy_iter_obj;
    384      1.1  christos   struct symtab *symtab = NULL;
    385      1.1  christos 
    386      1.1  christos   LTPY_REQUIRE_VALID (self, symtab);
    387      1.1  christos 
    388      1.1  christos   ltpy_iter_obj = PyObject_New (ltpy_iterator_object,
    389      1.1  christos 				&ltpy_iterator_object_type);
    390      1.1  christos   if (ltpy_iter_obj == NULL)
    391      1.1  christos     return NULL;
    392      1.1  christos 
    393      1.1  christos   ltpy_iter_obj->current_index = 0;
    394      1.1  christos   ltpy_iter_obj->source = self;
    395      1.1  christos 
    396      1.1  christos   Py_INCREF (self);
    397      1.1  christos   return (PyObject *) ltpy_iter_obj;
    398      1.1  christos }
    399      1.1  christos 
    400      1.1  christos static void
    401      1.1  christos ltpy_iterator_dealloc (PyObject *obj)
    402      1.1  christos {
    403      1.1  christos   ltpy_iterator_object *iter_obj = (ltpy_iterator_object *) obj;
    404      1.1  christos 
    405      1.1  christos   Py_DECREF (iter_obj->source);
    406      1.1  christos }
    407      1.1  christos 
    408      1.1  christos /* Return a reference to the line table iterator.  */
    409      1.1  christos 
    410      1.1  christos static PyObject *
    411      1.1  christos ltpy_iterator (PyObject *self)
    412      1.1  christos {
    413      1.1  christos   ltpy_iterator_object *iter_obj = (ltpy_iterator_object *) self;
    414      1.1  christos   struct symtab *symtab;
    415      1.1  christos 
    416      1.1  christos   LTPY_REQUIRE_VALID (iter_obj->source, symtab);
    417      1.1  christos 
    418      1.1  christos   Py_INCREF (self);
    419      1.1  christos   return self;
    420      1.1  christos }
    421      1.1  christos 
    422      1.1  christos /* Return the next line table entry in the iteration through the line
    423      1.1  christos    table data structure.  */
    424      1.1  christos 
    425      1.1  christos static PyObject *
    426      1.1  christos ltpy_iternext (PyObject *self)
    427      1.1  christos {
    428      1.1  christos   ltpy_iterator_object *iter_obj = (ltpy_iterator_object *) self;
    429      1.1  christos   struct symtab *symtab;
    430      1.1  christos   int index;
    431      1.1  christos   PyObject *obj;
    432      1.1  christos   struct linetable_entry *item;
    433      1.1  christos 
    434      1.1  christos   LTPY_REQUIRE_VALID (iter_obj->source, symtab);
    435      1.1  christos 
    436      1.3  christos   if (iter_obj->current_index >= SYMTAB_LINETABLE (symtab)->nitems)
    437      1.1  christos     goto stop_iteration;
    438      1.1  christos 
    439      1.3  christos   item = &(SYMTAB_LINETABLE (symtab)->item[iter_obj->current_index]);
    440      1.1  christos 
    441      1.1  christos   /* Skip over internal entries such as 0.  0 signifies the end of
    442      1.1  christos      line table data and is not useful to the API user.  */
    443      1.1  christos   while (item->line < 1)
    444      1.1  christos     {
    445      1.1  christos       iter_obj->current_index++;
    446      1.1  christos 
    447      1.1  christos       /* Exit if the internal value is the last item in the line table.  */
    448      1.3  christos       if (iter_obj->current_index >= SYMTAB_LINETABLE (symtab)->nitems)
    449      1.1  christos 	goto stop_iteration;
    450      1.3  christos       item = &(SYMTAB_LINETABLE (symtab)->item[iter_obj->current_index]);
    451      1.1  christos     }
    452      1.1  christos 
    453      1.1  christos   obj = build_linetable_entry (item->line, item->pc);
    454      1.1  christos   iter_obj->current_index++;
    455      1.1  christos 
    456      1.1  christos   return obj;
    457      1.1  christos 
    458      1.1  christos  stop_iteration:
    459      1.1  christos   PyErr_SetNone (PyExc_StopIteration);
    460      1.1  christos   return NULL;
    461      1.1  christos }
    462      1.1  christos 
    463      1.1  christos /* Implementation of gdb.LinetableIterator.is_valid (self) -> Boolean.
    464      1.1  christos    Returns True if this line table iterator object still exists in
    465      1.1  christos    GDB.  */
    466      1.1  christos 
    467      1.1  christos static PyObject *
    468      1.1  christos ltpy_iter_is_valid (PyObject *self, PyObject *args)
    469      1.1  christos {
    470      1.1  christos   struct symtab *symtab = NULL;
    471      1.1  christos   ltpy_iterator_object *iter_obj = (ltpy_iterator_object *) self;
    472      1.1  christos 
    473      1.1  christos   symtab = symtab_object_to_symtab (get_symtab (iter_obj->source));
    474      1.1  christos 
    475      1.1  christos   if (symtab == NULL)
    476      1.1  christos     Py_RETURN_FALSE;
    477      1.1  christos 
    478      1.1  christos   Py_RETURN_TRUE;
    479      1.1  christos }
    480      1.1  christos 
    481      1.1  christos 
    482      1.1  christos 
    484      1.1  christos static PyMethodDef linetable_object_methods[] = {
    485      1.1  christos   { "line", ltpy_get_pcs_for_line, METH_VARARGS,
    486      1.1  christos     "line (lineno) -> Tuple\n\
    487      1.1  christos Return executable locations for a given source line." },
    488      1.1  christos   { "has_line", ltpy_has_line, METH_VARARGS,
    489      1.1  christos     "has_line (lineno) -> Boolean\n\
    490      1.1  christos Return TRUE if this line has executable information, FALSE if not." },
    491      1.1  christos   { "source_lines", ltpy_get_all_source_lines, METH_NOARGS,
    492      1.1  christos     "source_lines () -> FrozenSet\n\
    493      1.1  christos Return a frozen set of all executable source lines." },
    494      1.1  christos   { "is_valid", ltpy_is_valid, METH_NOARGS,
    495      1.1  christos     "is_valid () -> Boolean.\n\
    496      1.1  christos Return True if this Linetable is valid, False if not." },
    497      1.1  christos   {NULL}  /* Sentinel */
    498      1.1  christos };
    499  1.3.2.1  pgoyette 
    500      1.1  christos PyTypeObject linetable_object_type = {
    501      1.1  christos   PyVarObject_HEAD_INIT (NULL, 0)
    502      1.1  christos   "gdb.LineTable",	          /*tp_name*/
    503      1.1  christos   sizeof (linetable_object),	  /*tp_basicsize*/
    504      1.1  christos   0,				  /*tp_itemsize*/
    505      1.1  christos   ltpy_dealloc,                   /*tp_dealloc*/
    506      1.1  christos   0,				  /*tp_print*/
    507      1.1  christos   0,				  /*tp_getattr*/
    508      1.1  christos   0,				  /*tp_setattr*/
    509      1.1  christos   0,				  /*tp_compare*/
    510      1.1  christos   0,				  /*tp_repr*/
    511      1.1  christos   0,				  /*tp_as_number*/
    512      1.1  christos   0,				  /*tp_as_sequence*/
    513      1.1  christos   0,				  /*tp_as_mapping*/
    514      1.1  christos   0,				  /*tp_hash */
    515      1.1  christos   0,				  /*tp_call*/
    516      1.1  christos   0,				  /*tp_str*/
    517      1.1  christos   0,				  /*tp_getattro*/
    518      1.1  christos   0,				  /*tp_setattro*/
    519      1.1  christos   0,				  /*tp_as_buffer*/
    520      1.1  christos   Py_TPFLAGS_DEFAULT,             /*tp_flags*/
    521      1.1  christos   "GDB line table object",	  /* tp_doc */
    522      1.1  christos   0,				  /* tp_traverse */
    523      1.1  christos   0,				  /* tp_clear */
    524      1.1  christos   0,				  /* tp_richcompare */
    525      1.1  christos   0,				  /* tp_weaklistoffset */
    526      1.1  christos   ltpy_iter,			  /* tp_iter */
    527      1.1  christos   0,				  /* tp_iternext */
    528      1.1  christos   linetable_object_methods,	  /* tp_methods */
    529      1.1  christos   0,				  /* tp_members */
    530      1.1  christos   0,	                          /* tp_getset */
    531      1.1  christos   0,				  /* tp_base */
    532      1.1  christos   0,				  /* tp_dict */
    533      1.1  christos   0,				  /* tp_descr_get */
    534      1.1  christos   0,				  /* tp_descr_set */
    535      1.1  christos   0,				  /* tp_dictoffset */
    536      1.1  christos   0,    			  /* tp_init */
    537      1.1  christos   0,				  /* tp_alloc */
    538      1.1  christos };
    539      1.1  christos 
    540      1.1  christos static PyMethodDef ltpy_iterator_methods[] = {
    541      1.1  christos   { "is_valid", ltpy_iter_is_valid, METH_NOARGS,
    542      1.1  christos     "is_valid () -> Boolean.\n\
    543      1.1  christos Return True if this Linetable iterator is valid, False if not." },
    544      1.1  christos   {NULL}  /* Sentinel */
    545      1.1  christos };
    546  1.3.2.1  pgoyette 
    547      1.1  christos PyTypeObject ltpy_iterator_object_type = {
    548      1.1  christos   PyVarObject_HEAD_INIT (NULL, 0)
    549      1.1  christos   "gdb.LineTableIterator",		  /*tp_name*/
    550      1.1  christos   sizeof (ltpy_iterator_object),  /*tp_basicsize*/
    551      1.1  christos   0,				  /*tp_itemsize*/
    552      1.1  christos   ltpy_iterator_dealloc,	  /*tp_dealloc*/
    553      1.1  christos   0,				  /*tp_print*/
    554      1.1  christos   0,				  /*tp_getattr*/
    555      1.1  christos   0,				  /*tp_setattr*/
    556      1.1  christos   0,				  /*tp_compare*/
    557      1.1  christos   0,				  /*tp_repr*/
    558      1.1  christos   0,				  /*tp_as_number*/
    559      1.1  christos   0,				  /*tp_as_sequence*/
    560      1.1  christos   0,				  /*tp_as_mapping*/
    561      1.1  christos   0,				  /*tp_hash */
    562      1.1  christos   0,				  /*tp_call*/
    563      1.1  christos   0,				  /*tp_str*/
    564      1.1  christos   0,				  /*tp_getattro*/
    565      1.1  christos   0,				  /*tp_setattro*/
    566      1.1  christos   0,				  /*tp_as_buffer*/
    567      1.1  christos   Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,  /*tp_flags*/
    568      1.1  christos   "GDB line table iterator object",	      /*tp_doc */
    569      1.1  christos   0,				  /*tp_traverse */
    570      1.1  christos   0,				  /*tp_clear */
    571      1.1  christos   0,				  /*tp_richcompare */
    572      1.1  christos   0,				  /*tp_weaklistoffset */
    573      1.1  christos   ltpy_iterator,                  /*tp_iter */
    574      1.1  christos   ltpy_iternext,	          /*tp_iternext */
    575      1.1  christos   ltpy_iterator_methods           /*tp_methods */
    576      1.1  christos };
    577      1.1  christos 
    578      1.1  christos 
    579      1.1  christos static PyGetSetDef linetable_entry_object_getset[] = {
    580      1.1  christos   { "line", ltpy_entry_get_line, NULL,
    581      1.1  christos     "The line number in the source file.", NULL },
    582      1.1  christos   { "pc", ltpy_entry_get_pc, NULL,
    583      1.1  christos     "The memory address for this line number.", NULL },
    584      1.1  christos   { NULL }  /* Sentinel */
    585      1.1  christos };
    586  1.3.2.1  pgoyette 
    587      1.1  christos PyTypeObject linetable_entry_object_type = {
    588      1.1  christos   PyVarObject_HEAD_INIT (NULL, 0)
    589      1.1  christos   "gdb.LineTableEntry",	          /*tp_name*/
    590      1.1  christos   sizeof (linetable_entry_object), /*tp_basicsize*/
    591      1.1  christos   0,				  /*tp_itemsize*/
    592      1.1  christos   0,                              /*tp_dealloc*/
    593      1.1  christos   0,				  /*tp_print*/
    594      1.1  christos   0,				  /*tp_getattr*/
    595      1.1  christos   0,				  /*tp_setattr*/
    596      1.1  christos   0,				  /*tp_compare*/
    597      1.1  christos   0,				  /*tp_repr*/
    598      1.1  christos   0,				  /*tp_as_number*/
    599      1.1  christos   0,				  /*tp_as_sequence*/
    600      1.1  christos   0,				  /*tp_as_mapping*/
    601      1.1  christos   0,				  /*tp_hash */
    602      1.1  christos   0,				  /*tp_call*/
    603      1.1  christos   0,				  /*tp_str*/
    604      1.1  christos   0,				  /*tp_getattro*/
    605      1.1  christos   0,				  /*tp_setattro*/
    606      1.1  christos   0,				  /*tp_as_buffer*/
    607      1.1  christos   Py_TPFLAGS_DEFAULT,             /*tp_flags*/
    608      1.1  christos   "GDB line table entry object",  /* tp_doc */
    609      1.1  christos   0,				  /* tp_traverse */
    610      1.1  christos   0,				  /* tp_clear */
    611      1.1  christos   0,				  /* tp_richcompare */
    612      1.1  christos   0,				  /* tp_weaklistoffset */
    613      1.1  christos   0,			          /* tp_iter */
    614      1.1  christos   0,				  /* tp_iternext */
    615      1.1  christos   0,                              /* tp_methods */
    616      1.1  christos   0,				  /* tp_members */
    617      1.1  christos   linetable_entry_object_getset,  /* tp_getset */
    618      1.1  christos   0,				  /* tp_base */
    619      1.1  christos   0,				  /* tp_dict */
    620      1.1  christos   0,				  /* tp_descr_get */
    621      1.1  christos   0,				  /* tp_descr_set */
    622      1.1  christos   0,				  /* tp_dictoffset */
    623      1.1  christos   0,	                          /* tp_init */
    624      1.1  christos   0,				  /* tp_alloc */
    625                    };
    626