gdb/shnbsd-nat.c - gdb

Functions defined

Macros defined

Source code

  1. /* Native-dependent code for NetBSD/sh.

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

  3.    Contributed by Wasabi Systems, Inc.

  4.    This file is part of GDB.

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

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

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

  15. #include "defs.h"
  16. #include "inferior.h"

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

  20. #include "sh-tdep.h"
  21. #include "inf-ptrace.h"
  22. #include "regcache.h"


  23. /* Determine if PT_GETREGS fetches this register.  */
  24. #define GETREGS_SUPPLIES(gdbarch, regno) \
  25.   (((regno) >= R0_REGNUM && (regno) <= (R0_REGNUM + 15)) \
  26. || (regno) == gdbarch_pc_regnum (gdbarch) || (regno) == PR_REGNUM \
  27. || (regno) == MACH_REGNUM || (regno) == MACL_REGNUM \
  28. || (regno) == SR_REGNUM)

  29. /* Sizeof `struct reg' in <machine/reg.h>.  */
  30. #define SHNBSD_SIZEOF_GREGS        (21 * 4)

  31. static void
  32. shnbsd_fetch_inferior_registers (struct target_ops *ops,
  33.                                  struct regcache *regcache, int regno)
  34. {
  35.   if (regno == -1 || GETREGS_SUPPLIES (get_regcache_arch (regcache), regno))
  36.     {
  37.       struct reg inferior_registers;

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

  41.       sh_corefile_supply_regset (&sh_corefile_gregset, regcache, regno,
  42.                                  (char *) &inferior_registers,
  43.                                  SHNBSD_SIZEOF_GREGS);

  44.       if (regno != -1)
  45.         return;
  46.     }
  47. }

  48. static void
  49. shnbsd_store_inferior_registers (struct target_ops *ops,
  50.                                  struct regcache *regcache, int regno)
  51. {
  52.   if (regno == -1 || GETREGS_SUPPLIES (get_regcache_arch (regcache), regno))
  53.     {
  54.       struct reg inferior_registers;

  55.       if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
  56.                   (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
  57.         perror_with_name (_("Couldn't get registers"));

  58.       sh_corefile_collect_regset (&sh_corefile_gregset, regcache, regno,
  59.                                   (char *) &inferior_registers,
  60.                                   SHNBSD_SIZEOF_GREGS);

  61.       if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
  62.                   (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
  63.         perror_with_name (_("Couldn't set registers"));

  64.       if (regno != -1)
  65.         return;
  66.     }
  67. }

  68. /* Provide a prototype to silence -Wmissing-prototypes.  */
  69. void _initialize_shnbsd_nat (void);

  70. void
  71. _initialize_shnbsd_nat (void)
  72. {
  73.   struct target_ops *t;

  74.   t = inf_ptrace_target ();
  75.   t->to_fetch_registers = shnbsd_fetch_inferior_registers;
  76.   t->to_store_registers = shnbsd_store_inferior_registers;
  77.   add_target (t);
  78. }