gdb: make gdbarch_displaced_step_copy_insn return an std::unique_ptr
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 14 Feb 2020 20:29:08 +0000 (15:29 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Fri, 14 Feb 2020 20:29:08 +0000 (15:29 -0500)
This callback dynamically allocates a specialized displaced_step_closure, and
gives the ownership of the object to its caller.  So I think it would make
sense for the callback to return an std::unique_ptr, this is what this patch
implements.

gdb/ChangeLog:

* gdbarch.sh (displaced_step_copy_insn): Change return type to an
std::unique_ptr.
* gdbarch.c: Re-generate.
* gdbarch.h: Re-generate.
* infrun.c (displaced_step_prepare_throw): Adjust to std::unique_ptr
change.
* aarch64-tdep.c (aarch64_displaced_step_copy_insn): Change return
type to std::unique_ptr.
* aarch64-tdep.h (aarch64_displaced_step_copy_insn): Likewise.
* amd64-tdep.c (amd64_displaced_step_copy_insn): Likewise.
* amd64-tdep.h (amd64_displaced_step_copy_insn): Likewise.
* arm-linux-tdep.c (arm_linux_displaced_step_copy_insn): Likewise.
* i386-linux-tdep.c (i386_linux_displaced_step_copy_insn): Likewise.
* i386-tdep.c (i386_displaced_step_copy_insn): Likewise.
* i386-tdep.h (i386_displaced_step_copy_insn): Likewise.
* rs6000-tdep.c (ppc_displaced_step_copy_insn): Likewise.
* s390-tdep.c (s390_displaced_step_copy_insn): Likewise.

15 files changed:
gdb/ChangeLog
gdb/aarch64-tdep.c
gdb/aarch64-tdep.h
gdb/amd64-tdep.c
gdb/amd64-tdep.h
gdb/arm-linux-tdep.c
gdb/gdbarch.c
gdb/gdbarch.h
gdb/gdbarch.sh
gdb/i386-linux-tdep.c
gdb/i386-tdep.c
gdb/i386-tdep.h
gdb/infrun.c
gdb/rs6000-tdep.c
gdb/s390-tdep.c

index e3fa08165a7c0775c677e6ce4b70e3d7360baf40..b71251c6a209210d9baf9beb402d86501853ab16 100644 (file)
@@ -1,3 +1,23 @@
+2020-02-14  Simon Marchi  <simon.marchi@efficios.com>
+
+       * gdbarch.sh (displaced_step_copy_insn): Change return type to an
+       std::unique_ptr.
+       * gdbarch.c: Re-generate.
+       * gdbarch.h: Re-generate.
+       * infrun.c (displaced_step_prepare_throw): Adjust to std::unique_ptr
+       change.
+       * aarch64-tdep.c (aarch64_displaced_step_copy_insn): Change return
+       type to std::unique_ptr.
+       * aarch64-tdep.h (aarch64_displaced_step_copy_insn): Likewise.
+       * amd64-tdep.c (amd64_displaced_step_copy_insn): Likewise.
+       * amd64-tdep.h (amd64_displaced_step_copy_insn): Likewise.
+       * arm-linux-tdep.c (arm_linux_displaced_step_copy_insn): Likewise.
+       * i386-linux-tdep.c (i386_linux_displaced_step_copy_insn): Likewise.
+       * i386-tdep.c (i386_displaced_step_copy_insn): Likewise.
+       * i386-tdep.h (i386_displaced_step_copy_insn): Likewise.
+       * rs6000-tdep.c (ppc_displaced_step_copy_insn): Likewise.
+       * s390-tdep.c (s390_displaced_step_copy_insn): Likewise.
+
 2020-02-14  Simon Marchi  <simon.marchi@efficios.com>
 
        * infrun.c (get_displaced_step_closure_by_addr): Adjust to
index 1c44345e573132f7bb921b9eb0b488684c9c3bc3..1bf6bfdf92ccc56028c9106ab1d8109f16f57512 100644 (file)
@@ -2999,7 +2999,7 @@ static const struct aarch64_insn_visitor visitor =
 
 /* Implement the "displaced_step_copy_insn" gdbarch method.  */
 
-struct displaced_step_closure *
+std::unique_ptr<displaced_step_closure>
 aarch64_displaced_step_copy_insn (struct gdbarch *gdbarch,
                                  CORE_ADDR from, CORE_ADDR to,
                                  struct regcache *regs)
@@ -3053,7 +3053,7 @@ aarch64_displaced_step_copy_insn (struct gdbarch *gdbarch,
       dsc = NULL;
     }
 
-  return dsc.release ();
+  return dsc;
 }
 
 /* Implement the "displaced_step_fixup" gdbarch method.  */
