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 2/6] Use 'invalid' rather than 'predicate' in some gdbarch functions
Date: Mon, 04 Nov 2024 14:14:12 -0700	[thread overview]
Message-ID: <20241104-check-unused-gdbarch-v1-2-7082f2121077@tromey.com> (raw)
In-Reply-To: <20241104-check-unused-gdbarch-v1-0-7082f2121077@tromey.com>

The check-gdbarch.py script points out that a few gdbarch functions
have a predicate that is never called.  This patch changes these
functions to use 'invalid=False' instead, removing a bit of code.
---
 gdb/check-gdbarch.py      |  5 +---
 gdb/gdbarch-gen.c         | 75 +++++------------------------------------------
 gdb/gdbarch-gen.h         | 12 --------
 gdb/gdbarch_components.py | 13 ++++----
 4 files changed, 14 insertions(+), 91 deletions(-)

diff --git a/gdb/check-gdbarch.py b/gdb/check-gdbarch.py
index 1f7479e7d1bdfc177e62ae9f58d971b8b8e34ce9..6f2983c79841d0c8251fdc5c2b284be7702623c5 100755
--- a/gdb/check-gdbarch.py
+++ b/gdb/check-gdbarch.py
@@ -84,7 +84,4 @@ for line in fileinput.input(files=files):
 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}")
+    print(f"never called: {elt}")
diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c
index 0d00cd7c9933ecf0dc40a216f177858803fdd0eb..e50bb1e9a819fe8e2a0219314fe939eb307e4424 100644
--- a/gdb/gdbarch-gen.c
+++ b/gdb/gdbarch-gen.c
@@ -197,7 +197,7 @@ struct gdbarch
   gdbarch_displaced_step_copy_insn_closure_by_addr_ftype *displaced_step_copy_insn_closure_by_addr = nullptr;
   gdbarch_displaced_step_restore_all_in_ptid_ftype *displaced_step_restore_all_in_ptid = nullptr;
   ULONGEST displaced_step_buffer_length = 0;
-  gdbarch_relocate_instruction_ftype *relocate_instruction = NULL;
+  gdbarch_relocate_instruction_ftype *relocate_instruction = nullptr;
   gdbarch_overlay_update_ftype *overlay_update = nullptr;
   gdbarch_core_read_description_ftype *core_read_description = nullptr;
   int sofun_address_maybe_missing = 0;
@@ -332,7 +332,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
   /* Skip verify of pseudo_register_read, has predicate.  */
   /* Skip verify of pseudo_register_read_value, has predicate.  */
   /* Skip verify of pseudo_register_write, has predicate.  */
-  /* Skip verify of deprecated_pseudo_register_write, has predicate.  */
+  /* Skip verify of deprecated_pseudo_register_write, invalid_p == 0.  */
   if (gdbarch->num_regs == -1)
     log.puts ("\n\tnum_regs");
   /* Skip verify of num_pseudo_regs, invalid_p == 0.  */
@@ -435,12 +435,12 @@ verify_gdbarch (struct gdbarch *gdbarch)
   /* Skip verify of execute_dwarf_cfa_vendor_op, invalid_p == 0.  */
   /* Skip verify of address_class_name_to_type_flags, has predicate.  */
   /* Skip verify of register_reggroup_p, invalid_p == 0.  */
-  /* Skip verify of fetch_pointer_argument, has predicate.  */
+  /* Skip verify of fetch_pointer_argument, invalid_p == 0.  */
   /* Skip verify of iterate_over_regset_sections, has predicate.  */
   /* Skip verify of make_corefile_notes, has predicate.  */
   /* Skip verify of find_memory_regions, has predicate.  */
