s/get_regcache_arch (regcache)/regcache->arch ()/g
[deliverable/binutils-gdb.git] / gdb / mips-linux-nat.c
index 98f8d96d669a51f286a15ce6819d1a95b35a53e4..e6ef5a6170acead6564bdfc49c392e084a17d086 100644 (file)
@@ -1,6 +1,6 @@
 /* Native-dependent code for GNU/Linux on MIPS processors.
 
-   Copyright (C) 2001-2014 Free Software Foundation, Inc.
+   Copyright (C) 2001-2017 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -20,7 +20,6 @@
 #include "defs.h"
 #include "command.h"
 #include "gdbcmd.h"
-#include "gdb_assert.h"
 #include "inferior.h"
 #include "mips-tdep.h"
 #include "target.h"
 #include "gregset.h"
 
 #include <sgidefs.h>
-#include <sys/ptrace.h>
+#include "nat/gdb_ptrace.h"
 #include <asm/ptrace.h>
+#include "inf-ptrace.h"
 
-#include "mips-linux-watch.h"
-
-#include "features/mips-linux.c"
-#include "features/mips-dsp-linux.c"
-#include "features/mips64-linux.c"
-#include "features/mips64-dsp-linux.c"
+#include "nat/mips-linux-watch.h"
 
 #ifndef PTRACE_GET_THREAD_AREA
 #define PTRACE_GET_THREAD_AREA 25
    we'll clear this and use PTRACE_PEEKUSER instead.  */
 static int have_ptrace_regsets = 1;
 
-/* Whether or not to print the mirrored debug registers.  */
-
-static int maint_show_dr;
-
 /* Saved function pointers to fetch and store a single register using
    PTRACE_PEEKUSER and PTRACE_POKEUSER.  */
 
