target factories, target open and multiple instances of targets
[deliverable/binutils-gdb.git] / gdb / arm-nbsd-nat.c
index 95bb1b2ad097876665ad21ed7376eec2259c3ab2..3a1ddeaf4e859f68f9f06a0288420e8123f67a94 100644 (file)
@@ -1,6 +1,6 @@
 /* Native-dependent code for BSD Unix running on ARM's, for GDB.
 
-   Copyright (C) 1988-2017 Free Software Foundation, Inc.
+   Copyright (C) 1988-2018 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "arm-tdep.h"
 #include "inf-ptrace.h"
 
+class arm_netbsd_nat_target final : public inf_ptrace_target
+{
+public:
+  /* Add our register access methods.  */
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+};
+
+static arm_netbsd_nat_target the_arm_netbsd_nat_target;
+
 extern int arm_apcs_32;
 
 static void
@@ -47,7 +57,7 @@ arm_supply_gregset (struct regcache *regcache, struct reg *gregset)
   regcache_raw_supply (regcache, ARM_LR_REGNUM,
                       (char *) &gregset->r_lr);
   /* This is ok: we're running native...  */
-  r_pc = gdbarch_addr_bits_remove (get_regcache_arch (regcache), gregset->r_pc);
+  r_pc = gdbarch_addr_bits_remove (regcache->arch (), gregset->r_pc);
   regcache_raw_supply (regcache, ARM_PC_REGNUM, (char *) &r_pc);
 
   if (arm_apcs_32)
@@ -77,7 +87,7 @@ fetch_register (struct regcache *regcache, int regno)
   struct reg inferior_registers;
   int ret;
 
-  ret = ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
+  ret = ptrace (PT_GETREGS, ptid_get_pid (regcache_get_ptid (regcache)),
                (PTRACE_TYPE_ARG3) &inferior_registers, 0);
 
   if (ret < 0)
@@ -101,7 +111,7 @@ fetch_register (struct regcache *regcache, int regno)
     case ARM_PC_REGNUM:
       /* This is ok: we're running native...  */
       inferior_registers.r_pc = gdbarch_addr_bits_remove
-                                 (get_regcache_arch (regcache),
+                                 (regcache->arch (),
                                   inferior_registers.r_pc);
       regcache_raw_supply (regcache, ARM_PC_REGNUM,
                           (char *) &inferior_registers.r_pc);
@@ -130,7 +140,7 @@ fetch_regs (struct regcache *regcache)
   int ret;
   int regno;
 
-  ret = ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
+  ret = ptrace (PT_GETREGS, ptid_get_pid (regcache_get_ptid (regcache)),
                (PTRACE_TYPE_ARG3) &inferior_registers, 0);
 
   if (ret < 0)
@@ -148,7 +158,7 @@ fetch_fp_register (struct regcache *regcache, int regno)
   struct fpreg inferior_fp_registers;
   int ret;
 
-  ret = ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
+  ret = ptrace (PT_GETFPREGS, ptid_get_pid (regcache_get_ptid (regcache)),
                (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
 
   if (ret < 0)
@@ -178,7 +188,7 @@ fetch_fp_regs (struct regcache *regcache)
   int ret;
   int regno;
 
-  ret = ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
+  ret = ptrace (PT_GETFPREGS, ptid_get_pid (regcache_get_ptid (regcache)),
                (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
 
   if (ret < 0)
@@ -190,9 +200,8 @@ fetch_fp_regs (struct regcache *regcache)
   arm_supply_fparegset (regcache, &inferior_fp_registers);
 }
 
-static void
-armnbsd_fetch_registers (struct target_ops *ops,
-                        struct regcache *regcache, int regno)
+void
+arm_nbsd_nat_target::fetch_registers (struct regcache *regcache, int regno)
 {
   if (regno >= 0)
     {
@@ -212,11 +221,11 @@ armnbsd_fetch_registers (struct target_ops *ops,
 static void
 store_register (const struct regcache *regcache, int regno)
 {
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
   struct reg inferior_registers;
   int ret;
 
-  ret = ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
+  ret = ptrace (PT_GETREGS, ptid_get_pid (regcache_get_ptid (regcache)),
                (PTRACE_TYPE_ARG3) &inferior_registers, 0);
 
   if (ret < 0)
@@ -279,7 +288,7 @@ store_register (const struct regcache *regcache, int regno)
       break;
     }
 
-  ret = ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
+  ret = ptrace (PT_SETREGS, ptid_get_pid (regcache_get_ptid (regcache)),
                (PTRACE_TYPE_ARG3) &inferior_registers, 0);
 
   if (ret < 0)
@@ -289,7 +298,7 @@ store_register (const struct regcache *regcache, int regno)
 static void
 store_regs (const struct regcache *regcache)
 {
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
   struct reg inferior_registers;
   int ret;
   int regno;
@@ -327,7 +336,7 @@ store_regs (const struct regcache *regcache)
       inferior_registers.r_pc = pc_val | psr_val;
     }
 
-  ret = ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
+  ret = ptrace (PT_SETREGS, ptid_get_pid (regcache_get_ptid (regcache)),
                (PTRACE_TYPE_ARG3) &inferior_registers, 0);
 
   if (ret < 0)
@@ -340,7 +349,7 @@ store_fp_register (const struct regcache *regcache, int regno)
   struct fpreg inferior_fp_registers;
   int ret;
 
-  ret = ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
+  ret = ptrace (PT_GETFPREGS, ptid_get_pid (regcache_get_ptid (regcache)),
                (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
 
   if (ret < 0)
@@ -362,7 +371,7 @@ store_fp_register (const struct regcache *regcache, int regno)
       break;
     }
 
-  ret = ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
+  ret = ptrace (PT_SETFPREGS, ptid_get_pid (regcache_get_ptid (regcache)),
                (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
 
   if (ret < 0)
@@ -384,16 +393,15 @@ store_fp_regs (const struct regcache *regcache)
   regcache_raw_collect (regcache, ARM_FPS_REGNUM,
                        (char *) &inferior_fp_registers.fpr_fpsr);
 
-  ret = ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
+  ret = ptrace (PT_SETFPREGS, ptid_get_pid (regcache_get_ptid (regcache)),
                (PTRACE_TYPE_ARG3) &inferior_fp_registers, 0);
 
   if (ret < 0)
     warning (_("unable to store floating-point registers"));
 }
 
-static void
-armnbsd_store_registers (struct target_ops *ops,
-                        struct regcache *regcache, int regno)
+void
+arm_nbsd_nat_target::store_registers (struct regcache *regcache, int regno)
 {
   if (regno >= 0)
     {
@@ -461,12 +469,7 @@ static struct core_fns arm_netbsd_elfcore_fns =
 void
 _initialize_arm_netbsd_nat (void)
 {
-  struct target_ops *t;
-
-  t = inf_ptrace_target ();
-  t->to_fetch_registers = armnbsd_fetch_registers;
-  t->to_store_registers = armnbsd_store_registers;
-  add_target (t);
+  add_inf_child_target (&the_arm_netbsd_nat_target);
 
   deprecated_add_core_fns (&arm_netbsd_elfcore_fns);
 }
This page took 0.028703 seconds and 4 git commands to generate.