From patchwork Tue Apr 24 15:22:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26918 Received: (qmail 33779 invoked by alias); 24 Apr 2018 15:22:35 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 33733 invoked by uid 89); 24 Apr 2018 15:22:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=inspect, 9306, H*Ad:U*tom X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.143.39) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 24 Apr 2018 15:22:32 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 6C20C10E937 for ; Tue, 24 Apr 2018 10:22:31 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id Azm3fta2GA3CSAzm3fzV0z; Tue, 24 Apr 2018 10:22:31 -0500 X-Authority-Reason: nr=8 Received: from 97-122-176-117.hlrn.qwest.net ([97.122.176.117]:45490 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1fAzm3-002CeZ-7H; Tue, 24 Apr 2018 10:22:31 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 4/6] Expose type alignment on gdb.Type Date: Tue, 24 Apr 2018 09:22:20 -0600 Message-Id: <20180424152222.8053-5-tom@tromey.com> In-Reply-To: <20180424152222.8053-1-tom@tromey.com> References: <20180424152222.8053-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fAzm3-002CeZ-7H X-Source-Sender: 97-122-176-117.hlrn.qwest.net (pokyo.Home) [97.122.176.117]:45490 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This adds an "align" attribute to gdb.Type in the Python API. 2018-04-24 Tom Tromey * NEWS: Mention Type.align. * python/py-type.c (typy_get_align): New function. (type_object_getset): Add "align". 2018-04-24 Tom Tromey * python.texi (Types In Python): Document Type.align. 2018-04-24 Tom Tromey * gdb.python/py-type.exp: Check align attribute. * gdb.python/py-type.c: New "aligncheck" global. --- gdb/ChangeLog | 6 ++++++ gdb/NEWS | 4 ++++ gdb/doc/ChangeLog | 4 ++++ gdb/doc/python.texi | 7 +++++++ gdb/python/py-type.c | 24 ++++++++++++++++++++++++ gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.python/py-type.c | 2 ++ gdb/testsuite/gdb.python/py-type.exp | 4 ++++ 8 files changed, 56 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 98ea77816b..78acc26f4a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2018-04-24 Tom Tromey + + * NEWS: Mention Type.align. + * python/py-type.c (typy_get_align): New function. + (type_object_getset): Add "align". + 2018-04-24 Tom Tromey * python/py-type.c (type_object_getset): Reindent. diff --git a/gdb/NEWS b/gdb/NEWS index 6631b53475..6193070023 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 83d48781f9..57df264c1b 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,7 @@ +2018-04-24 Tom Tromey + + * python.texi (Types In Python): Document Type.align. + 2018-04-13 Andreas Arnez * gdb.texinfo (Symbols): Mention the fact that "info diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index ebd48fffe7..e5fd713e0a 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.align +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 fcd6ed5621..bc49ec66ac 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_align (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[] = { + { "align", typy_get_align, 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 ad7889b677..50c1851c4d 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-04-24 Tom Tromey + + * gdb.python/py-type.exp: Check align attribute. + * gdb.python/py-type.c: New "aligncheck" global. + 2018-04-24 Tom Tromey PR exp/17095: diff --git a/gdb/testsuite/gdb.python/py-type.c b/gdb/testsuite/gdb.python/py-type.c index 2626d4e418..9531c9e6cb 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 b87e86cdf6..382bdff118 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())" \ "" + set sint [get_sizeof int 0] + gdb_test "python print(gdb.parse_and_eval('aligncheck').type.align)" \ + $sint + with_test_prefix "lang_c" { runto_bp "break to inspect struct and array." test_fields "c"