-  /* Skip verify of create_memtag_section, has predicate.  */
-  /* Skip verify of fill_memtag_section, has predicate.  */
+  /* Skip verify of create_memtag_section, invalid_p == 0.  */
+  /* Skip verify of fill_memtag_section, invalid_p == 0.  */
   /* Skip verify of decode_memtag_section, has predicate.  */
   /* Skip verify of core_xfer_shared_libraries, has predicate.  */
   /* Skip verify of core_xfer_shared_libraries_aix, has predicate.  */
@@ -453,7 +453,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
   /* Skip verify of vbit_in_delta, invalid_p == 0.  */
   /* Skip verify of skip_permanent_breakpoint, invalid_p == 0.  */
   /* Skip verify of max_insn_length, has predicate.  */
-  /* Skip verify of displaced_step_copy_insn, has predicate.  */
+  /* Skip verify of displaced_step_copy_insn, invalid_p == 0.  */
   /* Skip verify of displaced_step_hw_singlestep, invalid_p == 0.  */
   if ((gdbarch->displaced_step_copy_insn == nullptr) != (gdbarch->displaced_step_fixup == nullptr))
     log.puts ("\n\tdisplaced_step_fixup");
@@ -466,7 +466,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
     gdbarch->displaced_step_buffer_length = gdbarch->max_insn_length;
   if (gdbarch->displaced_step_buffer_length < gdbarch->max_insn_length)
     log.puts ("\n\tdisplaced_step_buffer_length");
-  /* Skip verify of relocate_instruction, has predicate.  */
+  /* Skip verify of relocate_instruction, invalid_p == 0.  */
   /* Skip verify of overlay_update, has predicate.  */
   /* Skip verify of core_read_description, has predicate.  */
   /* Skip verify of sofun_address_maybe_missing, invalid_p == 0.  */
@@ -657,9 +657,6 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
   gdb_printf (file,
 	      "gdbarch_dump: pseudo_register_write = <%s>\n",
 	      host_address_to_string (gdbarch->pseudo_register_write));
-  gdb_printf (file,
-	      "gdbarch_dump: gdbarch_deprecated_pseudo_register_write_p() = %d\n",
-	      gdbarch_deprecated_pseudo_register_write_p (gdbarch));
   gdb_printf (file,
 	      "gdbarch_dump: deprecated_pseudo_register_write = <%s>\n",
 	      host_address_to_string (gdbarch->deprecated_pseudo_register_write));
@@ -1011,9 +1008,6 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
   gdb_printf (file,
 	      "gdbarch_dump: register_reggroup_p = <%s>\n",
 	      host_address_to_string (gdbarch->register_reggroup_p));
-  gdb_printf (file,
-	      "gdbarch_dump: gdbarch_fetch_pointer_argument_p() = %d\n",
-	      gdbarch_fetch_pointer_argument_p (gdbarch));
   gdb_printf (file,
 	      "gdbarch_dump: fetch_pointer_argument = <%s>\n",
 	      host_address_to_string (gdbarch->fetch_pointer_argument));
@@ -1035,15 +1029,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
   gdb_printf (file,
 	      "gdbarch_dump: find_memory_regions = <%s>\n",
 	      host_address_to_string (gdbarch->find_memory_regions));
-  gdb_printf (file,
-	      "gdbarch_dump: gdbarch_create_memtag_section_p() = %d\n",
-	      gdbarch_create_memtag_section_p (gdbarch));
   gdb_printf (file,
 	      "gdbarch_dump: create_memtag_section = <%s>\n",
 	      host_address_to_string (gdbarch->create_memtag_section));
-  gdb_printf (file,
-	      "gdbarch_dump: gdbarch_fill_memtag_section_p() = %d\n",
-	      gdbarch_fill_memtag_section_p (gdbarch));
   gdb_printf (file,
 	      "gdbarch_dump: fill_memtag_section = <%s>\n",
 	      host_address_to_string (gdbarch->fill_memtag_section));
@@ -1110,9 +1098,6 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
   gdb_printf (file,
 	      "gdbarch_dump: max_insn_length = %s\n",
 	      plongest (gdbarch->max_insn_length));
