From patchwork Sun Dec 1 03:48:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 36395 Received: (qmail 90823 invoked by alias); 1 Dec 2019 03:48:49 -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 90746 invoked by uid 89); 1 Dec 2019 03:48:38 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.3 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.1 spammy=HX-HELO:sk:gateway, H*RU:sk:gateway, HX-Spam-Relays-External:sk:gateway, fedora X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.47.125) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 01 Dec 2019 03:48:36 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 752C7681 for ; Sat, 30 Nov 2019 21:48:34 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id bGDqiKVCrOdBHbGDqiVuUU; Sat, 30 Nov 2019 21:48:34 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=o7+LP4bfm6YX8Grlq0yWy+GhoVmwL98jOGevsTTRtBI=; b=etNqVP8B9Bj8480ur77sAcqyCf pCgj5D/dCIqb64OPCsOx24N7da9fRWODjZafTIPa76LYe7kKMiCRmVekvDIpVfle5wG/pGM9asSTF JOv3k7AcTtJNH1leSjN+ODDmV; Received: from 97-118-104-188.hlrn.qwest.net ([97.118.104.188]:34870 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1ibGDq-003tD8-8q; Sat, 30 Nov 2019 20:48:34 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [FYI] Correctly compute length of DW_TAG_variant_part union Date: Sat, 30 Nov 2019 20:48:31 -0700 Message-Id: <20191201034831.20358-1-tom@tromey.com> Currently, gdb internally transforms DW_TAG_variant_part into a union (with some special attbributes). When doing so, it computes the length of this union from the length of the fields. However, this computation didn't include the offset of these fields, resulting in the length being too short. This is not a problem given the way the code currently works. However, I have a patch series to switch gdb to value-based printing, where this does have an impact. Tested on x86-64 Fedora 28; and, considering that this only affects Rust, I am checking it in. gdb/ChangeLog 2019-11-30 Tom Tromey * dwarf2read.c (dwarf2_add_field): Include field offset when computing variant part length. Change-Id: I25d84fc237eb3c1e7f11f6eaf35ffe198efde6cc --- gdb/ChangeLog | 5 +++++ gdb/dwarf2read.c | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 40626a1562f..fd7d21c02e9 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -15252,13 +15252,18 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die, /* Normally a DW_TAG_variant_part won't have a size, but our representation requires one, so set it to the maximum of the - child sizes. */ + child sizes, being sure to account for the offset at which + each child is seen. */ if (TYPE_LENGTH (fp->type) == 0) { unsigned max = 0; for (int i = 0; i < TYPE_NFIELDS (fp->type); ++i) - if (TYPE_LENGTH (TYPE_FIELD_TYPE (fp->type, i)) > max) - max = TYPE_LENGTH (TYPE_FIELD_TYPE (fp->type, i)); + { + unsigned len = ((TYPE_FIELD_BITPOS (fp->type, i) + 7) / 8 + + TYPE_LENGTH (TYPE_FIELD_TYPE (fp->type, i))); + if (len > max) + max = len; + } TYPE_LENGTH (fp->type) = max; } }