From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sonic309-24.consmr.mail.ir2.yahoo.com (sonic309-24.consmr.mail.ir2.yahoo.com [77.238.179.82]) by sourceware.org (Postfix) with ESMTPS id EEA88385DC1C for ; Sat, 25 Apr 2020 13:41:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EEA88385DC1C X-YMail-OSG: IV1tlsIVM1mBwjlUz3o7TkzuI748QFv4kngHMD7p6dViQa9PR93MG3uhtKs7pdi WpwBB9_VNoZW88P76IE0VTkZRMRx4omcYCCs4RY6nIVKcc7sAxagUpgFOuCH7Zq5Uo5oO.qN2SUg H5MNYCpj3TxoiU5OVN_6c2HNXwlUxz3VKCRHPj1ev3Ybsl1atmzj7489i.ehgtht8XAbXHI2jj.B DH6K9wqGf.XlovEpk2yXUv_eCX2OpNv8xQ8PeDsATrh_cX0PAxXmeft7RHlLeMtrIzMCkzmaOfo6 0SiDbCt8HCu5fjk99E2S2B5749r1rZEwAqdKde5saS5aoBZ99vnYWtvMA1qfqdNoFH0jDU6Ul71r XUY7jhWxXEN59Vk2hVTwnV24GAmkCxS4nWu153R36wTeaHrEXbx3eGoOBJzTi80hbEjXy1HQ.fFe M63UHesnNhZtNvauVre7Kug.Vk6aNJBSXf56EgAc7yTzSHTaDahwq3zVrySOMBTl5b9flJylI_CX rHXwrFFWxKa1i05Io1Qk05SHIMYOjExG.z032xaZHGsRw7Om0t5jR8kVYTtXY3KkLUnPTAYwT7bU S_QyRLkcvAhbRMdu0VNIWzAzwnuOhH91QMvevO4mG.wlOTXgf.oaTJFKPfc_rBYcFTxSivRnAxAk 7BZmk5_FcUe4WB5FfeTICgZuQgJHjqquqfv3b6LdCjdCdal5Ao77hDAidHv0Tkqa3.CWoUy0hOWS mIhIgm4GTvDYTaYuaTfaqNVWM_aLCOhw1jXzK91QVgn1yzzIvfNEP18yazxgG5yAa3Dy41nDbDJw A9Hg0WN6ceq1qjxrSsT_R3q_tuRaY5zIxDndh7MA9rEdm9_uyFU6u.WGWPXQirYTFBH73I8CqO72 TVxeoTKIzkCRLIHSYaAtT9VUAMdF7oAttkMZWw3C_s1i_dXP4dievgH9itHZ0I1kDRY4CySKE7TG 529YB6yHtCMF0v0yZIwrxePC9z15RvY.ABABXd1udd.B5IeUYlSTBSz0PS_xlV7GPvdj4U2Sf6va bNVYUaIaTSJfGZItPUG_3Y1ccZNhwalWwWGPOZS90qx3UdASreGq6f3CaOwM8cpthXMpw73fCJMo i2D.zfhAIOUHnYfXkh9mEQptYAUTix1ZATAbdbRc872E_t2zMwbu8NlOLkLQqytlvQpPq7OiwM94 YHSJ3hmmds0Sjk67ipJNfPSKB6U1xU2562UZ5pKE.B790eWd0.3XeOdBTSCJZ4b9Y93XJheReegA 1DGv25kkUGfj6lwKF6ZFZ1FGTXtoKZl4P.SapLCsxIJ6mIyiUCYZlL41Dn81O_oFKxlEz8CKa_Fg SN4FfRz3_j2PbgMnMoDxQ1bZeMZ5qnm2uIliPjQt4X7sIAuVIFYDBM7vYdSegctIf21EW.Wg- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ir2.yahoo.com with HTTP; Sat, 25 Apr 2020 13:41:33 +0000 Received: by smtp426.mail.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 90a4702e6baabd10bc95d87db8d90ef9; Sat, 25 Apr 2020 13:41:32 +0000 (UTC) From: Hannes Domani To: gdb-patches@sourceware.org Subject: [PATCH][PR gdb/24052] Implement 'set print zero-values on|off' Date: Sat, 25 Apr 2020 15:41:00 +0200 Message-Id: <20200425134100.3818-1-ssbssa@yahoo.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Antivirus: Avast (VPS 200424-2, 04/24/2020), Outbound message X-Antivirus-Status: Clean References: <20200425134100.3818-1-ssbssa.ref@yahoo.de> X-Spam-Status: No, score=-21.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_INVALID, DKIM_SIGNED, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, 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: Sat, 25 Apr 2020 13:41:38 -0000 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 -- 2.26.2