aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.rust
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2019-05-02 00:40:01 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2019-05-02 22:10:17 +0100
commit80062eb94959467fb0c27b988b87ac08dada4bd8 (patch)
treef52adf9f7d8ac622a03731195615afa7537661ae /gdb/testsuite/gdb.rust
parent06f74c5cb868cfd37af3e680d29784c217700bdf (diff)
downloadgdb-80062eb94959467fb0c27b988b87ac08dada4bd8.zip
gdb-80062eb94959467fb0c27b988b87ac08dada4bd8.tar.gz
gdb-80062eb94959467fb0c27b988b87ac08dada4bd8.tar.bz2
gdb/rust: Handle printing structures containing strings
When printing a rust structure that contains a string GDB can currently fail to read the fields that define the string. This is because GDB mistakenly treats a value that is the parent structure as though it is the structure that defines the string, and then fails to find the fields needed to extract a string. The solution is to create a new value to represent the string field of the parent value. gdb/ChangeLog: * rust-lang.c (val_print_struct): Handle printing structures containing strings. gdb/testsuite/ChangeLog: * gdb.rust/simple.exp: Add new test case. * gdb.rust/simple.rs (struct StringAtOffset): New struct. (main): Initialise an instance of the new struct.
Diffstat (limited to 'gdb/testsuite/gdb.rust')
-rw-r--r--gdb/testsuite/gdb.rust/simple.exp3
-rw-r--r--gdb/testsuite/gdb.rust/simple.rs8
2 files changed, 11 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp
index 91afe85..7211bd2 100644
--- a/gdb/testsuite/gdb.rust/simple.exp
+++ b/gdb/testsuite/gdb.rust/simple.exp
@@ -239,6 +239,9 @@ gdb_test "print custom_some" \
" = simple::NonZeroOptimized::Value\\(\[a-z\]+::string::String .*"
gdb_test "print custom_none" " = simple::NonZeroOptimized::Empty"
+gdb_test "print st" \
+ " = simple::StringAtOffset {field1: \"hello\", field2: 1, field3: \"world\"}"
+
proc test_one_slice {svar length base range} {
global hex
diff --git a/gdb/testsuite/gdb.rust/simple.rs b/gdb/testsuite/gdb.rust/simple.rs
index 19f5ef9..e6e0efd 100644
--- a/gdb/testsuite/gdb.rust/simple.rs
+++ b/gdb/testsuite/gdb.rust/simple.rs
@@ -85,6 +85,12 @@ union Union {
f2: u8,
}
+struct StringAtOffset {
+ pub field1: &'static str,
+ pub field2: i32,
+ pub field3: &'static str,
+}
+
// A simple structure whose layout won't be changed by the compiler,
// so that ptype/o testing will work on any platform.
struct SimpleLayout {
@@ -146,6 +152,8 @@ fn main () {
let to1 = &w[..3];
let to2 = &slice[..1];
+ let st = StringAtOffset { field1: "hello", field2: 1, field3: "world" };
+
// tests for enum optimizations
let str_some = Some("hi".to_string());