rust/25535 Apply embedded offset to enum variant calculation
authorDoug Evans <dje@google.com>
Wed, 19 Feb 2020 20:54:59 +0000 (13:54 -0700)
committerTom Tromey <tromey@adacore.com>
Wed, 19 Feb 2020 20:59:31 +0000 (13:59 -0700)
Hopefully straightforward (and I didn't miss anything ...).

gdb/ChangeLog
2020-02-19  Doug Evans  <dje@google.com>

PR rust/25535
* rust-lang.c (rust_print_enum): Apply embedded_offset to
rust_enum_variant calculation.

gdb/testsuite/ChangeLog
2020-02-19  Doug Evans  <dje@google.com>

PR rust/25535
* gdb.rust/simple.exp: Add test.
* gdb.rust/simple.rs: Add test.

gdb/ChangeLog
gdb/rust-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.rust/simple.exp
gdb/testsuite/gdb.rust/simple.rs

index 3fdebc9b153bac4d60e39ddf810687f4dda6f56f..6d3027234af0490c555261722703cbc5612d2e07 100644 (file)
@@ -1,3 +1,9 @@
+2020-02-19  Doug Evans  <dje@google.com>
+
+       PR rust/25535
+       * rust-lang.c (rust_print_enum): Apply embedded_offset to
+       rust_enum_variant calculation.
+
 2020-02-19  Tom Tromey  <tromey@adacore.com>
 
        * mips-tdep.h (mips_pc_is_mips): Parameter type is CORE_ADDR.
index 9123bf2146d516dabb72f9d9caff728dced98ef0..18dc6a56471378387d2d299d3c7960a6a791c310 100644 (file)
@@ -481,7 +481,8 @@ rust_print_enum (struct type *type, int embedded_offset,
     }
 
   const gdb_byte *valaddr = value_contents_for_printing (val);
-  struct field *variant_field = rust_enum_variant (type, valaddr);
+  struct field *variant_field = rust_enum_variant (type,
+                                                  valaddr + embedded_offset);
   embedded_offset += FIELD_BITPOS (*variant_field) / 8;
   struct type *variant_type = FIELD_TYPE (*variant_field);
 
index e599791f58aa51730fb4fdd89e880a99a605b566..0dff20d38357e2fdba80eb695d4486dde185462a 100644 (file)
@@ -1,3 +1,9 @@
+2020-02-19  Doug Evans  <dje@google.com>
+
+       PR rust/25535
+       * gdb.rust/simple.exp: Add test.
+       * gdb.rust/simple.rs: Add test.
+
 2020-02-19  Tom de Vries  <tdevries@suse.de>
 
        * gdb.base/corefile-buildid.exp (check_exec_file): Match info files
index aa64e6b08f1c79f0e1a46e919f1b04d9a60f80c1..b4fcf274261d6dd4b09b85a498b3eecfbd711550 100644 (file)
@@ -357,6 +357,8 @@ gdb_test_sequence "ptype/o SimpleLayout" "" {
 
 gdb_test "print u2" " = simple::Union2 {name: \\\[1\\\]}"
 
+gdb_test "print nonzero_offset" " = simple::EnumWithNonzeroOffset {a: core::option::Option<u8>::Some\\(1\\), b: core::option::Option<u8>::None}"
+
 # PR rust/23626 - this used to crash.  Note that the results are
 # fairly lax because most existing versions of Rust (those before the
 # DW_TAG_variant patches) do not emit what gdb wants here; and there
index 1280e04449bae478c916e4beb9361473bb89de05..36448ec45c6e7a76ce97bb10053707d8aabaf8f4 100644 (file)
@@ -104,6 +104,12 @@ struct SimpleLayout {
 
 enum EmptyEnum {}
 
+#[derive(Debug)]
+struct EnumWithNonzeroOffset {
+    a: Option<u8>,
+    b: Option<u8>,
+}
+
 fn main () {
     let a = ();
     let b : [i32; 0] = [];
@@ -186,6 +192,8 @@ fn main () {
 
     let u2 = Union2 { name: [1] };
 
+    let nonzero_offset = EnumWithNonzeroOffset { a: Some(1), b: None };
+
     println!("{}, {}", x.0, x.1);        // set breakpoint here
     println!("{}", diff2(92, 45));
     empty();
This page took 0.035671 seconds and 4 git commands to generate.