From patchwork Thu May 17 21:23:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 27319 Received: (qmail 7731 invoked by alias); 17 May 2018 21:23:13 -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 7699 invoked by uid 89); 17 May 2018 21:23:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 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=hole X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (192.185.188.18) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 17 May 2018 21:23:11 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 86310400E90AC for ; Thu, 17 May 2018 16:23:09 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id JQMffUV3qlAdrJQMff0Q0W; Thu, 17 May 2018 16:23:09 -0500 X-Authority-Reason: nr=8 Received: from 174-29-44-154.hlrn.qwest.net ([174.29.44.154]:33712 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1fJQMf-003p5p-Ay; Thu, 17 May 2018 16:23:09 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Show padding in ptype/o output Date: Thu, 17 May 2018 15:23:07 -0600 Message-Id: <20180517212307.29102-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fJQMf-003p5p-Ay X-Source-Sender: 174-29-44-154.hlrn.qwest.net (bapiya.Home) [174.29.44.154]:33712 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes I was recently using ptype/o to look at the layout of some objects in gdb. I noticed that trailing padding was not shown -- but I wanted to be able to look at that, too. This patch changes ptype/o to also print trailing holes. Tested on x86-64 Fedora 26. gdb/ChangeLog 2018-05-17 Tom Tromey * c-typeprint.c (maybe_print_hole): New function. (c_print_type_struct_field_offset): Update. (c_type_print_base_struct_union): Call maybe_print_hole. gdb/testsuite/ChangeLog 2018-05-17 Tom Tromey * gdb.base/ptype-offsets.exp: Update. --- gdb/ChangeLog | 6 ++++++ gdb/c-typeprint.c | 6 ++++++ gdb/testsuite/ChangeLog | 4 ++++ gdb/testsuite/gdb.base/ptype-offsets.exp | 12 ++++++++++++ 4 files changed, 28 insertions(+) diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index fdfa8aee52..cb793f0770 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -937,6 +937,12 @@ c_print_type_union_field_offset (struct type *type, unsigned int field_idx, fprintf_filtered (stream, "/* %4u */", TYPE_LENGTH (ftype)); } +/* Helper function for ptype/o implementation that prints information + about a hole, if necessary. STREAM is where to print. BITPOS is + the bitpos of the current field. PODATA is the offset-printing + state. FOR_WHAT is a string describing the purpose of the + hole. */ + static void maybe_print_hole (struct ui_file *stream, unsigned int bitpos, struct print_offset_data *podata, const char *for_what) diff --git a/gdb/testsuite/gdb.base/ptype-offsets.exp b/gdb/testsuite/gdb.base/ptype-offsets.exp index 003e294a74..d8718d581b 100644 --- a/gdb/testsuite/gdb.base/ptype-offsets.exp +++ b/gdb/testsuite/gdb.base/ptype-offsets.exp @@ -52,6 +52,7 @@ gdb_test "ptype /o struct abc" \ { /\* total size \(bytes\): 8 \*/} \ { \} field8;} \ {/\* 48 | 4 \*/ my_int_type field9;} \ +{/\* XXX 4-byte padding \*/} \ {} \ { /\* total size \(bytes\): 56 \*/} \ { \}}] @@ -81,6 +82,7 @@ gdb_test "ptype /oTM struct abc" \ { ~abc\(\);} \ {} \ { typedef int my_int_type;} \ +{/\* XXX 4-byte padding \*/} \ {} \ { /\* total size \(bytes\): 56 \*/} \ { \}}] @@ -105,6 +107,7 @@ gdb_test "ptype /TMo struct abc" \ { /\* total size \(bytes\): 8 \*/} \ { \} field8;} \ {/\* 48 | 4 \*/ my_int_type field9;} \ +{/\* XXX 4-byte padding \*/} \ {} \ { /\* total size \(bytes\): 56 \*/} \ { \}}] @@ -133,6 +136,7 @@ gdb_test "ptype /o struct pqr" \ { \} ff2;} \ {/\* XXX 28-byte hole \*/} \ {/\* 72 | 1 \*/ signed char ff3;} \ +{/\* XXX 7-byte padding \*/} \ {} \ { /\* total size \(bytes\): 56 \*/} \ { \}}] @@ -148,6 +152,7 @@ gdb_test "ptype /o union qwe" \ {/\* XXX 4-byte hole \*/} \ {/\* 8 | 8 \*/ signed char \*a2;} \ {/\* 16 | 4 \*/ int a3;} \ +{/\* XXX 4-byte padding \*/} \ {} \ { /\* total size \(bytes\): 24 \*/} \ { \} fff1;} \ @@ -161,6 +166,7 @@ gdb_test "ptype /o union qwe" \ {/\* XXX 4-byte hole \*/} \ {/\* 24 | 8 \*/ signed char \*a2;} \ {/\* 32 | 4 \*/ int a3;} \ +{/\* XXX 4-byte padding \*/} \ {} \ { /\* total size \(bytes\): 24 \*/} \ { \} f4;} \ @@ -184,6 +190,7 @@ gdb_test "ptype /o struct poi" \ {/\* XXX 4-byte hole \*/} \ {/\* 16 | 8 \*/ signed char \*a2;} \ {/\* 24 | 4 \*/ int a3;} \ +{/\* XXX 4-byte padding \*/} \ {} \ { /\* total size \(bytes\): 24 \*/} \ { \} fff1;} \ @@ -197,9 +204,11 @@ gdb_test "ptype /o struct poi" \ {/\* XXX 4-byte hole \*/} \ {/\* 32 | 8 \*/ signed char \*a2;} \ {/\* 40 | 4 \*/ int a3;} \ +{/\* XXX 4-byte padding \*/} \ {} \ { /\* total size \(bytes\): 24 \*/} \ { \} f4;} \ +{/\* XXX 32-byte padding \*/} \ {} \ { /\* total size \(bytes\): 40 \*/} \ { \} fff2;} \ @@ -221,6 +230,7 @@ gdb_test "ptype /o struct poi" \ {/\* XXX 4-byte hole \*/} \ {/\* 112 | 8 \*/ signed char \*a2;} \ {/\* 120 | 4 \*/ int a3;} \ +{/\* XXX 4-byte padding \*/} \ {} \ { /\* total size \(bytes\): 24 \*/} \ { \} f4;} \ @@ -228,6 +238,7 @@ gdb_test "ptype /o struct poi" \ { /\* total size \(bytes\): 40 \*/} \ { \} ff2;} \ {/\* 152 | 1 \*/ signed char ff3;} \ +{/\* XXX 7-byte padding \*/} \ {} \ { /\* total size \(bytes\): 56 \*/} \ { \} f4;} \ @@ -262,6 +273,7 @@ gdb_test "ptype /o struct tyu" \ {/\* 8 | 8 \*/ int64_t a5;} \ {/\* 16:27 | 4 \*/ int a6 : 5;} \ {/\* 16:56 | 8 \*/ int64_t a7 : 3;} \ +{/\* XXX 7-byte padding \*/} \ {} \ { /\* total size \(bytes\): 24 \*/} \ { \}}]