gdb/vaxbsd-nat.c - gdb

Functions defined

Source code

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

  2.    Copyright (C) 2004-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 "vax-tdep.h"
  22. #include "inf-ptrace.h"

  23. /* Supply the general-purpose registers stored in GREGS to REGCACHE.  */

  24. static void
  25. vaxbsd_supply_gregset (struct regcache *regcache, const void *gregs)
  26. {
  27.   const gdb_byte *regs = gregs;
  28.   int regnum;

  29.   for (regnum = 0; regnum < VAX_NUM_REGS; regnum++)
  30.     regcache_raw_supply (regcache, regnum, regs + regnum * 4);
  31. }

  32. /* Collect the general-purpose registers from REGCACHE and store them
  33.    in GREGS.  */

  34. static void
  35. vaxbsd_collect_gregset (const struct regcache *regcache,
  36.                         void *gregs, int regnum)
  37. {
  38.   gdb_byte *regs = gregs;
  39.   int i;

  40.   for (i = 0; i <= VAX_NUM_REGS; i++)
  41.     {
  42.       if (regnum == -1 || regnum == i)
  43.         regcache_raw_collect (regcache, i, regs + i * 4);
  44.     }
  45. }


  46. /* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
  47.    for all registers.  */

  48. static void
  49. vaxbsd_fetch_inferior_registers (struct target_ops *ops,
  50.                                  struct regcache *regcache, int regnum)
  51. {
  52.   struct reg regs;

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

  56.   vaxbsd_supply_gregset (regcache, &regs);
  57. }

  58. /* Store register REGNUM back into the inferior.  If REGNUM is -1, do
  59.    this for all registers.  */

  60. static void
  61. vaxbsd_store_inferior_registers (struct target_ops *ops,
  62.                                  struct regcache *regcache, int regnum)
  63. {
  64.   struct reg regs;

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

  68.   vaxbsd_collect_gregset (regcache, &regs, regnum);

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


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

  74. #include <machine/pcb.h>

  75. #include "bsd-kvm.h"

  76. static int
  77. vaxbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
  78. {
  79.   int regnum;

  80.   /* The following is true for OpenBSD 3.5:

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

  83.   /* The stack pointer shouldn't be zero.  */
  84.   if (pcb->KSP == 0)
  85.     return 0;

  86.   for (regnum = VAX_R0_REGNUM; regnum < VAX_AP_REGNUM; regnum++)
  87.     regcache_raw_supply (regcache, regnum, &pcb->R[regnum - VAX_R0_REGNUM]);
  88.   regcache_raw_supply (regcache, VAX_AP_REGNUM, &pcb->AP);
  89.   regcache_raw_supply (regcache, VAX_FP_REGNUM, &pcb->FP);
  90.   regcache_raw_supply (regcache, VAX_SP_REGNUM, &pcb->KSP);
  91.   regcache_raw_supply (regcache, VAX_PC_REGNUM, &pcb->PC);
  92.   regcache_raw_supply (regcache, VAX_PS_REGNUM, &pcb->PSL);

  93.   return 1;
  94. }


  95. /* Provide a prototype to silence -Wmissing-prototypes.  */
  96. void _initialize_vaxbsd_nat (void);

  97. void
  98. _initialize_vaxbsd_nat (void)
  99. {
  100.   struct target_ops *t;

  101.   t = inf_ptrace_target ();
  102.   t->to_fetch_registers = vaxbsd_fetch_inferior_registers;
  103.   t->to_store_registers = vaxbsd_store_inferior_registers;
  104.   add_target (t);

  105.   /* Support debugging kernel virtual memory images.  */
  106.   bsd_kvm_add_target (vaxbsd_supply_pcb);
  107. }