-  gdb_printf (file,
-	      "gdbarch_dump: gdbarch_displaced_step_copy_insn_p() = %d\n",
-	      gdbarch_displaced_step_copy_insn_p (gdbarch));
   gdb_printf (file,
 	      "gdbarch_dump: displaced_step_copy_insn = <%s>\n",
 	      host_address_to_string (gdbarch->displaced_step_copy_insn));
@@ -1143,9 +1128,6 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
   gdb_printf (file,
 	      "gdbarch_dump: displaced_step_buffer_length = %s\n",
 	      plongest (gdbarch->displaced_step_buffer_length));
-  gdb_printf (file,
-	      "gdbarch_dump: gdbarch_relocate_instruction_p() = %d\n",
-	      gdbarch_relocate_instruction_p (gdbarch));
   gdb_printf (file,
 	      "gdbarch_dump: relocate_instruction = <%s>\n",
 	      host_address_to_string (gdbarch->relocate_instruction));
@@ -1934,13 +1916,6 @@ set_gdbarch_pseudo_register_write (struct gdbarch *gdbarch,
   gdbarch->pseudo_register_write = pseudo_register_write;
 }
 
-bool
-gdbarch_deprecated_pseudo_register_write_p (struct gdbarch *gdbarch)
-{
-  gdb_assert (gdbarch != NULL);
-  return gdbarch->deprecated_pseudo_register_write != NULL;
-}
-
 void
 gdbarch_deprecated_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, int cookednum, const gdb_byte *buf)
 {
@@ -3715,13 +3690,6 @@ set_gdbarch_register_reggroup_p (struct gdbarch *gdbarch,
   gdbarch->register_reggroup_p = register_reggroup_p;
 }
 
-bool
-gdbarch_fetch_pointer_argument_p (struct gdbarch *gdbarch)
-{
-  gdb_assert (gdbarch != NULL);
-  return gdbarch->fetch_pointer_argument != NULL;
-}
-
 CORE_ADDR
 gdbarch_fetch_pointer_argument (struct gdbarch *gdbarch, const frame_info_ptr &frame, int argi, struct type *type)
 {
@@ -3811,13 +3779,6 @@ set_gdbarch_find_memory_regions (struct gdbarch *gdbarch,
   gdbarch->find_memory_regions = find_memory_regions;
 }
 
-bool
-gdbarch_create_memtag_section_p (struct gdbarch *gdbarch)
-{
-  gdb_assert (gdbarch != NULL);
-  return gdbarch->create_memtag_section != NULL;
-}
-
 asection *
 gdbarch_create_memtag_section (struct gdbarch *gdbarch, bfd *obfd, CORE_ADDR address, size_t size)
 {
@@ -3835,13 +3796,6 @@ set_gdbarch_create_memtag_section (struct gdbarch *gdbarch,
   gdbarch->create_memtag_section = create_memtag_section;
 }
 
-bool
-gdbarch_fill_memtag_section_p (struct gdbarch *gdbarch)
-{
-  gdb_assert (gdbarch != NULL);
-  return gdbarch->fill_memtag_section != NULL;
-}
-
 bool
 gdbarch_fill_memtag_section (struct gdbarch *gdbarch, asection *osec)
 {
@@ -4128,13 +4082,6 @@ set_gdbarch_max_insn_length (struct gdbarch *gdbarch,
   gdbarch->max_insn_length = max_insn_length;
 }
 
-bool
-gdbarch_displaced_step_copy_insn_p (struct gdbarch *gdbarch)
-{
-  gdb_assert (gdbarch != NULL);
-  return gdbarch->displaced_step_copy_insn != NULL;
-}
-
 displaced_step_copy_insn_closure_up
 gdbarch_displaced_step_copy_insn (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct regcache *regs)
 {
@@ -4286,19 +4233,11 @@ set_gdbarch_displaced_step_buffer_length (struct gdbarch *gdbarch,
   gdbarch->displaced_step_buffer_length = displaced_step_buffer_length;
 }
 
-bool
-gdbarch_relocate_instruction_p (struct gdbarch *gdbarch)
-{
-  gdb_assert (gdbarch != NULL);
-  return gdbarch->relocate_instruction != NULL;
-}
-
 void
 gdbarch_relocate_instruction (struct gdbarch *gdbarch, CORE_ADDR *to, CORE_ADDR from)
 {
   gdb_assert (gdbarch != NULL);
   gdb_assert (gdbarch->relocate_instruction != NULL);
-  /* Do not check predicate: gdbarch->relocate_instruction != NULL, allow call.  */
   if (gdbarch_debug >= 2)
     gdb_printf (gdb_stdlog, "gdbarch_relocate_instruction called\n");
   gdbarch->relocate_instruction (gdbarch, to, from);
diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h
index b982fd7cd092e071d90b010b9deee2c270520855..582c682de21412b6ead55280fc936c2ce37ee4b7 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -220,8 +220,6 @@ extern void set_gdbarch_pseudo_register_write (struct gdbarch *gdbarch, gdbarch_
 
    Implementations should be migrated to implement pseudo_register_write instead. */
 
-extern bool gdbarch_deprecated_pseudo_register_write_p (struct gdbarch *gdbarch);
-
 typedef void (gdbarch_deprecated_pseudo_register_write_ftype) (struct gdbarch *gdbarch, struct regcache *regcache, int cookednum, const gdb_byte *buf);
 extern void gdbarch_deprecated_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, int cookednum, const gdb_byte *buf);
 extern void set_gdbarch_deprecated_pseudo_register_write (struct gdbarch *gdbarch, gdbarch_deprecated_pseudo_register_write_ftype *deprecated_pseudo_register_write);
@@ -925,8 +923,6 @@ extern void set_gdbarch_register_reggroup_p (struct gdbarch *gdbarch, gdbarch_re
 
 /* Fetch the pointer to the ith function argument. */
 
-extern bool gdbarch_fetch_pointer_argument_p (struct gdbarch *gdbarch);
-
 typedef CORE_ADDR (gdbarch_fetch_pointer_argument_ftype) (const frame_info_ptr &frame, int argi, struct type *type);
 extern CORE_ADDR gdbarch_fetch_pointer_argument (struct gdbarch *gdbarch, const frame_info_ptr &frame, int argi, struct type *type);
 extern void set_gdbarch_fetch_pointer_argument (struct gdbarch *gdbarch, gdbarch_fetch_pointer_argument_ftype *fetch_pointer_argument);
@@ -962,16 +958,12 @@ extern void set_gdbarch_find_memory_regions (struct gdbarch *gdbarch, gdbarch_fi
 
 /* Given a bfd OBFD, segment ADDRESS and SIZE, create a memory tag section to be dumped to a core file */
 
-extern bool gdbarch_create_memtag_section_p (struct gdbarch *gdbarch);
-
 typedef asection * (gdbarch_create_memtag_section_ftype) (struct gdbarch *gdbarch, bfd *obfd, CORE_ADDR address, size_t size);
 extern asection * gdbarch_create_memtag_section (struct gdbarch *gdbarch, bfd *obfd, CORE_ADDR address, size_t size);
 extern void set_gdbarch_create_memtag_section (struct gdbarch *gdbarch, gdbarch_create_memtag_section_ftype *create_memtag_section);
 
 /* Given a memory tag section OSEC, fill OSEC's contents with the appropriate tag data */
 
-extern bool gdbarch_fill_memtag_section_p (struct gdbarch *gdbarch);
-
 typedef bool (gdbarch_fill_memtag_section_ftype) (struct gdbarch *gdbarch, asection *osec);
 extern bool gdbarch_fill_memtag_section (struct gdbarch *gdbarch, asection *osec);
 extern void set_gdbarch_fill_memtag_section (struct gdbarch *gdbarch, gdbarch_fill_memtag_section_ftype *fill_memtag_section);
@@ -1099,8 +1091,6 @@ extern void set_gdbarch_max_insn_length (struct gdbarch *gdbarch, ULONGEST max_i
    core falls back to stepping past the instruction in-line instead in
    that case. */
 
-extern bool gdbarch_displaced_step_copy_insn_p (struct gdbarch *gdbarch);
-
 typedef displaced_step_copy_insn_closure_up (gdbarch_displaced_step_copy_insn_ftype) (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct regcache *regs);
 extern displaced_step_copy_insn_closure_up gdbarch_displaced_step_copy_insn (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct regcache *regs);
 extern void set_gdbarch_displaced_step_copy_insn (struct gdbarch *gdbarch, gdbarch_displaced_step_copy_insn_ftype *displaced_step_copy_insn);
@@ -1203,8 +1193,6 @@ extern void set_gdbarch_displaced_step_buffer_length (struct gdbarch *gdbarch, U
    relative branches, and other PC-relative instructions need the
    offset adjusted; etc. */
 
-extern bool gdbarch_relocate_instruction_p (struct gdbarch *gdbarch);
-
 typedef void (gdbarch_relocate_instruction_ftype) (struct gdbarch *gdbarch, CORE_ADDR *to, CORE_ADDR from);
 extern void gdbarch_relocate_instruction (struct gdbarch *gdbarch, CORE_ADDR *to, CORE_ADDR from);
 extern void set_gdbarch_relocate_instruction (struct gdbarch *gdbarch, gdbarch_relocate_instruction_ftype *relocate_instruction);
diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py
index 4006380076dc7e25aadb13e640c9788ca326b65d..1c7a0aea35e40fe4b05349ee7815ba92a82bda7a 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -453,7 +453,7 @@ Implementations should be migrated to implement pseudo_register_write instead.
         ("int", "cookednum"),
         ("const gdb_byte *", "buf"),
     ],
-    predicate=True,
+    invalid=False,
 )
 
 Value(
@@ -1600,7 +1600,7 @@ Fetch the pointer to the ith function argument.
         ("int", "argi"),
         ("struct type *", "type"),
     ],
-    predicate=True,
+    invalid=False,
 )
 
 Method(
@@ -1649,7 +1649,7 @@ Given a bfd OBFD, segment ADDRESS and SIZE, create a memory tag section to be du
     type="asection *",
     name="create_memtag_section",
     params=[("bfd *", "obfd"), ("CORE_ADDR", "address"), ("size_t", "size")],
-    predicate=True,
+    invalid=False,
 )
 
 Method(
@@ -1659,7 +1659,7 @@ Given a memory tag section OSEC, fill OSEC's contents with the appropriate tag d
     type="bool",
     name="fill_memtag_section",
     params=[("asection *", "osec")],
-    predicate=True,
+    invalid=False,
 )
 
 Method(
@@ -1829,7 +1829,7 @@ that case.
     type="displaced_step_copy_insn_closure_up",
     name="displaced_step_copy_insn",
     params=[("CORE_ADDR", "from"), ("CORE_ADDR", "to"), ("struct regcache *", "regs")],
-    predicate=True,
+    invalid=False,
 )
 
 Method(
@@ -1971,8 +1971,7 @@ offset adjusted; etc.
     type="void",
     name="relocate_instruction",
     params=[("CORE_ADDR *", "to"), ("CORE_ADDR", "from")],
-    predicate=True,
-    predefault="NULL",
+    invalid=False,
 )
 
 Function(

-- 
2.46.1


  parent reply	other threads:[~2024-11-04 21:15 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 ` [PATCH 1/6] Add check-gdbarch.py Tom Tromey
2024-12-05 22:47   ` Keith Seitz
2024-11-04 21:14 ` Tom Tromey [this message]
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-2-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