From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from AUS01-ME3-obe.outbound.protection.outlook.com (mail-me3aus01olkn2175.outbound.protection.outlook.com [40.92.63.175]) by sourceware.org (Postfix) with ESMTPS id C30393858429 for ; Sat, 18 Sep 2021 13:18:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C30393858429 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JOjhAZo0Fmj552mZ1/qb9vZwf2ZNZsdXKD/lOVqNdyuchG+cGlZGYFDPR+fezxALZCI3zO3xbiGi9VmtNeVV3POZemni95Noa1Xo7iN3xok1TA3QDQtsEJW+4W+cdmMRxbeiThmSlBIoXyL4qQc7lH8vB3K/JW6NyrrowxJywXb9sID18tOnWnFs0h442giPAwi1Tov4kmrR2S7A06YgA7ht3/kLg6tvW4vHJfhGdYWV557dJxGdz8+85FpAV41EfLcN3wRNv5l8ZpmHWuw7lfdVGW0YYvcdpGYddZrKFxhCWwUSc3x1M2F6xiDlh+70TqxxlW2U2iclJd+UCNlLeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=DyampKPwVg1fIywuawyOiLYrKA9mmj+OlvzyAeoj1qA=; b=muxeKHDq5Qu0Ocd1yqppibkil9jp6gQwxsyfWRHoUHJayIXRCFXWS+FNVqY4hHb/lVtzfhzhJrIahmKtjcX3lApe4s3yFiPkkO0n1u+D7xbS3FjUjsXjjACzStcYN3B45TuTYa4TXSOAQJ2Mf0mWksi35MW/medWKFMu+l4FPN30Py2lmLOyQW5eNxyABhr9iDxcpSCuMNmXGevSWNT1JTV/24K6TcYIxfNxCfZ6oBVUkwl6+NecR3XLcgYpqUyz8J8R+yycFWie2fHZUmizMfmrwj+NrXCqydb0T7TOlzQIJ0vE90CJB/nWtHNn8pBJk8jPc+JhGGqKPZWLPL9fow== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM (2603:10c6:220:71::10) by ME4P282MB0791.AUSP282.PROD.OUTLOOK.COM (2603:10c6:220:9e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16; Sat, 18 Sep 2021 13:18:04 +0000 Received: from MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM ([fe80::9c0b:b6e6:1749:22ad]) by MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM ([fe80::9c0b:b6e6:1749:22ad%5]) with mapi id 15.20.4523.018; Sat, 18 Sep 2021 13:18:04 +0000 Subject: [PING][PATCH v4] gdb: Add new 'print nibbles' feature To: gdb-patches@sourceware.org References: From: Enze Li Message-ID: Date: Sat, 18 Sep 2021 21:18:00 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-TMN: [0InZx+/MsMpBTHxGkovpLwVjzITjz/aC] X-ClientProxiedBy: HK2PR04CA0072.apcprd04.prod.outlook.com (2603:1096:202:15::16) To MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM (2603:10c6:220:71::10) X-Microsoft-Original-Message-ID: <34300dc6-1867-0cce-e9cd-164cd6f244b6@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.3.105] (61.48.214.232) by HK2PR04CA0072.apcprd04.prod.outlook.com (2603:1096:202:15::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Sat, 18 Sep 2021 13:18:04 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a39387d4-1719-437e-2c7a-08d97aa6bf7e X-MS-TrafficTypeDiagnostic: ME4P282MB0791: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dq3R4uUJ+7haMLRZXKy9sMuwQwjJ6RL7p+pnS+xR3jvz3QdgTtz8NN/CCGTUkRLaCMIZOiZ5/drbGqj3IasIwDLCxi3mrfYbsk2iU8Q/OWX259CgDRs4rjk7b6Nxghqd1AgI8+ThC8SMCXaMYxcFtxLY9hqNk3smxRnNFuIzVdgcNfk2CGgGEylgqUB3gzpmepUReiw7anGa7h5e9gE/AhG6tjjEyJ5Pfwq3dLvnhpOHYUkJvZWfEynAY1B/QGkVTCPCae9eYNEZkRSzhc8EXwwkI1Tq5btSArvRx8AQiCICVdK/n19kjPdtiDa55pBtgEaZ7SUZ0PXIMef+XkEwSAD6Z1yYVCn2pX4jflqsYlRbeXi5HoNNMSySrmgdiwlHWDxIiWA+tqjvw0QOjFM9mUtM7vkAusEtnwcNTBkWEfy9KJ+wNMwfU1sf78jlCfjnwdwynYizLnOfXXeam4hxhs4rQlxIMdI6Bc7C7IaMoFs= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7JGeCFpbpHfgbLyyukxz/m+y1bdXxQlFYrnS8UkZ7e+AJVpi4lsNPAgokLihIQHX/gIw6ZeTGgJVmrHFxmNEasz2NjK/Eyo30cp6am0EBXIdsBLPqxuLSkIe4IoKOh4Li2LMj+fg7lrYmFxu63O/tw== X-OriginatorOrg: sct-15-20-3174-20-msonline-outlook-8dac2.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: a39387d4-1719-437e-2c7a-08d97aa6bf7e X-MS-Exchange-CrossTenant-AuthSource: MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2021 13:18:04.8581 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: ME4P282MB0791 X-Spam-Status: No, score=-8.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_MUA_MOZILLA, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, 18 Sep 2021 13:18:11 -0000 Ping. Thanks, Enze On 9/4/21 8:42 PM, Enze Li via Gdb-patches wrote: > Make an introduction of a new print setting that can be set by 'set > print nibbles [on|off]. The default value is OFF, and it would be > changed by users manually. > > And of course, 'show print nibbles' is also included in the patch. > > The new feature could display binary values in groups, and each group > has four bits. > > Here's a GDB session before this patch is applied. > (gdb) print var_a > $1 = 1230 > (gdb) print/t var_a > $2 = 10011001110 > > With this patch applied, we have a new print setting to use. > (gdb) print var_a > $1 = 1230 > (gdb) print/t var_a > $2 = 10011001110 > (gdb) set print nibbles on > (gdb) print/t a > $3 = 100 1100 1110 > > Tested on x86_64-linux(little-endian) and mips-linux(big-endian). > > gdb/ChangeLog: > 2021-09-03 Enze Li > > * NEWS: Metion new command. > * printcmd.c (print_scalar_formatted): Add new parameter and pass > it to print_binary_chars. > * valprint.c (struct value_print_options) : > New member. > (show_binary_groups): New function. > (print_binary_chars): Add new parameter `value_print_option *` > and use it. > * valprint.h (struct value_print_options): > (print_binary_chars): Add new parameter to declaration. > > gdb/doc/ChangeLog: > 2021-09-03 Enze Li > > * gdb.texinfo (Print Settings): Document 'print nibbles'. > > gdb/testsuite/ChangeLog: > 2021-09-03 Enze Li > > * gdb.base/printcmds.exp: Update to use new > 'print nibbles' command. > * gdb.base/options.exp: Add -nibbles in the print completion list. > --- > gdb/NEWS | 5 ++++ > gdb/doc/gdb.texinfo | 35 ++++++++++++++++++++++++---- > gdb/printcmd.c | 2 +- > gdb/testsuite/gdb.base/options.exp | 1 + > gdb/testsuite/gdb.base/printcmds.exp | 14 +++++++++++ > gdb/valprint.c | 26 ++++++++++++++++++++- > gdb/valprint.h | 6 ++++- > 7 files changed, 82 insertions(+), 7 deletions(-) > > diff --git a/gdb/NEWS b/gdb/NEWS > index ec3058ea118..272b4c5be86 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -135,6 +135,11 @@ set debug event-loop > show debug event-loop > Control the display of debug output about GDB's event loop. > > +set print nibbles [on|off] > +show print nibbles > + This controls whether the 'print/t' command will display binary values > + in groups of four bits, known as "nibbles". The default is 'off'. > + > set print memory-tag-violations > show print memory-tag-violations > Control whether to display additional information about memory tag violations > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo > index 58479ef3ed6..6242dcd08b1 100644 > --- a/gdb/doc/gdb.texinfo > +++ b/gdb/doc/gdb.texinfo > @@ -2141,10 +2141,10 @@ on @code{-} after the command name. For example: > > @smallexample > (@value{GDBP}) print -@key{TAB}@key{TAB} > --address -max-depth -raw-values -union > --array -null-stop -repeats -vtbl > --array-indexes -object -static-members > --elements -pretty -symbol > +-address -max-depth -pretty -symbol > +-array -nibbles -raw-values -union > +-array-indexes -null-stop -repeats -vtbl > +-elements -object -static-members > @end smallexample > > Completion will in some cases guide you with a suggestion of what kind > @@ -9977,6 +9977,10 @@ Set limit on string chars or array elements to print. The value > Set the threshold after which nested structures are replaced with > ellipsis. Related setting: @ref{set print max-depth}. > > +@item -nibbles [@code{on}|@code{off}] > +Set whether to print binary values in groups of four bits, known > +as ``nibbles''. @xref{set print nibbles}. > + > @item -null-stop [@code{on}|@code{off}] > Set printing of char arrays to stop at first null char. Related > setting: @ref{set print null-stop}. > @@ -11335,6 +11339,29 @@ Stop printing element indexes when displaying arrays. > Show whether the index of each element is printed when displaying > arrays. > > +@anchor{set print nibbles} > +@item set print nibbles > +@itemx set print nibbles on > +@cindex print binary values in groups of four bits > +Print binary values in groups of four bits, known as @dfn{nibbles}, > +when using the print command of @value{GDBN} with the option @samp{/t}. > +For example, this is what it looks like with @code{set print nibbles on}: > + > +@smallexample > +@group > +(@value{GDBP}) print val_flags > +$1 = 1230 > +(@value{GDBP}) print/t val_flags > +$2 = 100 1100 1110 > +@end group > +@end smallexample > + > +@item set print nibbles off > +Don't printing binary values in groups. This is the default. > + > +@item show print nibbles > +Show whether to print binary values in groups of four bits. > + > @anchor{set print elements} > @item set print elements @var{number-of-elements} > @itemx set print elements unlimited > diff --git a/gdb/printcmd.c b/gdb/printcmd.c > index 2fe3f4b0cc5..62713f1a91f 100644 > --- a/gdb/printcmd.c > +++ b/gdb/printcmd.c > @@ -490,7 +490,7 @@ print_scalar_formatted (const gdb_byte *valaddr, struct type *type, > break; > > case 't': > - print_binary_chars (stream, valaddr, len, byte_order, size > 0); > + print_binary_chars (stream, valaddr, len, byte_order, size > 0, options); > break; > case 'x': > print_hex_chars (stream, valaddr, len, byte_order, size > 0); > diff --git a/gdb/testsuite/gdb.base/options.exp b/gdb/testsuite/gdb.base/options.exp > index 6b48a0f4a4b..1f331b270eb 100644 > --- a/gdb/testsuite/gdb.base/options.exp > +++ b/gdb/testsuite/gdb.base/options.exp > @@ -167,6 +167,7 @@ proc_with_prefix test-print {{prefix ""}} { > "-array-indexes" > "-elements" > "-max-depth" > + "-nibbles" > "-memory-tag-violations" > "-null-stop" > "-object" > diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp > index 8967de3e948..0dbcf92815c 100644 > --- a/gdb/testsuite/gdb.base/printcmds.exp > +++ b/gdb/testsuite/gdb.base/printcmds.exp > @@ -690,6 +690,19 @@ proc test_print_char_arrays {} { > gdb_test_no_output "set print address off" "address off char arrays" > } > > +proc test_print_nibbles {} { > + gdb_test_no_output "set print nibbles on" > + gdb_test "p/t 0" " = 0" > + gdb_test "p/t 0x0" " = 0" > + gdb_test "p/t 0x30" " = 11 0000" > + gdb_test "p/t 0xff" " = 1111 1111" > + gdb_test "p/t 0x0f" " = 1111" > + gdb_test "p/t 0x01" " = 1" > + gdb_test "p/t 0xf0f" " = 1111 0000 1111" > + gdb_test "p/t 0x70f" " = 111 0000 1111" > + gdb_test_no_output "set print nibbles off" > +} > + > proc test_print_string_constants {} { > global gdb_prompt > > @@ -1068,6 +1081,7 @@ test_print_int_arrays > test_print_typedef_arrays > test_artificial_arrays > test_print_char_arrays > +test_print_nibbles > # We used to do the runto main here. > test_print_string_constants > test_print_array_constants > diff --git a/gdb/valprint.c b/gdb/valprint.c > index 324055da93f..c797d89798a 100644 > --- a/gdb/valprint.c > +++ b/gdb/valprint.c > @@ -108,6 +108,7 @@ struct value_print_options user_print_options = > 0, /* vtblprint */ > 1, /* unionprint */ > 1, /* addressprint */ > + false, /* nibblesprint */ > 0, /* objectprint */ > PRINT_MAX_DEFAULT, /* print_max */ > 10, /* repeat_count_threshold */ > @@ -260,6 +261,15 @@ show_unionprint (struct ui_file *file, int from_tty, > value); > } > > +static void > +show_nibbles (struct ui_file *file, int from_tty, > + struct cmd_list_element *c, const char *value) > +{ > + fprintf_filtered (file, > + _("Printing binary values in groups is %s.\n"), > + value); > +} > + > /* If nonzero, causes machine addresses to be printed in certain contexts. */ > > static void > @@ -1367,7 +1377,8 @@ print_floating (const gdb_byte *valaddr, struct type *type, > > void > print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr, > - unsigned len, enum bfd_endian byte_order, bool zero_pad) > + unsigned len, enum bfd_endian byte_order, bool zero_pad, > + const struct value_print_options *options) > { > const gdb_byte *p; > unsigned int i; > @@ -1390,6 +1401,8 @@ print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr, > > for (i = 0; i < (HOST_CHAR_BIT * sizeof (*p)); i++) > { > + if (options->nibblesprint && seen_a_one && i % 4 == 0) > + fputc_filtered (' ', stream); > if (*p & (mask >> i)) > b = '1'; > else > @@ -1410,6 +1423,8 @@ print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr, > { > for (i = 0; i < (HOST_CHAR_BIT * sizeof (*p)); i++) > { > + if (options->nibblesprint && seen_a_one && i % 4 == 0) > + fputc_filtered (' ', stream); > if (*p & (mask >> i)) > b = '1'; > else > @@ -3016,6 +3031,15 @@ static const gdb::option::option_def value_print_option_defs[] = { > NULL, /* help_doc */ > }, > > + boolean_option_def { > + "nibbles", > + [] (value_print_options *opt) { return &opt->nibblesprint; }, > + show_nibbles, /* show_cmd_cb */ > + N_("Set whether to print binary values in groups of four bits."), > + N_("Show whether to print binary values in groups of four bits."), > + NULL, /* help_doc */ > + }, > + > uinteger_option_def { > "elements", > [] (value_print_options *opt) { return &opt->print_max; }, > diff --git a/gdb/valprint.h b/gdb/valprint.h > index e1dae2cc8fc..bb19c41ab68 100644 > --- a/gdb/valprint.h > +++ b/gdb/valprint.h > @@ -44,6 +44,9 @@ struct value_print_options > /* Controls printing of addresses. */ > bool addressprint; > > + /* Controls printing of nibbles. */ > + bool nibblesprint; > + > /* Controls looking up an object's derived type using what we find > in its vtables. */ > bool objectprint; > @@ -149,7 +152,8 @@ extern void value_print_scalar_formatted > int size, struct ui_file *stream); > > extern void print_binary_chars (struct ui_file *, const gdb_byte *, > - unsigned int, enum bfd_endian, bool); > + unsigned int, enum bfd_endian, bool, > + const struct value_print_options *options); > > extern void print_octal_chars (struct ui_file *, const gdb_byte *, > unsigned int, enum bfd_endian);