diff options
author | Tom Tromey <tom@tromey.com> | 2018-04-20 15:43:56 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-04-30 11:25:31 -0600 |
commit | 6d7bb8246b3beaf60ea9c2abe183705e876519cd (patch) | |
tree | 57eeee53543aa1091d282fc6ffe553902446b706 /gdb/python | |
parent | 007e1530347330d4dbba387c4e35aae05bc06498 (diff) | |
download | gdb-6d7bb8246b3beaf60ea9c2abe183705e876519cd.zip gdb-6d7bb8246b3beaf60ea9c2abe183705e876519cd.tar.gz gdb-6d7bb8246b3beaf60ea9c2abe183705e876519cd.tar.bz2 |
Expose type alignment on gdb.Type
This adds an "alignof" attribute to gdb.Type in the Python API.
2018-04-30 Tom Tromey <tom@tromey.com>
* NEWS: Mention Type.align.
* python/py-type.c (typy_get_alignof): New function.
(type_object_getset): Add "alignof".
2018-04-30 Tom Tromey <tom@tromey.com>
* python.texi (Types In Python): Document Type.align.
2018-04-30 Tom Tromey <tom@tromey.com>
* gdb.python/py-type.exp: Check align attribute.
* gdb.python/py-type.c: New "aligncheck" global.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-type.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 8a948ee..cbdcd21 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -730,6 +730,28 @@ typy_get_sizeof (PyObject *self, void *closure) return gdb_py_long_from_longest (TYPE_LENGTH (type)); } +/* Return the alignment of the type represented by SELF, in bytes. */ +static PyObject * +typy_get_alignof (PyObject *self, void *closure) +{ + struct type *type = ((type_object *) self)->type; + + ULONGEST align = 0; + TRY + { + align = type_align (type); + } + CATCH (except, RETURN_MASK_ALL) + { + align = 0; + } + END_CATCH + + /* Ignore exceptions. */ + + return gdb_py_object_from_ulongest (align); +} + static struct type * typy_lookup_typename (const char *type_name, const struct block *block) { @@ -1410,6 +1432,8 @@ gdbpy_initialize_types (void) static gdb_PyGetSetDef type_object_getset[] = { + { "alignof", typy_get_alignof, NULL, + "The alignment of this type, in bytes.", NULL }, { "code", typy_get_code, NULL, "The code for this type.", NULL }, { "name", typy_get_name, NULL, |