summaryrefslogtreecommitdiff
path: root/gdb/python/py-utils.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2012-02-17 19:24:25 +0000
committerTom Tromey <tromey@redhat.com>2012-02-17 19:24:25 +0000
commitdb362f800c98416e9654e51c60e22ef96d0d341c (patch)
tree0459bb3f7df1608a7daccb66ae190eb2c60a27d4 /gdb/python/py-utils.c
parent7fff0957621ce0850a0a67ff7abcff29c7670427 (diff)
downloadgdb-db362f800c98416e9654e51c60e22ef96d0d341c.tar.gz
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/py-utils.c')
-rw-r--r--gdb/python/py-utils.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index 3579720674d..bf50e37d5b0 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;
+}