GDB (API)
/home/stan/gdb/src/gdb/vaxbsd-nat.c
Go to the documentation of this file.
00001 /* Native-dependent code for modern VAX BSD's.
00002 
00003    Copyright (C) 2004-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "inferior.h"
00022 #include "regcache.h"
00023 #include "target.h"
00024 
00025 #include <sys/types.h>
00026 #include <sys/ptrace.h>
00027 #include <machine/reg.h>
00028 
00029 #include "vax-tdep.h"
00030 #include "inf-ptrace.h"
00031 
00032 /* Supply the general-purpose registers stored in GREGS to REGCACHE.  */
00033 
00034 static void
00035 vaxbsd_supply_gregset (struct regcache *regcache, const void *gregs)
00036 {
00037   const gdb_byte *regs = gregs;
00038   int regnum;
00039 
00040   for (regnum = 0; regnum < VAX_NUM_REGS; regnum++)
00041     regcache_raw_supply (regcache, regnum, regs + regnum * 4);
00042 }
00043 
00044 /* Collect the general-purpose registers from REGCACHE and store them
00045    in GREGS.  */
00046 
00047 static void
00048 vaxbsd_collect_gregset (const struct regcache *regcache,
00049                         void *gregs, int regnum)
00050 {
00051   gdb_byte *regs = gregs;
00052   int i;
00053 
00054   for (i = 0; i <= VAX_NUM_REGS; i++)
00055     {
00056       if (regnum == -1 || regnum == i)
00057         regcache_raw_collect (regcache, i, regs + i * 4);
00058     }
00059 }
00060 
00061 
00062 /* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
00063    for all registers.  */
00064 
00065 static void
00066 vaxbsd_fetch_inferior_registers (struct target_ops *ops,
00067                                  struct regcache *regcache, int regnum)
00068 {
00069   struct reg regs;
00070 
00071   if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
00072               (PTRACE_TYPE_ARG3) &regs, 0) == -1)
00073     perror_with_name (_("Couldn't get registers"));
00074 
00075   vaxbsd_supply_gregset (regcache, &regs);
00076 }
00077 
00078 /* Store register REGNUM back into the inferior.  If REGNUM is -1, do
00079    this for all registers.  */
00080 
00081 static void
00082 vaxbsd_store_inferior_registers (struct target_ops *ops,
00083                                  struct regcache *regcache, int regnum)
00084 {
00085   struct reg regs;
00086 
00087   if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
00088               (PTRACE_TYPE_ARG3) &regs, 0) == -1)
00089     perror_with_name (_("Couldn't get registers"));
00090 
00091   vaxbsd_collect_gregset (regcache, &regs, regnum);
00092 
00093   if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
00094               (PTRACE_TYPE_ARG3) &regs, 0) == -1)
00095     perror_with_name (_("Couldn't write registers"));
00096 }
00097 
00098 
00099 /* Support for debugging kernel virtual memory images.  */
00100 
00101 #include <sys/types.h>
00102 #include <machine/pcb.h>
00103 
00104 #include "bsd-kvm.h"
00105 
00106 static int
00107 vaxbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
00108 {
00109   int regnum;
00110 
00111   /* The following is true for OpenBSD 3.5:
00112 
00113      The pcb contains the register state at the context switch inside
00114      cpu_switch().  */
00115 
00116   /* The stack pointer shouldn't be zero.  */
00117   if (pcb->KSP == 0)
00118     return 0;
00119 
00120   for (regnum = VAX_R0_REGNUM; regnum < VAX_AP_REGNUM; regnum++)
00121     regcache_raw_supply (regcache, regnum, &pcb->R[regnum - VAX_R0_REGNUM]);
00122   regcache_raw_supply (regcache, VAX_AP_REGNUM, &pcb->AP);
00123   regcache_raw_supply (regcache, VAX_FP_REGNUM, &pcb->FP);
00124   regcache_raw_supply (regcache, VAX_SP_REGNUM, &pcb->KSP);
00125   regcache_raw_supply (regcache, VAX_PC_REGNUM, &pcb->PC);
00126   regcache_raw_supply (regcache, VAX_PS_REGNUM, &pcb->PSL);
00127 
00128   return 1;
00129 }
00130 
00131 
00132 /* Provide a prototype to silence -Wmissing-prototypes.  */
00133 void _initialize_vaxbsd_nat (void);
00134 
00135 void
00136 _initialize_vaxbsd_nat (void)
00137 {
00138   struct target_ops *t;
00139 
00140   t = inf_ptrace_target ();
00141   t->to_fetch_registers = vaxbsd_fetch_inferior_registers;
00142   t->to_store_registers = vaxbsd_store_inferior_registers;
00143   add_target (t);
00144 
00145   /* Support debugging kernel virtual memory images.  */
00146   bsd_kvm_add_target (vaxbsd_supply_pcb);
00147 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines