From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01olkn2091.outbound.protection.outlook.com [40.92.98.91]) by sourceware.org (Postfix) with ESMTPS id 7490E3857831 for ; Sun, 4 Sep 2022 08:36:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7490E3857831 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cu68iNcx0tqh1HuKB9lYnU/TVJyew3viOgQPIuZvd7I5GE4pd/6EgRIl6RY+9eCmuDXLFEH6a7KpwEgMNi9eLyJOKQxQSA7WmFHNXUPJA/tVovjLfdoNdJryH56griEi1NvqVPmT4DjXg/TA6Be9mGiggdtrmEzaekk+pcv/OyM9lX0CC6lDo9szc7drbLOASRUk+/uGw0DxN/EzbxQY1T+LXRTo8InO4e6ijUaOaoqrqbRqgaV/++YhKJLgQvXc1hxhY+lz1bdQdDCEVlsgy/BJ0swUWrx1pDtCQ4PvZv91OCYcsfts0rE+VnsKARaj1OwAcgq2VrlTXJYthMWu2w== 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=bgaOUkRsCC2APwlNkMtrsnjwkIsmVogwGSKO/kpT70A=; b=F2rHda9Yo5vNPZoxf4MVKaoEfAAIG5PGm7L4BkE99kg79t24mvKDL89Cl5VKZJmx2QHfBk6ktl0DLLCNYo2DOjL94jlRb8wZ/Rw2vyg1Oe5jHFDupDAna+qVDlSvZpiHyWwDnZuk/CsQW9Gbut6wbyzLC8J8RMsJpW3ruBvj7i4sneO/YmD9bah7RwnMTpH8siLRpu04VtvdIlS4ifZmfhKEGJivSXDt8TdL98zI2TxfiJcJMtVsJWudA455QxuDPwvwfUvyIVBgZIB72GCsLx3O0u8X91FR7auAgTtFWjQklPtwg5AkZGAAXjI7W9Lun15gNThzwPTkff3/EmJx2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from OS3P286MB2152.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:197::9) by OS3P286MB1832.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:172::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Sun, 4 Sep 2022 08:36:20 +0000 Received: from OS3P286MB2152.JPNP286.PROD.OUTLOOK.COM ([fe80::871:c111:c492:604a]) by OS3P286MB2152.JPNP286.PROD.OUTLOOK.COM ([fe80::871:c111:c492:604a%4]) with mapi id 15.20.5588.017; Sun, 4 Sep 2022 08:36:20 +0000 From: Enze Li To: gdb-patches@sourceware.org Cc: enze.li@gmx.com Subject: [PATCH] gdb: add a numeric check after the exponent (PR cli/24124) Date: Sun, 4 Sep 2022 16:36:01 +0800 Message-ID: X-Mailer: git-send-email 2.37.2 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TMN: [KpbkUKPVKvOxcbVK2ZweCabBkDhtFpe1] X-ClientProxiedBy: SG2PR06CA0223.apcprd06.prod.outlook.com (2603:1096:4:68::31) To OS3P286MB2152.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:197::9) X-Microsoft-Original-Message-ID: <20220904083601.31114-1-enze.li@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 722089f6-771c-45ee-f8a2-08da8e508a45 X-MS-TrafficTypeDiagnostic: OS3P286MB1832:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yuh7+qPkLuvaVBP87hEYHu2JcDVzfYjGaSauatZOfKuKYgLJspz5dUYVS148eg+NKIhcJ/IEQWTVq3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+S6r5UZw5aY+7AwrOCtYm9V8KqUj4?= =?us-ascii?Q?MJz8mQHF9pnD7MFVh5H4VbQE76S15gX0V6MGRzTBSA=3D=3D?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-05f45.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 722089f6-771c-45ee-f8a2-08da8e508a45 X-MS-Exchange-CrossTenant-AuthSource: OS3P286MB2152.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Sep 2022 08:36:20.4873 (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: OS3P286MB1832 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Sun, 04 Sep 2022 08:36:25 -0000 PR cli/24124 points out that `b *804874d` or `b *804874f` gives output `Invalid number "804874d".` or `Invalid number "804874f".` And the output of `b *804874e` is `Breakpoint 1 at 0xc480a`. That is to say, when "e" or "E" appears after a decimal value, it will be incorrectly parsed as a floating point number. Importantly, this parsing is not consistent with the C language. The initial idea was to perform a "0x" or "0X" check of the address. But Tom pointed out that the text after the "*" is an arbitrary expression, not just an integer. Therefore, I realized that this idea was going in the wrong direction. After digging a bit deeper, I found that the root cause of this problem is that the lex_one_token function doesn't check for the case where the exponent has no digits. If we check this, GDB will not continue parsing the invalid numbers. Before this patch applied, things like (gdb) b *804874d Invalid number "804874d". (gdb) b *804874e Breakpoint 1 at 0xc480a (gdb) print 80d Invalid number "80d". (gdb) ptype 80d Invalid number "80d". (gdb) print 80e $1 = 80 (gdb) ptype 80e type = double The new behavior is (gdb) b *804874d Invalid number "804874d". (gdb) b *804874e Invalid number "804874e". (gdb) print 80d Invalid number "80d". (gdb) ptype 80d Invalid number "80d". (gdb) print 80e Invalid number "80e". (gdb) ptype 80e Invalid number "80e". Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24124 --- gdb/c-exp.y | 3 ++- gdb/testsuite/gdb.base/commands.exp | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 61a61fcba09c..b13de967b1b6 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -2769,7 +2769,8 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) /* This test includes !hex because 'e' is a valid hex digit and thus does not indicate a floating point number when the radix is hex. */ - if (!hex && !got_e && !got_p && (*p == 'e' || *p == 'E')) + if (!hex && !got_e && !got_p && (*p == 'e' || *p == 'E') + && p[1] >= '0' && p[1] <= '9') got_dot = got_e = 1; else if (!got_e && !got_p && (*p == 'p' || *p == 'P')) got_dot = got_p = 1; diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp index 3eb4463cd1a5..ca30b757e38a 100644 --- a/gdb/testsuite/gdb.base/commands.exp +++ b/gdb/testsuite/gdb.base/commands.exp @@ -278,6 +278,13 @@ proc_with_prefix breakpoint_command_test {} { gdb_test "continue" \ "Breakpoint \[0-9\]*, factorial.*Now the value is 5" gdb_test "print value" " = 5" + + gdb_test "break *804874d" "Invalid number.*" "804874d is an invalid number" + gdb_test "break *804874e" "Invalid number.*" "804874e is an invalid number" + gdb_test "print 80d" "Invalid number.*" "(print) 80d is an invalid number" + gdb_test "ptype 80d" "Invalid number.*" "(ptype) 80d is an invalid number" + gdb_test "print 80e" "Invalid number.*" "(print) 80e is an invalid number" + gdb_test "ptype 80e" "Invalid number.*" "(ptype) 80e is an invalid number" } # Test clearing the commands of several breakpoints with one single "end". -- 2.37.2