summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-06-11 10:34:31 -0600
committerTom Tromey <tom@tromey.com>2020-06-11 10:34:31 -0600
commit2b4e6a3f4b66284556254f548716c7b21b93524a (patch)
tree347344736ca24012aceb5c9c8bc4e0dd06e50dcd
parent4412332f4b3a4ec570c378ff98ec671dd83a2959 (diff)
downloadbinutils-gdb-2b4e6a3f4b66284556254f548716c7b21b93524a.tar.gz
Fix hex floating point lexing
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-11 Tom Tromey <tom@tromey.com> PR gdb/18318: * c-exp.y (lex_one_token): Handle 'p' like 'e'. gdb/testsuite/ChangeLog 2020-06-11 Tom Tromey <tom@tromey.com> PR gdb/18318: * gdb.base/printcmds.exp (test_float_accepted): Add more hex floating point tests.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/c-exp.y11
-rw-r--r--gdb/testsuite/ChangeLog6
-rw-r--r--gdb/testsuite/gdb.base/printcmds.exp18
4 files changed, 27 insertions, 13 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e5008f66870..5ef6ee6aca4 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2020-06-11 Tom Tromey <tom@tromey.com>
+
+ PR gdb/18318:
+ * c-exp.y (lex_one_token): Handle 'p' like 'e'.
+
2020-06-09 Jonny Grant <jg@jguk.org>
2020-06-09 Simon Marchi <simon.marchi@polymtl.ca>
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/ChangeLog b/gdb/testsuite/ChangeLog
index 7ff7de2b526..0523f7cb881 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2020-06-11 Tom Tromey <tom@tromey.com>
+
+ PR gdb/18318:
+ * gdb.base/printcmds.exp (test_float_accepted): Add more hex
+ floating point tests.
+
2020-06-11 Keith Seitz <keiths@redhat.com>
PR gdb/21356
diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp
index 066e7fce87b..0a96b228b89 100644
--- a/gdb/testsuite/gdb.base/printcmds.exp
+++ b/gdb/testsuite/gdb.base/printcmds.exp
@@ -127,15 +127,15 @@ 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
+ } {
+ gdb_test "p $num" " = [string_to_regexp $result]"
}
}