public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Sergio Durigan Junior <sergiodj@redhat.com>
Cc: Simon Marchi <simon.marchi@ericsson.com>,
	GDB Patches <gdb-patches@sourceware.org>,
	Tom Tromey <tom@tromey.com>, Eli Zaretskii <eliz@gnu.org>
Subject: Re: [PATCH v2] Implement pahole-like 'ptype /o' option
Date: Mon, 11 Dec 2017 23:46:00 -0000	[thread overview]
Message-ID: <0d314798-6e0d-f7a9-ace8-3cb43bda9947@redhat.com> (raw)
In-Reply-To: <87fu8gdgl8.fsf@redhat.com>

On 12/11/2017 10:50 PM, Sergio Durigan Junior wrote:

>>> Fair enough.  I use this trick for function prototypes, but not for the
>>> definitions.
>>
>> Simon's format is what I've been using for a long while too.
> 
> Well, I could post a few examples of the format I chose, but I'm pretty
> sure this would be worthless.  As I said, I will change my code.
> 

By stating the format that I've been using too, my intention
is to show that Simon's format isn't his own unique snowflake
either.

If there are many examples of the format you chose, I've not seem
many.  Maybe it depends on area of code one is touching, or IOW, on
the preferences of who wrote specific areas of the codebase.

IMO, the right way to go about this is to decide on a format,
document it in the wiki and then we can point everyone at it with a URL.
(ISTR that GCC's coding conventions documents yet another
way to break the line, and in that case, not even GCC follows it.)

IMO, the format you've chosen isn't ideal because it requires
manual right-alignment for every line, while breaking before the
parens makes emacs's TAB automatically align the following lines.
The latter also gives a lot more space for the params again; it's
sort of a "well, I have to do something, so might as well start
way back from the left again).

>>>> But I don't mind it, it just stuck out as a little inconsistency.
>>>
>>> I don't see the inconsistency.
>>>
>>> If a field is inside a struct, it has its offset *and* size printed.  No
>>> matter if the field is an int, another struct, or an union.
>>>
>>> If a field is inside an union, it has only its size printed.
>>>
>>> In the case above, it makes sense to have the offsets printed for the
>>> fields inside the two structs (inside the union), because there might be
>>> holes to report (well, one can argue that it doesn't matter if there are
>>> holes or not in this case, because if the other struct is bigger then
>>> the union size will stay the same).  However, it doesn't make sense to
>>> print the offsets for the two structs themselves, because they are
>>> members of the union.
>>>
>>> I hope it makes more sense now.
>>
>> But why do we need the special case?  Does it help anything?
>> So far, it seems it only added confusion.
> 
> What do you mean by "special case"?

Special case:

  "If a field is inside a union, it has only its size printed; otherwise
   print the offset and size." 

No special case:

  "Always print the offset and size."

> 
> This is what pahole does, and as I've said a few times, the output of
> 'ptype /o' has been based on pahole's output.  

That's abundantly clear, but I don't see why we need to follow
"pahole"'s output religiously...

> I don't consider this a
> special case; I consider it to be the natural thing to do, because
> offsets don't make much sense in unions.

Of course they do.  You can do 'offsetof(foo_union, foo_field)' just
fine, for example.  Saying that the offsets happen to be the same
is not the same as saying that the offsets don't exist.

I asked:

>> Does it help anything?
>> So far, it seems it only added confusion.

I think a much better rationale for omitting the offsets
would be:

Not printing the offsets in the case of union members helps
by increasing signal/noise ratio.

Why?  

With patch as is:

/*    0      |    32 */    struct general_symbol_info {
/*    0      |     8 */        const char *name;
/*    8      |     8 */        union {
/*                 8 */            LONGEST ivalue;
/*                 8 */            const block *block;
/*                 8 */            const gdb_byte *bytes;
/*                 8 */            CORE_ADDR address;
/*                 8 */            const common_block *common_block;
/*                 8 */            symbol *chain;
                               } /* total size:    8 bytes */ value;

vs always-print-offset:

/*    0      |    32 */    struct general_symbol_info {
/*    0      |     8 */        const char *name;
/*    8      |     8 */        union {
/*    8            8 */            LONGEST ivalue;
/*    8            8 */            const block *block;
/*    8            8 */            const gdb_byte *bytes;
/*    8            8 */            CORE_ADDR address;
/*    8            8 */            const common_block *common_block;
/*    8            8 */            symbol *chain;
                               } /* total size:    8 bytes */ value;

Note that it can be argued that the version that does _not_ print
the offsets includes _more_ information, or less noise, because
with that version it's much easier to not get distracted with
the offsets of the union fields, which can do nothing about.

So from that angle, I see value in not printing the offsets
of union members.

(Also note that the assertion that offsets of union members would
be 0 every time is inaccurate.  When printing a union that is itself
a field of a struct, and the union is at offset > 0 in the
containing struct, the offset to print would be offset > 0.)

> 
>> The option is "/o" for "print offsets".  Why not print offsets always?
> 
> I hope I explained it above.
> 
>> BTW, shouldn't the documentation in the manual include an example
>> of GDB's output?
> 
> I can include an example, OK.

Thanks,
Pedro Alves

  reply	other threads:[~2017-12-11 23:46 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 [this message]
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 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 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 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
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 1/2] Reorganize code to handle TYPE_CODE_{STRUCT,UNION} on 'c_type_print_base' 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-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=0d314798-6e0d-f7a9-ace8-3cb43bda9947@redhat.com \
    --to=palves@redhat.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=sergiodj@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).