From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id /A1zGpOSiWFqMQAAWB0awg (envelope-from ) for ; Mon, 08 Nov 2021 16:11:47 -0500 Received: by simark.ca (Postfix, from userid 112) id 58C591F0C1; Mon, 8 Nov 2021 16:11:47 -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.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_DYNAMIC, URIBL_BLOCKED autolearn=ham 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 B82B61E813 for ; Mon, 8 Nov 2021 16:11:46 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 47B3C3858003 for ; Mon, 8 Nov 2021 21:11:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47B3C3858003 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1636405906; bh=3ttBcCVpynsVIJWtrf8ZOA2BjIDsbcHE/iT4srKmvxs=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=h9HadfM1iZXDTfc/uYa/jr1MpuSlF9hcfKghpQ8SvXtvvQ7ioybDG7Uw8FJR5oCG9 R/hG0x6ebmLi6uBbDdigc1yB/uDuZwY/V/zlRbfSSOgzXWCWy/Wb0y/TnsIPuYRjIj Kdhkq9NavyPCZYxZFpVNRh653RVGJhrhqIPVoRyg= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 166DE3858D3C for ; Mon, 8 Nov 2021 21:11:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 166DE3858D3C Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 1A8LBHnJ031234 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 8 Nov 2021 16:11:22 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 1A8LBHnJ031234 Received: from [172.16.0.95] (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 9D75B1E813; Mon, 8 Nov 2021 16:11:17 -0500 (EST) Subject: Re: [PATCH 2/4] gdbsupport: add array_view copy function To: Simon Marchi , gdb-patches@sourceware.org References: <20211108210609.353208-1-simon.marchi@efficios.com> <20211108210609.353208-2-simon.marchi@efficios.com> Message-ID: Date: Mon, 8 Nov 2021 16:11:17 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20211108210609.353208-2-simon.marchi@efficios.com> Content-Type: text/plain; charset=utf-8 Content-Language: tl Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Mon, 8 Nov 2021 21:11:17 +0000 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" On 2021-11-08 4:06 p.m., Simon Marchi wrote: > From: Simon Marchi > > An assertion was recently added to array_view::operator[] to ensure we > don't do out of bounds accesses. However, when the array_view is copied > to or from using memcpy, it bypasses this safety. > > To address this, add a `copy` free function that copies data from an > array view to another. It ensures that the destination and source array > views have the same size and element size, which prevents any kind of > overflow in the source and in the destination. > > I have chosen to allow the array views to have different types, because > I am thinking we might want to copy arrays of bfd_byte into arrays of > gdb_byte, for example. > > Change a few randomly selected spots to use the new function, to show > how it can be used. > > Change-Id: Ibeaca04e0028410fd44ce82f72e60058d6230a03 Hi Tom, This patch of mine causes the following test failure: Running /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.ada/packed_array_assign.exp ... FAIL: gdb.ada/packed_array_assign.exp: print pra(1) := pr (GDB internal error) I couldn't figure out if this is a mistake on my part, or if my assert points out an existing bug. Could you give it a quick look? The problem is that the values we are copying from and to don't have the same length: (top-gdb) p toval.type.length $1 = 5 (top-gdb) p fromval.type.length $2 = 8 ... and that trips on the new assert. The two values appear to have the same type, so I don't understand where the different lengths come from. Simon