diff options
Diffstat (limited to 'gdb/python/py-objfile.c')
-rw-r--r-- | gdb/python/py-objfile.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index 9fa6813..5d2398f 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -32,6 +32,9 @@ typedef struct /* The pretty-printer list of functions. */ PyObject *printers; + + /* The type-printer list. */ + PyObject *type_printers; } objfile_object; static PyTypeObject objfile_object_type; @@ -58,6 +61,7 @@ objfpy_dealloc (PyObject *o) objfile_object *self = (objfile_object *) o; Py_XDECREF (self->printers); + Py_XDECREF (self->type_printers); self->ob_type->tp_free ((PyObject *) self); } @@ -76,6 +80,13 @@ objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords) Py_DECREF (self); return NULL; } + + self->type_printers = PyList_New (0); + if (!self->type_printers) + { + Py_DECREF (self); + return NULL; + } } return (PyObject *) self; } @@ -118,6 +129,48 @@ objfpy_set_printers (PyObject *o, PyObject *value, void *ignore) return 0; } +/* Get the 'type_printers' attribute. */ + +static PyObject * +objfpy_get_type_printers (PyObject *o, void *ignore) +{ + objfile_object *self = (objfile_object *) o; + + Py_INCREF (self->type_printers); + return self->type_printers; +} + +/* Set the 'type_printers' attribute. */ + +static int +objfpy_set_type_printers (PyObject *o, PyObject *value, void *ignore) +{ + PyObject *tmp; + objfile_object *self = (objfile_object *) o; + + if (! value) + { + PyErr_SetString (PyExc_TypeError, + _("Cannot delete the type_printers attribute.")); + return -1; + } + + if (! PyList_Check (value)) + { + PyErr_SetString (PyExc_TypeError, + _("The type_printers attribute must be a list.")); + return -1; + } + + /* Take care in case the LHS and RHS are related somehow. */ + tmp = self->type_printers; + Py_INCREF (value); + self->type_printers = value; + Py_XDECREF (tmp); + + return 0; +} + /* Implementation of gdb.Objfile.is_valid (self) -> Boolean. Returns True if this object file still exists in GDB. */ @@ -172,6 +225,13 @@ objfile_to_objfile_object (struct objfile *objfile) return NULL; } + object->type_printers = PyList_New (0); + if (!object->type_printers) + { + Py_DECREF (object); + return NULL; + } + set_objfile_data (objfile, objfpy_objfile_data_key, object); } } @@ -210,6 +270,8 @@ static PyGetSetDef objfile_getset[] = "The objfile's filename, or None.", NULL }, { "pretty_printers", objfpy_get_printers, objfpy_set_printers, "Pretty printers.", NULL }, + { "type_printers", objfpy_get_type_printers, objfpy_set_type_printers, + "Type printers.", NULL }, { NULL } }; |