aboutsummaryrefslogtreecommitdiff
path: root/gdb/rust-lang.c
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/rust-lang.c
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/rust-lang.c')
-rw-r--r--gdb/rust-lang.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 2fada46..79f1331 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -378,6 +378,14 @@ val_print_struct (struct type *type, int embedded_offset,
if (rust_slice_type_p (type) && strcmp (TYPE_NAME (type), "&str") == 0)
{
+ /* If what we are printing here is actually a string within a
+ structure then VAL will be the original parent value, while TYPE
+ will be the type of the structure representing the string we want
+ to print.
+ However, RUST_VAL_PRINT_STR looks up the fields of the string
+ inside VAL, assuming that VAL is the string.
+ So, recreate VAL as a value representing just the string. */
+ val = value_at_lazy (type, value_address (val) + embedded_offset);
rust_val_print_str (stream, val, options);
return;
}