[binutils-gdb] gdb: remove gdbarch_displaced_step_fixup_p

Andrew Burgess aburgess@sourceware.org
Wed Mar 22 21:21:50 GMT 2023


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4144571254685a89f57b3b0f602c5a9d4bc20a3c

commit 4144571254685a89f57b3b0f602c5a9d4bc20a3c
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Wed Feb 22 17:13:07 2023 +0000

    gdb: remove gdbarch_displaced_step_fixup_p
    
    The comment on the gdbarch_displaced_step_fixup gdbarch method
    indicates that this method is optional and that GDB will perform some
    default if this method is not supplied.  As such we define a predicate
    gdbarch_displaced_step_fixup_p.
    
    It may have been true at one point that the fixup method was optional,
    but it is no longer true.  If this method is not defined and GDB tries
    to complete a displaced step, then GDB is going to crash.
    
    Additionally the gdbarch_displaced_step_fixup_p predicate is not used
    anywhere in GDB.
    
    In this commit I have removed the gdbarch_displaced_step_fixup_p
    predicate, and I have updated the validation check for the
    gdbarch_displaced_step_fixup method; if the
    gdbarch_displaced_step_copy_insn method is defined then the fixup
    method must also be defined.
    
    I believe I've manually checked all the current places where
    gdbarch_displaced_step_copy_insn is defined and they all also define
    the fixup method, so this change should cause no problems for anyone.
    
    There should be no user visible changes after this commit.
    
    Approved-By: Pedro Alves <pedro@palves.net>

Diff:
---
 gdb/gdbarch-gen.h         |  2 --
 gdb/gdbarch.c             | 14 ++------------
 gdb/gdbarch_components.py |  3 ++-
 3 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h
index 76d12a15317..a3fc0b9272b 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -1085,8 +1085,6 @@ extern void set_gdbarch_displaced_step_hw_singlestep (struct gdbarch *gdbarch, g
    For a general explanation of displaced stepping and how GDB uses it,
    see the comments in infrun.c. */
 
-extern bool gdbarch_displaced_step_fixup_p (struct gdbarch *gdbarch);
-
 typedef void (gdbarch_displaced_step_fixup_ftype) (struct gdbarch *gdbarch, struct displaced_step_copy_insn_closure *closure, CORE_ADDR from, CORE_ADDR to, struct regcache *regs);
 extern void gdbarch_displaced_step_fixup (struct gdbarch *gdbarch, struct displaced_step_copy_insn_closure *closure, CORE_ADDR from, CORE_ADDR to, struct regcache *regs);
 extern void set_gdbarch_displaced_step_fixup (struct gdbarch *gdbarch, gdbarch_displaced_step_fixup_ftype *displaced_step_fixup);
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index b4763aa6bf4..b676e346fd0 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -446,7 +446,8 @@ verify_gdbarch (struct gdbarch *gdbarch)
   /* Skip verify of max_insn_length, has predicate.  */
   /* Skip verify of displaced_step_copy_insn, has predicate.  */
   /* Skip verify of displaced_step_hw_singlestep, invalid_p == 0 */
-  /* Skip verify of displaced_step_fixup, has predicate.  */
+  if ((gdbarch->displaced_step_copy_insn == nullptr) != (gdbarch->displaced_step_fixup == nullptr))
+    log.puts ("\n\tdisplaced_step_fixup");
   /* Skip verify of displaced_step_prepare, has predicate.  */
   if ((! gdbarch->displaced_step_finish) != (! gdbarch->displaced_step_prepare))
     log.puts ("\n\tdisplaced_step_finish");
@@ -1090,9 +1091,6 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
   gdb_printf (file,
 	      "gdbarch_dump: displaced_step_hw_singlestep = <%s>\n",
 	      host_address_to_string (gdbarch->displaced_step_hw_singlestep));
-  gdb_printf (file,
-	      "gdbarch_dump: gdbarch_displaced_step_fixup_p() = %d\n",
-	      gdbarch_displaced_step_fixup_p (gdbarch));
   gdb_printf (file,
 	      "gdbarch_dump: displaced_step_fixup = <%s>\n",
 	      host_address_to_string (gdbarch->displaced_step_fixup));
@@ -4058,19 +4056,11 @@ set_gdbarch_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
   gdbarch->displaced_step_hw_singlestep = displaced_step_hw_singlestep;
 }
 
-bool
-gdbarch_displaced_step_fixup_p (struct gdbarch *gdbarch)
-{
-  gdb_assert (gdbarch != NULL);
-  return gdbarch->displaced_step_fixup != NULL;
-}
-
 void
 gdbarch_displaced_step_fixup (struct gdbarch *gdbarch, struct displaced_step_copy_insn_closure *closure, CORE_ADDR from, CORE_ADDR to, struct regcache *regs)
 {
   gdb_assert (gdbarch != NULL);
   gdb_assert (gdbarch->displaced_step_fixup != NULL);
-  /* Do not check predicate: gdbarch->displaced_step_fixup != NULL, allow call.  */
   if (gdbarch_debug >= 2)
     gdb_printf (gdb_stdlog, "gdbarch_displaced_step_fixup called\n");
   gdbarch->displaced_step_fixup (gdbarch, closure, from, to, regs);
diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py
index 92c501d2a72..2b1a2b4f602 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -1796,8 +1796,9 @@ see the comments in infrun.c.
         ("CORE_ADDR", "to"),
         ("struct regcache *", "regs"),
     ],
-    predicate=True,
+    predicate=False,
     predefault="NULL",
+    invalid="(gdbarch->displaced_step_copy_insn == nullptr) != (gdbarch->displaced_step_fixup == nullptr)",
 )
 
 Method(


More information about the Gdb-cvs mailing list