diff options
author | Tom Tromey <tromey@adacore.com> | 2022-02-16 12:01:52 -0700 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2022-03-07 08:25:11 -0700 |
commit | c9bfa277e9e6467dad91641357e09bf0a7ac0dc2 (patch) | |
tree | 0ff02e7601896ff486779069c992446f2dc60306 /gdb | |
parent | 47a39c6e18324360b3ef9b72f03e206417f2ce9c (diff) | |
download | fsf-binutils-gdb-c9bfa277e9e6467dad91641357e09bf0a7ac0dc2.zip fsf-binutils-gdb-c9bfa277e9e6467dad91641357e09bf0a7ac0dc2.tar.gz fsf-binutils-gdb-c9bfa277e9e6467dad91641357e09bf0a7ac0dc2.tar.bz2 |
Fix Ada integer literals with exponents
While working on another patch, I noticed that Ada integer literals
with exponents did not work. For example, with one form you get an
error:
(gdb) print 8e2
Invalid digit `e' in based literal
And with another form you get an incorrect value:
(gdb) print 16#8#e2
$2 = 8
This patch fixes the bugs and adds tests.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ada-lex.l | 9 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/literals.exp | 36 |
2 files changed, 42 insertions, 3 deletions
diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l index f698ad4..e4f18f1 100644 --- a/gdb/ada-lex.l +++ b/gdb/ada-lex.l @@ -103,8 +103,9 @@ static int paren_depth; {NUM10}{POSEXP} { canonicalizeNumeral (numbuf, yytext); - return processInt (pstate, NULL, numbuf, - strrchr (numbuf, 'e') + 1); + char *e_ptr = strrchr (numbuf, 'e'); + *e_ptr = '\0'; + return processInt (pstate, nullptr, numbuf, e_ptr + 1); } {NUM10} { @@ -114,9 +115,11 @@ static int paren_depth; {NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#"{POSEXP} { canonicalizeNumeral (numbuf, yytext); + char *e_ptr = strrchr (numbuf, 'e'); + *e_ptr = '\0'; return processInt (pstate, numbuf, strchr (numbuf, '#') + 1, - strrchr(numbuf, '#') + 1); + e_ptr + 1); } {NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#" { diff --git a/gdb/testsuite/gdb.ada/literals.exp b/gdb/testsuite/gdb.ada/literals.exp new file mode 100644 index 0000000..92a9a19 --- /dev/null +++ b/gdb/testsuite/gdb.ada/literals.exp @@ -0,0 +1,36 @@ +# Copyright 2022 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test some literal syntax. + +load_lib "ada.exp" + +if { [skip_ada_tests] } { return -1 } + +clean_restart + +gdb_test_no_output "set lang ada" +gdb_test "print 7#10#" " = 7" +gdb_test "print 77#10#" "Invalid base: 77." +gdb_test "print 7#8#" "Invalid digit `8' in based literal" + +gdb_test "print 8e2" " = 800" +gdb_test "print 9999999999999999999999999999999999999999999999" \ + "Integer literal out of range" +gdb_test "print 2e1000" "Integer literal out of range" + +gdb_test "print 16#ffff#" " = 65535" +gdb_test "print 16#f#e1" " = 240" +gdb_test "print 16#1#e10" " = 1099511627776" |