From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway24.websitewelcome.com (gateway24.websitewelcome.com [192.185.50.45]) by sourceware.org (Postfix) with ESMTPS id 6D6F83851C17 for ; Sat, 6 Jun 2020 20:18:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6D6F83851C17 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 868CD519D6 for ; Sat, 6 Jun 2020 15:18:08 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id hfGajXVQIXVkQhfGajY5mU; Sat, 06 Jun 2020 15:18:08 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=qNit9QHmZPsiMT7wwsqeIgjcM8oGDA6JBnsm0VkcEqI=; b=QmNgNzPwCGsUn8++uYHGhSRDa6 iohAH1iyIwCK3oKGvzQ5JojY/09siREDcvosbO9b6F1Ok9VYcgQJUHlOj3srw4yllNfCWILuQ2qEK SmAi7tVm/1UCpv9spQhzylhJR; Received: from 174-16-104-48.hlrn.qwest.net ([174.16.104.48]:55894 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1jhfGa-002CFz-6x; Sat, 06 Jun 2020 14:18:08 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix hex floating point lexing Date: Sat, 6 Jun 2020 14:18:06 -0600 Message-Id: <20200606201806.19353-1-tom@tromey.com> X-Mailer: git-send-email 2.17.2 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 174.16.104.48 X-Source-L: No X-Exim-ID: 1jhfGa-002CFz-6x X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174-16-104-48.hlrn.qwest.net (bapiya.Home) [174.16.104.48]:55894 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, URIBL_CSS, URIBL_CSS_A autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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, 06 Jun 2020 20:18:13 -0000 PR gdb/18318 notes that gdb will sometimes incorrectly handle hex floating point input. This turns out to be a bug in the C lexer; the 'p' was not being correctly recognized, and so the exponent was not always passed to the floating point "from_string" method. Tested by the buildbot "Fedora-x86_64-m64" builder. gdb/ChangeLog 2020-06-06 Tom Tromey PR gdb/18318: * c-exp.y (lex_one_token): Handle 'p' like 'e'. gdb/testsuite/ChangeLog 2020-06-06 Tom Tromey PR gdb/18318: * gdb.base/printcmds.exp (test_float_accepted): Add more hex floating point tests. --- gdb/ChangeLog | 5 +++++ gdb/c-exp.y | 11 +++++++---- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.base/printcmds.exp | 27 +++++++++++++++++++-------- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index e7d0a0dc4ad..5ec84eb8ed7 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -2748,7 +2748,7 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) case '9': { /* It's a number. */ - int got_dot = 0, got_e = 0, toktype; + int got_dot = 0, got_e = 0, got_p = 0, toktype; const char *p = tokstart; int hex = input_radix > 10; @@ -2768,13 +2768,16 @@ 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 && (*p == 'e' || *p == 'E')) + if (!hex && !got_e && !got_p && (*p == 'e' || *p == 'E')) got_dot = got_e = 1; + else if (!got_e && !got_p && (*p == 'p' || *p == 'P')) + got_dot = got_p = 1; /* This test does not include !hex, because a '.' always indicates a decimal floating point number regardless of the radix. */ else if (!got_dot && *p == '.') got_dot = 1; - else if (got_e && (p[-1] == 'e' || p[-1] == 'E') + else if (((got_e && (p[-1] == 'e' || p[-1] == 'E')) + || (got_p && (p[-1] == 'p' || p[-1] == 'P'))) && (*p == '-' || *p == '+')) /* This is the sign of the exponent, not the end of the number. */ @@ -2787,7 +2790,7 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) break; } toktype = parse_number (par_state, tokstart, p - tokstart, - got_dot|got_e, &yylval); + got_dot | got_e | got_p, &yylval); if (toktype == ERROR) { char *err_copy = (char *) alloca (p - tokstart + 1); diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp index 066e7fce87b..05ababff78c 100644 --- a/gdb/testsuite/gdb.base/printcmds.exp +++ b/gdb/testsuite/gdb.base/printcmds.exp @@ -127,14 +127,25 @@ proc test_float_accepted {} { gdb_test "p 1.5l" " = 1.5" # Test hexadecimal floating point. - set test "p 0x1.1" - gdb_test_multiple $test $test { - -re " = 1\\.0625\r\n$gdb_prompt $" { - pass $test - } - -re "Invalid number \"0x1\\.1\"\\.\r\n$gdb_prompt $" { - # Older glibc does not support hex float, newer does. - xfail $test + foreach {num result} { + 0x1.1 1.0625 + 0x1.8480000000000p+6 97.125 + 0x1.8480000000000p6 97.125 + 0x00.1p0 0.0625 + 0x00.1p1 0.125 + 0x00.1p-1 0.03125 + } { + set test "p $num" + set rxn [string_to_regexp $num] + set rxr [string_to_regexp $result] + gdb_test_multiple $test $test { + -re " = $result\r\n$gdb_prompt $" { + pass $test + } + -re "Invalid number \".*\"\\.\r\n$gdb_prompt $" { + # Older glibc does not support hex float, newer does. + xfail $test + } } } } -- 2.17.2