aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-04-20 15:43:56 -0600
committerTom Tromey <tom@tromey.com>2018-04-30 11:25:31 -0600
commit6d7bb8246b3beaf60ea9c2abe183705e876519cd (patch)
tree57eeee53543aa1091d282fc6ffe553902446b706
parent007e1530347330d4dbba387c4e35aae05bc06498 (diff)
downloadgdb-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.
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/NEWS4
-rw-r--r--gdb/doc/ChangeLog4
-rw-r--r--gdb/doc/python.texi7
-rw-r--r--gdb/python/py-type.c24
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.python/py-type.c2
-rw-r--r--gdb/testsuite/gdb.python/py-type.exp4
8 files changed, 56 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 27bf1dd..0053b90 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
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>
+
PR exp/17095:
* NEWS: Update.
* std-operator.def (UNOP_ALIGNOF): New operator.
diff --git a/gdb/NEWS b/gdb/NEWS
index 6631b53..6193070 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -27,6 +27,10 @@ set|show record btrace cpu
Controls the processor to be used for enabling errata workarounds for
branch trace decode.
+* Python API
+
+ ** Type alignment is now exposed via the "align" attribute of a gdb.Type.
+
* New targets
RiscV ELF riscv*-*-elf
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 83d4878..2da4984 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2018-04-30 Tom Tromey <tom@tromey.com>
+
+ * python.texi (Types In Python): Document Type.align.
+
2018-04-13 Andreas Arnez <arnez@linux.vnet.ibm.com>
* gdb.texinfo (Symbols): Mention the fact that "info
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index ebd48ff..05703fb 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -930,6 +930,13 @@ description of the @code{Type.fields} method for a description of the
An instance of @code{Type} has the following attributes:
+@defvar Type.alignof
+The alignment of this type, in bytes. Type alignment comes from the
+debugging information; if it was not specified, then @value{GDBN} will
+use the relevant ABI to try to determine the alignment. In some
+cases, even this is not possible, and zero will be returned.
+@end defvar
+
@defvar Type.code
The type code for this type. The type code will be one of the
@code{TYPE_CODE_} constants defined below.
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,
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index e8b55aa..4e48934 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2018-04-30 Tom Tromey <tom@tromey.com>
+ * gdb.python/py-type.exp: Check align attribute.
+ * gdb.python/py-type.c: New "aligncheck" global.
+
+2018-04-30 Tom Tromey <tom@tromey.com>
+
PR exp/17095:
* gdb.dwarf2/dw2-align.exp: New file.
* gdb.cp/align.exp: New file.
diff --git a/gdb/testsuite/gdb.python/py-type.c b/gdb/testsuite/gdb.python/py-type.c
index 2626d4e..9531c9e 100644
--- a/gdb/testsuite/gdb.python/py-type.c
+++ b/gdb/testsuite/gdb.python/py-type.c
@@ -30,6 +30,8 @@ struct SS
typedef struct s TS;
TS ts;
+int aligncheck;
+
#ifdef __cplusplus
struct C
{
diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp
index b87e86c..8fe0221 100644
--- a/gdb/testsuite/gdb.python/py-type.exp
+++ b/gdb/testsuite/gdb.python/py-type.exp
@@ -278,6 +278,10 @@ if { [build_inferior "${binfile}" "c"] == 0 } {
gdb_test "python print(gdb.lookup_type('int').optimized_out())" \
"<optimized out>"
+ set sint [get_sizeof int 0]
+ gdb_test "python print(gdb.parse_and_eval('aligncheck').type.alignof)" \
+ $sint
+
with_test_prefix "lang_c" {
runto_bp "break to inspect struct and array."
test_fields "c"