From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2066 invoked by alias); 28 Oct 2016 19:57:30 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 2046 invoked by uid 89); 28 Oct 2016 19:57:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=UD:rs, 2223, ptype, gdb.rust X-HELO: mail-wm0-f43.google.com Received: from mail-wm0-f43.google.com (HELO mail-wm0-f43.google.com) (74.125.82.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Oct 2016 19:57:19 +0000 Received: by mail-wm0-f43.google.com with SMTP id p190so33408998wmp.1 for ; Fri, 28 Oct 2016 12:57:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=GvrCXnT5f/dV46OgBVkhymU8JgVcZmD2fv6aHn+1b5Y=; b=bJad1+3rCcTDXG8MpDHPLrlO++mm0s6QF5jBIslBI0Ptr2DUdnmv0a9YN5Dzm/2x2z tc1Msfus/mzZl0VtlDbMqnaR3TpyMD09vxhuoU9weMgblcIOcRXRjANr7lx2UiDvEnFH 0+SaAD3RW7sNBwq4zFvjUcMl/QX30mAXyh1t5gJ4MVdbf361VcR9J8Bw7S9LtZFHMPj6 4n8pXybiHrI96Rce6jgXbUo8+85+NZuXBQpuVhte4pN2S4kUhQ9zaV78IoEsL1j/Rd3v qy4qAXMYI9Bfsu99uvRlSE3ps3FrvEHvLhsLfKJ73vQZuQ81jDmZR7q53eKrSzuzueaR gIdQ== X-Gm-Message-State: ABUngvfVmAQDCaz44QBrK19wgupb/mS0ZKuqMpMI/DDaO2/Cnn2TYO0vk8qbd6IqPR5pG5nO8Y1y86dM2Iv7wn7P X-Received: by 10.28.113.18 with SMTP id m18mr281848wmc.101.1477684637281; Fri, 28 Oct 2016 12:57:17 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.131.21 with HTTP; Fri, 28 Oct 2016 12:56:56 -0700 (PDT) In-Reply-To: References: From: Manish Goregaokar Date: Fri, 28 Oct 2016 19:57:00 -0000 Message-ID: Subject: Re: [PATCH] Fix handling of discriminantless univariant enums in Rust To: gdb-patches@sourceware.org Cc: Tom Tromey Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg00826.txt.bz2 Fixed another enum issue, reported in the same PR: (I'm not sure if this is the correct fix) From: Manish Goregaokar Date: Thu, 27 Oct 2016 16:46:34 -0700 Subject: Handle field access on encoded struct-like enums 2016-10-28 Manish Goregaokar gdb/ChangeLog: * rust-lang.c (rust_evaluate_subexp): Handle field access on encoded struct-like enums gdb/testsuite/ChangeLog: * simple.rs: Add test for encoded struct-like enums * simple.exp: Add test expectations --- gdb/rust-lang.c | 4 +++- gdb/testsuite/gdb.rust/simple.exp | 6 ++++++ gdb/testsuite/gdb.rust/simple.rs | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 9d13353..9569584 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -1736,7 +1736,9 @@ tuple structs, and tuple-like enum variants")); variant_type = TYPE_FIELD_TYPE (type, disr.field_no); 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, \ which has only anonymous fields"), field_name, disr.name); diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp index dbfc88a..075bff7 100644 --- a/gdb/testsuite/gdb.rust/simple.exp +++ b/gdb/testsuite/gdb.rust/simple.exp @@ -222,3 +222,9 @@ gdb_test "print (1,)" "Tuple expressions not supported yet" gdb_test "print (1)" " = 1" gdb_test "print 23..97.0" "Range expression with different types" + +gdb_test "print (*parametrized.next.val)" \ + " = simple::ParametrizedStruct {next: simple::ParametrizedEnum>>::Empty, value: 1}" +gdb_test "print parametrized.next.val" " = \\(simple::ParametrizedStruct \\*\\) $hex" +gdb_test "print parametrized" \ + " = simple::ParametrizedStruct \\{next: simple::ParametrizedEnum>>::Val\\{val: $hex\\}, value: 0\\}" \ No newline at end of file diff --git a/gdb/testsuite/gdb.rust/simple.rs b/gdb/testsuite/gdb.rust/simple.rs index b2e29ae..e756296 100644 --- a/gdb/testsuite/gdb.rust/simple.rs +++ b/gdb/testsuite/gdb.rust/simple.rs @@ -67,6 +67,16 @@ enum Univariant { Foo {a: u8} } +enum ParametrizedEnum { + Val { val: T }, + Empty, +} + +struct ParametrizedStruct { + next: ParametrizedEnum>>, + value: T +} + fn main () { let a = (); let b : [i32; 0] = []; @@ -123,6 +133,16 @@ fn main () { let custom_some = NonZeroOptimized::Value("hi".into()); 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!("{}", diff2(92, 45)); empty(); -- 2.10.1 -Manish On Thu, Oct 27, 2016 at 4:51 PM, Manish Goregaokar wrote: > Fixes an issue caught by TimNN in https://github.com/rust-lang/rust/pull/37410 > > > From: Manish Goregaokar > Date: Thu, 27 Oct 2016 16:46:34 -0700 > Subject: Fix handling of discriminantless univariant enums in Rust > > 2016-10-27 Manish Goregaokar > > gdb/ChangeLog: > * rust-lang.c (rust_get_disr_info): Treat univariant enums > without discriminants as encoded enums with a real field > > gdb/testsuite/ChangeLog: > * simple.rs: Add test for univariant enums without discriminants > * simple.exp: Add test expectations > --- > gdb/rust-lang.c | 13 ++++++++++++- > gdb/testsuite/gdb.rust/simple.exp | 2 ++ > gdb/testsuite/gdb.rust/simple.rs | 6 ++++++ > 3 files changed, 20 insertions(+), 1 deletion(-) > > diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c > index 82cd3f9..9d13353 100644 > --- a/gdb/rust-lang.c > +++ b/gdb/rust-lang.c > @@ -194,7 +194,18 @@ rust_get_disr_info (struct type *type, const > gdb_byte *valaddr, > has changed its debuginfo format. */ > 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)); > + ret.name = concat (TYPE_NAME (type), "::", > + rust_last_path_segment (field_name), > + (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) > error (_("Rust debug format has changed")); > > diff --git a/gdb/testsuite/gdb.rust/simple.exp > b/gdb/testsuite/gdb.rust/simple.exp > index 5e00b03..dbfc88a 100644 > --- a/gdb/testsuite/gdb.rust/simple.exp > +++ b/gdb/testsuite/gdb.rust/simple.exp > @@ -103,6 +103,8 @@ gdb_test_sequence "ptype z" "" { > } > gdb_test "print z.1" " = 8" > > +gdb_test "print univariant" " = simple::Univariant::Foo{a: 1}" > + > gdb_test_sequence "ptype simple::ByeBob" "" { > " = struct simple::ByeBob \\(" > " i32," > diff --git a/gdb/testsuite/gdb.rust/simple.rs b/gdb/testsuite/gdb.rust/simple.rs > index eeff3d7..b2e29ae 100644 > --- a/gdb/testsuite/gdb.rust/simple.rs > +++ b/gdb/testsuite/gdb.rust/simple.rs > @@ -63,6 +63,10 @@ enum SpaceSaver { > Nothing, > } > > +enum Univariant { > + Foo {a: u8} > +} > + > fn main () { > let a = (); > let b : [i32; 0] = []; > @@ -93,6 +97,8 @@ fn main () { > let y = HiBob {field1: 7, field2: 8}; > let z = ByeBob(7, 8); > > + let univariant = Univariant::Foo {a : 1}; > + > let slice = &w[2..3]; > let fromslice = slice[0]; > let slice2 = &slice[0..1]; > -- > 2.10.1