index 732f78b5ba50df8dff87a952b7d0993192783977..fc397967cd8eef0701c77d2465b748e98c7d8ca1 100644 (file)
@@ -106,7 +106,7 @@ const target_desc *aarch64_read_description (uint64_t vq, bool pauth_p);
 extern int aarch64_process_record (struct gdbarch *gdbarch,
                                struct regcache *regcache, CORE_ADDR addr);
 
-struct displaced_step_closure *
+struct std::unique_ptr<displaced_step_closure>
   aarch64_displaced_step_copy_insn (struct gdbarch *gdbarch,
                                    CORE_ADDR from, CORE_ADDR to,
                                    struct regcache *regs);
index f5ec40f37e8cbd3dc989aacdd435d3a0aeb0aed8..35ddfbaa32df7cd25e6b554844815bc8eb9f046a 100644 (file)
@@ -1465,7 +1465,7 @@ fixup_displaced_copy (struct gdbarch *gdbarch,
     }
 }
 
-struct displaced_step_closure *
+std::unique_ptr<displaced_step_closure>
 amd64_displaced_step_copy_insn (struct gdbarch *gdbarch,
                                CORE_ADDR from, CORE_ADDR to,
                                struct regcache *regs)
@@ -1474,8 +1474,8 @@ amd64_displaced_step_copy_insn (struct gdbarch *gdbarch,
   /* Extra space for sentinels so fixup_{riprel,displaced_copy} don't have to
      continually watch for running off the end of the buffer.  */
   int fixup_sentinel_space = len;
-  amd64_displaced_step_closure *dsc
-    = new amd64_displaced_step_closure (len + fixup_sentinel_space);
+  std::unique_ptr<amd64_displaced_step_closure> dsc
+    (new amd64_displaced_step_closure (len + fixup_sentinel_space));
   gdb_byte *buf = &dsc->insn_buf[0];
   struct amd64_insn *details = &dsc->insn_details;
 
@@ -1500,7 +1500,7 @@ amd64_displaced_step_copy_insn (struct gdbarch *gdbarch,
 
   /* Modify the insn to cope with the address where it will be executed from.
      In particular, handle any rip-relative addressing.         */
-  fixup_displaced_copy (gdbarch, dsc, from, to, regs);
+  fixup_displaced_copy (gdbarch, dsc.get (), from, to, regs);
 
   write_memory (to, buf, len);
 
index 4c6d13222216fec60bae54cdd01f88f547f73b6a..33ef0c3cea7e8e875df8e97033e9a205a61d4bdf 100644 (file)
@@ -87,7 +87,7 @@ enum amd64_regnum
 
 #define AMD64_NUM_REGS         (AMD64_GSBASE_REGNUM + 1)
 
-extern struct displaced_step_closure *amd64_displaced_step_copy_insn
+extern std::unique_ptr<displaced_step_closure> amd64_displaced_step_copy_insn
   (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to,
    struct regcache *regs);
 extern void amd64_displaced_step_fixup (struct gdbarch *gdbarch,
index 363e67161c847f78438b72a13d898b8700038c12..b3ae04fb431fb3bd98219101a3d5d011f5b095d6 100644 (file)
@@ -1103,12 +1103,13 @@ arm_catch_kernel_helper_return (struct gdbarch *gdbarch, CORE_ADDR from,
    the program has stepped into a Linux kernel helper routine (which must be
    handled as a special case).  */
 
-static struct displaced_step_closure *
+static std::unique_ptr<displaced_step_closure>
 arm_linux_displaced_step_copy_insn (struct gdbarch *gdbarch,
                                    CORE_ADDR from, CORE_ADDR to,
                                    struct regcache *regs)
 {
-  arm_displaced_step_closure *dsc = new arm_displaced_step_closure;
+  std::unique_ptr<arm_displaced_step_closure> dsc
+    (new arm_displaced_step_closure);
 
   /* Detect when we enter an (inaccessible by GDB) Linux kernel helper, and
      stop at the return location.  */
@@ -1118,17 +1119,17 @@ arm_linux_displaced_step_copy_insn (struct gdbarch *gdbarch,
         fprintf_unfiltered (gdb_stdlog, "displaced: detected kernel helper "
                            "at %.8lx\n", (unsigned long) from);
 
-      arm_catch_kernel_helper_return (gdbarch, from, to, regs, dsc);
+      arm_catch_kernel_helper_return (gdbarch, from, to, regs, dsc.get ());
     }
   else
     {
       /* Override the default handling of SVC instructions.  */
       dsc->u.svc.copy_svc_os = arm_linux_copy_svc;
 
-      arm_process_displaced_insn (gdbarch, from, to, regs, dsc);
+      arm_process_displaced_insn (gdbarch, from, to, regs, dsc.get ());
     }
 
-  arm_displaced_init_closure (gdbarch, from, to, dsc);
+  arm_displaced_init_closure (gdbarch, from, to, dsc.get ());
 
   return dsc;
 }
index d763fc85e6f743b6c2a9c91b58cda3757c97e4a0..4e59b375f7888f0e0c62bec60a4fdab74c644734 100644 (file)
@@ -3936,7 +3936,7 @@ gdbarch_displaced_step_copy_insn_p (struct gdbarch *gdbarch)
   return gdbarch->displaced_step_copy_insn != NULL;
 }
 
-struct displaced_step_closure *
+std::unique_ptr<displaced_step_closure>
 gdbarch_displaced_step_copy_insn (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct regcache *regs)
 {
   gdb_assert (gdbarch != NULL);
index 800a4e8b16140cd6d1dad4475be1d3a95c94b569..8a3a07181c544f0df300ed63ff3596a2d0948ad5 100644 (file)
@@ -1036,8 +1036,8 @@ extern void set_gdbarch_max_insn_length (struct gdbarch *gdbarch, ULONGEST max_i
 
 extern int gdbarch_displaced_step_copy_insn_p (struct gdbarch *gdbarch);
 
-typedef struct displaced_step_closure * (gdbarch_displaced_step_copy_insn_ftype) (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct regcache *regs);
-extern struct displaced_step_closure * gdbarch_displaced_step_copy_insn (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct regcache *regs);
+typedef std::unique_ptr<displaced_step_closure> (gdbarch_displaced_step_copy_insn_ftype) (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct regcache *regs);
+extern std::unique_ptr<displaced_step_closure> 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);
 
 /* Return true if GDB should use hardware single-stepping to execute
index a86de961196bb1c6c937ab3fefe317377763b392..d4170c9822357f78e6e2b4b7d39b1c2db6039667 100755 (executable)
@@ -816,7 +816,7 @@ V;ULONGEST;max_insn_length;;;0;0
 # If the instruction cannot execute out of line, return NULL.  The
 # core falls back to stepping past the instruction in-line instead in
 # that case.
-M;struct displaced_step_closure *;displaced_step_copy_insn;CORE_ADDR from, CORE_ADDR to, struct regcache *regs;from, to, regs
+M;std::unique_ptr<displaced_step_closure>;displaced_step_copy_insn;CORE_ADDR from, CORE_ADDR to, struct regcache *regs;from, to, regs
 
 # Return true if GDB should use hardware single-stepping to execute
 # the displaced instruction identified by CLOSURE.  If false,
index f4a5f0a7616176db26f3bb911157a0ae897548b6..7170687f4deb7a44e2beab0e30c14d5eb59f20bb 100644 (file)
@@ -797,12 +797,12 @@ i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
    which does not seem worth it.  The same effect is achieved by patching that
    'nop' instruction there instead.  */
 
-static struct displaced_step_closure *
+static std::unique_ptr<displaced_step_closure>
 i386_linux_displaced_step_copy_insn (struct gdbarch *gdbarch,
                                     CORE_ADDR from, CORE_ADDR to,
                                     struct regcache *regs)
 {
-  displaced_step_closure *closure_
+  std::unique_ptr<displaced_step_closure> closure_
     =  i386_displaced_step_copy_insn (gdbarch, from, to, regs);
 
   if (i386_linux_get_syscall_number_from_regcache (regs) != -1)
@@ -810,7 +810,7 @@ i386_linux_displaced_step_copy_insn (struct gdbarch *gdbarch,
       /* The closure returned by i386_displaced_step_copy_insn is simply a
         buffer with a copy of the instruction. */
       i386_displaced_step_closure *closure
-       = (i386_displaced_step_closure *) closure_;
+       = (i386_displaced_step_closure *) closure_.get ();
 
       /* Fake nop.  */
       closure->buf[0] = 0x90;
index f71444f6528665564486de9400fbbb77f696476c..4b6f3d0ecdcf41ef7c05cd1b0e8dc9bd91a75cce 100644 (file)
@@ -798,13 +798,14 @@ i386_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
 
 /* Some kernels may run one past a syscall insn, so we have to cope.  */
 
-struct displaced_step_closure *
+std::unique_ptr<displaced_step_closure>
 i386_displaced_step_copy_insn (struct gdbarch *gdbarch,
                               CORE_ADDR from, CORE_ADDR to,
                               struct regcache *regs)
 {
   size_t len = gdbarch_max_insn_length (gdbarch);
-  i386_displaced_step_closure *closure = new i386_displaced_step_closure (len);
+  std::unique_ptr<i386_displaced_step_closure> closure
+    (new i386_displaced_step_closure (len));
   gdb_byte *buf = closure->buf.data ();
 
   read_memory (from, buf, len);
index 14bab37205f8bb7d2fd1055f08e71f7dcafb71cd..41faf515868dcac7c298b94394cbe7dde0e4df64 100644 (file)
@@ -428,7 +428,7 @@ extern void
 
 typedef buf_displaced_step_closure i386_displaced_step_closure;
 
-extern struct displaced_step_closure *i386_displaced_step_copy_insn
+extern std::unique_ptr<displaced_step_closure> i386_displaced_step_copy_insn
   (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to,
    struct regcache *regs);
 extern void i386_displaced_step_fixup (struct gdbarch *gdbarch,
index e3e4bdb9b847483a1dd6ef9c32dcf61282495489..d9a6f733519486bd86ee25c571334b78803f8e1f 100644 (file)
@@ -1646,7 +1646,6 @@ displaced_step_prepare_throw (thread_info *tp)
   const address_space *aspace = regcache->aspace ();
   CORE_ADDR original, copy;
   ULONGEST len;
-  struct displaced_step_closure *closure;
   int status;
 
   /* We should never reach this function if the architecture does not
@@ -1738,9 +1737,9 @@ displaced_step_prepare_throw (thread_info *tp)
                                 len);
     };
 
-  closure = gdbarch_displaced_step_copy_insn (gdbarch,
-                                             original, copy, regcache);
-  if (closure == NULL)
+  displaced->step_closure
+    = gdbarch_displaced_step_copy_insn (gdbarch, original, copy, regcache);
+  if (displaced->step_closure == NULL)
     {
       /* The architecture doesn't know how or want to displaced step
         this instruction or instruction sequence.  Fallback to
@@ -1752,7 +1751,6 @@ displaced_step_prepare_throw (thread_info *tp)
      succeeds.  */
   displaced->step_thread = tp;
   displaced->step_gdbarch = gdbarch;
-  displaced->step_closure.reset (closure);
   displaced->step_original = original;
   displaced->step_copy = copy;
 
index 919bebc71b2254b16a3886113d9a0e4c3b4585f3..010bbc9e01a9529508a0c3c0763645a9d00fbb87 100644 (file)
@@ -855,7 +855,7 @@ typedef buf_displaced_step_closure ppc_displaced_step_closure;
 
 /* We can't displaced step atomic sequences.  */
 
-static struct displaced_step_closure *
+static std::unique_ptr<displaced_step_closure>
 ppc_displaced_step_copy_insn (struct gdbarch *gdbarch,
                              CORE_ADDR from, CORE_ADDR to,
                              struct regcache *regs)
@@ -894,7 +894,7 @@ ppc_displaced_step_copy_insn (struct gdbarch *gdbarch,
       displaced_step_dump_bytes (gdb_stdlog, buf, len);
     }
 
-  return closure.release ();
+  return closure;
 }
 
 /* Fix up the state of registers and memory after having single-stepped
index 5f3cb7e81e757475a138dd6cb586968922760e93..313d459cb3a32417904acec8afe09c3f9ec2d8a6 100644 (file)
@@ -425,7 +425,7 @@ typedef buf_displaced_step_closure s390_displaced_step_closure;
 
 /* Implementation of gdbarch_displaced_step_copy_insn.  */
 
-static struct displaced_step_closure *
+static std::unique_ptr<displaced_step_closure>
 s390_displaced_step_copy_insn (struct gdbarch *gdbarch,
                               CORE_ADDR from, CORE_ADDR to,
                               struct regcache *regs)
@@ -477,7 +477,7 @@ s390_displaced_step_copy_insn (struct gdbarch *gdbarch,
       displaced_step_dump_bytes (gdb_stdlog, buf, len);
     }
 
-  return closure.release ();
+  return closure;
 }
 
 /* Fix up the state of registers and memory after having single-stepped
This page took 0.038413 seconds and 4 git commands to generate.