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>,
	GDB Patches <gdb-patches@sourceware.org>
Cc: Tom Tromey <tom@tromey.com>, Eli Zaretskii <eliz@gnu.org>,
	Simon Marchi <simon.marchi@ericsson.com>,
	Keith Seitz <keiths@redhat.com>
Subject: Re: [PATCH v7 2/2] Implement pahole-like 'ptype /o' option
Date: Fri, 15 Dec 2017 17:24:00 -0000	[thread overview]
Message-ID: <b3dae1ed-8368-442c-ae0a-243e36076a39@redhat.com> (raw)
In-Reply-To: <20171215011247.7396-3-sergiodj@redhat.com>

Hi Sergio,

I found a couple more nits to pick, but this is close.

This is OK with the issues below addressed.  Please address
them, and push this in.  Please post the end result for the
archives.

On 12/15/2017 01:12 AM, Sergio Durigan Junior wrote:

> @@ -867,15 +913,121 @@ output_access_specifier (struct ui_file *stream,
>        if (last_access != s_public)
>  	{
>  	  last_access = s_public;
> -	  fprintfi_filtered (level + 2, stream,
> -			     "public:\n");
> +	  print_spaces_filtered_with_print_options (level + 2, stream, flags);
> +	  fprintf_filtered (stream, "public:\n");
>  	}
>      }
>  
>    return last_access;
>  }
>  
> -/* Return true is an access label (i.e., "public:", "private:",
> +/* Print information about field at index FIELD_IDX of the union type
> +   TYPE.  Since union fields don't have the concept of offsets, we
> +   just print their sizes.
> +
> +   The output is strongly based on pahole(1).  */
> +
> +static void
> +c_print_type_union_field_offset (struct type *type, unsigned int field_idx,
> +				 struct ui_file *stream)
> +{
> +  struct type *ftype = check_typedef (TYPE_FIELD_TYPE (type, field_idx));
> +
> +  fprintf_filtered (stream, "/*              %4u */", TYPE_LENGTH (ftype));
> +}
> +
> +/* Print information about field at index FIELD_IDX of the struct type
> +   TYPE.
> +
> +   END_BITPOS is the one-past-the-end bit position of the previous
> +   field (where we expect this field to be if there is no hole).  At
> +   the end, ENDPOS is updated to the one-past-the-end bit position of
> +   the current field.

There's still a reference to ENDPOS above that I assume should
be END_BITPOS.  Now that I'm looking at this, do we still need
this parameter, given print_offset_data->end_bitpos exists?
What's the relationship between the two?  It's a bit confusing
to have two things for the same.  I think the comment could/should
clarify this.

> +
> +   OFFSET_BITPOS is the offset value we carry over when we are
> +   printing a struct that is inside another struct; this is useful so
> +   that the offset is constantly incremented (if we didn't carry it
> +   over, the offset would be reset to zero when printing the inner
> +   struct).

This parameter no longer exists (it's a field of print_offset_data now,
right?).  The comment should be adjusted, moved elsewhere, or deleted.

> +
> +   The output is strongly based on pahole(1).  */
> +
> +static void
> +c_print_type_struct_field_offset (struct type *type, unsigned int field_idx,
> +				  struct ui_file *stream,
> +				  unsigned int *end_bitpos,
> +				  struct print_offset_data *podata)
> +{


> @@ -1143,9 +1347,16 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
>  		       && !is_full_physname_constructor  /* " " */
>  		       && !is_type_conversion_operator (type, i, j))
>  		{
> -		  c_print_type (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
> -				"", stream, -1, 0,
> -				&local_flags);
> +		  unsigned int old_po = local_flags.print_offsets;
> +
> +		  /* Temporarily disable print_offsets, because it
> +		     would mess with indentation.  */
> +		  local_flags.print_offsets = 0;
> +		  c_print_type_1 (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
> +				  "", stream, -1, 0,
> +				  &local_flags, podata);
> +		  local_flags.print_offsets = old_po;

This pattern appears in several places.  Would it make sense to
add a c_print_type_no_offsets routine that handled the
print_offsets save/restore?

> +++ b/gdb/testsuite/gdb.base/ptype-offsets.exp
> @@ -0,0 +1,317 @@
> +# This testcase is part of GDB, the GNU debugger.
> +
> +# Copyright 2017 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +# This testcase exercises the "ptype /o" feature, which can be used to
> +# print the offsets and sizes of each field of a struct/union/class.
> +
> +standard_testfile .cc
> +
> +# Test only works on LP64 targets.  That's how we guarantee that the
> +# expected holes will be present in the struct.
> +if { ![is_lp64_target] } {
> +    untested "test work only on lp64 targets"
> +    return 0
> +}
> +
> +if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
> +	  { debug c++ }] } {
> +    return -1
> +}
> +
> +# Test general offset printing, ctor/dtor printing, union, formatting.
> +gdb_test "ptype /o struct abc" \
> +    [multi_line \

...

> +{                         \}}] \
> +    "ptype offset struct abc"

I notice that you're replacing the "/o" in most test
names/messages.  Is there a reason for that?  Why
not just let the test name default to the command
invocation?  I.e., remove the 3rd argument in all
these calls to gdb_test.


> +
> +# Test "ptype /oTM".
> +gdb_test "ptype /oTM struct abc" \
> +    [multi_line \

..

> +    "ptype /oTM struct abc"

Here the "/" persisted, so I'm curious why the other cases
have "/o" replaced by "offset".

I'd just remove the explicit test messages.  It just seems
like potential for getting out of sync otherwise.

> +# Because dealing with bitfields and offsets is difficult, it can be
> +# tricky to confirm that the output of the this command is accurate.

typo: "of the this"

> @@ -499,6 +514,11 @@ whatis_exp (const char *exp, int show)
>  	real_type = value_rtti_type (val, &full, &top, &using_enc);
>      }
>  
> +  if (flags.print_offsets
> +      && (TYPE_CODE (type) == TYPE_CODE_STRUCT
> +	  || TYPE_CODE (type) == TYPE_CODE_UNION))
> +    fprintf_filtered (gdb_stdout, "/* offset    |  size */  ");

I noticed that "whatis" also prints this header:

 (top-gdb) whatis/o minimal_symbol
 /* offset    |  size */  type = minimal_symbol

I guess it shouldn't, for it's pointless.  You could either
use the "show" parameter here, or just ignore /o for whatis
where the options are parsed, further above.

And then please add a test covering that.  :-)

You'll have to use gdb_test_multiple with an anchor,
because 

   gdb_test "whatis/o minimal_symbol" \
      "type = minimal_symbol"

would match the bad output anyway.

So something like:

   set test "whatis /o minimal_symbol"
   gdb_test_multiple $test $test {
      -ex "^$test\r\ntype = minimal_symbol\r\n$gdb_prompt $" {
          pass $test
   }

As mentioned, OK with these issues addressed.  Please push and post.

Thanks,
Pedro Alves

  reply	other threads:[~2017-12-15 17:24 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
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 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-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-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 [this message]
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=b3dae1ed-8368-442c-ae0a-243e36076a39@redhat.com \
    --to=palves@redhat.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=keiths@redhat.com \
    --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).