gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdbserver / linux-nios2-low.cc
index bfc5aee165d284e0202e3f6c52bd1873f7b05413..838b0e9d8a60433b17f459ee2e469067fdf8e3a4 100644 (file)
 #define PTRACE_GET_THREAD_AREA 25
 #endif
 
+/* Linux target op definitions for the NIOS II architecture.  */
+
+class nios2_target : public linux_process_target
+{
+public:
+
+  const regs_info *get_regs_info () override;
+
+  const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override;
+
+protected:
+
+  void low_arch_setup () override;
+
+  bool low_cannot_fetch_register (int regno) override;
+
+  bool low_cannot_store_register (int regno) override;
+
+  bool low_supports_breakpoints () override;
+
+  CORE_ADDR low_get_pc (regcache *regcache) override;
+
+  void low_set_pc (regcache *regcache, CORE_ADDR newpc) override;
+
+  bool low_breakpoint_at (CORE_ADDR pc) override;
+};
+
+/* The singleton target ops object.  */
+
+static nios2_target the_nios2_target;
+
+bool
+nios2_target::low_supports_breakpoints ()
+{
+  return true;
+}
+
+CORE_ADDR
+nios2_target::low_get_pc (regcache *regcache)
+{
+  return linux_get_pc_32bit (regcache);
+}
+
+void
+nios2_target::low_set_pc (regcache *regcache, CORE_ADDR pc)
+{
+  linux_set_pc_32bit (regcache, pc);
+}
+
 /* The following definition must agree with the number of registers
    defined in "struct user_regs" in GLIBC
    (sysdeps/unix/sysv/linux/nios2/sys/user.h), and also with
@@ -65,34 +114,28 @@ static int nios2_regmap[] = {
   0
 };
 
-/* Implement the arch_setup linux_target_ops method.  */
+/* Implement the low_arch_setup linux target ops method.  */
 
-static void
-nios2_arch_setup (void)
+void
+nios2_target::low_arch_setup ()
 {
   current_process ()->tdesc = tdesc_nios2_linux;
 }
 
-/* Implement the cannot_fetch_register linux_target_ops method.  */
+/* Implement the low_cannot_fetch_register linux target ops method.  */
 
-static int
-nios2_cannot_fetch_register (int regno)
+bool
+nios2_target::low_cannot_fetch_register (int regno)
 {
-  if (nios2_regmap[regno] == -1)
-    return 1;
-
-  return 0;
+  return (nios2_regmap[regno] == -1);
 }
 
-/* Implement the cannot_store_register linux_target_ops method.  */
+/* Implement the low_cannot_store_register linux target ops method.  */
 
-static int
-nios2_cannot_store_register (int regno)
+bool
+nios2_target::low_cannot_store_register (int regno)
 {
-  if (nios2_regmap[regno] == -1)
-    return 1;
-
-  return 0;
+  return (nios2_regmap[regno] == -1);
 }
 
 /* Breakpoint support.  Also see comments on nios2_breakpoint_from_pc
@@ -113,33 +156,33 @@ nios2_cannot_store_register (int regno)
 static const unsigned int nios2_breakpoint = NIOS2_BREAKPOINT;
 #define nios2_breakpoint_len 4
 
-/* Implementation of linux_target_ops method "sw_breakpoint_from_kind".  */
+/* Implementation of target ops method "sw_breakpoint_from_kind".  */
 
-static const gdb_byte *
-nios2_sw_breakpoint_from_kind (int kind, int *size)
+const gdb_byte *
+nios2_target::sw_breakpoint_from_kind (int kind, int *size)
 {
   *size = nios2_breakpoint_len;
   return (const gdb_byte *) &nios2_breakpoint;
 }
 
-/* Implement the breakpoint_at linux_target_ops method.  */
+/* Implement the low_breakpoint_at linux target ops method.  */
 
-static int
-nios2_breakpoint_at (CORE_ADDR where)
+bool
+nios2_target::low_breakpoint_at (CORE_ADDR where)
 {
   unsigned int insn;
 
   /* For R2, first check for the 2-byte CDX trap.n breakpoint encoding.  */
 #if defined(__nios2_arch__) && __nios2_arch__ == 2
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 2);
+  read_memory (where, (unsigned char *) &insn, 2);
   if (insn == CDX_BREAKPOINT)
-    return 1;
+    return true;
 #endif
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
+  read_memory (where, (unsigned char *) &insn, 4);
   if (insn == nios2_breakpoint)
-    return 1;
-  return 0;
+    return true;
+  return false;
 }
 
 /* Fetch the thread-local storage pointer for libthread_db.  */
@@ -221,34 +264,22 @@ static struct usrregs_info nios2_usrregs_info =
     nios2_regmap,
   };
 
-static struct regs_info regs_info =
+static struct regs_info myregs_info =
   {
     NULL, /* regset_bitmap */
     &nios2_usrregs_info,
     &nios2_regsets_info
   };
 
-static const struct regs_info *
-nios2_regs_info (void)
+const regs_info *
+nios2_target::get_regs_info ()
 {
-  return &regs_info;
+  return &myregs_info;
 }
 
-struct linux_target_ops the_low_target =
-{
-  nios2_arch_setup,
-  nios2_regs_info,
-  nios2_cannot_fetch_register,
-  nios2_cannot_store_register,
-  NULL,
-  linux_get_pc_32bit,
-  linux_set_pc_32bit,
-  NULL, /* breakpoint_kind_from_pc */
-  nios2_sw_breakpoint_from_kind,
-  NULL, /* get_next_pcs */
-  0,
-  nios2_breakpoint_at,
-};
+/* The linux target ops object.  */
+
+linux_process_target *the_linux_target = &the_nios2_target;
 
 void
 initialize_low_arch (void)
This page took 0.027261 seconds and 4 git commands to generate.