public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: Sergio Durigan Junior <sergiodj@redhat.com>
Cc: 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 20:45:00 -0000	[thread overview]
Message-ID: <99286acb-ce9f-42f0-41c3-ef10e03171ff@ericsson.com> (raw)
In-Reply-To: <87o9n5drbn.fsf@redhat.com>

>>> +/* Use 'print_spaces_filtered', but take into consideration the
>>> +   type_print_options FLAGS in order to determine how many whitespaces
>>> +   will be printed.  */
>>> +
>>> +static void
>>> +print_spaces_filtered_with_print_options (int level, struct ui_file *stream,
>>> +					const struct type_print_options *flags)
>>
>> Missing spaces here.
> 
> This is actually on purpose.  If I indent the line, it will have more
> than 80 chars.  I believe this is a well known method for avoiding this
> problem...?

I am not aware of that.  In this case I would put the parameter list on the next,
I'm not sure if it's 100% GNU-style approved, but nobody complained when I did it
so far :)

static void
print_spaces_filtered_with_print_options
  (int level, struct ui_file *stream, const struct type_print_options *flags);

It helps with long function names.  In this case, I would probably just drop the
"struct" to save a few chars, because C++.

>>> +if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
>>> +	  { debug c++ optimize=-O0 }] } {
>>
>> optimize=-O0 seems unnecessary to me, I've never seen it specified explicitly in a test.
> 
> There are very few tests that use it (2, currently).  I understand it's
> not very common to explicitly specify -O0, but I put it there because I
> decided to be on the safe side.  If the compiler performs any
> optimization at all, it could mess with the layout of the structs.

If GCC decided to optimize by default, so many things would break in the GDB testsuite.
We would then probably make gdb_compile add -O0, so that we wouldn't need to do it in
all tests.  The point is that IMO, tests should expect no optimization by default.

>> I also noticed that the offset is not shown in front of the struct-in-union,
>> as show above, but it is in the case of struct-in-struct:
>>
>>   /* offset    |  size */
>>   type = struct my_struct_3 {
>>   /*    0      |     8 */    struct my_struct_1 {
>>   /*    0      |     4 */        int a;
>>   /*    4      |     4 */        int b;
>>                              } /* total size:    8 bytes */ s1;
>>   /*    8      |     8 */    struct my_struct_2 {
>>   /*    8      |     4 */        int c;
>>   /*   12      |     4 */        int d;
>>                              } /* total size:    8 bytes */ s2;
>>   } /* total size:   16 bytes */
>>
>> Is this difference on purpose?
> 
> Yes; offsets are not shown for fields inside unions (not only structs,
> but all types of fields), because it doesn't make much sense: they'd be
> 0 every time.  This is also inspired from pahole's output.

Not if that union is itself in a struct.  For example with this:

struct hello
{
        int i;
        union {
                struct {
                        int x, y;
                } a;
                struct {
                        int x, y;
                } b;
        };
};

(gdb) ptype /o struct hello
/* offset    |  size */
type = struct hello {
/*    0      |     4 */    int i;
/*    4      |     8 */    union {
/*                 8 */        struct {
/*    4      |     4 */            int x;
/*    8      |     4 */            int y;
                               } /* total size:    8 bytes */ a;
/*                 8 */        struct {
/*    4      |     4 */            int x;
/*    8      |     4 */            int y;
                               } /* total size:    8 bytes */ b;
                           } /* total size:    8 bytes */;
} /* total size:   12 bytes */


But I don't mind it, it just stuck out as a little inconsistency.

I'll look at v3 now.

Simon

  reply	other threads:[~2017-12-11 20:45 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 [this message]
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
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=99286acb-ce9f-42f0-41c3-ef10e03171ff@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=sergiodj@redhat.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).