From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01olkn2024.outbound.protection.outlook.com [40.92.98.24]) by sourceware.org (Postfix) with ESMTPS id C25633858CDA for ; Mon, 5 Sep 2022 13:57:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C25633858CDA ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fpDA99tj1e7RdiGXBizEXBbfw9LoUX6wPJ144ZRwfKzZiR89hY9g+k51SN9gyUyiDWDIAnsd2priRlx0AKTjQPaLlSrmCS/xpkH6/db6Qhci+xG/G8wqnXxZCmnaqqI2ab+YXi118pfJiw63Ek3AJZpaUq5NuSaAF25908+WGwaxay7aj3pUNhFV4Ipp3uMszTB1GJv9QIaLH2KwZxgP0Xc1owZ7K4kgCJqfdy8oXZTOcG/NufxYhoqsUPgIqN3qIIrt/U+ECSkpgzTgCkVepIdogYZPmS9UwafMNAhbl+CZ/ubFChVC8IKfyBOI2CpqbCYU/10BNqNfQr7HI4gawg== 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=E+HoOp0iY1lvukgPpbI1Or1BuXRJ5xx8n+ULheyVhdw=; b=S8MYvci5Sx/15eF251viyofaZmmS3+h2me69mCJI7d3wPRQixl70sLjODlks4tI1xLRZk2yeABXB+eoPjILG7ODwdkzqZJfzD2jBDDsQvhQ4I4awv1icFBzqxqCn4p717zNgWE0UZGxOnONIo5WRqTxwPcQQRB0XpB57FSlIEP48OC/HA6jCDr4Xf7ahg21bnHWz6m/tumQQlt61zc8Ddgi3uZQQ5bVTofbOtHNxGgzD6rtjvxepOeOhAiFkCdpE0HG0ICKaM1tc6RI99NHca7seygPutie1RGDLuu6gQXA0kxgojeKwFaHZU30G1HKVd5JN20oF1W7jMgR9Zzjs7g== 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 TYCP286MB2447.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:18e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.12; Mon, 5 Sep 2022 13:57:53 +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; Mon, 5 Sep 2022 13:57:53 +0000 From: Enze Li To: gdb-patches@sourceware.org Cc: enze.li@gmx.com, schwab@linux-m68k.org Subject: [PATCH v2] gdb: add a numeric check after the exponent (PR cli/24124) Date: Mon, 5 Sep 2022 21:57:36 +0800 Message-ID: X-Mailer: git-send-email 2.37.2 In-Reply-To: References: Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TMN: [02nm5JIhjk2N1SjGGkAht9ti0qaPBBec] X-ClientProxiedBy: SG2P153CA0019.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c7::6) To OS3P286MB2152.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:197::9) X-Microsoft-Original-Message-ID: <20220905135736.6692-1-enze.li@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1c71199e-b447-4f0c-139d-08da8f46a0b8 X-MS-TrafficTypeDiagnostic: TYCP286MB2447:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f7RHOuvhYHWvF2T43/2wLJGunBQJaZ5vRivdokG0Pc8CdYQH7qIAxL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5ySvdHvqUQBDnlKhINCx5oV/QQyyM+YsqMwE7Y9UFpi4?= =?us-ascii?Q?4zMFyKk2KVwJlKoVu37rAp/i99t+NQlR146m15AqLA=3D=3D?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-05f45.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 1c71199e-b447-4f0c-139d-08da8f46a0b8 X-MS-Exchange-CrossTenant-AuthSource: OS3P286MB2152.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2022 13:57:53.6684 (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: TYCP286MB2447 X-Spam-Status: No, score=-11.9 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: Mon, 05 Sep 2022 13:57:58 -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". New in v2: - Address Andreas's comments, avoid breaking the resolution of the sign of the exponent. - Add test cases for exponent with sign. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24124 --- gdb/c-exp.y | 10 ++++++++++ gdb/testsuite/gdb.base/commands.exp | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 61a61fcba09c..9827de9ad549 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -2752,6 +2752,7 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) int got_dot = 0, got_e = 0, got_p = 0, toktype; const char *p = tokstart; int hex = input_radix > 10; + int exp_num = 0; if (c == '0' && (p[1] == 'x' || p[1] == 'X')) { @@ -2783,6 +2784,9 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) /* This is the sign of the exponent, not the end of the number. */ continue; + /* This is the digit of the exponent. */ + else if (got_e && *p >= '0' && *p <= '9') + exp_num++; /* We will take any letters or digits. parse_number will complain if past the radix, or if L or U are not final. */ else if ((*p < '0' || *p > '9') @@ -2790,6 +2794,12 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) && (*p < 'A' || *p > 'Z'))) break; } + + /* If the exponent has no digits, it must be invalid. There is + no need to continue parsing. */ + if (got_e && exp_num == 0) + error (_("Invalid number \"%s\"."), tokstart); + toktype = parse_number (par_state, tokstart, p - tokstart, got_dot | got_e | got_p, &yylval); if (toktype == ERROR) diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp index 3eb4463cd1a5..10c4c2722901 100644 --- a/gdb/testsuite/gdb.base/commands.exp +++ b/gdb/testsuite/gdb.base/commands.exp @@ -278,6 +278,17 @@ 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" + gdb_test "print 80e0" " = 80" "(print) 80e0" + gdb_test "print 80e1" " = 800" "(print) 80e1" + gdb_test "print 80e+2" " = 8000" "(print) 80e+2" + gdb_test "ptype 80e-1" " = double" "(ptype) 80e-1" } # Test clearing the commands of several breakpoints with one single "end". -- 2.37.2