From patchwork Wed Feb 12 01:01:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Terekhov, Mikhail via Gdb-patches" X-Patchwork-Id: 37985 Received: (qmail 38157 invoked by alias); 12 Feb 2020 01:01:48 -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 38148 invoked by uid 89); 12 Feb 2020 01:01:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=UD:rs, H*M:google X-HELO: mail-pf1-f201.google.com Received: from mail-pf1-f201.google.com (HELO mail-pf1-f201.google.com) (209.85.210.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 12 Feb 2020 01:01:43 +0000 Received: by mail-pf1-f201.google.com with SMTP id q1so362348pfg.2 for ; Tue, 11 Feb 2020 17:01:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:message-id:date:subject:from:to:cc; bh=6slzlIUSGjzV+98SrdfBRIEongxlD1sSM4InA72MuJ0=; b=DTyFIFzyXx3KEdlMaXGoLVz3+Odgm++IfE2Z1FukGq93pwSQ1Wpu8LFTk29Yb+q0Xn L48/1qGSecA86nw9anW8tPuyHzD7K5EbkhdL/DSTtjJwO8KzFjjaKrwUzRuh9j/HJP1s u1vPNRwZ7+lobh6y1wOTPScCyem20pRmt67sPKKLV0gu6mvHb4uAloWJAnQmKWvTN8Cw eAVsQaGanMUxlGOD3mvgT9xYfXzNSDswy86wzcLaZl5Q/fMSXnj/zvqxlTK4y7K7VEDr EftCQN+irI+NGaarruMGQIRnfpE7IqpoSKfsZl0Gfbu0YRP9IVSG36H0OFjufTS2m5JJ Iggg== MIME-Version: 1.0 Message-ID: <000000000000fb79ae059e568398@google.com> Date: Wed, 12 Feb 2020 01:01:42 +0000 Subject: [PATCH] rust/25535 Apply embedded offset to enum variant calculation X-Patchwork-Original-From: "Doug Evans via gdb-patches" From: "Terekhov, Mikhail via Gdb-patches" Reply-To: Doug Evans To: gdb-patches@sourceware.org Cc: ibobyr@google.com X-IsSubscribed: yes Hopefully straightforward (and I didn't miss anything ...). gdb/ChangeLog PR rust/25535 * rust-lang.c (rust_print_enum): Apply embedded_offset to rust_enum_variant calculation. gdb/testsuite/ChangeLog PR rust/25535 * gdb.rust/simple.exp: Add test. * gdb.rust/simple.rs: Add test. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 91d7cec98af..1d8af99d8d6 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2020-02-11 Doug Evans + + PR rust/25535 + * rust-lang.c (rust_print_enum): Apply embedded_offset to + rust_enum_variant calculation. + 2020-02-11 Christian Biesinger * cris-tdep.c (cris_supply_gregset): Change signature to match diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 9123bf2146d..18dc6a56471 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -481,7 +481,8 @@ rust_print_enum (struct type *type, int embedded_offset, } const gdb_byte *valaddr = value_contents_for_printing (val); - struct field *variant_field = rust_enum_variant (type, valaddr); + struct field *variant_field = rust_enum_variant (type, + valaddr + embedded_offset); embedded_offset += FIELD_BITPOS (*variant_field) / 8; struct type *variant_type = FIELD_TYPE (*variant_field); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 06826746d5f..a613c1e6565 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2020-02-11 Doug Evans + + PR rust/25535 + * gdb.rust/simple.exp: Add test. + * gdb.rust/simple.rs: Add test. + 2020-02-11 Sergio Durigan Junior PR tui/25126 diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp index aa64e6b08f1..b4fcf274261 100644 --- a/gdb/testsuite/gdb.rust/simple.exp +++ b/gdb/testsuite/gdb.rust/simple.exp @@ -357,6 +357,8 @@ gdb_test_sequence "ptype/o SimpleLayout" "" { gdb_test "print u2" " = simple::Union2 {name: \\\[1\\\]}" +gdb_test "print nonzero_offset" " = simple::EnumWithNonzeroOffset {a: core::option::Option::Some\\(1\\), b: core::option::Option::None}" + # PR rust/23626 - this used to crash. Note that the results are # fairly lax because most existing versions of Rust (those before the # DW_TAG_variant patches) do not emit what gdb wants here; and there diff --git a/gdb/testsuite/gdb.rust/simple.rs b/gdb/testsuite/gdb.rust/simple.rs index 1280e04449b..36448ec45c6 100644 --- a/gdb/testsuite/gdb.rust/simple.rs +++ b/gdb/testsuite/gdb.rust/simple.rs @@ -104,6 +104,12 @@ struct SimpleLayout { enum EmptyEnum {} +#[derive(Debug)] +struct EnumWithNonzeroOffset { + a: Option, + b: Option, +} + fn main () { let a = (); let b : [i32; 0] = []; @@ -186,6 +192,8 @@ fn main () { let u2 = Union2 { name: [1] }; + let nonzero_offset = EnumWithNonzeroOffset { a: Some(1), b: None }; + println!("{}, {}", x.0, x.1); // set breakpoint here println!("{}", diff2(92, 45)); empty();