From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from AUS01-SY4-obe.outbound.protection.outlook.com (mail-sy4aus01olkn2150.outbound.protection.outlook.com [40.92.62.150]) by sourceware.org (Postfix) with ESMTPS id 2D6873858407 for ; Sat, 23 Apr 2022 09:17:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2D6873858407 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UKSNCEgbS57EWXZJdMZIeuNM1X9ETqNdlCzec1zOJNgh2ujGeFio0L97vXcU+cYS5DsenKWLiKGQ4cxsvwOg+edQfvQyuIclravaSFC7wiRL6UtFrBLsdwqqBVZ4ouWVBCAn+92gXMxYy/fpogLrJHH1c3xKinaFvjCDK+E2FACrPY5xIvwzigXedE6aU9Y8fMKB+gVPSGXcPWBqAYXTKVo94C8Xms8WM57z2NTulIj4/bo7bunTLzxyQZMCTStHnh2ikXRg9/D+GeouGLD+ZhzhTnyYrBtp2MCZeZlmlhaoRhIt68p8Y+mWvv9ZKWTCuZ4TWXnDQc7worm2cYmO/g== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UNCAQfWR227HvE9unXptTs5G0bfMK0fTLEVegL5HBso=; b=dDL+AQvGaCxpHbbr7W6hWzq3Wg/ofldXkXKdlQgV6YyKGsxm1SSYtJPwVyZLgg/eGFJDprjxFH02Zv70t30XppIX1ZlxMGuZXmMxzvYszfjsoO0RoqKw3LHaZ9NBnRgo5ArNPmEc5mtZ6AizWdmR933A3uvhSYG3bNyovGIWji8iOqnRY2YaGlbeg/QyzBqyxvdxoZKanaBId/sb/PLvsdXn34oFEYi/oHBfynRDdr0b0A4tOTCgDDIq9fEdP42grY9X/WXWLE+fbG3IkHNdHey2CUAtEFjyaGsdCvd1LEOpzgUAxb7WMDiHgs9jGjfS8l6/eFqpyRzdIFgTEQHxSw== 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 SYBP282MB2724.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:153::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15; Sat, 23 Apr 2022 09:17:11 +0000 Received: from MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM ([fe80::5804:c2bb:bc94:3cec]) by MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM ([fe80::5804:c2bb:bc94:3cec%6]) with mapi id 15.20.5186.018; Sat, 23 Apr 2022 09:17:11 +0000 From: Enze Li To: pedro@palves.net, tom@tromey.com Cc: gdb-patches@sourceware.org Subject: [PATCH v8 3/3] gdb/python: Export nibbles to python layer Date: Sat, 23 Apr 2022 17:16:55 +0800 Message-ID: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TMN: [2bh9rxU4+t3jWJ18B41dRXDxrwW32OkA] X-ClientProxiedBy: HK2PR02CA0132.apcprd02.prod.outlook.com (2603:1096:202:16::16) To MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM (2603:10c6:220:71::10) X-Microsoft-Original-Message-ID: <20220423091655.19336-1-lienze2010@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dde6ed3c-696e-4d34-e15e-08da250a0c1d X-MS-TrafficTypeDiagnostic: SYBP282MB2724:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3BMqb1fj7qJbY7Z6KnKC+mXgAHbmgG0OWUAAuaT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8viBnPGFpP?= =?us-ascii?Q?cNyfYs/h4kZPJJ3doFQGAAsW20g4qTTgDNoxJKJy8cHI9/Y3PumpFmY4CV82?= =?us-ascii?Q?EJq/+thCez1lZs/1D8x0tYW9Drvc0m7275NC7OipXe+twJqq0yjItQZmBShV?= =?us-ascii?Q?AzraulvdMgrkARrpMHQpfMHTJYp7EAef8fn7KAN2EloJv683ffdVCXGYkRx1?= =?us-ascii?Q?C4Gz/CJqqUY=3D?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-746f3.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: dde6ed3c-696e-4d34-e15e-08da250a0c1d X-MS-Exchange-CrossTenant-AuthSource: MEAP282MB0293.AUSP282.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2022 09:17:11.2188 (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: SYBP282MB2724 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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, 23 Apr 2022 09:17:17 -0000 This patch makes it possible to allow Value.format_string() to return nibbles output. When we set the parameter of nibbles to True, we can achieve the displaying binary values in groups of every four bits. Here's an example: (gdb) py print (gdb.Value (1230).format_string (format='t', nibbles=True)) 0100 1100 1110 (gdb) Note that the parameter nibbles is only useful if format='t' is also used. This patch also includes update to the relevant testcase and documentation. Tested on x86_64 openSUSE Tumbleweed(VERSION_ID="20220413"). --- gdb/doc/python.texi | 5 ++ gdb/python/py-value.c | 7 +- gdb/testsuite/gdb.python/py-format-string.exp | 73 +++++++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index cb5283e03c0..5fd757d4891 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -1094,6 +1094,11 @@ union} in @ref{Print Settings}). address, @code{False} if it shouldn't (see @code{set print address} in @ref{Print Settings}). +@item nibbles +@code{True} if binary values should be displayed in groups of four bits, +known as nibbles. @code{False} if it shouldn't (see @code{set print +nibbles} in @ref{Print Settings}). + @item deref_refs @code{True} if C@t{++} references should be resolved to the value they refer to, @code{False} (the default) if they shouldn't. Note that, unlike diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index e779f491b5b..4a51ff0f94d 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -640,6 +640,7 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw) "unions", /* See set print union on|off. */ "address", /* See set print address on|off. */ "styling", /* Should we apply styling. */ + "nibbles", /* See set print nibbles on|off. */ /* C++ options. */ "deref_refs", /* No corresponding setting. */ "actual_objects", /* See set print object on|off. */ @@ -685,13 +686,14 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw) PyObject *unions_obj = NULL; PyObject *address_obj = NULL; PyObject *styling_obj = Py_False; + PyObject *nibbles_obj = NULL; PyObject *deref_refs_obj = NULL; PyObject *actual_objects_obj = NULL; PyObject *static_members_obj = NULL; char *format = NULL; if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, - "|O!O!O!O!O!O!O!O!O!O!O!IIIs", + "|O!O!O!O!O!O!O!O!O!O!O!O!IIIs", keywords, &PyBool_Type, &raw_obj, &PyBool_Type, &pretty_arrays_obj, @@ -701,6 +703,7 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw) &PyBool_Type, &unions_obj, &PyBool_Type, &address_obj, &PyBool_Type, &styling_obj, + &PyBool_Type, &nibbles_obj, &PyBool_Type, &deref_refs_obj, &PyBool_Type, &actual_objects_obj, &PyBool_Type, &static_members_obj, @@ -725,6 +728,8 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw) return NULL; if (!copy_py_bool_obj (&opts.addressprint, address_obj)) return NULL; + if (!copy_py_bool_obj (&opts.nibblesprint, nibbles_obj)) + return NULL; if (!copy_py_bool_obj (&opts.deref_ref, deref_refs_obj)) return NULL; if (!copy_py_bool_obj (&opts.objectprint, actual_objects_obj)) diff --git a/gdb/testsuite/gdb.python/py-format-string.exp b/gdb/testsuite/gdb.python/py-format-string.exp index 63b87e73476..7705a245ee2 100644 --- a/gdb/testsuite/gdb.python/py-format-string.exp +++ b/gdb/testsuite/gdb.python/py-format-string.exp @@ -536,6 +536,78 @@ proc_with_prefix test_address {} { } } +# Test the nibbles option for gdb.Value.format_string. +proc_with_prefix test_nibbles {} { + global current_lang + + set opts "format='t', nibbles=True" + with_test_prefix $opts { + if { $current_lang == "c" } { + set binary_pointer_regexp "\[ 0-1\]+" + gdb_test "python print (gdb.Value (42).format_string (${opts}))" \ + "0010 1010" \ + "42 with option ${opts}" + + check_format_string "a_point_t" $opts + check_format_string "a_point_t_pointer" $opts \ + $binary_pointer_regexp + check_format_string "another_point" $opts + + check_format_string "a_struct_with_union" $opts \ + "\\{the_union = \\{an_int = 0010 1010 0010 1010 0010 1010 0010 1010, a_char = 0010 1010\\}\\}" + check_format_string "an_enum" $opts \ + "0001" + check_format_string "a_string" $opts \ + $binary_pointer_regexp + check_format_string "a_binary_string" $opts \ + $binary_pointer_regexp + check_format_string "a_binary_string_array" $opts \ + "\\{0110 1000, 0110 0101, 0110 1100, 0110 1100, 0110 1111, 0, 0111 0111, 0110 1111, 0111 0010, 0110 1100, 0110 0100, 0\\}" + check_format_string "a_big_string" $opts \ + "\\{0100 0001, 0100 0010, 0100 0011, 0100 0100, 0100 0101, \[, 0-1\]+\.\.\.\\}" + check_format_string "an_array" $opts \ + "\\{0010, 0011, 0101\\}" + check_format_string "an_array_with_repetition" $opts \ + "\\{0001, 0011 , 0101, 0101, 0101\\}" + check_format_string "a_symbol_pointer" $opts \ + $binary_pointer_regexp + } + if { $current_lang == "c++" } { + set binary_pointer_regexp "\['0-1\]+" + gdb_test "python print (gdb.Value (42).format_string (${opts}))" \ + "0010'1010" \ + "42 with option ${opts}" + + check_format_string "a_point_t" $opts + check_format_string "a_point_t_pointer" $opts \ + $binary_pointer_regexp + check_format_string "another_point" $opts + + check_format_string "a_struct_with_union" $opts \ + "\\{the_union = \\{an_int = 0010'1010'0010'1010'0010'1010'0010'1010, a_char = 0010'1010\\}\\}" + check_format_string "an_enum" $opts \ + "0001" + check_format_string "a_string" $opts \ + $binary_pointer_regexp + check_format_string "a_binary_string" $opts \ + $binary_pointer_regexp + check_format_string "a_binary_string_array" $opts \ + "\\{0110'1000, 0110'0101, 0110'1100, 0110'1100, 0110'1111, 0, 0111'0111, 0110'1111, 0111'0010, 0110'1100, 0110'0100, 0\\}" + check_format_string "a_big_string" $opts \ + "\\{0100'0001, 0100'0010, 0100'0011, 0100'0100, 0100'0101, \[, '0-1\]+\.\.\.\\}" + check_format_string "an_array" $opts \ + "\\{0010, 0011, 0101\\}" + check_format_string "an_array_with_repetition" $opts \ + "\\{0001, 0011 , 0101, 0101, 0101\\}" + check_format_string "a_symbol_pointer" $opts \ + $binary_pointer_regexp + + check_format_string "a_point_t_ref" $opts + check_format_string "a_base_ref" $opts + } + } +} + # Test the deref_refs option for gdb.Value.format_string. proc_with_prefix test_deref_refs {} { global current_lang @@ -1047,6 +1119,7 @@ proc_with_prefix test_all_common {} { test_symbols test_unions test_address + test_nibbles test_deref_refs test_actual_objects test_static_members -- 2.35.3