From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 105856 invoked by alias); 28 Mar 2017 22:23:29 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 105813 invoked by uid 89); 28 Mar 2017 22:23:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=remembered X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 28 Mar 2017 22:23:27 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B9530C04BD27; Tue, 28 Mar 2017 22:23:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B9530C04BD27 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B9530C04BD27 Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id C846C18B48; Tue, 28 Mar 2017 22:23:24 +0000 (UTC) Subject: Re: extract_unsigned_integer API (Re: [PATCH] Remove MAX_REGISTER_SIZE from frame.c) To: Yao Qi References: <86lgspqisk.fsf@gmail.com> <5f2f0cb0-6265-46aa-4ad6-eda5ba817da4@redhat.com> <8660itnzvv.fsf@gmail.com> <93774758-0354-c67b-9733-005b3d56fbfa@redhat.com> Cc: Alan Hayward , "gdb-patches@sourceware.org" , nd From: Pedro Alves Message-ID: <2427e9d3-4d91-7d63-a8e4-36aeb233b86e@redhat.com> Date: Tue, 28 Mar 2017 22:23:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <93774758-0354-c67b-9733-005b3d56fbfa@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-03/txt/msg00491.txt.bz2 On 03/28/2017 05:57 PM, Pedro Alves wrote: > Yes, and that can sorted by e.g., passing the size to the buffer() > method, as I mentioned in the comment. Like: > > extractor extr; > frame_unwind_register (frame, regnum, ext.buffer (size)); > return extr.extract (size, byte_order); > > extractor::buffer(size_t) would throw error on overflow. > > Or pass it to the ctor (which would likewise throw error on overflow): > > extractor extr (size); > frame_unwind_register (frame, regnum, ext.buffer ()); > return extr.extract (size, byte_order); > > Could even store the size and byte order inside the extractor > object, and avoid writing the size more than once: > > extractor extr (size, byte_order); > frame_unwind_register (frame, regnum, ext.buffer ()); > return extr.extract (); > > Or make "extrator::buffer" remember the last size, so extractors > can be reused. Or even support both, ctor with and without size, > buffer() with and without size. extractror::extract would always > used the last remembered size. > > So I still don't see any advantage in a callback-based interface. Thinking about this a bit more, if we went this direction, I think the simplest would be to add an extract::size() method that returned the size of the buffer, and use that for bounds when filling in the data, like: extractor extr; frame_unwind_register (frame, regnum, ext.buffer (), ext.size ()); return extr.extract (type_len, byte_order); If type_len is larger than the buffer size, then we'll still get an error either inside extractor::extract, and maybe earlier inside frame_unwind_register (if it had that size parameter). Though for the particular case of frame_unwind_register, since the frame machinery works with struct value's, inside frame_unwind_register there's going to be a value created already, and that has a contents buffer we could access directly. So e.g., inside frame_unwind_register_signed, we should be able to use frame_unwind_register_value directly thus avoid the need for the local buffer and copying data. Thanks, Pedro Alves