From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailsec113.isp.belgacom.be (mailsec113.isp.belgacom.be [195.238.20.109]) by sourceware.org (Postfix) with ESMTPS id E1F5838930D0 for ; Wed, 29 Apr 2020 12:14:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E1F5838930D0 IronPort-SDR: Mse7TBIxhjHJetdijhJgnVaN8R8MVF7TNvWLZefqb3CbXv84YMVBL8FUrkZfwsOSa5g4VwbWsL Ou9RzRuDSA5ROeJVk0qCp1xwmX8gp1WqQZcov/41YW/WJWM5M8XVGkOenvK6A2zgLKVOFLgLZn z1XJ9+TjjGcntuG+hKbiXcvqWptWEAaCA9CoGFrtjtpcCEdXWFIfDPmubk0Oox1iyMRJ8c4rV8 h0ogclZexgC/4Y/YKc0BgVOLGRCBwHDGBVEjG0lK8Q796q219LtI6QDm9YGBV+riROENe3WxSs l9E= IronPort-PHdr: =?us-ascii?q?9a23=3AY5/RIRGUc5qV22diZ3WIhZ1GYnF86YWxBRYc79?= =?us-ascii?q?8ds5kLTJ7zosywAkXT6L1XgUPTWs2DsrQY0reQ7furBTNIyK3CmUhKSIZLWR?= =?us-ascii?q?4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TW94jEIBx?= =?us-ascii?q?rwKxd+KPjrFY7OlcS30P2594HObwlSizexfLN/IA+3oAjfucUbjolvIbstxx?= =?us-ascii?q?XUpXdFZ/5Yzn5yK1KJmBb86Maw/Jp9/ClVpvks6c1OX7jkcqohVbBXAygoPG?= =?us-ascii?q?4z5M3wqBnMVhCP6WcGUmUXiRVHHQ7I5wznU5jrsyv6su192DSGPcDzULs5Vy?= =?us-ascii?q?iu47ttRRT1jioMKjw3/3zNisFoj6xVvRKvqQJxzYHWboGaKPRxcazSc94BWW?= =?us-ascii?q?pMXNxcWzBdDo6mbYYCCfcKM+ZCr4n6olsDtQGwBQmtBOPryz9Inmf20rMn2O?= =?us-ascii?q?shCw7GxgsgH8sTsHTVstr1LrwSWv2ywanQzTXDbvdW2Tbl6IjQbB8tu/+NUq?= =?us-ascii?q?hqccrW0EkvCgLFgUuKqYz+JD6VzecNsmid7+V+SeKjkXUopB9orzWp28wiiZ?= =?us-ascii?q?HJi5oLxlzZ9yh12ps5KNO5RUJhYtOoDYFcui+UOoZwX8gsWXtnuDwgxb0DoZ?= =?us-ascii?q?O7eS8Kx4k5yBPHcPyHdpSI4grkVOaMPTd0nHJld6y7hxa16UWgz/DzWtG10F?= =?us-ascii?q?ZMsCVFjsHBum4Q2xHR8MSLV/Vw80a71TuMygzf8O9JLE4smareMZEhw7owlp?= =?us-ascii?q?QJsUTEGy/7gF32jK+XdkUg++io8/znbav8qp6SLYB0kAb+Mr0zmsy+H+s4KB?= =?us-ascii?q?MOUnOA+eS/1Lzj+1P2QKlQgvItjKbVqIraKtgDpq6lHw9V1Z4u6w2kDzi9y9?= =?us-ascii?q?QYhmMIIUlFeR2dj4jpPFbOLOrlAvihm16siitkx+jaPr39BZXANnfDn6r6cr?= =?us-ascii?q?pk805T0hYzwsxf551KEbEMO+nzWkjstNzCEhA2LQK1zPz9CNpjzI8eXniPAq?= =?us-ascii?q?DKeJ/V5H+B4OQiOKGgY4ocvje1f+M+7eX1hFcokF8aeu+l0M1TIH+0FLF+Kl?= =?us-ascii?q?mSYXf3qswGDH0BsxU3VuGsj0eNAhBJYHPnZ6I94jAjEI/uMo7ZQZmwgbGbx2?= =?us-ascii?q?/vBp1XYmFeEl3KDn7ycJyZWvoWcwqJId5nnyBCX7X3GNxp7g2nqAKvk+kvFe?= =?us-ascii?q?HT4CBN7Z8=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2CAAAAhb6le/yFRiNlmGgEBAQEBAQE?= =?us-ascii?q?BAQEDAQEBARIBAQEBAgIBAQEBQIFHgiqBQiESKoQhiQGICoEBiHWRZAsBAQE?= =?us-ascii?q?BAQEBAQEILAECBAEBhEQCgionOBMCAwEBAQMCBQEBBgEBAQEBAQQEAWwEAQE?= =?us-ascii?q?HCoRRIQEDAQEFCgFDgjsigxUBBSMELxYdCAMOCgICJgICVwYBEoVyAzKzOH8?= =?us-ascii?q?zhVGDZYFAgQ4qiEaECoFMP4ERgls1PoEEgRqCMIMSgmAEi3IIi3qBBZhAMko?= =?us-ascii?q?Hgkh/BJJChEIdnQeQBYwQkSWBaSKBVm2DPFAlkkcMC44nQjA2AgYIAQEDCXQ?= =?us-ascii?q?IE5FbAQE?= X-IPAS-Result: =?us-ascii?q?A2CAAAAhb6le/yFRiNlmGgEBAQEBAQEBAQEDAQEBARIBA?= =?us-ascii?q?QEBAgIBAQEBQIFHgiqBQiESKoQhiQGICoEBiHWRZAsBAQEBAQEBAQEILAECB?= =?us-ascii?q?AEBhEQCgionOBMCAwEBAQMCBQEBBgEBAQEBAQQEAWwEAQEHCoRRIQEDAQEFC?= =?us-ascii?q?gFDgjsigxUBBSMELxYdCAMOCgICJgICVwYBEoVyAzKzOH8zhVGDZYFAgQ4qi?= =?us-ascii?q?EaECoFMP4ERgls1PoEEgRqCMIMSgmAEi3IIi3qBBZhAMkoHgkh/BJJChEIdn?= =?us-ascii?q?QeQBYwQkSWBaSKBVm2DPFAlkkcMC44nQjA2AgYIAQEDCXQIE5FbAQE?= Received: from 33.81-136-217.adsl-dyn.isp.belgacom.be (HELO md) ([217.136.81.33]) by relay.skynet.be with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 29 Apr 2020 14:14:32 +0200 Message-ID: <23bc7f53cd0f5b77287635cdee26a0ebb5943c6f.camel@skynet.be> Subject: Re: [PATCH][PR gdb/24052] Implement 'set print zero-values on|off' From: Philippe Waroquiers To: Hannes Domani , gdb-patches@sourceware.org Date: Wed, 29 Apr 2020 14:14:32 +0200 In-Reply-To: <20200425134100.3818-1-ssbssa@yahoo.de> References: <20200425134100.3818-1-ssbssa.ref@yahoo.de> <20200425134100.3818-1-ssbssa@yahoo.de> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5-1.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-22.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Apr 2020 12:14:38 -0000 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 , > 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 , > t2 = { > v1 = 3 > }, > t3 = { > v1 = 4, > v2 = 5 > } > } > > gdb/ChangeLog: > > 2020-04-25 Hannes Domani > > 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 > > 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); > +} > + > > > /* 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