From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 5ACBC3858D28 for ; Thu, 18 Aug 2022 16:27:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5ACBC3858D28 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 27IGR4cl005444 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 Aug 2022 12:27:09 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 27IGR4cl005444 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 C6E251E13B; Thu, 18 Aug 2022 12:27:04 -0400 (EDT) Message-ID: Date: Thu, 18 Aug 2022 12:27:04 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] dwarf2: Fix dwarf stack fetch array view size mismatch Content-Language: fr To: Denis Lukianov , gdb-patches@sourceware.org Cc: andrew.burgess@embecosm.com References: <36c80f43b57fcfce3b9db6619e75366db360ae9c.camel@voxelsoft.com> From: Simon Marchi In-Reply-To: <36c80f43b57fcfce3b9db6619e75366db360ae9c.camel@voxelsoft.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 18 Aug 2022 16:27:05 +0000 X-Spam-Status: No, score=-3038.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , X-List-Received-Date: Thu, 18 Aug 2022 16:27:12 -0000 On 8/8/22 07:24, Denis Lukianov wrote: > Following change 4bce7cdaf4 "gdbsupport: add array_view copy function", > dwarf stack fetch sometimes cause an internal-error in > array_view::copy, where a gdb_assert expects the source and destination > view sizes to match. When called from dwarf_expr_context::fetch_result > sometimes the lengths don't match. > > Both the source and destination views each have a separate implicit > length. The source is correctly sliced for the copy. However, the > destination is passed with the full allocated length, which does not > necessarily match the source length. > > This patch slices the destination to match the source length. > > diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c > index 3549745df04..aa203e87bfb 100644 > --- a/gdb/dwarf2/expr.c > +++ b/gdb/dwarf2/expr.c > @@ -1025,7 +1025,7 @@ dwarf_expr_context::fetch_result (struct type > *type, struct type *subobj_type, > subobj_offset += n - max; > > copy (value_contents_all (val).slice (subobj_offset, len), > - value_contents_raw (retval)); > + value_contents_raw (retval).slice (0, len)); > } > break; > Hi Denis, Do you have a reproducer for this, that we could turn into a test? I don't think your change is necessary. retval's content length comes from the length of `subobj_type`: retval = allocate_value (subobj_type); and the variable `len`, used to slice the source view, also comes from the length of `subobj_type`: size_t len = TYPE_LENGTH (subobj_type); So the two views should be of that same length. Your patch reminded me of a pending patch I had in the same area, which I just merged: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=bde195b84a862f31ac111c0881ad13b89ee89492 Maybe you were seeing the same problem as described there? Simon