gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / hppa-linux-nat.c
index daabe3d935983a2e7217ad4e96fa979866c68b00..f352c25a3e63345a5b7f9211e095f72d0b446814 100644 (file)
@@ -1,12 +1,12 @@
 /* Functions specific to running GDB native on HPPA running GNU/Linux.
 
-   Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2004-2020 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 2 of the License, or
+   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,
    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, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
 #include "gdbcore.h"
 #include "regcache.h"
-#include "gdb_string.h"
 #include "inferior.h"
 #include "target.h"
 #include "linux-nat.h"
+#include "inf-ptrace.h"
+#include "gdbarch.h"
 
 #include <sys/procfs.h>
-#include <sys/ptrace.h>
+#include "nat/gdb_ptrace.h"
 #include <linux/version.h>
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,43)
-#include <asm/offset.h>
-#else
-#include <asm/offsets.h>
-#endif
+#include <asm/ptrace.h>
+#include "hppa-linux-offsets.h"
 
 #include "hppa-tdep.h"
 
-/* Prototypes for supply_gregset etc. */
+class hppa_linux_nat_target final : public linux_nat_target
+{
+public:
+  /* Add our register access methods.  */
+  void fetch_registers (struct regcache *, int) override;
+  void store_registers (struct regcache *, int) override;
+};
+
+static hppa_linux_nat_target the_hppa_linux_nat_target;
+
+/* Prototypes for supply_gregset etc.  */
 #include "gregset.h"
 
 /* These must match the order of the register names.
@@ -158,7 +164,7 @@ hppa_linux_register_addr (int regno, CORE_ADDR blockend)
 {
   CORE_ADDR addr;
 
-  if ((unsigned) regno >= NUM_REGS)
+  if ((unsigned) regno >= ARRAY_SIZE (u_offsets))
     error (_("Invalid register number %d."), regno);
 
   if (u_offsets[regno] == -1)
@@ -218,50 +224,48 @@ static const int greg_map[] =
 static void
 fetch_register (struct regcache *regcache, int regno)
 {
-  int tid;
+  struct gdbarch *gdbarch = regcache->arch ();
+  pid_t tid;
   int val;
 
-  if (gdbarch_cannot_fetch_register (current_gdbarch, regno))
+  if (gdbarch_cannot_fetch_register (gdbarch, regno))
     {
-      regcache_raw_supply (regcache, regno, NULL);
+      regcache->raw_supply (regno, NULL);
       return;
     }
 
-  /* GNU/Linux LWP ID's are process ID's.  */
-  tid = TIDGET (inferior_ptid);
-  if (tid == 0)
-    tid = PIDGET (inferior_ptid); /* Not a threaded program.  */
+  tid = get_ptrace_pid (regcache->ptid ());
 
   errno = 0;
   val = ptrace (PTRACE_PEEKUSER, tid, hppa_linux_register_addr (regno, 0), 0);
   if (errno != 0)
-    error (_("Couldn't read register %s (#%d): %s."), REGISTER_NAME (regno),
+    error (_("Couldn't read register %s (#%d): %s."), 
+          gdbarch_register_name (gdbarch, regno),
           regno, safe_strerror (errno));
 
-  regcache_raw_supply (regcache, regno, &val);
+  regcache->raw_supply (regno, &val);
 }
 