@@ -63,7 +54,7 @@ static void (*super_fetch_registers) (struct target_ops *,
 static void (*super_store_registers) (struct target_ops *,
                                      struct regcache *, int);
 
-static void (*super_close) (void);
+static void (*super_close) (struct target_ops *);
 
 /* Map gdb internal register number to ptrace ``address''.
    These ``addresses'' are normally defined in <asm/ptrace.h>. 
@@ -157,7 +148,7 @@ mips64_linux_register_addr (struct gdbarch *gdbarch, int regno, int store)
 /* Fetch the thread-local storage pointer for libthread_db.  */
 
 ps_err_e
-ps_get_thread_area (const struct ps_prochandle *ph,
+ps_get_thread_area (struct ps_prochandle *ph,
                     lwpid_t lwpid, int idx, void **base)
 {
   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
@@ -176,7 +167,7 @@ ps_get_thread_area (const struct ps_prochandle *ph,
 void
 supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
 {
-  if (mips_isa_regsize (get_regcache_arch (regcache)) == 4)
+  if (mips_isa_regsize (regcache->arch ()) == 4)
     mips_supply_gregset (regcache, (const mips_elf_gregset_t *) gregsetp);
   else
     mips64_supply_gregset (regcache, (const mips64_elf_gregset_t *) gregsetp);
@@ -186,7 +177,7 @@ void
 fill_gregset (const struct regcache *regcache,
              gdb_gregset_t *gregsetp, int regno)
 {
-  if (mips_isa_regsize (get_regcache_arch (regcache)) == 4)
+  if (mips_isa_regsize (regcache->arch ()) == 4)
     mips_fill_gregset (regcache, (mips_elf_gregset_t *) gregsetp, regno);
   else
     mips64_fill_gregset (regcache, (mips64_elf_gregset_t *) gregsetp, regno);
@@ -195,7 +186,7 @@ fill_gregset (const struct regcache *regcache,
 void
 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
 {
-  if (mips_isa_regsize (get_regcache_arch (regcache)) == 4)
+  if (mips_isa_regsize (regcache->arch ()) == 4)
     mips_supply_fpregset (regcache, (const mips_elf_fpregset_t *) fpregsetp);
   else
     mips64_supply_fpregset (regcache,
@@ -206,7 +197,7 @@ void
 fill_fpregset (const struct regcache *regcache,
               gdb_fpregset_t *fpregsetp, int regno)
 {
-  if (mips_isa_regsize (get_regcache_arch (regcache)) == 4)
+  if (mips_isa_regsize (regcache->arch ()) == 4)
     mips_fill_fpregset (regcache, (mips_elf_fpregset_t *) fpregsetp, regno);
   else
     mips64_fill_fpregset (regcache,
@@ -221,7 +212,7 @@ static void
 mips64_linux_regsets_fetch_registers (struct target_ops *ops,
                                      struct regcache *regcache, int regno)
 {
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
   int is_fp, is_dsp;
   int have_dsp;
   int regi;
@@ -249,9 +240,7 @@ mips64_linux_regsets_fetch_registers (struct target_ops *ops,
   else
     is_dsp = 0;
 
-  tid = ptid_get_lwp (inferior_ptid);
-  if (tid == 0)
-    tid = ptid_get_pid (inferior_ptid);
+  tid = get_ptrace_pid (regcache_get_ptid (regcache));
 
   if (regno == -1 || (!is_fp && !is_dsp))
     {
@@ -309,7 +298,7 @@ static void
 mips64_linux_regsets_store_registers (struct target_ops *ops,
                                      struct regcache *regcache, int regno)
 {
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
   int is_fp, is_dsp;
   int have_dsp;
   int regi;
@@ -337,9 +326,7 @@ mips64_linux_regsets_store_registers (struct target_ops *ops,
   else
     is_dsp = 0;
 
-  tid = ptid_get_lwp (inferior_ptid);
-  if (tid == 0)
-    tid = ptid_get_pid (inferior_ptid);
+  tid = get_ptrace_pid (regcache_get_ptid (regcache));
 
   if (regno == -1 || (!is_fp && !is_dsp))
     {
@@ -440,6 +427,7 @@ mips_linux_read_description (struct target_ops *ops)
       if (tid == 0)
        tid = ptid_get_pid (inferior_ptid);
 
+      errno = 0;
       ptrace (PTRACE_PEEKUSER, tid, DSP_CONTROL, 0);
       switch (errno)
        {
@@ -512,7 +500,9 @@ mips_show_dr (const char *func, CORE_ADDR addr,
    handle the specified watch type.  */
 
 static int
-mips_linux_can_use_hw_breakpoint (int type, int cnt, int ot)
+mips_linux_can_use_hw_breakpoint (struct target_ops *self,
+                                 enum bptype type,
+                                 int cnt, int ot)
 {
   int i;
   uint32_t wanted_mask, irw_mask;
@@ -588,7 +578,8 @@ mips_linux_stopped_data_address (struct target_ops *t, CORE_ADDR *paddr)
    the specified region can be covered by the watch registers.  */
 
 static int
-mips_linux_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
+mips_linux_region_ok_for_hw_watchpoint (struct target_ops *self,
+                                       CORE_ADDR addr, int len)
 {
   struct pt_watch_regs dummy_regs;
   int i;
@@ -616,7 +607,7 @@ write_watchpoint_regs (void)
   ALL_LWPS (lp)
     {
       tid = ptid_get_lwp (lp->ptid);
-      if (ptrace (PTRACE_SET_WATCH_REGS, tid, &watch_mirror) == -1)
+      if (ptrace (PTRACE_SET_WATCH_REGS, tid, &watch_mirror, NULL) == -1)
        perror_with_name (_("Couldn't write debug register"));
     }
   return 0;
@@ -628,15 +619,14 @@ write_watchpoint_regs (void)
 static void
 mips_linux_new_thread (struct lwp_info *lp)
 {
-  int tid;
+  long tid = lp->ptid.lwp ();
 
-  if (!mips_linux_read_watch_registers (ptid_get_lwp (inferior_ptid),
+  if (!mips_linux_read_watch_registers (tid,
                                        &watch_readback,
                                        &watch_readback_valid, 0))
     return;
 
-  tid = ptid_get_lwp (lp->ptid);
-  if (ptrace (PTRACE_SET_WATCH_REGS, tid, &watch_mirror) == -1)
+  if (ptrace (PTRACE_SET_WATCH_REGS, tid, &watch_mirror, NULL) == -1)
     perror_with_name (_("Couldn't write debug register"));
 }
 
@@ -644,7 +634,9 @@ mips_linux_new_thread (struct lwp_info *lp)
    watch.  Return zero on success.  */
 
 static int
-mips_linux_insert_watchpoint (CORE_ADDR addr, int len, int type,
+mips_linux_insert_watchpoint (struct target_ops *self,
+                             CORE_ADDR addr, int len,
+                             enum target_hw_bp_type type,
                              struct expression *cond)
 {
   struct pt_watch_regs regs;
@@ -672,8 +664,7 @@ mips_linux_insert_watchpoint (CORE_ADDR addr, int len, int type,
     return -1;
 
   /* It fit.  Stick it on the end of the list.  */
-  new_watch = (struct mips_watchpoint *)
-    xmalloc (sizeof (struct mips_watchpoint));
+  new_watch = XNEW (struct mips_watchpoint);
   new_watch->addr = addr;
   new_watch->len = len;
   new_watch->type = type;
@@ -687,7 +678,7 @@ mips_linux_insert_watchpoint (CORE_ADDR addr, int len, int type,
   watch_mirror = regs;
   retval = write_watchpoint_regs ();
 
-  if (maint_show_dr)
+  if (show_debug_regs)
     mips_show_dr ("insert_watchpoint", addr, len, type);
 
   return retval;
@@ -697,7 +688,9 @@ mips_linux_insert_watchpoint (CORE_ADDR addr, int len, int type,
    Return zero on success.  */
 
 static int
-mips_linux_remove_watchpoint (CORE_ADDR addr, int len, int type,
+mips_linux_remove_watchpoint (struct target_ops *self,
+                             CORE_ADDR addr, int len,
+                             enum target_hw_bp_type type,
                              struct expression *cond)
 {
   int retval;
@@ -734,7 +727,7 @@ mips_linux_remove_watchpoint (CORE_ADDR addr, int len, int type,
 
   retval = write_watchpoint_regs ();
 
-  if (maint_show_dr)
+  if (show_debug_regs)
     mips_show_dr ("remove_watchpoint", addr, len, type);
 
   return retval;
@@ -760,18 +753,16 @@ mips_linux_close (struct target_ops *self)
   current_watches = NULL;
 
   if (super_close)
-    super_close ();
+    super_close (self);
 }
 
-void _initialize_mips_linux_nat (void);
-
 void
 _initialize_mips_linux_nat (void)
 {
   struct target_ops *t;
 
   add_setshow_boolean_cmd ("show-debug-regs", class_maintenance,
-                          &maint_show_dr, _("\
+                          &show_debug_regs, _("\
 Set whether to show variables that mirror the mips debug registers."), _("\
 Show whether to show variables that mirror the mips debug registers."), _("\
 Use \"on\" to enable, \"off\" to disable.\n\
@@ -805,10 +796,4 @@ triggers a breakpoint or watchpoint."),
 
   linux_nat_add_target (t);
   linux_nat_set_new_thread (t, mips_linux_new_thread);
-
-  /* Initialize the standard target descriptions.  */
-  initialize_tdesc_mips_linux ();
-  initialize_tdesc_mips_dsp_linux ();
-  initialize_tdesc_mips64_linux ();
-  initialize_tdesc_mips64_dsp_linux ();
 }
This page took 0.045008 seconds and 4 git commands to generate.