gdb/mipsnbsd-nat.c - gdb

Functions defined

Source code

  1. /* Native-dependent code for MIPS systems running NetBSD.

  2.    Copyright (C) 2000-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "inferior.h"
  16. #include "regcache.h"
  17. #include "target.h"

  18. #include <sys/types.h>
  19. #include <sys/ptrace.h>
  20. #include <machine/reg.h>

  21. #include "mips-tdep.h"
  22. #include "mipsnbsd-tdep.h"
  23. #include "inf-ptrace.h"

  24. /* Determine if PT_GETREGS fetches this register.  */
  25. static int
  26. getregs_supplies (struct gdbarch *gdbarch, int regno)
  27. {
  28.   return ((regno) >= MIPS_ZERO_REGNUM
  29.           && (regno) <= gdbarch_pc_regnum (gdbarch));
  30. }

  31. static void
  32. mipsnbsd_fetch_inferior_registers (struct target_ops *ops,
  33.                                    struct regcache *regcache, int regno)
  34. {
  35.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  36.   if (regno == -1 || getregs_supplies (gdbarch, regno))
  37.     {
  38.       struct reg regs;

  39.       if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
  40.                   (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  41.         perror_with_name (_("Couldn't get registers"));

  42.       mipsnbsd_supply_reg (regcache, (char *) &regs, regno);
  43.       if (regno != -1)
  44.         return;
  45.     }

  46.   if (regno == -1
  47.       || regno >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
  48.     {
  49.       struct fpreg fpregs;

  50.       if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
  51.                   (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
  52.         perror_with_name (_("Couldn't get floating point status"));

  53.       mipsnbsd_supply_fpreg (regcache, (char *) &fpregs, regno);
  54.     }
  55. }

  56. static void
  57. mipsnbsd_store_inferior_registers (struct target_ops *ops,
  58.                                    struct regcache *regcache, int regno)
  59. {
  60.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  61.   if (regno == -1 || getregs_supplies (gdbarch, regno))
  62.     {
  63.       struct reg regs;

  64.       if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
  65.                   (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  66.         perror_with_name (_("Couldn't get registers"));

  67.       mipsnbsd_fill_reg (regcache, (char *) &regs, regno);

  68.       if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
  69.                   (PTRACE_TYPE_ARG3) &regs, 0) == -1)
  70.         perror_with_name (_("Couldn't write registers"));

  71.       if (regno != -1)
  72.         return;
  73.     }

  74.   if (regno == -1
  75.       || regno >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
  76.     {
  77.       struct fpreg fpregs;

  78.       if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
  79.                   (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
  80.         perror_with_name (_("Couldn't get floating point status"));

  81.       mipsnbsd_fill_fpreg (regcache, (char *) &fpregs, regno);

  82.       if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
  83.                   (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
  84.         perror_with_name (_("Couldn't write floating point status"));
  85.     }
  86. }


  87. /* Provide a prototype to silence -Wmissing-prototypes.  */
  88. void _initialize_mipsnbsd_nat (void);

  89. void
  90. _initialize_mipsnbsd_nat (void)
  91. {
  92.   struct target_ops *t;

  93.   t = inf_ptrace_target ();
  94.   t->to_fetch_registers = mipsnbsd_fetch_inferior_registers;
  95.   t->to_store_registers = mipsnbsd_store_inferior_registers;
  96.   add_target (t);
  97. }