From 42d940118a6372d6e85f71a54fed75fdf5c606bd Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 6 Jul 2016 10:55:10 +0530 Subject: [PATCH] Allow subscripting raw pointers This will be useful for dealing with vectors; regardless of our final solution for the Index trait. 2016-07-06 Manish Goregaokar gdb/ChangeLog: * rust-lang.c (rust_subscript): Allow subscripting pointers gdb/testsuite/ChangeLog: * simple.rs: Add test for raw pointer subscripting * simple.exp: Add test expectations --- gdb/ChangeLog | 4 ++++ gdb/rust-lang.c | 6 ++++++ gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.rust/simple.exp | 1 + gdb/testsuite/gdb.rust/simple.rs | 1 + 5 files changed, 17 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index acd29c3babb..7cec5ad8c23 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2016-07-06 Manish Goregaokar + + * rust-lang.c (rust_subscript): Allow subscripting pointers + 2016-07-05 Jan Kratochvil * configure: Regenerate. diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 1849349f49a..17b20c66aab 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -1415,6 +1415,12 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside, low_bound = 0; high_bound = value_as_long (len); } + else if (TYPE_CODE (type) == TYPE_CODE_PTR) + { + base = lhs; + low_bound = 0; + high_bound = LONGEST_MAX; + } else error (_("Cannot subscript non-array type")); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index be0cf9d2227..6445a10fb41 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-07-06 Manish Goregaokar + + * simple.rs: Add test for raw pointer subscripting + * simple.exp: Add test expectations + 2016-07-05 Yao Qi * gdb.mi/mi-reverse.exp: Match =record-started output. diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp index 4622f75b1d3..32b3785c971 100644 --- a/gdb/testsuite/gdb.rust/simple.exp +++ b/gdb/testsuite/gdb.rust/simple.exp @@ -73,6 +73,7 @@ gdb_test "print w" " = \\\[1, 2, 3, 4\\\]" gdb_test "ptype w" " = \\\[i32; 4\\\]" gdb_test "print w\[2\]" " = 3" gdb_test "print w\[2\] @ 2" " = \\\[3, 4\\\]" +gdb_test "print w_ptr\[2\]" " = 3" gdb_test "print fromslice" " = 3" gdb_test "print slice\[0\]" " = 3" gdb_test "print slice as &\[i32\]\[0\]" " = 3" diff --git a/gdb/testsuite/gdb.rust/simple.rs b/gdb/testsuite/gdb.rust/simple.rs index 3d28e272982..49808261324 100644 --- a/gdb/testsuite/gdb.rust/simple.rs +++ b/gdb/testsuite/gdb.rust/simple.rs @@ -87,6 +87,7 @@ fn main () { let v = Something::Three; let w = [1,2,3,4]; + let w_ptr = &w[0]; let x = (23, 25.5); let y = HiBob {field1: 7, field2: 8}; let z = ByeBob(7, 8); -- 2.30.2