aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2014-10-30 17:05:17 -0700
committerDoug Evans <dje@google.com>2014-10-30 17:05:17 -0700
commit02be9a71009c94840f2367aa5554cbe5b71f56d1 (patch)
tree5ea6265fa492caee6ec30f97bcf84e2cfaa05414 /gdb/python
parentc21c8bde378b41f80ef61313ffbf653592e4ba28 (diff)
downloadgdb-02be9a71009c94840f2367aa5554cbe5b71f56d1.zip
gdb-02be9a71009c94840f2367aa5554cbe5b71f56d1.tar.gz
gdb-02be9a71009c94840f2367aa5554cbe5b71f56d1.tar.bz2
Add ability to add attributes to gdb.Objfile and gdb.Progspace objects.
gdb/ChangeLog: * NEWS: Mention ability add attributes to gdb.Objfile and gdb.Progspace objects. * python/py-objfile.c (objfile_object): New member dict. (objfpy_dealloc): Py_XDECREF dict. (objfpy_initialize): Initialize dict. (objfile_getset): Add __dict__. (objfile_object_type): Set tp_dictoffset member. * python/py-progspace.c (progspace_object): New member dict. (pspy_dealloc): Py_XDECREF dict. (pspy_initialize): Initialize dict. (pspace_getset): Add __dict__. (pspace_object_type): Set tp_dictoffset member. gdb/doc/ChangeLog: * python.texi (Progspaces In Python): Document ability to add random attributes to gdb.Progspace objects. (Objfiles In Python): Document ability to add random attributes to gdb.objfile objects. gdb/testsuite/ChangeLog: * gdb.python/py-objfile.exp: Add tests for setting random attributes in objfiles. * gdb.python/py-progspace.exp: Add tests for setting random attributes in progspaces.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-objfile.c10
-rw-r--r--gdb/python/py-progspace.c10
2 files changed, 18 insertions, 2 deletions
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index e868223..c99de87 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -30,6 +30,10 @@ typedef struct
/* The corresponding objfile. */
struct objfile *objfile;
+ /* Dictionary holding user-added attributes.
+ This is the __dict__ attribute of the object. */
+ PyObject *dict;
+
/* The pretty-printer list of functions. */
PyObject *printers;
@@ -85,6 +89,7 @@ objfpy_dealloc (PyObject *o)
{
objfile_object *self = (objfile_object *) o;
+ Py_XDECREF (self->dict);
Py_XDECREF (self->printers);
Py_XDECREF (self->frame_filters);
Py_XDECREF (self->type_printers);
@@ -99,6 +104,7 @@ static int
objfpy_initialize (objfile_object *self)
{
self->objfile = NULL;
+ self->dict = NULL;
self->printers = PyList_New (0);
if (self->printers == NULL)
@@ -354,6 +360,8 @@ Return true if this object file is valid, false if not." },
static PyGetSetDef objfile_getset[] =
{
+ { "__dict__", gdb_py_generic_dict, NULL,
+ "The __dict__ for this objfile.", &objfile_object_type },
{ "filename", objfpy_get_filename, NULL,
"The objfile's filename, or None.", NULL },
{ "progspace", objfpy_get_progspace, NULL,
@@ -405,7 +413,7 @@ static PyTypeObject objfile_object_type =
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
- 0, /* tp_dictoffset */
+ offsetof (objfile_object, dict), /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
objfpy_new, /* tp_new */
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index 4280032..96339b1 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -32,6 +32,10 @@ typedef struct
/* The corresponding pspace. */
struct program_space *pspace;
+ /* Dictionary holding user-added attributes.
+ This is the __dict__ attribute of the object. */
+ PyObject *dict;
+
/* The pretty-printer list of functions. */
PyObject *printers;
@@ -75,6 +79,7 @@ pspy_dealloc (PyObject *self)
{
pspace_object *ps_self = (pspace_object *) self;
+ Py_XDECREF (ps_self->dict);
Py_XDECREF (ps_self->printers);
Py_XDECREF (ps_self->frame_filters);
Py_XDECREF (ps_self->type_printers);
@@ -89,6 +94,7 @@ static int
pspy_initialize (pspace_object *self)
{
self->pspace = NULL;
+ self->dict = NULL;
self->printers = PyList_New (0);
if (self->printers == NULL)
@@ -331,6 +337,8 @@ gdbpy_initialize_pspace (void)
static PyGetSetDef pspace_getset[] =
{
+ { "__dict__", gdb_py_generic_dict, NULL,
+ "The __dict__ for this progspace.", &pspace_object_type },
{ "filename", pspy_get_filename, NULL,
"The progspace's main filename, or None.", NULL },
{ "pretty_printers", pspy_get_printers, pspy_set_printers,
@@ -380,7 +388,7 @@ static PyTypeObject pspace_object_type =
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
- 0, /* tp_dictoffset */
+ offsetof (pspace_object, dict), /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
pspy_new, /* tp_new */