From patchwork Thu Mar 29 17:51:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26510 Received: (qmail 13573 invoked by alias); 29 Mar 2018 17:51:41 -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 11193 invoked by uid 89); 29 Mar 2018 17:51:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=UD:gdb.ada, gdb.ada, gdbada, UD:ada X-HELO: gateway33.websitewelcome.com Received: from gateway33.websitewelcome.com (HELO gateway33.websitewelcome.com) (192.185.146.97) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Mar 2018 17:51:33 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway33.websitewelcome.com (Postfix) with ESMTP id BC08AECAEF for ; Thu, 29 Mar 2018 12:51:31 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 1bhzfKfN8A3CS1bhzfV8PK; Thu, 29 Mar 2018 12:51:31 -0500 Received: from 174-29-48-109.hlrn.qwest.net ([174.29.48.109]:44698 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1f1bhz-000ETG-HA; Thu, 29 Mar 2018 12:51:31 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Fix crash in quirk_rust_enum Date: Thu, 29 Mar 2018 11:51:26 -0600 Message-Id: <20180329175126.30863-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1f1bhz-000ETG-HA X-Source-Sender: 174-29-48-109.hlrn.qwest.net (pokyo.Home) [174.29.48.109]:44698 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes I noticed that quirk_rust_enum can crash when presented with a union whose fields are all scalar types. This patch adds a new test case and fixes the bug. Regression tested on Fedora 26 x86-64. 2018-03-29 Tom Tromey * dwarf2read.c (quirk_rust_enum): Handle unions correctly. 2018-03-29 Tom Tromey * gdb.rust/simple.rs (Union): New type. (main): New local "u". * gdb.rust/simple.exp (test_one_slice): Add new test case. --- gdb/ChangeLog | 4 ++++ gdb/dwarf2read.c | 8 +++++++- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.rust/simple.exp | 1 + gdb/testsuite/gdb.rust/simple.rs | 7 +++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 78f427fb7e..45e4a6f444 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2018-03-29 Tom Tromey + + * dwarf2read.c (quirk_rust_enum): Handle unions correctly. + 2018-03-27 Tom Tromey * utils.c (prompt_for_continue): Use unique_xmalloc_ptr. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index dfa69d1dbb..772d994737 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -10078,9 +10078,15 @@ quirk_rust_enum (struct type *type, struct objfile *objfile) { disr_type = TYPE_FIELD_TYPE (type, i); - if (TYPE_NFIELDS (disr_type) == 0) + if (TYPE_CODE (disr_type) != TYPE_CODE_STRUCT) + { + /* All fields of a true enum will be structs. */ + return; + } + else if (TYPE_NFIELDS (disr_type) == 0) { /* Could be data-less variant, so keep going. */ + disr_type = nullptr; } else if (strcmp (TYPE_FIELD_NAME (disr_type, 0), "RUST$ENUM$DISR") != 0) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 806744dd45..3e762472ab 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-03-29 Tom Tromey + + * gdb.rust/simple.rs (Union): New type. + (main): New local "u". + * gdb.rust/simple.exp (test_one_slice): Add new test case. + 2018-03-27 Joel Brobecker * gdb.ada/varsize_limit: New testcase. diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp index 2db596b932..09179575b1 100644 --- a/gdb/testsuite/gdb.rust/simple.exp +++ b/gdb/testsuite/gdb.rust/simple.exp @@ -274,6 +274,7 @@ gdb_test "print parametrized.next.val" \ gdb_test "print parametrized" \ " = simple::ParametrizedStruct \\{next: simple::ParametrizedEnum<\[a-z:\]*Box>>::Val\\{val: $hex\\}, value: 0\\}" +gdb_test "print u" " = simple::Union {f1: -1, f2: 255}" load_lib gdb-python.exp if {[skip_python_tests]} { diff --git a/gdb/testsuite/gdb.rust/simple.rs b/gdb/testsuite/gdb.rust/simple.rs index b2b5dfe0f6..e5bbe52122 100644 --- a/gdb/testsuite/gdb.rust/simple.rs +++ b/gdb/testsuite/gdb.rust/simple.rs @@ -80,6 +80,11 @@ struct ParametrizedStruct { value: T } +union Union { + f1: i8, + f2: u8, +} + fn main () { let a = (); let b : [i32; 0] = []; @@ -153,6 +158,8 @@ fn main () { value: 0, }; + let u = Union { f2: 255 }; + println!("{}, {}", x.0, x.1); // set breakpoint here println!("{}", diff2(92, 45)); empty();