Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
To: Hannes Domani <ssbssa@yahoo.de>, gdb-patches@sourceware.org
Subject: Re: [PATCH][PR gdb/24052] Implement 'set print zero-values on|off'
Date: Wed, 29 Apr 2020 14:14:32 +0200	[thread overview]
Message-ID: <23bc7f53cd0f5b77287635cdee26a0ebb5943c6f.camel@skynet.be> (raw)
In-Reply-To: <20200425134100.3818-1-ssbssa@yahoo.de>

Nice idea.
Could that be applied on array also ?
(as for arrays containing zeroes here and there, -repeats 2 or 3
does not bring much in space gained).

Thanks
Philippe


On Sat, 2020-04-25 at 15:41 +0200, Hannes Domani via Gdb-patches wrote:
> With this option it's possible to suppress any zero value members when printing
> a structure.
> 
> Consider this example:
> 
> (gdb) p t1
> $1 = {
>   i1 = 0,
>   i2 = 0,
>   i3 = 1,
>   d1 = 0,
>   d2 = 2.5,
>   d3 = 0,
>   p1 = 0x407098 <ix>,
>   p2 = 0x0,
>   p3 = 0x0,
>   t1 = {
>     v1 = 0,
>     v2 = 0
>   },
>   t2 = {
>     v1 = 3,
>     v2 = 0
>   },
>   t3 = {
>     v1 = 4,
>     v2 = 5
>   }
> }
> 
> With suppressed zero value members, the ouput is concise:
> 
> (gdb) set print zero-values off
> (gdb) p t1
> $2 = {
>   i3 = 1,
>   d2 = 2.5,
>   p1 = 0x407098 <ix>,
>   t2 = {
>     v1 = 3
>   },
>   t3 = {
>     v1 = 4,
>     v2 = 5
>   }
> }
> 
> gdb/ChangeLog:
> 
> 2020-04-25  Hannes Domani  <ssbssa@yahoo.de>
> 
> 	PR gdb/24052
> 	* cp-valprint.c (cp_print_value_fields): Skip zero value members
> 	if requested.
> 	* valprint.c (struct value_print_options): Add zero_value_print.
> 	(show_zero_value_print): New function.
> 	* valprint.h (struct value_print_options): Add zero_value_print.
> 
> gdb/doc/ChangeLog:
> 
> 2020-04-25  Hannes Domani  <ssbssa@yahoo.de>
> 
> 	PR gdb/24052
> 	* gdb.texinfo: Document 'print zero-values'.
> ---
>  gdb/cp-valprint.c   | 21 +++++++++++++++++++++
>  gdb/doc/gdb.texinfo | 18 +++++++++++++++++-
>  gdb/valprint.c      | 23 ++++++++++++++++++++++-
>  gdb/valprint.h      |  3 +++
>  4 files changed, 63 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
> index 5625a58ee7..090f2627eb 100644
> --- a/gdb/cp-valprint.c
> +++ b/gdb/cp-valprint.c
> @@ -194,6 +194,27 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
>  	      && field_is_static (&TYPE_FIELD (type, i)))
>  	    continue;
>  
> +	  /* If requested, skip printing of zero value fields.  */
> +	  if (!options->zero_value_print
> +	      && !field_is_static (&TYPE_FIELD (type, i)))
> +	    {
> +	      if (TYPE_FIELD_IGNORE (type, i))
> +		continue;
> +
> +	      struct value *v = value_primitive_field (val, 0, i, type);
> +	      struct type *field_type = check_typedef (value_type (v));
> +	      const gdb_byte *field_addr = value_contents_for_printing (v);
> +	      unsigned int field_len = TYPE_LENGTH (field_type);
> +	      unsigned int zeros;
> +	      for (zeros = 0; zeros < field_len; zeros++)
> +		{
> +		  if (field_addr[zeros] != 0)
> +		    break;
> +		}
> +	      if (zeros == field_len)
> +		continue;
> +	    }
> +
>  	  if (fields_seen)
>  	    {
>  	      fputs_filtered (",", stream);
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 239c078af3..dd8340fa61 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -1978,7 +1978,7 @@ on @code{-} after the command name.  For example:
>  (@value{GDBP}) print -@key{TAB}@key{TAB}
>  -address         -max-depth       -raw-values      -union
>  -array           -null-stop       -repeats         -vtbl
> --array-indexes   -object          -static-members
> +-array-indexes   -object          -static-members  -zero-values
>  -elements        -pretty          -symbol
>  @end smallexample
>  
> @@ -9754,6 +9754,10 @@ Set printing of unions interior to structures.  Related setting:
>  @item -vtbl [@code{on}|@code{off}]
>  Set printing of C++ virtual function tables.  Related setting:
>  @ref{set print vtbl}.
> +
> +@item -zero-values [@code{on}|@code{off}]
> +Set printing of zero value members. Related setting: @ref{set print
> +zero-values}.
>  @end table
>  
>  Because the @code{print} command accepts arbitrary expressions which
> @@ -11543,6 +11547,18 @@ Do not pretty print C@t{++} virtual function tables.
>  
>  @item show print vtbl
>  Show whether C@t{++} virtual function tables are pretty printed, or not.
> +
> +@anchor{set print zero-values}
> +@item set print zero-values
> +@itemx set print zero-values on
> +@cindex zero value members
> +Print zero value members of structures.  The default is on.
> +
> +@item set print zero-values off
> +Do not print zero value members of structures.
> +
> +@item show print zero-values
> +Show whether zero value members are printed or not.
>  @end table
>  
>  @node Pretty Printing
> diff --git a/gdb/valprint.c b/gdb/valprint.c
> index d10b33ab0a..411c9c1448 100644
> --- a/gdb/valprint.c
> +++ b/gdb/valprint.c
> @@ -117,7 +117,8 @@ struct value_print_options user_print_options =
>    0,				/* summary */
>    1,				/* symbol_print */
>    PRINT_MAX_DEPTH_DEFAULT,	/* max_depth */
> -  1				/* finish_print */
> +  1,				/* finish_print */
> +  1,				/* zero_value_print */
>  };
>  
>  /* Initialize *OPTS to be a copy of the user print options.  */
> @@ -2984,6 +2985,17 @@ show_static_field_print (struct ui_file *file, int from_tty,
>  		    value);
>  }
>  
> +/* Controls printing of zero value members.  */
> +static void
> +show_zero_value_print (struct ui_file *file, int from_tty,
> +		       struct cmd_list_element *c,
> +		       const char *value)
> +{
> +  fprintf_filtered (file,
> +		    _("Printing of zero value members is %s.\n"),
> +		    value);
> +}
> +
>  \f
>  
>  /* A couple typedefs to make writing the options a bit more
> @@ -3127,6 +3139,15 @@ pretty-printers for that value.")
>      N_("Show printing of C++ virtual function tables."),
>      NULL, /* help_doc */
>    },
> +
> +  boolean_option_def {
> +    "zero-values",
> +    [] (value_print_options *opt) { return &opt->zero_value_print; },
> +    show_zero_value_print, /* show_cmd_cb */
> +    N_("Set printing of zero value members."),
> +    N_("Show printing of zero value members."),
> +    NULL, /* help_doc */
> +  },
>  };
>  
>  /* See valprint.h.  */
> diff --git a/gdb/valprint.h b/gdb/valprint.h
> index 57bc0339fc..915d8f3f7e 100644
> --- a/gdb/valprint.h
> +++ b/gdb/valprint.h
> @@ -100,6 +100,9 @@ struct value_print_options
>  
>    /* Whether "finish" should print the value.  */
>    bool finish_print;
> +
> +  /* If true, print fields with a zero value.  */
> +  bool zero_value_print;
>  };
>  
>  /* Create an option_def_group for the value_print options, with OPTS



  reply	other threads:[~2020-04-29 12:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200425134100.3818-1-ssbssa.ref@yahoo.de>
2020-04-25 13:41 ` Hannes Domani
2020-04-29 12:14   ` Philippe Waroquiers [this message]
2020-04-29 12:43     ` Hannes Domani
2020-04-29 16:41       ` Philippe Waroquiers

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=23bc7f53cd0f5b77287635cdee26a0ebb5943c6f.camel@skynet.be \
    --to=philippe.waroquiers@skynet.be \
    --cc=gdb-patches@sourceware.org \
    --cc=ssbssa@yahoo.de \
    /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