From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id WAu7BLiRiWG5MAAAWB0awg (envelope-from ) for ; Mon, 08 Nov 2021 16:08:08 -0500 Received: by simark.ca (Postfix, from userid 112) id 0F85F1F0C1; Mon, 8 Nov 2021 16:08:07 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 5C3E61E813 for ; Mon, 8 Nov 2021 16:08:07 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F18003858417 for ; Mon, 8 Nov 2021 21:08:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F18003858417 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1636405687; bh=Hsd+fIRsCNkisghMgUJUg5GqlnkQplol10CP1SEf3BA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=iYj/JCElELw10K/XGhsyOa9koibYPTKfZBEM/J0lvEYYrIHMhaawwArUpLxkrZUsa RoVEqMLnpiSJMgB+LpAJkjCx4dFfcW+K2UwhXeb3Y/YePcGNmt1faDqWhJKAMonuQ9 AhCEfJeYTEKioJPZryMAmgoNpLVFS1lJ/Cs4PB28= Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 447E73858428 for ; Mon, 8 Nov 2021 21:06:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 447E73858428 X-ASG-Debug-ID: 1636405570-0c856e0387959ce0001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id aA8ZdRVaoJ4mx4iW (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 08 Nov 2021 16:06:10 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from epycamd.internal.efficios.com (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtp.ebox.ca (Postfix) with ESMTP id 660CC441D65; Mon, 8 Nov 2021 16:06:10 -0500 (EST) X-Barracuda-RBL-IP: 192.222.180.24 X-Barracuda-Effective-Source-IP: 192-222-180-24.qc.cable.ebox.net[192.222.180.24] X-Barracuda-Apparent-Source-IP: 192.222.180.24 To: gdb-patches@sourceware.org Subject: [PATCH 1/4] gdb: fix length of array view returned by some value_contents functions Date: Mon, 8 Nov 2021 16:06:06 -0500 X-ASG-Orig-Subj: [PATCH 1/4] gdb: fix length of array view returned by some value_contents functions Message-Id: <20211108210609.353208-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1636405570 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 2202 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.93830 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" From: Simon Marchi In commit 50888e42dcd3 ("gdb: change functions returning value contents to use gdb::array_view"), I believe I made a mistake with the length of the array views returned by some functions. All functions return a view of `TYPE_LENGTH (value_type (type))` length. This is not correct when the value's enclosing type is larger than the value's type. In that case, the value's contents buffer is of the size of the enclosing type, and the value's actual contents is a slice of that (as returned by value_contents). So, functions value_contents_all_raw, value_contents_for_printing and value_contents_for_printing_const are not correct. Since they are meant to return the value's contents buffer as a whole, they should have the size of the enclosing type. There is nothing that uses the returned array view size at the moment, so this didn't cause a problem. But it became apparent when trying to adjust some callers. Change-Id: Ib4e8837e1069111d2b2784d3253d5f3002419e68 --- gdb/value.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gdb/value.c b/gdb/value.c index 998bec321a2..8669ad8fe70 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1164,7 +1164,7 @@ value_contents_all_raw (struct value *value) { allocate_value_contents (value); - ULONGEST length = TYPE_LENGTH (value_type (value)); + ULONGEST length = TYPE_LENGTH (value_enclosing_type (value)); return gdb::make_array_view (value->contents.get (), length); } @@ -1249,7 +1249,7 @@ value_contents_for_printing (struct value *value) if (value->lazy) value_fetch_lazy (value); - ULONGEST length = TYPE_LENGTH (value_type (value)); + ULONGEST length = TYPE_LENGTH (value_enclosing_type (value)); return gdb::make_array_view (value->contents.get (), length); } @@ -1258,7 +1258,7 @@ value_contents_for_printing_const (const struct value *value) { gdb_assert (!value->lazy); - ULONGEST length = TYPE_LENGTH (value_type (value)); + ULONGEST length = TYPE_LENGTH (value_enclosing_type (value)); return gdb::make_array_view (value->contents.get (), length); } -- 2.33.0