From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 3nVyH6wt0l8IQQAAWB0awg (envelope-from ) for ; Thu, 10 Dec 2020 09:16:12 -0500 Received: by simark.ca (Postfix, from userid 112) id 73EB21F0A9; Thu, 10 Dec 2020 09:16:12 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_REPLYTO_END_DIGIT,MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id AE09E1E590 for ; Thu, 10 Dec 2020 09:16:07 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A456B3857835; Thu, 10 Dec 2020 14:16:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A456B3857835 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1607609766; bh=+VRJW9KVzwi9zAH1E/mHT1ohwu0He5+dPf8VZoOU7po=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FFoE579aeYT6Qf6MfZ7VNFi5D6L/lzxYh+5EsQYnKnNIaz3nLY8Bcynxcghtni87/ wwpT1HJbz/+fSsHzRSLnFB/welyNCoHWOc/zoaKB29FB7jOHvxVqqTevi5lIlGJxw8 piQLwba/n6wZ5dkLAtATJ0QHE/YitUclZEFoiVPA= Received: from APC01-PU1-obe.outbound.protection.outlook.com (mail-oln040092254086.outbound.protection.outlook.com [40.92.254.86]) by sourceware.org (Postfix) with ESMTPS id 5C6893857835 for ; Thu, 10 Dec 2020 14:15:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5C6893857835 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b4fl8/25xNyiigQld3ff54SAYba9VPSH85DVH3TjP31jnBbfMWieC+yPM4cnY8tz74LZau+1rakImst3wWKG4SXS1uxQHI9wN9JEovGC/BlysWp1USK3SpwjKK/ETEiB7d9YVqvBQsic7p6M2MilOwimIWd6YxbzxaaHXzO87uCzX8HVMCc8xCNyuwBwbs9uCBt6x8M3C0WhyS0SnBd78ClqyZ+dQkFvL2ct8EUl/Pqmj4/bgDFJBLmen8d9rcKJXIE3aJpLWg20ijGTAOfSbLOGnHxXjb6ojeZ6gl5r0F7RPVEQNRHFzacdAoeLIYYKHEyh+GU5l3LnX8zummC01A== 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:X-MS-Exchange-SenderADCheck; bh=+VRJW9KVzwi9zAH1E/mHT1ohwu0He5+dPf8VZoOU7po=; b=lPeuJPxW4hPDqcg4La9HHtSidh/Bz3pSO9GAbi20e/7POBjnLaDJkpYI6WCDCungkYixiRKzEcJuDodW5ccnN1GuGOOYnDxRYZw6qJawIkVug/Eo7FoqSIHMGuU+BPuXdEZWOIAqCVNWMg81Njoo5boN4hyEUcJBNZ64aH5fIHLrro/VXcRmpT4vxo07hlo5Y8J2BXT2uattNBJkIn/jrDwNCtaN/fCpK+gNKFEAE7IkBJZyWjyGfff7H/H/GkY4A5QnSaytYCBNc7GmD+u+D3+tvjdpE7NDWgGne3dHAqHou80W9vv3MO/1MgPv46SYpCxxXaZMdIi6S6yvFXkoSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from PU1APC01FT003.eop-APC01.prod.protection.outlook.com (2a01:111:e400:7ebe::44) by PU1APC01HT236.eop-APC01.prod.protection.outlook.com (2a01:111:e400:7ebe::178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12; Thu, 10 Dec 2020 14:15:41 +0000 Received: from MEAPR01MB3672.ausprd01.prod.outlook.com (2a01:111:e400:7ebe::46) by PU1APC01FT003.mail.protection.outlook.com (2a01:111:e400:7ebe::95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12 via Frontend Transport; Thu, 10 Dec 2020 14:15:40 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:FC559146020B0864603C57A90EBFF85751A048A999EEF96B45DA69DF70F3740B; UpperCasedChecksum:0160088A3BADD232491DBD70615D6B739C8EC53FA07180A804E0DC31699DC907; SizeAsReceived:7231; Count:44 Received: from MEAPR01MB3672.ausprd01.prod.outlook.com ([fe80::5851:af56:ad62:8ed]) by MEAPR01MB3672.ausprd01.prod.outlook.com ([fe80::5851:af56:ad62:8ed%7]) with mapi id 15.20.3632.026; Thu, 10 Dec 2020 14:15:40 +0000 To: gdb-patches@sourceware.org Subject: [PATCH v2] Add new 'print nibbles' feature Date: Thu, 10 Dec 2020 22:15:15 +0800 Message-ID: X-Mailer: git-send-email 2.27.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TMN: [CwiDzJnCJ8MXpOMaYce1EOen6eq6oP1k] X-ClientProxiedBy: HK2PR04CA0053.apcprd04.prod.outlook.com (2603:1096:202:14::21) To MEAPR01MB3672.ausprd01.prod.outlook.com (2603:10c6:201:3a::15) X-Microsoft-Original-Message-ID: <20201210141515.2171446-1-lienze2010@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (61.48.208.153) by HK2PR04CA0053.apcprd04.prod.outlook.com (2603:1096:202:14::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12 via Frontend Transport; Thu, 10 Dec 2020 14:15:39 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 44 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 52c20d00-e593-44f4-e5cf-08d89d16131e X-MS-TrafficTypeDiagnostic: PU1APC01HT236: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3O6pFuIVcynJfzIu778XAQSTlZumE1keebO/Jvs34ooXukkkiOTOn902p7MRlYt9u+QAFBEp1Xy8zkdeZJ6niTfW1TH08FIrWXE888WYrBp64+zgtYcovIJBICSXQ0RE0XXD1hdNEnsllW9mdapvpfPAyFB9kcZiIOob6Yef1wFC7bQvpvKrmdcyVhPiWKhGkisMure/vHIA/52m3zJwyg== X-MS-Exchange-AntiSpam-MessageData: BMLMCDvfdduBaxZLHcbMn7qG8obXoZGYpcd8gbRf4axVloa5G6vWvSdqo1VbPdLI2UtLXKjHI3newC0/XF7fKwnOjd5i1kxlNZ+kcnRKDEOFKFT8cfk/Auhg+91ZBlbBr7zirHfiOH/qtO/kJRsk0Q== X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2020 14:15:40.7788 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-Network-Message-Id: 52c20d00-e593-44f4-e5cf-08d89d16131e X-MS-Exchange-CrossTenant-AuthSource: PU1APC01FT003.eop-APC01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU1APC01HT236 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: , From: Enze Li via Gdb-patches Reply-To: Enze Li Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 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 = 371 (gdb) print/t var_a $2 = 101110011 With this patch applied, we have a new print setting to use. (gdb) print var_a $1 = 371 (gdb) print/t var_a $2 = 101110011 (gdb) set print nibbles on (gdb) print/t a $3 = 1 0111 0011 Tested on x86_64-linux(little-endian) and mips-linux(big-endian). gdb/ChangeLog: 2020-12-10 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: 2020-12-10 Enze Li * gdb.texinfo: Document 'print nibbles'. gdb/testsuite/ChangeLog: 2020-12-10 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 | 34 ++++++++++++++++++++++++---- 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, 81 insertions(+), 7 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index d75992e78e..afb49fc8d8 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -39,6 +39,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 the binary + value in groups, and each group has four bits. The default is 'off'. + * Changed commands break [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 01dcac941c..8a06cb59af 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -2034,10 +2034,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 @@ -9938,6 +9938,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. +Related setting: @ref{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}. @@ -11213,6 +11217,28 @@ 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 +Print binary values in groups of four bits 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 = 371 +(@value{GDBP}) print/t val_flags +$2 = 1 0111 0011 +@end group +@end smallexample + +@item set print nibbles off +Stop 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 e95b880295..402c395871 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -475,7 +475,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 3c4f9060a9..77a0246aa6 100644 --- a/gdb/testsuite/gdb.base/options.exp +++ b/gdb/testsuite/gdb.base/options.exp @@ -165,6 +165,7 @@ proc_with_prefix test-print {{prefix ""}} { "-array-indexes" "-elements" "-max-depth" + "-nibbles" "-null-stop" "-object" "-pretty" diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp index 08a0961303..98fcbb9d4c 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 50278ac309..197d9057f0 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -105,6 +105,7 @@ struct value_print_options user_print_options = 0, /* vtblprint */ 1, /* unionprint */ 1, /* addressprint */ + 0, /* nibblesprint */ 0, /* objectprint */ PRINT_MAX_DEFAULT, /* print_max */ 10, /* repeat_count_threshold */ @@ -245,6 +246,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 @@ -1353,7 +1363,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; @@ -1376,6 +1387,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 @@ -1396,6 +1409,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 @@ -3040,6 +3055,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 ef9ebfa84f..8c8a04740a 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; @@ -146,7 +149,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); -- 2.27.0