aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@adacore.com>2013-12-23 07:18:51 +0400
committerJoel Brobecker <brobecker@adacore.com>2014-01-07 07:11:17 +0400
commitc0d4881122d0491f5dea9fa2c017ab5d2ae5fe89 (patch)
tree954f3b213cf597faf57e249d3de4c92253060a2f /gdb/python
parentc26e9cbb0ce70e8fca32a40c434a0837bf46750a (diff)
downloadgdb-c0d4881122d0491f5dea9fa2c017ab5d2ae5fe89.zip
gdb-c0d4881122d0491f5dea9fa2c017ab5d2ae5fe89.tar.gz
gdb-c0d4881122d0491f5dea9fa2c017ab5d2ae5fe89.tar.bz2
[python] Add gdb.Type.name attribute.
Consider the following declarations: typedef long our_time_t; our_time_t current_time = 1384395743; The purpose of this patch is to allow the use of a pretty-printer for variables of type our_time_t. Normally, pretty-printing sniffers use the tag name in order to determine which, if any, pretty-printer should be used. But in the case above, the tag name is not set, since it does not apply to integral types. This patch extends the gdb.Type list of attributes to also include the name of the type, thus allowing the sniffer to match against that name. With that change, I was able to write a pretty-printer which displays our variable as follow: (gdb) print current_time $1 = Thu Nov 14 02:22:23 2013 (1384395743) gdb/ChangeLog: * python/py-type.c (typy_get_name): New function. (type_object_getset): Add entry for attribute "name". * NEWS: Add entry mentioning this new attribute. gdb/doc/ChangeLog: * gdb.texinfo (Types In Python): Document new attribute Types.name. gdb/testsuite: * gdb.python/py-pp-integral.c: New file. * gdb.python/py-pp-integral.py: New file. * gdb.python/py-pp-integral.exp: New file. Tested on x86_64-linux.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-type.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 3941a11..16bb442 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -414,6 +414,18 @@ typy_items (PyObject *self, PyObject *args)
return typy_fields_items (self, iter_items);
}
+/* Return the type's name, or None. */
+
+static PyObject *
+typy_get_name (PyObject *self, void *closure)
+{
+ struct type *type = ((type_object *) self)->type;
+
+ if (TYPE_NAME (type) == NULL)
+ Py_RETURN_NONE;
+ return PyString_FromString (TYPE_NAME (type));
+}
+
/* Return the type's tag, or None. */
static PyObject *
typy_get_tag (PyObject *self, void *closure)
@@ -1395,6 +1407,8 @@ static PyGetSetDef type_object_getset[] =
{
{ "code", typy_get_code, NULL,
"The code for this type.", NULL },
+ { "name", typy_get_name, NULL,
+ "The name for this type, or None.", NULL },
{ "sizeof", typy_get_sizeof, NULL,
"The size of this type, in bytes.", NULL },
{ "tag", typy_get_tag, NULL,