mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-19 14:34:07 +08:00
Implement Rust raw identifiers
This patch implements Rust raw identifiers in the lexer in gdb. There was an earlier patch to do this, but the contributor didn't reply to my email asking whether he had sorted out his copyright assignment. This is relatively straightforward, but a small test suite addition was needd to ensure that the new test is skipped on older versions of rustc -- ones that predate the introduction of raw identifiers. gdb/ChangeLog 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. gdb/testsuite/ChangeLog 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.
This commit is contained in:
parent
2748c1b17e
commit
48ec4c05c6
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -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):
|
||||
|
41
gdb/testsuite/gdb.rust/rawids.exp
Normal file
41
gdb/testsuite/gdb.rust/rawids.exp
Normal file
@ -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"
|
26
gdb/testsuite/gdb.rust/rawids.rs
Normal file
26
gdb/testsuite/gdb.rust/rawids.rs
Normal file
@ -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
|
||||
}
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user