From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA] Show padding in ptype/o output
Date: Thu, 17 May 2018 21:27:00 -0000 [thread overview]
Message-ID: <20180517212307.29102-1-tom@tromey.com> (raw)
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 <tom@tromey.com>
* 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 <tom@tromey.com>
* 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 \*/} \
{ \}}]
--
2.13.6
next reply other threads:[~2018-05-17 21:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-17 21:27 Tom Tromey [this message]
2018-05-18 0:25 ` Tom Tromey
2018-05-18 1:56 ` Sergio Durigan Junior
2018-05-18 19:03 ` Joel Brobecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180517212307.29102-1-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox