This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v4 2/2] Implement pahole-like 'ptype /o' option
- From: Simon Marchi <simark at simark dot ca>
- To: Sergio Durigan Junior <sergiodj at redhat dot com>, GDB Patches <gdb-patches at sourceware dot org>
- Cc: Tom Tromey <tom at tromey dot com>, Eli Zaretskii <eliz at gnu dot org>, Simon Marchi <simon dot marchi at ericsson dot com>, Pedro Alves <palves at redhat dot com>, André Pönitz <apoenitz at t-online dot de>, Keith Seitz <keiths at redhat dot com>
- Date: Mon, 11 Dec 2017 20:58:59 -0500
- Subject: Re: [PATCH v4 2/2] Implement pahole-like 'ptype /o' option
- Authentication-results: sourceware.org; auth=none
- References: <20171121160709.23248-1-sergiodj@redhat.com> <20171211234345.27351-1-sergiodj@redhat.com> <20171211234345.27351-3-sergiodj@redhat.com>
On 2017-12-11 06:43 PM, Sergio Durigan Junior 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.
That patch LGTM as-is, as well as with the union offsets :)
Simon