GDB (xrefs)
/tmp/gdb-7.10/gdb/alphabsd-nat.c
Go to the documentation of this file.
1 /* Native-dependent code for Alpha BSD's.
2 
3  Copyright (C) 2000-2015 Free Software Foundation, Inc.
4 
5  This file is part of GDB.
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #include "defs.h"
21 #include "inferior.h"
22 #include "regcache.h"
23 
24 #include "alpha-tdep.h"
25 #include "alphabsd-tdep.h"
26 #include "inf-ptrace.h"
27 
28 #include <sys/types.h>
29 #include <sys/ptrace.h>
30 #include <machine/reg.h>
31 
32 #ifdef HAVE_SYS_PROCFS_H
33 #include <sys/procfs.h>
34 #endif
35 
36 #ifndef HAVE_GREGSET_T
37 typedef struct reg gregset_t;
38 #endif
39 
40 #ifndef HAVE_FPREGSET_T
41 typedef struct fpreg fpregset_t;
42 #endif
43 
44 #include "gregset.h"
45 
46 /* Provide *regset() wrappers around the generic Alpha BSD register
47  supply/fill routines. */
48 
49 void
50 supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
51 {
52  alphabsd_supply_reg (regcache, (const char *) gregsetp, -1);
53 }
54 
55 void
56 fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno)
57 {
58  alphabsd_fill_reg (regcache, (char *) gregsetp, regno);
59 }
60 
61 void
62 supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
63 {
64  alphabsd_supply_fpreg (regcache, (const char *) fpregsetp, -1);
65 }
66 
67 void
69  fpregset_t *fpregsetp, int regno)
70 {
71  alphabsd_fill_fpreg (regcache, (char *) fpregsetp, regno);
72 }
73 
74 /* Determine if PT_GETREGS fetches this register. */
75 
76 static int
77 getregs_supplies (int regno)
78 {
79  return ((regno >= ALPHA_V0_REGNUM && regno <= ALPHA_ZERO_REGNUM)
80  || regno >= ALPHA_PC_REGNUM);
81 }
82 
83 /* Fetch register REGNO from the inferior. If REGNO is -1, do this
84  for all registers (including the floating point registers). */
85 
86 static void
88  struct regcache *regcache, int regno)
89 {
90  if (regno == -1 || getregs_supplies (regno))
91  {
92  struct reg gregs;
93 
94  if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
95  (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
96  perror_with_name (_("Couldn't get registers"));
97 
98  alphabsd_supply_reg (regcache, (char *) &gregs, regno);
99  if (regno != -1)
100  return;
101  }
102 
103  if (regno == -1
104  || regno >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
105  {
106  struct fpreg fpregs;
107 
108  if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
109  (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
110  perror_with_name (_("Couldn't get floating point status"));
111 
112  alphabsd_supply_fpreg (regcache, (char *) &fpregs, regno);
113  }
114 }
115 
116 /* Store register REGNO back into the inferior. If REGNO is -1, do
117  this for all registers (including the floating point registers). */
118 
119 static void
121  struct regcache *regcache, int regno)
122 {
123  if (regno == -1 || getregs_supplies (regno))
124  {
125  struct reg gregs;
126  if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
127  (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
128  perror_with_name (_("Couldn't get registers"));
129 
130  alphabsd_fill_reg (regcache, (char *) &gregs, regno);
131 
132  if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
133  (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
134  perror_with_name (_("Couldn't write registers"));
135 
136  if (regno != -1)
137  return;
138  }
139 
140  if (regno == -1
141  || regno >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
142  {
143  struct fpreg fpregs;
144 
145  if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
146  (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
147  perror_with_name (_("Couldn't get floating point status"));
148 
149  alphabsd_fill_fpreg (regcache, (char *) &fpregs, regno);
150 
151  if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
152  (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
153  perror_with_name (_("Couldn't write floating point status"));
154  }
155 }
156 
157 
158 /* Support for debugging kernel virtual memory images. */
159 
160 #include <sys/signal.h>
161 #include <machine/pcb.h>
162 
163 #include "bsd-kvm.h"
164 
165 static int
166 alphabsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
167 {
168  int regnum;
169 
170  /* The following is true for OpenBSD 3.9:
171 
172  The pcb contains the register state at the context switch inside
173  cpu_switch(). */
174 
175  /* The stack pointer shouldn't be zero. */
176  if (pcb->pcb_hw.apcb_ksp == 0)
177  return 0;
178 
179  regcache_raw_supply (regcache, ALPHA_SP_REGNUM, &pcb->pcb_hw.apcb_ksp);
180 
181  for (regnum = ALPHA_S0_REGNUM; regnum < ALPHA_A0_REGNUM; regnum++)
182  regcache_raw_supply (regcache, regnum,
183  &pcb->pcb_context[regnum - ALPHA_S0_REGNUM]);
184  regcache_raw_supply (regcache, ALPHA_RA_REGNUM, &pcb->pcb_context[7]);
185 
186  return 1;
187 }
188 
189 
190 /* Provide a prototype to silence -Wmissing-prototypes. */
191 void _initialize_alphabsd_nat (void);
192 
193 void
195 {
196  struct target_ops *t;
197 
198  t = inf_ptrace_target ();
201  add_target (t);
202 
203  /* Support debugging kernel virtual memory images. */
205 }
void add_target(struct target_ops *t)
Definition: target.c:395
void _initialize_alphabsd_nat(void)
Definition: alphabsd-nat.c:194
void alphabsd_fill_fpreg(const struct regcache *regcache, char *fpregs, int regno)
Definition: alphabsd-tdep.c:52
struct gdbarch * get_regcache_arch(const struct regcache *regcache)
Definition: regcache.c:297
#define ALPHA_A0_REGNUM
Definition: alpha-tdep.h:40
void alphabsd_fill_reg(const struct regcache *regcache, char *regs, int regno)
Definition: alphabsd-tdep.c:37
#define ALPHA_SP_REGNUM
Definition: alpha-tdep.h:45
#define _(String)
Definition: gdb_locale.h:40
struct target_ops * inf_ptrace_target(void)
Definition: inf-ptrace.c:668
PTRACE_TYPE_RET ptrace()
static int getregs_supplies(int regno)
Definition: alphabsd-nat.c:77
static int alphabsd_supply_pcb(struct regcache *regcache, struct pcb *pcb)
Definition: alphabsd-nat.c:166
#define ALPHA_PC_REGNUM
Definition: alpha-tdep.h:50
void supply_fpregset(struct regcache *regcache, const fpregset_t *fpregsetp)
Definition: alphabsd-nat.c:62
#define ALPHA_V0_REGNUM
Definition: alpha-tdep.h:36
#define ALPHA_RA_REGNUM
Definition: alpha-tdep.h:42
static void alphabsd_store_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regno)
Definition: alphabsd-nat.c:120
int regnum
Definition: aarch64-tdep.c:69
#define ALPHA_S0_REGNUM
Definition: alpha-tdep.h:38
Definition: regdef.h:22
#define ALPHA_ZERO_REGNUM
Definition: alpha-tdep.h:46
int ptid_get_pid(ptid_t ptid)
Definition: ptid.c:52
void fill_fpregset(const struct regcache *regcache, fpregset_t *fpregsetp, int regno)
Definition: alphabsd-nat.c:68
void(* to_fetch_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_IGNORE()
Definition: target.h:472
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
Definition: utils.c:979
int gdbarch_fp0_regnum(struct gdbarch *gdbarch)
Definition: gdbarch.c:2032
static void alphabsd_fetch_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regno)
Definition: alphabsd-nat.c:87
void alphabsd_supply_fpreg(struct regcache *regcache, const char *fpregs, int regno)
Definition: alphabsd-tdep.c:44
ptid_t inferior_ptid
Definition: infcmd.c:124
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1041
#define PTRACE_TYPE_ARG3
Definition: config.h:658
void bsd_kvm_add_target(int(*supply_pcb)(struct regcache *, struct pcb *))
Definition: bsd-kvm.c:351
void fill_gregset(const struct regcache *regcache, gregset_t *gregsetp, int regno)
Definition: alphabsd-nat.c:56
void(* to_store_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:474
struct fpreg fpregset_t
Definition: alphabsd-nat.c:41
void supply_gregset(struct regcache *regcache, const gregset_t *gregsetp)
Definition: alphabsd-nat.c:50
void alphabsd_supply_reg(struct regcache *regcache, const char *regs, int regno)
Definition: alphabsd-tdep.c:30