This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2] Implement pahole-like 'ptype /o' option


On Tuesday, December 12 2017, John Baldwin wrote:

> On 12/11/17 8:25 PM, Simon Marchi wrote:
>> On 2017-12-11 19:51, Pedro Alves wrote:
>>>>> So from that angle, I see value in not printing the offsets
>>>>> of union members.
>>>>
>>>> Since it's still not clear whether the offsets should be printed or 
>>>> not
>>>> in this case, and I am not a global maintainer, I adjusted the code to
>>>> print them and will post the patch as a reply to the v4 e-mail.  This
>>>> way you can decide which version is best.
>>>
>>> Fun, just when I agreed with not printing the offsets... :-P  :-)
>> 
>> Damn, sorry for starting you guys on that track!  I just wanted to know 
>> if it was intentional or not, I am fine with either.
>
> The only reason I would find the offset usable is to know the offset of
> a structure member inside of a union.  E.g.:
>
> struct foo {
>      int x;
>      union {
>          struct {
>              int y;
>              int z;
>          };
>          int a;
>      };
> };
>
> I think it is useful to know the offset of 'foo.z' within the overall
> structure.

You'll have that:

(gdb) ptype /o struct foo
/* offset    |  size */
struct foo {
/*    0      |     4 */    int x;
/*    4      |     8 */    union {
/*                 8 */        struct {
/*    4      |     4 */            int y;
/*    8      |     4 */            int z;
                               } /* total size:    8 bytes */;
/*                 4 */        int a;
                           } /* total size:    8 bytes */;
} /* total size:   12 bytes */


-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]