Fix handling of discriminantless univariant enums in Rust; fix bug with encoded enums
2016-10-27 Manish Goregaokar <manish@mozilla.com> gdb/ChangeLog: * rust-lang.c (rust_get_disr_info): Treat univariant enums without discriminants as encoded enums with a real field * rust-lang.c (rust_evaluate_subexp): Handle field access on encoded struct-like enums gdb/testsuite/ChangeLog: * simple.rs: Add test for univariant enums without discriminants and for encoded struct-like enums * simple.exp: Add test expectations
This commit is contained in:
parent
98d0e90cca
commit
51a789c3bf
|
@ -1,3 +1,11 @@
|
||||||
|
|
||||||
|
2016-10-27 Manish Goregaokar <manish@mozilla.com>
|
||||||
|
|
||||||
|
* rust-lang.c (rust_get_disr_info): Treat univariant enums
|
||||||
|
without discriminants as encoded enums with a real field
|
||||||
|
* rust-lang.c (rust_evaluate_subexp): Handle field access
|
||||||
|
on encoded struct-like enums
|
||||||
|
|
||||||
2016-11-03 Yao Qi <yao.qi@linaro.org>
|
2016-11-03 Yao Qi <yao.qi@linaro.org>
|
||||||
|
|
||||||
* Makefile.in (.y.c): Replace YY_NULL with YY_NULLPTR.
|
* Makefile.in (.y.c): Replace YY_NULL with YY_NULLPTR.
|
||||||
|
|
|
@ -194,6 +194,18 @@ rust_get_disr_info (struct type *type, const gdb_byte *valaddr,
|
||||||
has changed its debuginfo format. */
|
has changed its debuginfo format. */
|
||||||
error (_("Could not find enum discriminant field"));
|
error (_("Could not find enum discriminant field"));
|
||||||
}
|
}
|
||||||
|
else if (TYPE_NFIELDS (type) == 1)
|
||||||
|
{
|
||||||
|
/* Sometimes univariant enums are encoded without a
|
||||||
|
discriminant. In that case, treating it as an encoded enum
|
||||||
|
with the first field being the actual type works. */
|
||||||
|
const char *field_name = TYPE_NAME (TYPE_FIELD_TYPE (type, 0));
|
||||||
|
const char *last = rust_last_path_segment (field_name);
|
||||||
|
ret.name = concat (TYPE_NAME (type), "::", last, (char *) NULL);
|
||||||
|
ret.field_no = RUST_ENCODED_ENUM_REAL;
|
||||||
|
ret.is_encoded = 1;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp (TYPE_FIELD_NAME (disr_type, 0), "RUST$ENUM$DISR") != 0)
|
if (strcmp (TYPE_FIELD_NAME (disr_type, 0), "RUST$ENUM$DISR") != 0)
|
||||||
error (_("Rust debug format has changed"));
|
error (_("Rust debug format has changed"));
|
||||||
|
@ -1725,7 +1737,9 @@ tuple structs, and tuple-like enum variants"));
|
||||||
variant_type = TYPE_FIELD_TYPE (type, disr.field_no);
|
variant_type = TYPE_FIELD_TYPE (type, disr.field_no);
|
||||||
|
|
||||||
if (variant_type == NULL
|
if (variant_type == NULL
|
||||||
|| rust_tuple_variant_type_p (variant_type))
|
|| (disr.is_encoded
|
||||||
|
? rust_tuple_struct_type_p (variant_type)
|
||||||
|
: rust_tuple_variant_type_p (variant_type)))
|
||||||
error(_("Attempting to access named field %s of tuple variant %s, \
|
error(_("Attempting to access named field %s of tuple variant %s, \
|
||||||
which has only anonymous fields"),
|
which has only anonymous fields"),
|
||||||
field_name, disr.name);
|
field_name, disr.name);
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
2016-10-27 Manish Goregaokar <manish@mozilla.com>
|
||||||
|
|
||||||
|
* gdb.rust/simple.rs: Add test for univariant enums without discriminants
|
||||||
|
and for encoded struct-like enums
|
||||||
|
|
||||||
2016-10-28 Pedro Alves <palves@redhat.com>
|
2016-10-28 Pedro Alves <palves@redhat.com>
|
||||||
|
|
||||||
* gdb.base/maint.exp <maint info line-table w/o a file name>: Use
|
* gdb.base/maint.exp <maint info line-table w/o a file name>: Use
|
||||||
|
|
|
@ -103,6 +103,11 @@ gdb_test_sequence "ptype z" "" {
|
||||||
}
|
}
|
||||||
gdb_test "print z.1" " = 8"
|
gdb_test "print z.1" " = 8"
|
||||||
|
|
||||||
|
gdb_test "print univariant" " = simple::Univariant::Foo{a: 1}"
|
||||||
|
gdb_test "print univariant.a" " = 1"
|
||||||
|
gdb_test "print univariant_anon" " = simple::UnivariantAnon::Foo\\(1\\)"
|
||||||
|
gdb_test "print univariant_anon.0" " = 1"
|
||||||
|
|
||||||
gdb_test_sequence "ptype simple::ByeBob" "" {
|
gdb_test_sequence "ptype simple::ByeBob" "" {
|
||||||
" = struct simple::ByeBob \\("
|
" = struct simple::ByeBob \\("
|
||||||
" i32,"
|
" i32,"
|
||||||
|
@ -220,3 +225,10 @@ gdb_test "print (1,)" "Tuple expressions not supported yet"
|
||||||
gdb_test "print (1)" " = 1"
|
gdb_test "print (1)" " = 1"
|
||||||
|
|
||||||
gdb_test "print 23..97.0" "Range expression with different types"
|
gdb_test "print 23..97.0" "Range expression with different types"
|
||||||
|
|
||||||
|
gdb_test "print (*parametrized.next.val)" \
|
||||||
|
" = simple::ParametrizedStruct<i32> {next: simple::ParametrizedEnum<Box<simple::ParametrizedStruct<i32>>>::Empty, value: 1}"
|
||||||
|
gdb_test "print parametrized.next.val" \
|
||||||
|
" = \\(simple::ParametrizedStruct<i32> \\*\\) $hex"
|
||||||
|
gdb_test "print parametrized" \
|
||||||
|
" = simple::ParametrizedStruct<i32> \\{next: simple::ParametrizedEnum<Box<simple::ParametrizedStruct<i32>>>::Val\\{val: $hex\\}, value: 0\\}"
|
||||||
|
|
|
@ -63,6 +63,23 @@ enum SpaceSaver {
|
||||||
Nothing,
|
Nothing,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Univariant {
|
||||||
|
Foo {a: u8}
|
||||||
|
}
|
||||||
|
enum UnivariantAnon {
|
||||||
|
Foo(u8)
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ParametrizedEnum<T> {
|
||||||
|
Val { val: T },
|
||||||
|
Empty,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ParametrizedStruct<T> {
|
||||||
|
next: ParametrizedEnum<Box<ParametrizedStruct<T>>>,
|
||||||
|
value: T
|
||||||
|
}
|
||||||
|
|
||||||
fn main () {
|
fn main () {
|
||||||
let a = ();
|
let a = ();
|
||||||
let b : [i32; 0] = [];
|
let b : [i32; 0] = [];
|
||||||
|
@ -93,6 +110,9 @@ fn main () {
|
||||||
let y = HiBob {field1: 7, field2: 8};
|
let y = HiBob {field1: 7, field2: 8};
|
||||||
let z = ByeBob(7, 8);
|
let z = ByeBob(7, 8);
|
||||||
|
|
||||||
|
let univariant = Univariant::Foo {a : 1};
|
||||||
|
let univariant_anon = UnivariantAnon::Foo(1);
|
||||||
|
|
||||||
let slice = &w[2..3];
|
let slice = &w[2..3];
|
||||||
let fromslice = slice[0];
|
let fromslice = slice[0];
|
||||||
let slice2 = &slice[0..1];
|
let slice2 = &slice[0..1];
|
||||||
|
@ -117,6 +137,16 @@ fn main () {
|
||||||
let custom_some = NonZeroOptimized::Value("hi".into());
|
let custom_some = NonZeroOptimized::Value("hi".into());
|
||||||
let custom_none = NonZeroOptimized::Empty;
|
let custom_none = NonZeroOptimized::Empty;
|
||||||
|
|
||||||
|
let parametrized = ParametrizedStruct {
|
||||||
|
next: ParametrizedEnum::Val {
|
||||||
|
val: Box::new(ParametrizedStruct {
|
||||||
|
next: ParametrizedEnum::Empty,
|
||||||
|
value: 1,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
value: 0,
|
||||||
|
};
|
||||||
|
|
||||||
println!("{}, {}", x.0, x.1); // set breakpoint here
|
println!("{}, {}", x.0, x.1); // set breakpoint here
|
||||||
println!("{}", diff2(92, 45));
|
println!("{}", diff2(92, 45));
|
||||||
empty();
|
empty();
|
||||||
|
|
Loading…
Reference in New Issue