[PATCH v4 2/2] Implement pahole-like 'ptype /o' option
Simon Marchi
simark@simark.ca
Tue Dec 12 01:59:00 GMT 2017
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
More information about the Gdb-patches
mailing list