aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/rust-parse.c32
-rw-r--r--gdb/testsuite/ChangeLog7
-rw-r--r--gdb/testsuite/gdb.rust/rawids.exp41
-rw-r--r--gdb/testsuite/gdb.rust/rawids.rs26
-rw-r--r--gdb/testsuite/lib/rust-support.exp17
6 files changed, 124 insertions, 6 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 549ea69..30c2aa7 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2021-06-11 Tom Tromey <tom@tromey.com>
+
+ PR rust/23427
+ * rust-parse.c (rust_parser::lex_identifier): Handle raw
+ identifiers.
+ (rust_lex_tests): Add raw identifier tests.
+
2021-06-10 Simon Marchi <simon.marchi@polymtl.ca>
* lib/gdb.exp (default_gdb_exit): Unset gdb_tty_name.
diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
index 2f2afcf..539e1c8 100644
--- a/gdb/rust-parse.c
+++ b/gdb/rust-parse.c
@@ -747,12 +747,21 @@ rust_identifier_start_p (char c)
int
rust_parser::lex_identifier ()
{
- const char *start = pstate->lexptr;
unsigned int length;
const struct token_info *token;
int i;
int is_gdb_var = pstate->lexptr[0] == '$';
+ bool is_raw = false;
+ if (pstate->lexptr[0] == 'r'
+ && pstate->lexptr[1] == '#'
+ && rust_identifier_start_p (pstate->lexptr[2]))
+ {
+ is_raw = true;
+ pstate->lexptr += 2;
+ }
+
+ const char *start = pstate->lexptr;
gdb_assert (rust_identifier_start_p (pstate->lexptr[0]));
++pstate->lexptr;
@@ -769,13 +778,16 @@ rust_parser::lex_identifier ()
length = pstate->lexptr - start;
token = NULL;
- for (i = 0; i < ARRAY_SIZE (identifier_tokens); ++i)
+ if (!is_raw)
{
- if (length == strlen (identifier_tokens[i].name)
- && strncmp (identifier_tokens[i].name, start, length) == 0)
+ for (i = 0; i < ARRAY_SIZE (identifier_tokens); ++i)
{
- token = &identifier_tokens[i];
- break;
+ if (length == strlen (identifier_tokens[i].name)
+ && strncmp (identifier_tokens[i].name, start, length) == 0)
+ {
+ token = &identifier_tokens[i];
+ break;
+ }
}
}
@@ -789,6 +801,7 @@ rust_parser::lex_identifier ()
}
}
else if (token == NULL
+ && !is_raw
&& (strncmp (start, "thread", length) == 0
|| strncmp (start, "task", length) == 0)
&& space_then_number (pstate->lexptr))
@@ -2300,6 +2313,13 @@ rust_lex_tests (void)
rust_lex_stringish_test (&parser, "hibob", "hibob", IDENT);
rust_lex_stringish_test (&parser, "hibob__93", "hibob__93", IDENT);
rust_lex_stringish_test (&parser, "thread", "thread", IDENT);
+ rust_lex_stringish_test (&parser, "r#true", "true", IDENT);
+
+ const int expected1[] = { IDENT, DECIMAL_INTEGER, 0 };
+ rust_lex_test_sequence (&parser, "r#thread 23", ARRAY_SIZE (expected1),
+ expected1);
+ const int expected2[] = { IDENT, '#', 0 };
+ rust_lex_test_sequence (&parser, "r#", ARRAY_SIZE (expected2), expected2);
rust_lex_stringish_test (&parser, "\"string\"", "string", STRING);
rust_lex_stringish_test (&parser, "\"str\\ting\"", "str\ting", STRING);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 3737664..9168a6a 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2021-06-11 Tom Tromey <tom@tromey.com>
+
+ PR rust/23427
+ * lib/rust-support.exp (rust_compiler_version): New caching proc.
+ * gdb.rust/rawids.exp: New file.
+ * gdb.rust/rawids.rs: New file.
+
2021-06-10 Tom de Vries <tdevries@suse.de>
* gdb.mi/user-selected-context-sync.c (child_sub_function, main):
diff --git a/gdb/testsuite/gdb.rust/rawids.exp b/gdb/testsuite/gdb.rust/rawids.exp
new file mode 100644
index 0000000..31a56d3
--- /dev/null
+++ b/gdb/testsuite/gdb.rust/rawids.exp
@@ -0,0 +1,41 @@
+# Copyright (C) 2021 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 raw identifiers.
+
+load_lib rust-support.exp
+if {[skip_rust_tests]} {
+ continue
+}
+
+set v [split [rust_compiler_version] .]
+if {[lindex $v 0] == 1 && [lindex $v 1] < 30} {
+ untested "raw identifiers require rust 1.30 or greater"
+ return -1
+}
+
+standard_testfile .rs
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug rust}]} {
+ return -1
+}
+
+set line [gdb_get_line_number "set breakpoint here"]
+if {![runto ${srcfile}:$line]} {
+ untested "could not run to breakpoint"
+ return -1
+}
+
+gdb_test "print r#if" " = 23"
+gdb_test "print r#thread" " = 27"
diff --git a/gdb/testsuite/gdb.rust/rawids.rs b/gdb/testsuite/gdb.rust/rawids.rs
new file mode 100644
index 0000000..f37e862
--- /dev/null
+++ b/gdb/testsuite/gdb.rust/rawids.rs
@@ -0,0 +1,26 @@
+// Copyright (C) 2021 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/>.
+
+#![allow(dead_code)]
+#![allow(unused_variables)]
+#![allow(unused_assignments)]
+
+
+fn main () {
+ let r#if = 23;
+ let thread = 27;
+
+ println!("{}, {}", r#if, r#thread); // set breakpoint here
+}
diff --git a/gdb/testsuite/lib/rust-support.exp b/gdb/testsuite/lib/rust-support.exp
index d2ffac9..2896ac8 100644
--- a/gdb/testsuite/lib/rust-support.exp
+++ b/gdb/testsuite/lib/rust-support.exp
@@ -54,3 +54,20 @@ gdb_caching_proc rust_llvm_version {
}
return 0.0
}
+
+# Return the version of the Rust compiler.
+gdb_caching_proc rust_compiler_version {
+ set rustc [find_rustc]
+ if {$rustc == ""} {
+ verbose "could not find rustc"
+ } else {
+ set output [lindex [remote_exec host "$rustc --version --verbose"] 1]
+ foreach line [split $output \n] {
+ if {[regexp "rustc (\[0-9.\]+) .*\$" $output ignore version]} {
+ return $version
+ }
+ }
+ verbose "could not match rustc version output: $output"
+ }
+ return 0.0
+}