From patchwork Fri Mar 10 18:43:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 66251 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 35C28385B535 for ; Fri, 10 Mar 2023 18:45:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35C28385B535 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678473920; bh=CbUt/TebqHdXnnRmQWbKO6z8GjNSASSPJq3BRDcNDw4=; 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=vXjHxfNkuAx+XEw6HXiARUaW14YzCL8kc8GlcMx77uEPDT4AYSZUHDp7pWvPfPvum 8If5MEipGNHodaQxyRDd9HRe07xDzZeisF80jI4jDnvGjcA9dg5oHGX1uOZ+hHIOTx 1+uWZ0P8O0Jo74GY28ksr56AEisBOC2dGBscanAw= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 76F903858032 for ; Fri, 10 Mar 2023 18:43:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 76F903858032 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-317-pSE3v7CQNMmczVSTwwJRrw-1; Fri, 10 Mar 2023 13:43:32 -0500 X-MC-Unique: pSE3v7CQNMmczVSTwwJRrw-1 Received: by mail-wm1-f71.google.com with SMTP id e17-20020a05600c219100b003e21fa60ec1so2330435wme.2 for ; Fri, 10 Mar 2023 10:43:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678473810; 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=CbUt/TebqHdXnnRmQWbKO6z8GjNSASSPJq3BRDcNDw4=; b=JoYFBGZYK2cq7nDZVRuKvZktauID7ReI5ovPp64vArbCNUJW3fHxD635XQZKhIYwin PH0m2LcZ2NqGYbkDR4V7mFfWwrYSiHr6Gb6MeXp4VVpo7TTBHmA1P59NB/EmYEz/cFy1 DjHtyivJ1Q4FniBOgYAZCjBQLUuef9w3DeOQzkTSFYr1jnO1Fua/MF2L8vreYzQWjml9 S4GsxZWNzTkVwykLnBXRGfU7Gx7V/98LOv7om1kYj5hOmXJkY3kP5Jm2a6ZJ4Rgy8nJX MUglffhq8XhrZXgTXtTfHRkVZLY/GEvW4i9bpYw7X9eXWQF988KbhaLG3kgrrGKgb3Qj 7AAw== X-Gm-Message-State: AO0yUKXtKCfkNtEd80HZ3+cMXZjFW33Rht+cUlGwgLeasqcqK0cbUELi cUw+MTU5mkA3WzkcbW8gvqjV7CcJ90dYxoTNEGpzWA7M8w0N6XF5KZ6ezIIb+6LgEeK5c84uK3g S7Ru+BdY/ASec0xdYw5dVdw8MoXvbsSjuVbq3elMj2UANpRuEndSp0MShKyNcRtdQuv99XeCeB6 wZgeHaCw== X-Received: by 2002:a05:600c:3ba3:b0:3e2:91c:7cb7 with SMTP id n35-20020a05600c3ba300b003e2091c7cb7mr3908384wms.39.1678473810764; Fri, 10 Mar 2023 10:43:30 -0800 (PST) X-Google-Smtp-Source: AK7set8BhJ2q6+Bn3j97lG/PlOnEZlm3TfsrSZxfX2Y/lTSGXvMqEf2A0U59iomW4Bbkuea7pHH4TA== X-Received: by 2002:a05:600c:3ba3:b0:3e2:91c:7cb7 with SMTP id n35-20020a05600c3ba300b003e2091c7cb7mr3908368wms.39.1678473810482; Fri, 10 Mar 2023 10:43:30 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id t1-20020a05600c2f8100b003e896d953a8sm705072wmn.17.2023.03.10.10.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 10:43:30 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 6/9] gdbarch: improve generation of validation in gdbarch getters Date: Fri, 10 Mar 2023 18:43:15 +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" We currently generate some validation code within the gdbarch getter methods. This commit adjusts the algorithm used to generate this validation slightly to make the gdbarch.py code (I think) clearer; there's no significant changes to what is generated. The validation algorithm for gdbarch values is now: - If the Value has an 'invalid' field that is a string, use that for validation, - If the Value has its 'predicate' field set to true, then check the predicate returns true, this ensures the predicate has been called, - If the Value has its 'invalid' field set to True, or the Value has 'postdefault' field, then check the fields has changed from its initial value, - Otherwise no validation is performed. The only changes after this commit are: - Some comments change slightly, and - For 'gcore_bfd_target' and 'max_insn_length' we now validate by calling the predicate rather than checking the field value directly, the underlying check being performed is unchanged though. There should be no user visible changes after this commit. --- gdb/gdbarch.c | 18 +++++++++--------- gdb/gdbarch.py | 16 +++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 064afd7c226..6018c632f91 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -1658,7 +1658,7 @@ int gdbarch_wchar_signed (struct gdbarch *gdbarch) { gdb_assert (gdbarch != NULL); - /* Check variable changed from pre-default. */ + /* Check variable changed from its initial value. */ gdb_assert (gdbarch->wchar_signed != -1); if (gdbarch_debug >= 2) gdb_printf (gdb_stdlog, "gdbarch_wchar_signed called\n"); @@ -1710,7 +1710,7 @@ int gdbarch_addr_bit (struct gdbarch *gdbarch) { gdb_assert (gdbarch != NULL); - /* Check variable changed from pre-default. */ + /* Check variable changed from its initial value. */ gdb_assert (gdbarch->addr_bit != 0); if (gdbarch_debug >= 2) gdb_printf (gdb_stdlog, "gdbarch_addr_bit called\n"); @@ -1728,7 +1728,7 @@ int gdbarch_dwarf2_addr_size (struct gdbarch *gdbarch) { gdb_assert (gdbarch != NULL); - /* Check variable changed from pre-default. */ + /* Check variable changed from its initial value. */ gdb_assert (gdbarch->dwarf2_addr_size != 0); if (gdbarch_debug >= 2) gdb_printf (gdb_stdlog, "gdbarch_dwarf2_addr_size called\n"); @@ -1746,7 +1746,7 @@ int gdbarch_char_signed (struct gdbarch *gdbarch) { gdb_assert (gdbarch != NULL); - /* Check variable changed from pre-default. */ + /* Check variable changed from its initial value. */ gdb_assert (gdbarch->char_signed != -1); if (gdbarch_debug >= 2) gdb_printf (gdb_stdlog, "gdbarch_char_signed called\n"); @@ -1901,7 +1901,7 @@ int gdbarch_num_regs (struct gdbarch *gdbarch) { gdb_assert (gdbarch != NULL); - /* Check variable changed from pre-default. */ + /* Check variable changed from its initial value. */ gdb_assert (gdbarch->num_regs != -1); if (gdbarch_debug >= 2) gdb_printf (gdb_stdlog, "gdbarch_num_regs called\n"); @@ -3919,8 +3919,8 @@ const char * gdbarch_gcore_bfd_target (struct gdbarch *gdbarch) { gdb_assert (gdbarch != NULL); - /* Check variable changed from pre-default. */ - gdb_assert (gdbarch->gcore_bfd_target != 0); + /* Check predicate was used. */ + gdb_assert (gdbarch_gcore_bfd_target_p (gdbarch)); if (gdbarch_debug >= 2) gdb_printf (gdb_stdlog, "gdbarch_gcore_bfd_target called\n"); return gdbarch->gcore_bfd_target; @@ -3995,8 +3995,8 @@ ULONGEST gdbarch_max_insn_length (struct gdbarch *gdbarch) { gdb_assert (gdbarch != NULL); - /* Check variable changed from pre-default. */ - gdb_assert (gdbarch->max_insn_length != 0); + /* Check predicate was used. */ + gdb_assert (gdbarch_max_insn_length_p (gdbarch)); if (gdbarch_debug >= 2) gdb_printf (gdb_stdlog, "gdbarch_max_insn_length called\n"); return gdbarch->max_insn_length; 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)