From patchwork Thu Oct 27 23:51:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Goregaokar X-Patchwork-Id: 16875 Received: (qmail 117314 invoked by alias); 27 Oct 2016 23:52:15 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 117304 invoked by uid 89); 27 Oct 2016 23:52:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=enums, z1, UD:rs, 1038 X-HELO: mail-wm0-f45.google.com Received: from mail-wm0-f45.google.com (HELO mail-wm0-f45.google.com) (74.125.82.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Oct 2016 23:52:05 +0000 Received: by mail-wm0-f45.google.com with SMTP id b80so64544677wme.1 for ; Thu, 27 Oct 2016 16:52:04 -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:from:date:message-id:subject:to:cc; bh=6gcbTgs2zfnkbMYehO8qbyUgIkSR40oJ/2GcXgKL1kw=; b=RGPngqhPFelt8JmbPWZCO2T22GaHxjPlfeHdcv9xavEvngfSWlqnVRC/4b+1qWrmVO bfDu40aQLhQytUaNW7XtgXZzYt+1+dPAQ7egT5Cy+fU6Y+e4zoRwmRUO4hVpKpTVIfYQ kQOCqStsf8hmQMrcPTUGupjTA1F2GZmEoAXpX+sN0osGhinseWGG+r/EePNUsGQgQ+4a tRPz/LlFdzpLPlfMjLquI09LzohRRukvr2u5ZLPu01/QezEGLuekLuIr9axGyV7e1Yvu wwhZbWz/lyGpUMF8bzuoM8mZYccvY2sllpcdTcaAI0d9CzsZABqhCoPYTExQukB5WoLD cY5w== X-Gm-Message-State: ABUngvev60/z5baChWYReREXDXJPaILGRNZsOLcsVl0QzDq/HpyeavXSMLHn4W66RHPjcaMFfB0RX4xbDSAZu5P5 X-Received: by 10.194.157.169 with SMTP id wn9mr8736798wjb.195.1477612322782; Thu, 27 Oct 2016 16:52:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.131.21 with HTTP; Thu, 27 Oct 2016 16:51:42 -0700 (PDT) From: Manish Goregaokar Date: Thu, 27 Oct 2016 16:51:42 -0700 Message-ID: Subject: [PATCH] Fix handling of discriminantless univariant enums in Rust To: gdb-patches@sourceware.org Cc: Tom Tromey X-IsSubscribed: yes 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];