From: Sergio Durigan Junior <sergiodj@redhat.com>
To: GDB Patches <gdb-patches@sourceware.org>
Cc: "Tom Tromey" <tom@tromey.com>, "Eli Zaretskii" <eliz@gnu.org>,
"Simon Marchi" <simon.marchi@ericsson.com>,
"Pedro Alves" <palves@redhat.com>,
"André Pönitz" <apoenitz@t-online.de>,
"Keith Seitz" <keiths@redhat.com>
Subject: Re: [PATCH v4 2/2] Implement pahole-like 'ptype /o' option
Date: Tue, 12 Dec 2017 00:27:00 -0000 [thread overview]
Message-ID: <87zi6o7pue.fsf@redhat.com> (raw)
In-Reply-To: <20171211234345.27351-3-sergiodj@redhat.com> (Sergio Durigan Junior's message of "Mon, 11 Dec 2017 18:43:45 -0500")
On Monday, December 11 2017, I wrote:
> This commit implements the pahole-like '/o' option for 'ptype', which
> prints the offsets and sizes of struct fields, reporting whenever
> there is a hole found.
>
> The output is heavily based on pahole(1), with a few modifications
> here and there to adjust it to our reality. Here's an example:
>
> (gdb) ptype /o stap_probe
> /* offset | size */
> struct stap_probe {
> /* 0 | 40 */ struct probe {
> /* 0 | 8 */ const probe_ops *pops;
> /* 8 | 8 */ gdbarch *arch;
> /* 16 | 8 */ const char *name;
> /* 24 | 8 */ const char *provider;
> /* 32 | 8 */ CORE_ADDR address;
> } /* total size: 40 bytes */ p;
> /* 40 | 8 */ CORE_ADDR sem_addr;
> /* 48:31 | 4 */ unsigned int args_parsed : 1;
> /* XXX 7-bit hole */
> /* XXX 7-byte hole */
> /* 56 | 8 */ union {
> /* 8 */ const char *text;
> /* 8 */ VEC_stap_probe_arg_s *vec;
> } /* total size: 8 bytes */ args_u;
> } /* total size: 64 bytes */
>
> A big part of this patch handles the formatting logic of 'ptype',
> which is a bit messy. I tried to be not very invasive, but I had to
> do some cleanups here and there to make life easier.
>
> This patch is the start of a long-term work I'll do to flush the local
> patches we carry for Fedora GDB. In this specific case, I'm aiming at
> upstreaming the feature implemented by the 'pahole.py' script that is
> shipped with Fedora GDB:
>
> <https://src.fedoraproject.org/rpms/gdb/blob/master/f/gdb-archer.patch#_311>
>
> This has been regression-tested on the BuildBot. There's a new
> testcase for it, along with an update to the documentation. I also
> thought it was worth mentioning this feature in the NEWS file.
The patch below applies on top of this one and extends the output to
include offsets of union fields.
--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 23138d8a40..e66129f643 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -906,11 +906,15 @@ output_access_specifier (struct ui_file *stream,
static void
c_print_type_union_field_offset (struct type *type, unsigned int field_idx,
- struct ui_file *stream)
+ struct ui_file *stream,
+ unsigned int offset_bitpos)
{
struct type *ftype = check_typedef (TYPE_FIELD_TYPE (type, field_idx));
+ unsigned int bitpos = TYPE_FIELD_BITPOS (type, field_idx);
- fprintf_filtered (stream, "/* %4u */", TYPE_LENGTH (ftype));
+ fprintf_filtered (stream, "/* %4u | %4u */",
+ (bitpos + offset_bitpos) / TARGET_CHAR_BIT,
+ TYPE_LENGTH (ftype));
}
/* Print information about field at index FIELD_IDX of the struct type
@@ -1169,7 +1173,8 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
c_print_type_struct_field_offset (type, i, &endpos, stream,
flags->offset_bitpos);
else if (TYPE_CODE (type) == TYPE_CODE_UNION)
- c_print_type_union_field_offset (type, i, stream);
+ c_print_type_union_field_offset (type, i, stream,
+ flags->offset_bitpos);
}
else
print_spaces_filtered (OFFSET_SPC_LEN, stream);
diff --git a/gdb/testsuite/gdb.base/ptype-offsets.exp b/gdb/testsuite/gdb.base/ptype-offsets.exp
index fa1c0cb41c..7566dcaaab 100644
--- a/gdb/testsuite/gdb.base/ptype-offsets.exp
+++ b/gdb/testsuite/gdb.base/ptype-offsets.exp
@@ -44,8 +44,8 @@ gdb_test "ptype /o struct abc" \
"/\\\* XXX 7-byte hole \\\*/" \
"/\\\* 32 | 8 \\\*/ uint64_t field5;" \
"/\\\* 40 | 8 \\\*/ union {" \
-"/\\\* 8 \\\*/ void \\\*field6;" \
-"/\\\* 4 \\\*/ int field7;" \
+"/\\\* 40 | 8 \\\*/ void \\\*field6;" \
+"/\\\* 40 | 4 \\\*/ int field7;" \
" } /\\\* total size: 8 bytes \\\*/ field8;" \
"" \
" abc\\(void\\);" \
@@ -82,13 +82,13 @@ gdb_test "ptype /o struct pqr" \
gdb_test "ptype /o union qwe" \
[multi_line \
"/\\\* offset | size \\\*/" \
-"/\\\* 24 \\\*/ struct tuv {" \
+"/\\\* 0 | 24 \\\*/ struct tuv {" \
"/\\\* 0 | 4 \\\*/ int a1;" \
"/\\\* XXX 4-byte hole \\\*/" \
"/\\\* 8 | 8 \\\*/ char \\\*a2;" \
"/\\\* 16 | 4 \\\*/ int a3;" \
" } /\\\* total size: 24 bytes \\\*/ fff1;" \
-"/\\\* 40 \\\*/ struct xyz {" \
+"/\\\* 0 | 40 \\\*/ struct xyz {" \
"/\\\* 0 | 4 \\\*/ int f1;" \
"/\\\* 4 | 1 \\\*/ char f2;" \
"/\\\* XXX 3-byte hole \\\*/" \
@@ -111,13 +111,13 @@ gdb_test "ptype /o struct poi" \
"/\\\* 0 | 4 \\\*/ int f1;" \
"/\\\* XXX 4-byte hole \\\*/" \
"/\\\* 8 | 40 \\\*/ union qwe {" \
-"/\\\* 24 \\\*/ struct tuv {" \
+"/\\\* 8 | 24 \\\*/ struct tuv {" \
"/\\\* 8 | 4 \\\*/ int a1;" \
"/\\\* XXX 4-byte hole \\\*/" \
"/\\\* 16 | 8 \\\*/ char \\\*a2;" \
"/\\\* 24 | 4 \\\*/ int a3;" \
" } /\\\* total size: 24 bytes \\\*/ fff1;" \
-"/\\\* 40 \\\*/ struct xyz {" \
+"/\\\* 8 | 40 \\\*/ struct xyz {" \
"/\\\* 8 | 4 \\\*/ int f1;" \
"/\\\* 12 | 1 \\\*/ char f2;" \
"/\\\* XXX 3-byte hole \\\*/" \
next prev parent reply other threads:[~2017-12-12 0:27 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-21 16:07 [PATCH] " Sergio Durigan Junior
2017-11-21 16:16 ` Sergio Durigan Junior
2017-11-21 16:50 ` Eli Zaretskii
2017-11-21 17:00 ` Sergio Durigan Junior
2017-11-21 19:14 ` Eli Zaretskii
2017-11-26 19:27 ` Tom Tromey
2017-11-27 19:54 ` Sergio Durigan Junior
2017-11-27 22:20 ` Tom Tromey
2017-11-28 0:39 ` Sergio Durigan Junior
2017-11-28 21:21 ` [PATCH v2] " Sergio Durigan Junior
2017-11-29 3:28 ` Eli Zaretskii
2017-12-04 15:03 ` Sergio Durigan Junior
2017-12-04 15:41 ` Eli Zaretskii
2017-12-04 16:47 ` Sergio Durigan Junior
2017-12-08 21:32 ` Sergio Durigan Junior
2017-12-11 15:43 ` Simon Marchi
2017-12-11 18:59 ` Sergio Durigan Junior
2017-12-11 20:45 ` Simon Marchi
2017-12-11 21:07 ` Sergio Durigan Junior
2017-12-11 22:42 ` Pedro Alves
2017-12-11 22:50 ` Sergio Durigan Junior
2017-12-11 23:46 ` Pedro Alves
2017-12-12 0:25 ` Sergio Durigan Junior
2017-12-12 0:52 ` Pedro Alves
2017-12-12 1:25 ` Simon Marchi
2017-12-12 15:50 ` John Baldwin
2017-12-12 17:04 ` Sergio Durigan Junior
2017-12-11 19:58 ` [PATCH v3 0/2] Implement pahole-like 'ptype /o' option (and do some code reorg) Sergio Durigan Junior
2017-12-11 19:58 ` [PATCH v3 2/2] Implement pahole-like 'ptype /o' option Sergio Durigan Junior
2017-12-11 21:50 ` Simon Marchi
2017-12-11 23:24 ` Sergio Durigan Junior
2017-12-12 1:32 ` Simon Marchi
2017-12-12 6:19 ` Sergio Durigan Junior
2017-12-12 18:14 ` Pedro Alves
2017-12-12 18:40 ` Sergio Durigan Junior
2017-12-12 20:12 ` Pedro Alves
2017-12-11 19:58 ` [PATCH v3 1/2] Reorganize code to handle TYPE_CODE_{STRUCT,UNION} on 'c_type_print_base' Sergio Durigan Junior
2017-12-11 20:55 ` Simon Marchi
2017-12-11 23:05 ` Sergio Durigan Junior
2017-12-11 23:43 ` [PATCH v4 0/2] Implement pahole-like 'ptype /o' option (and do some code reorg) Sergio Durigan Junior
2017-12-11 23:44 ` [PATCH v4 1/2] Reorganize code to handle TYPE_CODE_{STRUCT,UNION} on 'c_type_print_base' Sergio Durigan Junior
2017-12-11 23:44 ` [PATCH v4 2/2] Implement pahole-like 'ptype /o' option Sergio Durigan Junior
2017-12-12 0:27 ` Sergio Durigan Junior [this message]
2017-12-12 0:29 ` Sergio Durigan Junior
2017-12-12 1:59 ` Simon Marchi
2017-12-12 3:39 ` Eli Zaretskii
2017-12-13 3:17 ` [PATCH v5 0/2] Implement pahole-like 'ptype /o' option (and do some code reorg) Sergio Durigan Junior
2017-12-13 3:17 ` [PATCH v5 2/2] Implement pahole-like 'ptype /o' option Sergio Durigan Junior
2017-12-13 4:50 ` Simon Marchi
2017-12-13 16:42 ` Sergio Durigan Junior
2017-12-13 16:17 ` Eli Zaretskii
2017-12-13 17:14 ` Sergio Durigan Junior
2017-12-13 16:19 ` Pedro Alves
2017-12-13 17:13 ` Sergio Durigan Junior
2017-12-13 20:36 ` Sergio Durigan Junior
2017-12-13 21:22 ` Pedro Alves
2017-12-13 21:30 ` Pedro Alves
2017-12-13 21:34 ` Sergio Durigan Junior
2017-12-13 16:20 ` Pedro Alves
2017-12-13 17:41 ` Sergio Durigan Junior
2017-12-13 3:17 ` [PATCH v5 1/2] Reorganize code to handle TYPE_CODE_{STRUCT,UNION} on 'c_type_print_base' Sergio Durigan Junior
2017-12-14 2:48 ` [PATCH v6 0/2] Implement pahole-like 'ptype /o' option (and do some code reorg) Sergio Durigan Junior
2017-12-14 2:48 ` [PATCH v6 1/2] Reorganize code to handle TYPE_CODE_{STRUCT,UNION} on 'c_type_print_base' Sergio Durigan Junior
2017-12-14 2:48 ` [PATCH v6 2/2] Implement pahole-like 'ptype /o' option Sergio Durigan Junior
2017-12-14 14:19 ` Pedro Alves
2017-12-14 20:31 ` Sergio Durigan Junior
2017-12-14 14:50 ` Pedro Alves
2017-12-14 20:29 ` Sergio Durigan Junior
2017-12-14 16:30 ` Eli Zaretskii
2017-12-15 1:12 ` [PATCH v7 0/2] Implement pahole-like 'ptype /o' option (and do some code reorg) Sergio Durigan Junior
2017-12-15 1:12 ` [PATCH v7 1/2] Reorganize code to handle TYPE_CODE_{STRUCT,UNION} on 'c_type_print_base' Sergio Durigan Junior
2017-12-15 1:13 ` [PATCH v7 2/2] Implement pahole-like 'ptype /o' option Sergio Durigan Junior
2017-12-15 17:24 ` Pedro Alves
2017-12-15 20:04 ` Sergio Durigan Junior
2017-12-15 20:11 ` [PATCH v7 0/2] Implement pahole-like 'ptype /o' option (and do some code reorg) Sergio Durigan Junior
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=87zi6o7pue.fsf@redhat.com \
--to=sergiodj@redhat.com \
--cc=apoenitz@t-online.de \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=keiths@redhat.com \
--cc=palves@redhat.com \
--cc=simon.marchi@ericsson.com \
--cc=tom@tromey.com \
/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