From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id BB0AKlE5KWcr0iUAWB0awg (envelope-from ) for ; Mon, 04 Nov 2024 16:14:57 -0500 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=OnSD9mWK; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 9434D1E5E0; Mon, 4 Nov 2024 16:14:57 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.5 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, URIBL_BLOCKED,URIBL_DBL_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 4F5A21E0C0 for ; Mon, 4 Nov 2024 16:14:56 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DA26B3857374 for ; Mon, 4 Nov 2024 21:14:55 +0000 (GMT) Received: from omta34.uswest2.a.cloudfilter.net (omta34.uswest2.a.cloudfilter.net [35.89.44.33]) by sourceware.org (Postfix) with ESMTPS id 349203858C2B for ; Mon, 4 Nov 2024 21:14:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 349203858C2B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 349203858C2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730754859; cv=none; b=wybc/mhwAsN9q3PnLo7yKjjkncwhhTVxL75WNkJB47MB3dxlhLZSIo9MgGnZntZAwLQnkKiphrjydsxxqLCRIt5W5kEg05aV+OE5GUXxIp/8sT3J672bMlUXhVZwi3UYqb8p2DU9+EEh7Z6X+Cu6dOsoQDA9VdGIAeCv/xIFsyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730754859; c=relaxed/simple; bh=XAB6LjKSFeqoTdxNaWveurkL9Lvv8hUar0u+/t5NbzQ=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=DI/2zdFUk0K3E+kxeJFA4oIcT1W+MLl0Mt5LAwCBeuK4D7eDe0xRaB+iM9wQJIOx5/kmXpna3a0B5BHf4ev5FGvjgVAiSbjYDSntVmL6xTskjFq1YpsZppWD0efqR+KqFOkO/09dDVhZnZTLxBy4zFdWttoBqWrhw/zTcsZTpd4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5008a.ext.cloudfilter.net ([10.0.29.246]) by cmsmtp with ESMTPS id 7zihtVeRPVpzp84OttSxqg; Mon, 04 Nov 2024 21:14:15 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id 84Ostb79GQsN584OstfkNk; Mon, 04 Nov 2024 21:14:14 +0000 X-Authority-Analysis: v=2.4 cv=SsGW6uO0 c=1 sm=1 tr=0 ts=67293926 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=VlfZXiiP6vEA:10 a=ItBw4LHWJt0A:10 a=mDV3o1hIAAAA:8 a=RB4UDY_W1U_PDMWHOAcA:9 a=QEXdDO2ut3YA:10 a=6Ogn3jAGHLSNbaov7Orx:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=/vMmKhIKSPDZ5vMzZB8hNhTCmmp5SJQdyaKOHrSesyQ=; b=OnSD9mWKO78Cdy86zmN25NFxYy e1gajRzhi05/mBydkQO5lkoGauuwLGkneQWpE8fLg2rCOLrYfFxm7qkRHw+E/OQbkdEJfyBwN2E20 7lLjOJZbYWETYLaMdWh8p7sC2; Received: from 97-122-113-155.hlrn.qwest.net ([97.122.113.155]:36924 helo=prentzel.local) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1t84Or-003uOz-2x; Mon, 04 Nov 2024 14:14:13 -0700 From: Tom Tromey Date: Mon, 04 Nov 2024 14:14:11 -0700 Subject: [PATCH 1/6] Add check-gdbarch.py MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20241104-check-unused-gdbarch-v1-1-7082f2121077@tromey.com> References: <20241104-check-unused-gdbarch-v1-0-7082f2121077@tromey.com> In-Reply-To: <20241104-check-unused-gdbarch-v1-0-7082f2121077@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.2 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.113.155 X-Source-L: No X-Exim-ID: 1t84Or-003uOz-2x X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-113-155.hlrn.qwest.net (prentzel.local) [97.122.113.155]:36924 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfFrOuZTy68u7GNAMGVJRfxgmdFFxdG+ruVoHWLFWeVKSfEMAkxknHp7ss5Omp9BAWu9SOz6ZsR9ENGBdttI8VNcuvFyl5+6lee/728DBBInkukkm58OR nJV0NYX50SJu+u1OkyymO+CKpsz/0aXaLa49DdKhJdIga1TuJA82ilRg4iIBTrlnp/OYiHp2/hhOrXFrt/n8jpejdbPXWtkIm/E= X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org This adds a new check-gdbarch.py script. This script checks the sources to see which gdbarch methods are set but never called, and which ones are called but never set. --- gdb/check-gdbarch.py | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/gdb/check-gdbarch.py b/gdb/check-gdbarch.py new file mode 100755 index 0000000000000000000000000000000000000000..1f7479e7d1bdfc177e62ae9f58d971b8b8e34ce9 --- /dev/null +++ b/gdb/check-gdbarch.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 + +# gdbarch checker. +# +# Copyright (C) 2024 Free Software Foundation, Inc. +# +# This file is part of GDB. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import fileinput +import glob +import re +import sys + +# gdbarch_components is imported only for its side-effect of filling +# `gdbarch_types.components`. +import gdbarch_components # noqa: F401 # type: ignore +from gdbarch_types import Component, Function, Info, Value, components + + +def not_info(c: Component): + "Filter function to omit Info components." + return type(c) is not Info + + +if len(sys.argv) != 1: + # Must be run in gdb srcdir. + print("usage: check-gdbarch.py") + sys.exit(1) + + +# Make a hash holding all the gdbarch customization names. +defined_names = set() +set_names = set() +called_names = set() +for c in filter(not_info, components): + if c.implement: + defined_names.add(c.name) + if c.predicate: + # Predicates are always "set". + pname = c.name + "_p" + set_names.add(pname) + defined_names.add(pname) + + +def find_local_files(): + result = [] + for name in glob.glob("*.[chyl]"): + if "gdbarch" not in name: + result.append(name) + return result + + +files = find_local_files() +files.extend(glob.glob("*/*.[ch]")) + +# FIXME could keep counts here and then look for deletion +# opportunities. +rx = re.compile(r"\b(set_)?gdbarch_([a-zA-Z0-9_]+)\b") +for line in fileinput.input(files=files): + m = rx.search(line) + if m: + if m[0] == "gdbarch_p": + # There are a few variables with this name, exclude them. + pass + elif m[1]: + set_names.add(m[2]) + else: + called_names.add(m[2]) + + +for elt in defined_names - set_names: + print(f"never set: {elt}") +for elt in defined_names - called_names: + # Don't report _p functions here, predicate=True is sometimes used + # to allow optional functions. + if not elt.endswith("_p"): + print(f"never called: {elt}") -- 2.46.1