+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.
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;
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;
+ }
}
}
}
}
else if (token == NULL
+ && !is_raw
&& (strncmp (start, "thread", length) == 0
|| strncmp (start, "task", length) == 0)
&& space_then_number (pstate->lexptr))
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);
+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):
--- /dev/null
+# 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"
--- /dev/null
+// 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
+}
}
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
+}