summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.rust
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-10-02 13:55:42 -0600
committerTom Tromey <tom@tromey.com>2017-10-02 14:06:48 -0600
commit45320ffa0450b27e232d933d2a1c6a09d94ac18b (patch)
tree82e528f5a61c63c6b01d67694039d754c7fad440 /gdb/testsuite/gdb.rust
parentb3e3859bc577db5b79bb3d39048fd46c0a0420ef (diff)
downloadbinutils-gdb-45320ffa0450b27e232d933d2a1c6a09d94ac18b.tar.gz
Fix &str printing in Rust
Printing a string slice ("&str") in Rust would print until the terminating \0; but that is incorrect because a slice has a length. This fixes &str printing, and arranges to preserve the type name when slicing a slice, so that printing a slice of an "&str" works as well. This is PR rust/22236. 2017-10-02 Tom Tromey <tom@tromey.com> PR rust/22236: * rust-lang.c (rust_val_print_str): New function. (val_print_struct): Call it. (rust_subscript): Preserve name of slice type. 2017-10-02 Tom Tromey <tom@tromey.com> PR rust/22236: * gdb.rust/simple.rs (main): New variable "fslice". * gdb.rust/simple.exp: Add slice tests. Update string tests.
Diffstat (limited to 'gdb/testsuite/gdb.rust')
-rw-r--r--gdb/testsuite/gdb.rust/simple.exp12
-rw-r--r--gdb/testsuite/gdb.rust/simple.rs2
2 files changed, 8 insertions, 6 deletions
diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp
index b01841f1e02..90516b96df6 100644
--- a/gdb/testsuite/gdb.rust/simple.exp
+++ b/gdb/testsuite/gdb.rust/simple.exp
@@ -64,6 +64,10 @@ gdb_test "ptype j2" " = struct simple::Unit"
gdb_test "print simple::Unit" " = simple::Unit"
gdb_test "print simple::Unit{}" " = simple::Unit"
+gdb_test "print f" " = \"hi bob\""
+gdb_test "print fslice" " = \"bob\""
+gdb_test "print &f\[3..\]" " = \"bob\""
+
gdb_test "print g" " = \\(u8 \\(\\*\\)\\\[6\\\]\\) $hex b\"hi bob\""
gdb_test "ptype g" " = u8 \\(\\*\\)\\\[6\\\]"
@@ -200,13 +204,9 @@ gdb_test "ptype empty" "fn \\(\\)"
gdb_test "print (diff2 as fn(i32, i32) -> i32)(19, -2)" " = 21"
-# We need the ".*" because currently we don't extract the length and
-# use it to intelligently print the string data.
-gdb_test "print \"hello rust\"" \
- " = &str \\{data_ptr: $hex \"hello rust.*\", length: 10\\}"
+gdb_test "print \"hello rust\"" " = \"hello rust.*\""
gdb_test "print \"hello" "Unexpected EOF in string"
-gdb_test "print r##\"hello \" rust\"##" \
- " = &str \\{data_ptr: $hex \"hello \\\\\" rust.*\", length: 12\\}"
+gdb_test "print r##\"hello \" rust\"##" " = \"hello \\\\\" rust.*\""
gdb_test "print r\"hello" "Unexpected EOF in string"
gdb_test "print r###\"###hello\"" "Unexpected EOF in string"
gdb_test "print r###\"###hello\"##" "Unexpected EOF in string"
diff --git a/gdb/testsuite/gdb.rust/simple.rs b/gdb/testsuite/gdb.rust/simple.rs
index 9c154e7c491..d6d1755e4d5 100644
--- a/gdb/testsuite/gdb.rust/simple.rs
+++ b/gdb/testsuite/gdb.rust/simple.rs
@@ -95,6 +95,8 @@ fn main () {
let g = b"hi bob";
let h = b'9';
+ let fslice = &f[3..];
+
let i = ["whatever"; 8];
let j = Unit;