From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 109931 invoked by alias); 31 Oct 2016 03:47:37 -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 109902 invoked by uid 89); 31 Oct 2016 03:47:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy=placement, tom@tromey.com, U*tom, D*tromey.com X-HELO: mail-wm0-f46.google.com Received: from mail-wm0-f46.google.com (HELO mail-wm0-f46.google.com) (74.125.82.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 31 Oct 2016 03:47:25 +0000 Received: by mail-wm0-f46.google.com with SMTP id t79so27241219wmt.0 for ; Sun, 30 Oct 2016 20:47:24 -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=ZK9khdDXMenM0OvF4gZCKDszsjhanBIm1JZZn0GXSu0=; b=Ty9epblXDfRWki6vsA9kZIQ8t6zgh7KdSryJ7nsOVFmGuqCMzHCaX5ga9bOAK2Occq d/+My6XTTVKVAr+cINT8+ZUbrCMVF2vdY6ocm1eFHbXyXQwK4kURXl0BR/cI9zsIocHs VnROQUQzb8Dc0sBQLe54w1F0CPtaiZcmX0y3ShoAKq9RQFBtAH80i0CmcsSZOILBrzGs iRkRtVD3sXQ6qlFhTdAHeU8FQifhSyLY/UM8X2AlJ0YpQX43YDoudlTmoxRTXo8g+Tr7 szTq6v4AK3oqL1aGu2AjoxEL/QMYS9ZJQJMmx2jz5RPb3q1sdZOpoIbQsZsJiF7xD5V9 rjzA== X-Gm-Message-State: ABUngvcfHfWdghzU/x9YYHtUvCqHCiNSyuzQIpFYxFliAQrKhe/fDAsT5kxzKyQyXY8dKFCCTNZivs0leTclCCrc X-Received: by 10.194.205.136 with SMTP id lg8mr20153278wjc.1.1477885643174; Sun, 30 Oct 2016 20:47:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.131.21 with HTTP; Sun, 30 Oct 2016 20:47:02 -0700 (PDT) In-Reply-To: <87oa21urfz.fsf@tromey.com> References: <87pomiwo1z.fsf@tromey.com> <87lgx6wntm.fsf@tromey.com> <87d1iiwlvx.fsf@tromey.com> <874m3tw784.fsf@tromey.com> <87oa21urfz.fsf@tromey.com> From: Manish Goregaokar Date: Mon, 31 Oct 2016 03:47:00 -0000 Message-ID: Subject: Re: [PATCH] Fix handling of discriminantless univariant enums in Rust To: Tom Tromey Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg00856.txt.bz2 Yeah, have gone through the document, but I still miss things :) >From 7a2296aabb423ade3bc6bb675cf97123ba939eb4 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 27 Oct 2016 16:46:34 -0700 Subject: [PATCH 1/3] Fix handling of discriminantless univariant enums in Rust; fix bug with encoded enums 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 * 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 --- gdb/rust-lang.c | 16 +++++++++++++++- gdb/testsuite/gdb.rust/simple.exp | 12 ++++++++++++ gdb/testsuite/gdb.rust/simple.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 82cd3f9..774eed9 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -194,6 +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)); + 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) 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); 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 5e00b03..8e84daa 100644 --- a/gdb/testsuite/gdb.rust/simple.exp +++ b/gdb/testsuite/gdb.rust/simple.exp @@ -103,6 +103,11 @@ gdb_test_sequence "ptype z" "" { } 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" "" { " = struct simple::ByeBob \\(" " i32," @@ -220,3 +225,10 @@ 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\\}" diff --git a/gdb/testsuite/gdb.rust/simple.rs b/gdb/testsuite/gdb.rust/simple.rs index eeff3d7..670f54e 100644 --- a/gdb/testsuite/gdb.rust/simple.rs +++ b/gdb/testsuite/gdb.rust/simple.rs @@ -63,6 +63,23 @@ enum SpaceSaver { Nothing, } +enum Univariant { + Foo {a: u8} +} +enum UnivariantAnon { + Foo(u8) +} + +enum ParametrizedEnum { + Val { val: T }, + Empty, +} + +struct ParametrizedStruct { + next: ParametrizedEnum>>, + value: T +} + fn main () { let a = (); let b : [i32; 0] = []; @@ -93,6 +110,9 @@ fn main () { let y = HiBob {field1: 7, field2: 8}; let z = ByeBob(7, 8); + let univariant = Univariant::Foo {a : 1}; + let univariant_anon = UnivariantAnon::Foo(1); + let slice = &w[2..3]; let fromslice = slice[0]; let slice2 = &slice[0..1]; @@ -117,6 +137,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 Sun, Oct 30, 2016 at 8:29 PM, Tom Tromey wrote: >>>>>> "Manish" == Manish Goregaokar writes: > > Manish> Updated. Not sure what the style issues are, could you point them out? > > Sure. There's also the GNU coding standards document, plus some docs on > the gdb wiki somewhere. > > Manish> } > Manish> + else if (TYPE_NFIELDS (type) == 1) { > > Brace placement. Should line up with that "}" just above. > > Manish> + /* Sometimes univariant enums are encoded without a > Manish> + discriminant. In that case, treating it as an encoded enum > Manish> + with the first field being the actual type works. */ > > Subsequent text in a multi-line comment should line up under the > "Sometimes". > > Period followed by two spaces ends a sentence, so one more space before > "In". > > Manish> + const char* field_name = TYPE_NAME (TYPE_FIELD_TYPE (type, 0)); > Manish> + const char* last = rust_last_path_segment (field_name); > > "char *" > > Manish> + ret.name = concat (TYPE_NAME (type), "::", last, (char *) NULL); > Manish> + ret.field_no = RUST_ENCODED_ENUM_REAL; > Manish> + ret.is_encoded = 1; > Manish> + return ret; > Manish> + } > > This brace and the whole block will be indented a bit more due to the > brace placement issue. > > thanks, > Tom