public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add Rust parser check for end of expression
@ 2022-03-18  4:44 Tom Tromey
  2022-03-18 16:00 ` Pedro Alves
  2022-03-28 21:16 ` Tom Tromey
  0 siblings, 2 replies; 4+ messages in thread
From: Tom Tromey @ 2022-03-18  4:44 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I noticed that "print 5," passed in Rust -- the parser wasn't checking
that the entire input was used.  This patch fixes the problem.  This
in turn pointed out another bug in the parser, namely that it didn't
lex the next token after handling a string token.  This is also fixed
here.
---
 gdb/rust-parse.c                | 6 +++++-
 gdb/testsuite/gdb.rust/expr.exp | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
index 4006df7086b..7d7d882872c 100644
--- a/gdb/rust-parse.c
+++ b/gdb/rust-parse.c
@@ -271,7 +271,10 @@ struct rust_parser
   operation_up parse_entry_point ()
   {
     lex ();
-    return parse_expr ();
+    operation_up result = parse_expr ();
+    if (current_token != 0)
+      error (_("Syntax error near '%s'"), pstate->prev_lexptr);
+    return result;
   }
 
   operation_up parse_tuple ();
@@ -2020,6 +2023,7 @@ rust_parser::parse_atom (bool required)
 
     case STRING:
       result = parse_string ();
+      lex ();
       break;
 
     case BYTESTRING:
diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.exp
index 0c445897338..bb0222bed4b 100644
--- a/gdb/testsuite/gdb.rust/expr.exp
+++ b/gdb/testsuite/gdb.rust/expr.exp
@@ -145,3 +145,5 @@ gdb_test "print 0x0 as fn(i64) -> ()" " = \\\(\\*mut fn \\\(i64\\\) -> \\\(\\\)\
 gdb_test "print r#" "No symbol 'r' in current context"
 
 gdb_test "printf \"%d %d\\n\", 23+1, 23-1" "24 22"
+
+gdb_test "print 5," "Syntax error near ','"
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add Rust parser check for end of expression
  2022-03-18  4:44 [PATCH] Add Rust parser check for end of expression Tom Tromey
@ 2022-03-18 16:00 ` Pedro Alves
  2022-03-18 16:58   ` Tom Tromey
  2022-03-28 21:16 ` Tom Tromey
  1 sibling, 1 reply; 4+ messages in thread
From: Pedro Alves @ 2022-03-18 16:00 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 2022-03-18 04:44, Tom Tromey wrote:
> I noticed that "print 5," passed in Rust -- the parser wasn't checking
> that the entire input was used.  This patch fixes the problem.  This
> in turn pointed out another bug in the parser, namely that it didn't
> lex the next token after handling a string token.  This is also fixed
> here.

OOC, is the lex-next-token bug something that is also covered by
the added test?  It doesn't seem to use strings.

Pedro Alves

> ---
>  gdb/rust-parse.c                | 6 +++++-
>  gdb/testsuite/gdb.rust/expr.exp | 2 ++
>  2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
> index 4006df7086b..7d7d882872c 100644
> --- a/gdb/rust-parse.c
> +++ b/gdb/rust-parse.c
> @@ -271,7 +271,10 @@ struct rust_parser
>    operation_up parse_entry_point ()
>    {
>      lex ();
> -    return parse_expr ();
> +    operation_up result = parse_expr ();
> +    if (current_token != 0)
> +      error (_("Syntax error near '%s'"), pstate->prev_lexptr);
> +    return result;
>    }
>  
>    operation_up parse_tuple ();
> @@ -2020,6 +2023,7 @@ rust_parser::parse_atom (bool required)
>  
>      case STRING:
>        result = parse_string ();
> +      lex ();
>        break;
>  
>      case BYTESTRING:
> diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.exp
> index 0c445897338..bb0222bed4b 100644
> --- a/gdb/testsuite/gdb.rust/expr.exp
> +++ b/gdb/testsuite/gdb.rust/expr.exp
> @@ -145,3 +145,5 @@ gdb_test "print 0x0 as fn(i64) -> ()" " = \\\(\\*mut fn \\\(i64\\\) -> \\\(\\\)\
>  gdb_test "print r#" "No symbol 'r' in current context"
>  
>  gdb_test "printf \"%d %d\\n\", 23+1, 23-1" "24 22"
> +
> +gdb_test "print 5," "Syntax error near ','"


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add Rust parser check for end of expression
  2022-03-18 16:00 ` Pedro Alves
@ 2022-03-18 16:58   ` Tom Tromey
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2022-03-18 16:58 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

>> I noticed that "print 5," passed in Rust -- the parser wasn't checking
>> that the entire input was used.  This patch fixes the problem.  This
>> in turn pointed out another bug in the parser, namely that it didn't
>> lex the next token after handling a string token.  This is also fixed
>> here.

Pedro> OOC, is the lex-next-token bug something that is also covered by
Pedro> the added test?  It doesn't seem to use strings.

Yes, if you remove that hunk there will be other regressions.

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add Rust parser check for end of expression
  2022-03-18  4:44 [PATCH] Add Rust parser check for end of expression Tom Tromey
  2022-03-18 16:00 ` Pedro Alves
@ 2022-03-28 21:16 ` Tom Tromey
  1 sibling, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2022-03-28 21:16 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> I noticed that "print 5," passed in Rust -- the parser wasn't checking
Tom> that the entire input was used.  This patch fixes the problem.  This
Tom> in turn pointed out another bug in the parser, namely that it didn't
Tom> lex the next token after handling a string token.  This is also fixed
Tom> here.

I meant to push this before the gdb 12 branch was made.  I'm going to
check it in and also backport it to the release branch.

Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-28 21:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-18  4:44 [PATCH] Add Rust parser check for end of expression Tom Tromey
2022-03-18 16:00 ` Pedro Alves
2022-03-18 16:58   ` Tom Tromey
2022-03-28 21:16 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).