aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2012-02-17 19:24:27 +0000
committerTom Tromey <tromey@redhat.com>2012-02-17 19:24:27 +0000
commit2e8265fd8b24634b3d5c9f47fae5fa0cd157714e (patch)
treedb2d168d6872b28be60c9fe8f9994cb6c091e94b /gdb/python
parent8544a1503d0764c676b1825e0f4024bfb1c0197d (diff)
downloadgdb-2e8265fd8b24634b3d5c9f47fae5fa0cd157714e.zip
gdb-2e8265fd8b24634b3d5c9f47fae5fa0cd157714e.tar.gz
gdb-2e8265fd8b24634b3d5c9f47fae5fa0cd157714e.tar.bz2
PR python/12070:
* python/py-event.c (event_object_getset): New global. (event_object_type): Reference it. * python/py-type.c (field_object_getset): New global. (field_object_type): Reference it. * python/python-internal.h (gdb_py_generic_dict): Declare. * python/py-utils.c (gdb_py_generic_dict): New function. testsuite/gdb * gdb.python/py-events.py (exit_handler): Add test for 'dir'. * gdb.python/py-events.exp: Check 'dir' output. * gdb.python/py-type.exp (test_fields): Add test for 'dir'.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-event.c9
-rw-r--r--gdb/python/py-type.c9
-rw-r--r--gdb/python/py-utils.c20
-rw-r--r--gdb/python/python-internal.h2
4 files changed, 38 insertions, 2 deletions
diff --git a/gdb/python/py-event.c b/gdb/python/py-event.c
index 7d4ff14..4789761 100644
--- a/gdb/python/py-event.c
+++ b/gdb/python/py-event.c
@@ -132,6 +132,13 @@ evpy_emit_event (PyObject *event,
return -1;
}
+static PyGetSetDef event_object_getset[] =
+{
+ { "__dict__", gdb_py_generic_dict, NULL,
+ "The __dict__ for this event.", &event_object_type },
+ { NULL }
+};
+
PyTypeObject event_object_type =
{
PyObject_HEAD_INIT (NULL)
@@ -164,7 +171,7 @@ PyTypeObject event_object_type =
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
- 0, /* tp_getset */
+ event_object_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 70ed5d6..d47d4c8 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1681,6 +1681,13 @@ static PyTypeObject type_object_type =
0, /* tp_new */
};
+static PyGetSetDef field_object_getset[] =
+{
+ { "__dict__", gdb_py_generic_dict, NULL,
+ "The __dict__ for this field.", &field_object_type },
+ { NULL }
+};
+
static PyTypeObject field_object_type =
{
PyObject_HEAD_INIT (NULL)
@@ -1713,7 +1720,7 @@ static PyTypeObject field_object_type =
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
- 0, /* tp_getset */
+ field_object_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index 3579720..bf50e37 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -373,3 +373,23 @@ gdb_py_int_as_long (PyObject *obj, long *result)
*result = PyInt_AsLong (obj);
return ! (*result == -1 && PyErr_Occurred ());
}
+
+
+
+/* Generic implementation of the __dict__ attribute for objects that
+ have a dictionary. The CLOSURE argument should be the type object.
+ This only handles positive values for tp_dictoffset. */
+
+PyObject *
+gdb_py_generic_dict (PyObject *self, void *closure)
+{
+ PyObject *result;
+ PyTypeObject *type_obj = closure;
+ char *raw_ptr;
+
+ raw_ptr = (char *) self + type_obj->tp_dictoffset;
+ result = * (PyObject **) raw_ptr;
+
+ Py_INCREF (result);
+ return result;
+}
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 1d6247d..bae61c2 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -342,4 +342,6 @@ PyObject *gdb_py_object_from_longest (LONGEST l);
PyObject *gdb_py_object_from_ulongest (ULONGEST l);
int gdb_py_int_as_long (PyObject *, long *);
+PyObject *gdb_py_generic_dict (PyObject *self, void *closure);
+
#endif /* GDB_PYTHON_INTERNAL_H */