From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oJFJE+EhE2FwGAAAWB0awg (envelope-from ) for ; Tue, 10 Aug 2021 21:03:29 -0400 Received: by simark.ca (Postfix, from userid 112) id 3DA661EDF7; Tue, 10 Aug 2021 21:03:29 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,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 8686E1E813 for ; Tue, 10 Aug 2021 21:03:28 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 33595386EC3A for ; Wed, 11 Aug 2021 01:03:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 33595386EC3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1628643808; bh=od+E+YKMBcB2vN8JDwIu27lT3lgH79WC2dcPfdNzKBQ=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=rdAvQy8wrN1YY+fMTO30kCiqN1QhAxwIZKJ8R7KdyztQLTi3kGKXlUTFxNy3erJuX T5SxDvtXLgWH1958mO6uDx1Z7do/DSYCRchjJyvQWa0KP4pMTkpIRFRWOC0uw/Ldi5 1VHVatMn3GmniAVGFRs0zp3hMSCLtoAmPhxtHy0k= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 80295385DC10 for ; Wed, 11 Aug 2021 01:02:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 80295385DC10 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 17B11qHJ003003 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Aug 2021 21:01:57 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 17B11qHJ003003 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (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 8C3301E813; Tue, 10 Aug 2021 21:01:52 -0400 (EDT) Subject: Re: [PATCH v2 3/4] gdb: Have setter and getter callbacks for settings To: Lancelot SIX References: <20210808192302.3768766-1-lsix@lancelotsix.com> <20210808192302.3768766-4-lsix@lancelotsix.com> <727ab80a-c72d-960a-6d6e-a731aaa147dd@polymtl.ca> <20210810221852.bqbb6opnrlaqgob5@Plymouth> Message-ID: <7de0a03d-77bf-3b09-9a11-4a109afce8a8@polymtl.ca> Date: Tue, 10 Aug 2021 21:01:52 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210810221852.bqbb6opnrlaqgob5@Plymouth> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 11 Aug 2021 01:01:52 +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 Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 2021-08-10 6:18 p.m., Lancelot SIX wrote: >>> @@ -231,25 +427,50 @@ struct base_setting >>> gdb_assert (var_type_uses (this->m_var_type)); >>> gdb_assert (!this->empty ()); >> >> I think this needs to call operator bool, like so: >> >> gdb_assert (*this); >> >> Otherwise, the assert fails when using a getter/setter (empty only >> checks for m_var to be non-NULL, which is false when using >> getter/setter). >> > > Thanks for spotting this. The second assertion should only be on the > branch that does not use the setter callback. > > I also realized that the 'set' method should use 'get_p () = v', which > includes this assertion making the one you ran into redundant. > > >> I don't find this notation super clear, it might be clearer if we could >> call a named method instead of operator bool. Maybe "empty" could mean >> "does not have a buffer nor getter/setter"? > > I think I got confused about what empty means when I rebased the patch > and handled the conflicts from the previous iteration. This is a good > indication that the naming is not as good as it could be. > > 'empty' refers to the fact that there is an underlying buffer register. > I could just check 'm_var != nullptr' in 'get_p' and 'operator bool()'. > This is a protected method not meant to be used outside of the class > anyway. > > The 'bool()' operator is intended to check if a setting is > valid, i.e. 'get' and 'set' can be called without a guarantied error. > We could use something like 'valid ()' instead (or 'good ()' if we want > to mimic iostream). Not that 'empty' would not work, I think I would > prefer to read > > if (foo.valid ()) > use (foo); > > over > > if (!foo.empty ()) > use (foo); > > I tend to prefer the affirmative version over the double negation. > > I’ll change that for the next iteration. Another option would be to use gdb::optional var; in cmd_list_element, and make it such that a setting can never exist in an invalid state. Two constructor would exist, one to construct a setting with a pointer to a buffer and another with the setter/getter. There would be no need (I think) for set_p and set_accessors. But otherwise, `valid` sounds good to me as well. Simon