-/* Store one register. */
+/* Store one register.  */
 
 static void
 store_register (const struct regcache *regcache, int regno)
 {
-  int tid;
+  struct gdbarch *gdbarch = regcache->arch ();
+  pid_t tid;
   int val;
 
-  if (gdbarch_cannot_store_register (current_gdbarch, regno))
+  if (gdbarch_cannot_store_register (gdbarch, regno))
     return;
 
-  /* GNU/Linux LWP ID's are process ID's.  */
-  tid = TIDGET (inferior_ptid);
-  if (tid == 0)
-    tid = PIDGET (inferior_ptid); /* Not a threaded program.  */
+  tid = get_ptrace_pid (regcache->ptid ());
 
   errno = 0;
-  regcache_raw_collect (regcache, regno, &val);
+  regcache->raw_collect (regno, &val);
   ptrace (PTRACE_POKEUSER, tid, hppa_linux_register_addr (regno, 0), val);
   if (errno != 0)
-    error (_("Couldn't write register %s (#%d): %s."), REGISTER_NAME (regno),
+    error (_("Couldn't write register %s (#%d): %s."),
+          gdbarch_register_name (gdbarch, regno),
           regno, safe_strerror (errno));
 }
 
@@ -269,12 +273,14 @@ store_register (const struct regcache *regcache, int regno)
    regno == -1, otherwise fetch all general registers or all floating
    point registers depending upon the value of regno.  */
 
-static void
-hppa_linux_fetch_inferior_registers (struct regcache *regcache, int regno)
+void
+hppa_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
 {
   if (-1 == regno)
     {
-      for (regno = 0; regno < NUM_REGS; regno++)
+      for (regno = 0;
+          regno < gdbarch_num_regs (regcache->arch ());
+          regno++)
         fetch_register (regcache, regno);
     }
   else 
@@ -287,12 +293,14 @@ hppa_linux_fetch_inferior_registers (struct regcache *regcache, int regno)
    regno == -1, otherwise store all general registers or all floating
    point registers depending upon the value of regno.  */
 
-static void
-hppa_linux_store_inferior_registers (struct regcache *regcache, int regno)
+void
+hppa_linux_nat_target::store_registers (struct regcache *regcache, int regno)
 {
   if (-1 == regno)
     {
-      for (regno = 0; regno < NUM_REGS; regno++)
+      for (regno = 0;
+          regno < gdbarch_num_regs (regcache->arch ());
+          regno++)
        store_register (regcache, regno);
     }
   else
@@ -313,7 +321,7 @@ supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
   for (i = 0; i < sizeof (greg_map) / sizeof (greg_map[0]); i++, regp++)
     {
       int regno = greg_map[i];
-      regcache_raw_supply (regcache, regno, regp);
+      regcache->raw_supply (regno, regp);
     }
 }
 
@@ -332,15 +340,13 @@ fill_gregset (const struct regcache *regcache,
       int mregno = greg_map[i];
 
       if (regno == -1 || regno == mregno)
-       {
-          regcache_raw_collect(regcache, mregno, &(*gregsetp)[i]);
-       }
+       regcache->raw_collect (mregno, &(*gregsetp)[i]);
     }
 }
 
 /*  Given a pointer to a floating point register set in /proc format
    (fpregset_t *), unpack the register contents and supply them as gdb's
-   idea of the current floating point register values. */
+   idea of the current floating point register values.  */
 
 void
 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
@@ -351,15 +357,15 @@ supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
   for (regi = 0; regi <= 31; regi++)
     {
       from = (const char *) &((*fpregsetp)[regi]);
-      regcache_raw_supply (regcache, 2*regi + HPPA_FP0_REGNUM, from);
-      regcache_raw_supply (regcache, 2*regi + HPPA_FP0_REGNUM + 1, from + 4);
+      regcache->raw_supply (2*regi + HPPA_FP0_REGNUM, from);
+      regcache->raw_supply (2*regi + HPPA_FP0_REGNUM + 1, from + 4);
     }
 }
 
 /*  Given a pointer to a floating point register set in /proc format
    (fpregset_t *), update the register specified by REGNO from gdb's idea
    of the current floating point register set.  If REGNO is -1, update
-   them all. */
+   them all.  */
 
 void
 fill_fpregset (const struct regcache *regcache,
@@ -374,24 +380,15 @@ fill_fpregset (const struct regcache *regcache,
       char *to = (char *) &((*fpregsetp)[(i - HPPA_FP0_REGNUM) / 2]);
       if ((i - HPPA_FP0_REGNUM) & 1)
        to += 4;
-      regcache_raw_collect (regcache, i, to);
+      regcache->raw_collect (i, to);
    }
 }
 
-void _initialize_hppa_linux_nat (void);
-
+void _initialize_hppa_linux_nat ();
 void
-_initialize_hppa_linux_nat (void)
+_initialize_hppa_linux_nat ()
 {
-  struct target_ops *t;
-
-  /* Fill in the generic GNU/Linux methods.  */
-  t = linux_target ();
-
-  /* Add our register access methods.  */
-  t->to_fetch_registers = hppa_linux_fetch_inferior_registers;
-  t->to_store_registers = hppa_linux_store_inferior_registers;
-
   /* Register the target.  */
-  linux_nat_add_target (t);
+  linux_target = &the_hppa_linux_nat_target;
+  add_inf_child_target (&the_hppa_linux_nat_target);
 }
This page took 0.028037 seconds and 4 git commands to generate.