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