From patchwork Fri Mar 10 18:43: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: 66248 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 E8CAC3850840 for ; Fri, 10 Mar 2023 18:44:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8CAC3850840 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678473871; bh=CNj8X7fDz/dAZU9YM894tKQMmcwBSiJPg/V2PUcy6fs=; 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=FZHu/6sK+XC6NreJz/XF3Dg2dLH/zJ7/ILkC5w5pUf35v0z5UJ6LIuxWxuCZpZsK/ h3b0vrra3jA0Ya5qMYIoED9mVb2H5+ZSaTWA6zxNmAUX/z++0pBFgVqZW0YTHTZnW9 VTBIyiltveHFXzGhGtbxN0srol1Kwx935jJmFzw8= 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 B724438582B0 for ; Fri, 10 Mar 2023 18:43:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B724438582B0 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-388-vnyFEd4PMuGtJ_Ao3sRO6A-1; Fri, 10 Mar 2023 13:43:27 -0500 X-MC-Unique: vnyFEd4PMuGtJ_Ao3sRO6A-1 Received: by mail-wr1-f69.google.com with SMTP id l14-20020a5d526e000000b002cd851d79b2so1180233wrc.5 for ; Fri, 10 Mar 2023 10:43:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678473806; 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=CNj8X7fDz/dAZU9YM894tKQMmcwBSiJPg/V2PUcy6fs=; b=GALkidXizEgclcaYfNWXgfjMuaCL/NXe3jY85w7S0JyRVuaTAIaKg/b8rWoe7aMLcJ PIt3gx+DSMNVBXOhPWxPaQpbDshF9/4dDzFghejCFfB0C/YP0HIuHfAezSR4Yu6RM85b 7V9OuAIMowD36mZEJyIyRJLEsW5X83hWnf5TqlOUBTORsRRL+Cu/q3khiXloWibTibS5 eW2zaa2IehEbvz8a9ukfYl3qUwZw/+a2gsm3lSSBYQfwkA7itsiNNDbLYIP+m4ayRhqZ /HvrMoDYb/s9oC+La0yL9MbylKhANTcRoPEkYLuhe6Ur8NWEQGX97Cz4/vCHBvqJIvFs 8BkA== X-Gm-Message-State: AO0yUKWyOgiK8F2G+CX0rPhZjPP9JO2y41XX/w0OEeaimiGVZSxeK8lg JV+iwSmlm4WmPwOpHRfxQT94MfWf87UBocA+B5zz42yFDssB3gn0JQFv7cwDI5KvzuUDVTWIJDS lvPo56xd5FDuI0exsyr4HEWr0E5GobuRj8f1qMr7oBDkRq8LNgx/aMTOngfSoQyzYkYR1qNAFcl z/N9vXmw== X-Received: by 2002:a05:600c:3582:b0:3eb:38b0:e748 with SMTP id p2-20020a05600c358200b003eb38b0e748mr2316655wmq.13.1678473806147; Fri, 10 Mar 2023 10:43:26 -0800 (PST) X-Google-Smtp-Source: AK7set+5J7fEaOq473O7jQG0z43EMknhFtUR1iqKfDG/CnRVKavQFFG+KrWVjAeFd1TSBVfWfokCfw== X-Received: by 2002:a05:600c:3582:b0:3eb:38b0:e748 with SMTP id p2-20020a05600c358200b003eb38b0e748mr2316636wmq.13.1678473805809; Fri, 10 Mar 2023 10:43:25 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id b14-20020a5d40ce000000b002c5539171d1sm454084wrq.41.2023.03.10.10.43.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 10:43:25 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 3/9] gdb/gdbarch: split postdefault setup from invalid check in gdbarch.py Date: Fri, 10 Mar 2023 18:43: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. --- gdb/gdbarch.py | 42 +++++++++++++++++++++++++-------------- gdb/gdbarch_components.py | 40 ++++++++++++++++--------------------- 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py index 93b1e8bf84e..5437c827f34 100755 --- a/gdb/gdbarch.py +++ b/gdb/gdbarch.py @@ -203,35 +203,47 @@ with open("gdbarch.c", "w") as f: file=f, ) for c in filter(not_info, components): + # An opportunity to write in the 'postdefault' value. We + # change field's value to the postdefault if its current value + # is not different to the initial value of the field. + if c.postdefault is not None: + init_value = c.predefault or "0" + print(f" if (gdbarch->{c.name} == {init_value})", 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 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: - 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) + 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: - 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: - print(f" if (gdbarch->{c.name} == 0)", file=f) - print(f""" log.puts ("\\n\\t{c.name}");""", file=f) + if c.postdefault is not None: + # 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: + init_value = c.predefault or "0" + print(f" if (gdbarch->{c.name} == {init_value})", file=f) + print(f""" log.puts ("\\n\\t{c.name}");""", file=f) 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 d3dfcfc806f..1f217123216 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 field's 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 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 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: #