Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 1/6] Add check-gdbarch.py
Date: Mon, 04 Nov 2024 14:14:11 -0700	[thread overview]
Message-ID: <20241104-check-unused-gdbarch-v1-1-7082f2121077@tromey.com> (raw)
In-Reply-To: <20241104-check-unused-gdbarch-v1-0-7082f2121077@tromey.com>

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 <http://www.gnu.org/licenses/>.
+
+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


  reply	other threads:[~2024-11-04 21:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-04 21:14 [PATCH 0/6] Add gdbarch-checking script Tom Tromey
2024-11-04 21:14 ` Tom Tromey [this message]
2024-12-05 22:47   ` [PATCH 1/6] Add check-gdbarch.py Keith Seitz
2024-11-04 21:14 ` [PATCH 2/6] Use 'invalid' rather than 'predicate' in some gdbarch functions Tom Tromey
2024-11-04 21:14 ` [PATCH 3/6] Remove solib_symbols_extension gdbarch hook Tom Tromey
2024-11-04 21:14 ` [PATCH 4/6] Remove skip_permanent_breakpoint " Tom Tromey
2024-11-04 21:14 ` [PATCH 5/6] Remove the print_vector_info " Tom Tromey
2024-12-05 22:49   ` Keith Seitz
2024-11-04 21:14 ` [PATCH 6/6] Remove the auto_charset " Tom Tromey
2024-12-05 22:50 ` [PATCH 0/6] Add gdbarch-checking script Keith Seitz
2024-12-06  2:58   ` Sergio Durigan Junior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241104-check-unused-gdbarch-v1-1-7082f2121077@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox