From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 2123C3851C00 for ; Sun, 17 May 2020 14:40:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2123C3851C00 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.193] (unknown [192.222.164.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 58DA81E5F9; Sun, 17 May 2020 10:40:05 -0400 (EDT) Subject: Re: [PATCH] Make BLOCK_START and BLOCK_END into rvalues To: Tom Tromey Cc: gdb-patches@sourceware.org References: <20200516151021.7080-1-tom@tromey.com> <87pnb264j2.fsf@tromey.com> From: Simon Marchi Message-ID: <2f349f8c-3e39-17cb-9b5c-d2d9c60ee41f@simark.ca> Date: Sun, 17 May 2020 10:40:04 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <87pnb264j2.fsf@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Language: tl Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Sun, 17 May 2020 14:40:07 -0000 On 2020-05-17 10:05 a.m., Tom Tromey wrote: > Simon> This is similar to what I'm doing to struct type, so it would be nice to agree > Simon> on the way forward for all these structures, and change them in a consistent > Simon> manner. > > Makes sense. > > Simon> Since you are changing the places that modify the field values, I'd suggest > Simon> adding the setter right away, it's a step in the right direction. > > Simon> And I'd suggest adding the getter too, changing the BLOCK_START macro to use > Simon> it, it shouldn't be much more work. And it will achieve the goal of making > Simon> the macro yield an rvalue. > > I wasn't sure whether setters and getters would provide any real value. > Aside from some maybe-future idea of changing the getter, in other > situations they are just wrappers for the field. It's true that simply wrapping a field with a getter / setter may not appear valuable. I think it is somewhat valuable to be able to put a breakpoint on the setter. If you are wondering where some block with a given start address is created, you can put a conditional breakpoint on the setter. And to avoid the field being changed behind the back of that setter, then that field must be private (ideally) and a getter becomes necessary as well. I also like getter / setters because they allow adding assertions to make sure things are in a coherent state. > For struct type, maybe it makes more sense, because one (very-) > long-term idea there would be to split up struct main_type into an > inheritance hierarchy, so that each type can be more obviously > type-safe, and also carry just the data it needs. > > I don't mind making the change -- it's easy enough to do. As you wish :) Simon