gdb/alphabsd-nat.c - gdb

Data types defined

Functions defined

Source code

  1. /* Native-dependent code for Alpha BSD's.

  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 "alpha-tdep.h"
  18. #include "alphabsd-tdep.h"
  19. #include "inf-ptrace.h"

  20. #include <sys/types.h>
  21. #include <sys/ptrace.h>
  22. #include <machine/reg.h>

  23. #ifdef HAVE_SYS_PROCFS_H
  24. #include <sys/procfs.h>
  25. #endif

  26. #ifndef HAVE_GREGSET_T
  27. typedef struct reg gregset_t;
  28. #endif

  29. #ifndef HAVE_FPREGSET_T
  30. typedef struct fpreg fpregset_t;
  31. #endif

  32. #include "gregset.h"

  33. /* Provide *regset() wrappers around the generic Alpha BSD register
  34.    supply/fill routines.  */

  35. void
  36. supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
  37. {
  38.   alphabsd_supply_reg (regcache, (const char *) gregsetp, -1);
  39. }

  40. void
  41. fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno)
  42. {
  43.   alphabsd_fill_reg (regcache, (char *) gregsetp, regno);
  44. }

  45. void
  46. supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
  47. {
  48.   alphabsd_supply_fpreg (regcache, (const char *) fpregsetp, -1);
  49. }

  50. void
  51. fill_fpregset (const struct regcache *regcache,
  52.                fpregset_t *fpregsetp, int regno)
  53. {
  54.   alphabsd_fill_fpreg (regcache, (char *) fpregsetp, regno);
  55. }

  56. /* Determine if PT_GETREGS fetches this register.  */

  57. static int
  58. getregs_supplies (int regno)
  59. {
  60.   return ((regno >= ALPHA_V0_REGNUM && regno <= ALPHA_ZERO_REGNUM)
  61.           || regno >= ALPHA_PC_REGNUM);
  62. }

  63. /* Fetch register REGNO from the inferior.  If REGNO is -1, do this
  64.    for all registers (including the floating point registers).  */

  65. static void
  66. alphabsd_fetch_inferior_registers (struct target_ops *ops,
  67.                                    struct regcache *regcache, int regno)
  68. {
  69.   if (regno == -1 || getregs_supplies (regno))
  70.     {
  71.       struct reg gregs;

  72.       if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
  73.                   (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
  74.         perror_with_name (_("Couldn't get registers"));

  75.       alphabsd_supply_reg (regcache, (char *) &gregs, regno);
  76.       if (regno != -1)
  77.         return;
  78.     }

  79.   if (regno == -1
  80.       || regno >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
  81.     {
  82.       struct fpreg fpregs;

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

  86.       alphabsd_supply_fpreg (regcache, (char *) &fpregs, regno);
  87.     }
  88. }

  89. /* Store register REGNO back into the inferior.  If REGNO is -1, do
  90.    this for all registers (including the floating point registers).  */

  91. static void
  92. alphabsd_store_inferior_registers (struct target_ops *ops,
  93.                                    struct regcache *regcache, int regno)
  94. {
  95.   if (regno == -1 || getregs_supplies (regno))
  96.     {
  97.       struct reg gregs;
  98.       if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
  99.                   (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
  100.         perror_with_name (_("Couldn't get registers"));

  101.       alphabsd_fill_reg (regcache, (char *) &gregs, regno);

  102.       if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
  103.                   (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
  104.         perror_with_name (_("Couldn't write registers"));

  105.       if (regno != -1)
  106.         return;
  107.     }

  108.   if (regno == -1
  109.       || regno >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
  110.     {
  111.       struct fpreg fpregs;

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

  115.       alphabsd_fill_fpreg (regcache, (char *) &fpregs, regno);

  116.       if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
  117.                   (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
  118.         perror_with_name (_("Couldn't write floating point status"));
  119.     }
  120. }


  121. /* Support for debugging kernel virtual memory images.  */

  122. #include <sys/signal.h>
  123. #include <machine/pcb.h>

  124. #include "bsd-kvm.h"

  125. static int
  126. alphabsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
  127. {
  128.   int regnum;

  129.   /* The following is true for OpenBSD 3.9:

  130.      The pcb contains the register state at the context switch inside
  131.      cpu_switch().  */

  132.   /* The stack pointer shouldn't be zero.  */
  133.   if (pcb->pcb_hw.apcb_ksp == 0)
  134.     return 0;

  135.   regcache_raw_supply (regcache, ALPHA_SP_REGNUM, &pcb->pcb_hw.apcb_ksp);

  136.   for (regnum = ALPHA_S0_REGNUM; regnum < ALPHA_A0_REGNUM; regnum++)
  137.     regcache_raw_supply (regcache, regnum,
  138.                          &pcb->pcb_context[regnum - ALPHA_S0_REGNUM]);
  139.   regcache_raw_supply (regcache, ALPHA_RA_REGNUM, &pcb->pcb_context[7]);

  140.   return 1;
  141. }


  142. /* Provide a prototype to silence -Wmissing-prototypes.  */
  143. void _initialize_alphabsd_nat (void);

  144. void
  145. _initialize_alphabsd_nat (void)
  146. {
  147.   struct target_ops *t;

  148.   t = inf_ptrace_target ();
  149.   t->to_fetch_registers = alphabsd_fetch_inferior_registers;
  150.   t->to_store_registers = alphabsd_store_inferior_registers;
  151.   add_target (t);

  152.   /* Support debugging kernel virtual memory images.  */
  153.   bsd_kvm_add_target (alphabsd_supply_pcb);
  154. }