From patchwork Tue Feb 28 16:51:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 65792 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 878F2385781A for ; Tue, 28 Feb 2023 16:51:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 878F2385781A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677603107; bh=JA8Friwz1c/dfOasowp4D6lek5vlCIxbpjgie+gJyBw=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=X3SsFYXryMITqUki57mUkjBh6fl2QWepwAAcPbIsxYNYqvT3CS3mbkuSRMtMzlVjr COJqn4tR8Vkn7HON76MLRP7Lp5tDhCnICNQ7q2ypBb5Y6K0Eep3v1vpyrcAn1ssPBs aYHn2zXPqJGybqrTAifqPuyQUzoBSUZM+oSvqqKQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 040AC3858C2B for ; Tue, 28 Feb 2023 16:51:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 040AC3858C2B Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-416-hmXEVnPYOCSofvhP8UMlLg-1; Tue, 28 Feb 2023 11:51:18 -0500 X-MC-Unique: hmXEVnPYOCSofvhP8UMlLg-1 Received: by mail-ed1-f72.google.com with SMTP id v12-20020a056402174c00b004acb5c6e52bso14673318edx.1 for ; Tue, 28 Feb 2023 08:51:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677603077; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JA8Friwz1c/dfOasowp4D6lek5vlCIxbpjgie+gJyBw=; b=yrH+cBzJzCB/ktWBIFdr9axvy8+WbkVdllSP4pXkb/VMUM1FQzppHetOh7FXXpui6G mkNMUromw0f2AA3unb7+i4rptVTyEn6jYLPj/Ku9tqlRRzQcc9ZiWO+EJWzL/MTJf6Xh MlnYyDEVTo0ILmJBsWdgWZ1dDovnxOq5NGCCw0xsZVN29wpF7bDI4Fs3NBjexYCTkt0H CRDjZsL1yMCaOexdELJjj3BYsvlEU3vVxqGQp4M3E+AqWDl9r0bvPfoxhl2XH73rNtJa if3YPxKOnFl+SIsZ8Is5gRC0fLodqTscDAxEVjB/nexFvkhAscNfOIuztPWeHQ6n+JUJ l3Sg== X-Gm-Message-State: AO0yUKU5QfZ5W8rknjkt7OS0YND2S7DyTd5yXLQlSnLd32UjximEtBte 8Q063N8NJXt3tg9xPlNS6XNwZnFc9c3ncP71RYif9JFd+GRrXU3qdg9nB8VQsTjoGDpWbNFvrN3 mwc76/dsVwsXgLaVs1K2Fi1wfq9g6K0YDTKaEoe0owYYgRM7iZIsW2WZDZ8zLVsTsJRHL6TJasz 5/OO0= X-Received: by 2002:a17:906:564a:b0:8af:4684:91cf with SMTP id v10-20020a170906564a00b008af468491cfmr3136432ejr.32.1677603077154; Tue, 28 Feb 2023 08:51:17 -0800 (PST) X-Google-Smtp-Source: AK7set/yGP8SYL+fhcTYytLl2fNI37uIc5r+BUtE7hFatQFNPUSOCsI8LkyBXaZeuLeqvTGjpo15fA== X-Received: by 2002:a17:906:564a:b0:8af:4684:91cf with SMTP id v10-20020a170906564a00b008af468491cfmr3136413ejr.32.1677603076786; Tue, 28 Feb 2023 08:51:16 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id p17-20020a170906229100b008e68d2c11d8sm4725244eja.218.2023.02.28.08.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 08:51:16 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/2] gdb: updates to gdbarch.py algorithm Date: Tue, 28 Feb 2023 16:51:12 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 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-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Restructure how gdbarch.py generates the verify_gdbarch function. Previously the postdefault handling was bundled together with the validation. This means that a field can't have both a postdefault, and set its invalid attribute to a string. This doesn't seem reasonable to me, I see no reason why a field can't have both a postdefault (used when the tdep doesn't set the field), and an invalid expression, which can be used to validate the value that a tdep might set. In this commit I restructure the verify_gdbarch generation code to allow the above, there is no change in the actual generated code in this commit, that will come in later commit. I did end up having to remove the "invalid" attribute (where the attribute was set to True) from a number of fields in this commit. This invalid attribute was never having an effect as these components all have a postdefault. Consider; the "postdefault" is applied if the field still has its initial value, while an "invalid" attribute set to True means error if the field still has its default value. But the field never will have its default value, it will always have its postdefault value. --- gdb/gdbarch.py | 31 ++++++++++++++++--------- gdb/gdbarch_components.py | 49 ++++++++++++++------------------------- 2 files changed, 37 insertions(+), 43 deletions(-) diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py index 93b1e8bf84e..7fea41c9572 100755 --- a/gdb/gdbarch.py +++ b/gdb/gdbarch.py @@ -203,35 +203,44 @@ with open("gdbarch.c", "w") as f: file=f, ) for c in filter(not_info, components): - if c.invalid is False: - print(f" /* Skip verify of {c.name}, invalid_p == 0 */", file=f) - elif c.predicate: - print(f" /* Skip verify of {c.name}, has predicate. */", file=f) - elif isinstance(c.invalid, str) and c.postdefault is not None: - print(f" if ({c.invalid})", file=f) - print(f" gdbarch->{c.name} = {c.postdefault};", file=f) - elif c.predefault is not None and c.postdefault is not None: + # An opportunity to write in the 'postdefault' value. + if c.postdefault is not None and c.predefault is not None: print(f" if (gdbarch->{c.name} == {c.predefault})", file=f) print(f" gdbarch->{c.name} = {c.postdefault};", file=f) elif c.postdefault is not None: print(f" if (gdbarch->{c.name} == 0)", file=f) print(f" gdbarch->{c.name} = {c.postdefault};", file=f) + + # Now validate the value. + if c.invalid is False: + print(f" /* Skip verify of {c.name}, invalid_p == 0 */", file=f) + elif c.predicate: + print(f" /* Skip verify of {c.name}, has predicate. */", file=f) + elif c.invalid is None: + # No validation has been requested for this component. + pass elif isinstance(c.invalid, str): print(f" if ({c.invalid})", file=f) print(f""" log.puts ("\\n\\t{c.name}");""", file=f) - elif c.predefault is not None: + elif c.invalid is True and c.predefault is not None: print(f" if (gdbarch->{c.name} == {c.predefault})", file=f) print(f""" log.puts ("\\n\\t{c.name}");""", file=f) - elif c.invalid is True: + elif c.invalid is True and c.postdefault is None: print(f" if (gdbarch->{c.name} == 0)", file=f) print(f""" log.puts ("\\n\\t{c.name}");""", file=f) + elif c.invalid is True: + # This component has its 'invalid' field set to True, but + # also has a postdefault. This makes no sense, the + # postdefault will have been applied above, so this field + # will not have a zero value. + raise Exception(f"component {c.name} has postdefault and invalid set to True") else: # We should not allow ourselves to simply do nothing here # because no other case applies. If we end up here then # either the input data needs adjusting so one of the # above cases matches, or we need additional cases adding # here. - raise Exception("unhandled case when generating gdbarch validation") + raise Exception(f"unhandled case when generating gdbarch validation: {c.name}") print(" if (!log.empty ())", file=f) print( """ internal_error (_("verify_gdbarch: the following are invalid ...%s"),""", diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py index caa65c334ec..1d420a513f9 100644 --- a/gdb/gdbarch_components.py +++ b/gdb/gdbarch_components.py @@ -63,34 +63,28 @@ # * "predefault", "postdefault", and "invalid" - These are used for # the initialization and verification steps: # -# A gdbarch is zero-initialized. Then, if a field has a pre-default, -# the field is set to that value. After initialization is complete -# (that is, after the tdep code has a chance to change the settings), -# the post-initialization step is done. +# A gdbarch is zero-initialized. Then, if a field has a "predefault", +# the field is set to that value. This becomes the fields initial +# value. # -# There is a generic algorithm to generate a "validation function" for -# all fields. If the field has an "invalid" attribute with a string -# value, then this string is the expression (note that a string-valued -# "invalid" and "predicate" are mutually exclusive; and the case where -# invalid is True means to ignore this field and instead use the -# default checking that is about to be described). Otherwise, if -# there is a "predefault", then the field is valid if it differs from -# the predefault. Otherwise, the check is done against 0 (really NULL -# for function pointers, but same idea). -# -# In post-initialization / validation, there are several cases. +# After initialization is complete (that is, after the tdep code has a +# chance to change the settings), the post-initialization step is +# done. # -# * If "invalid" is False, or if the field specifies "predicate", -# validation is skipped. Otherwise, a validation step is emitted. +# If the field still has its initial value (see above), and the field +# has a "postdefault", then the post field is set to this value. # -# * Otherwise, the validity is checked using the usual validation -# function (see above). If the field is considered valid, nothing is -# done. +# After the possible "postdefault" assignment, validation is +# performed for fields that don't have a "predicate". # -# * Otherwise, the field's value is invalid. If there is a -# "postdefault", then the field is assigned that value. +# If the field has an "invalid" attribute with a string value, then +# this string is the expression that should evaluate to true when the +# field is invalid. # -# * Otherwise, the gdbarch will fail validation and gdb will crash. +# Otherwise, if "invalid" is True, then the generic validation +# function is used: the field is considered invalid it it still +# contains its default value. This validation is what is used within +# the _p predicate function if the field has "predicate" set to True. # # Function and Method share: # @@ -206,7 +200,6 @@ Value( type="const struct floatformat **", name="bfloat16_format", postdefault="floatformats_bfloat16", - invalid=True, printer="pformat (gdbarch, gdbarch->bfloat16_format)", ) @@ -221,7 +214,6 @@ Value( type="const struct floatformat **", name="half_format", postdefault="floatformats_ieee_half", - invalid=True, printer="pformat (gdbarch, gdbarch->half_format)", ) @@ -236,7 +228,6 @@ Value( type="const struct floatformat **", name="float_format", postdefault="floatformats_ieee_single", - invalid=True, printer="pformat (gdbarch, gdbarch->float_format)", ) @@ -251,7 +242,6 @@ Value( type="const struct floatformat **", name="double_format", postdefault="floatformats_ieee_double", - invalid=True, printer="pformat (gdbarch, gdbarch->double_format)", ) @@ -266,7 +256,6 @@ Value( type="const struct floatformat **", name="long_double_format", postdefault="floatformats_ieee_double", - invalid=True, printer="pformat (gdbarch, gdbarch->long_double_format)", ) @@ -289,7 +278,6 @@ One if `wchar_t' is signed, zero if unsigned. name="wchar_signed", predefault="-1", postdefault="1", - invalid=True, ) Method( @@ -332,7 +320,6 @@ addr_bit is the size of a target address as represented in gdb name="addr_bit", predefault="0", postdefault="gdbarch_ptr_bit (gdbarch)", - invalid=True, ) Value( @@ -355,7 +342,6 @@ and if Dwarf versions < 4 need to be supported. name="dwarf2_addr_size", predefault="0", postdefault="gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT", - invalid=True, ) Value( @@ -366,7 +352,6 @@ One if `char' acts like `signed char', zero if `unsigned char'. name="char_signed", predefault="-1", postdefault="1", - invalid=True, ) Function(