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 E02343858D1E for ; Sat, 11 Mar 2023 02:57:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E02343858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [10.0.0.11] (unknown [217.28.27.60]) (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 C7E861E128; Fri, 10 Mar 2023 21:57:35 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1678503455; bh=EvsSZt71iozYIeNbIFtGcCEELkOnwjHZkBcG2EtNmBo=; h=Date:Subject:To:References:From:In-Reply-To:From; b=BL51nbU3ZODqO5h6IyXXvloc6TNNdqD2MBpFH7xDyDnzp5eA46Z8dxnoapWbXkFV8 nTKa3boDdQahyq4gfz2D9oj24N2+ChtxTJtSKBcp6e1HpoPyRIyqNztwKAXh0Or9/L 4FQNh5GqGOE7XQxUJ9ctpe38cfO0w1QX/VjgdhtA= Message-ID: Date: Fri, 10 Mar 2023 21:57:35 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCHv3 6/9] gdbarch: improve generation of validation in gdbarch getters Content-Language: en-US To: Andrew Burgess , gdb-patches@sourceware.org References: From: Simon Marchi In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py > index 7ff2cabe2e8..62592c1b13e 100755 > --- a/gdb/gdbarch.py > +++ b/gdb/gdbarch.py > @@ -351,15 +351,13 @@ with open("gdbarch.c", "w") as f: > if isinstance(c.invalid, str): > print(" /* Check variable is valid. */", file=f) > print(f" gdb_assert (!({c.invalid}));", file=f) > - elif c.postdefault is not None and c.predefault is not None: > - print(" /* Check variable changed from pre-default. */", file=f) > - print(f" gdb_assert (gdbarch->{c.name} != {c.predefault});", file=f) > - elif c.invalid: > - if c.predefault: > - print(" /* Check variable changed from pre-default. */", file=f) > - print( > - f" gdb_assert (gdbarch->{c.name} != {c.predefault});", file=f > - ) > + elif c.predicate: > + print(" /* Check predicate was used. */", file=f) > + print(f" gdb_assert (gdbarch_{c.name}_p (gdbarch));", file=f) > + elif c.invalid or c.postdefault is not None: > + init_value = c.predefault or "0" > + print(" /* Check variable changed from its initial value. */", file=f) > + print(f" gdb_assert (gdbarch->{c.name} != {init_value});", file=f) > else: > print(f" /* Skip verify of {c.name}, invalid_p == 0 */", file=f) > print(" if (gdbarch_debug >= 2)", file=f) I still have some trouble reading these snippets of if/elseif/.../else and explaining the logic to myself. But given that the generated file doesn't change in a significant way shows that it's a safe change in any case. Simon