GDB (xrefs)

/tmp/gdb-8.1/gdb/ppc-fbsd-nat.c
Go to the documentation of this file.
1 /* Native-dependent code for PowerPC's running FreeBSD, for GDB.
2
3 Copyright (C) 2013-2018 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 "gdbcore.h"
22 #include "inferior.h"
23 #include "regcache.h"
24
25 #include <sys/types.h>
26 #include <sys/procfs.h>
27 #include <sys/ptrace.h>
28 #include <sys/signal.h>
29 #include <machine/frame.h>
30 #include <machine/pcb.h>
31 #include <machine/reg.h>
32
33 #include "fbsd-nat.h"
34 #include "gregset.h"
35 #include "ppc-tdep.h"
36 #include "ppc-fbsd-tdep.h"
37 #include "inf-ptrace.h"
38 #include "bsd-kvm.h"
39
40 /* Fill GDB's register array with the general-purpose register values
41 in *GREGSETP. */
42
43 void
44 supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
45 {
46 const struct regset *regset = ppc_fbsd_gregset (sizeof (long));
47
48 ppc_supply_gregset (regset, regcache, -1, gregsetp, sizeof (*gregsetp));
49 }
50
51 /* Fill register REGNO (if a gpr) in *GREGSETP with the value in GDB's
52 register array. If REGNO is -1 do it for all registers. */
53
54 void
55 fill_gregset (const struct regcache *regcache,
56 gdb_gregset_t *gregsetp, int regno)
57 {
58 const struct regset *regset = ppc_fbsd_gregset (sizeof (long));
59
60 if (regno == -1)
61 memset (gregsetp, 0, sizeof (*gregsetp));
62 ppc_collect_gregset (regset, regcache, regno, gregsetp, sizeof (*gregsetp));
63 }
64
65 /* Fill GDB's register array with the floating-point register values
66 in *FPREGSETP. */
67
68 void
69 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t * fpregsetp)
70 {
71 const struct regset *regset = ppc_fbsd_fpregset ();
72
73 ppc_supply_fpregset (regset, regcache, -1,
74 fpregsetp, sizeof (*fpregsetp));
75 }
76
77 /* Fill register REGNO in *FGREGSETP with the value in GDB's
78 register array. If REGNO is -1 do it for all registers. */
79
80 void
81 fill_fpregset (const struct regcache *regcache,
82 gdb_fpregset_t *fpregsetp, int regno)
83 {
84 const struct regset *regset = ppc_fbsd_fpregset ();
85
86 ppc_collect_fpregset (regset, regcache, regno,
87 fpregsetp, sizeof (*fpregsetp));
88 }
89
90 /* Returns true if PT_GETFPREGS fetches this register. */
91
92 static int
93 getfpregs_supplies (struct gdbarch *gdbarch, int regno)
94 {
95 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
96
97 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
98 point registers. Traditionally, GDB's register set has still
99 listed the floating point registers for such machines, so this
100 code is harmless. However, the new E500 port actually omits the
101 floating point registers entirely from the register set --- they
102 don't even have register numbers assigned to them.
103
104 It's not clear to me how best to update this code, so this assert
105 will alert the first person to encounter the NetBSD/E500
106 combination to the problem. */
107
108 gdb_assert (ppc_floating_point_unit_p (gdbarch));
109
110 return ((regno >= tdep->ppc_fp0_regnum
111 && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)
112 || regno == tdep->ppc_fpscr_regnum);
113 }
114
115 /* Fetch register REGNO from the child process. If REGNO is -1, do it
116 for all registers. */
117
118 static void
119 ppcfbsd_fetch_inferior_registers (struct target_ops *ops,
120 struct regcache *regcache, int regno)
121 {
122 gdb_gregset_t regs;
123 pid_t pid = ptid_get_lwp (regcache_get_ptid (regcache));
124
125 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
126 perror_with_name (_("Couldn't get registers"));
127
128 supply_gregset (regcache, &regs);
129
130 if (regno == -1 || getfpregs_supplies (regcache->arch (), regno))
131 {
132 const struct regset *fpregset = ppc_fbsd_fpregset ();
133 gdb_fpregset_t fpregs;
134
135 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
136 perror_with_name (_("Couldn't get FP registers"));
137
138 ppc_supply_fpregset (fpregset, regcache, regno, &fpregs, sizeof fpregs);
139 }
140 }
141
142 /* Store register REGNO back into the child process. If REGNO is -1,
143 do this for all registers. */
144
145 static void
146 ppcfbsd_store_inferior_registers (struct target_ops *ops,
147 struct regcache *regcache, int regno)
148 {
149 gdb_gregset_t regs;
150 pid_t pid = ptid_get_lwp (regcache_get_ptid (regcache));
151
152 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
153 perror_with_name (_("Couldn't get registers"));
154
155 fill_gregset (regcache, &regs, regno);
156
157 if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
158 perror_with_name (_("Couldn't write registers"));
159
160 if (regno == -1 || getfpregs_supplies (regcache->arch (), regno))
161 {
162 gdb_fpregset_t fpregs;
163
164 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
165 perror_with_name (_("Couldn't get FP registers"));
166
167 fill_fpregset (regcache, &fpregs, regno);
168
169 if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
170 perror_with_name (_("Couldn't set FP registers"));
171 }
172 }
173
174 /* Architecture specific function that reconstructs the
175 register state from PCB (Process Control Block) and supplies it
176 to REGCACHE. */
177
178 static int
179 ppcfbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
180 {
181 struct gdbarch *gdbarch = regcache->arch ();
182 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
183 int i, regnum;
184
185 /* The stack pointer shouldn't be zero. */
186 if (pcb->pcb_sp == 0)
187 return 0;
188
189 regcache_raw_supply (regcache, gdbarch_sp_regnum (gdbarch), &pcb->pcb_sp);
190 regcache_raw_supply (regcache, tdep->ppc_cr_regnum, &pcb->pcb_cr);
191 regcache_raw_supply (regcache, tdep->ppc_lr_regnum, &pcb->pcb_lr);
192 for (i = 0, regnum = tdep->ppc_gp0_regnum + 14; i < 20; i++, regnum++)
193 regcache_raw_supply (regcache, regnum, &pcb->pcb_context[i]);
194
195 return 1;
196 }
197
198 void
199 _initialize_ppcfbsd_nat (void)
200 {
201 struct target_ops *t;
202
203 /* Add in local overrides. */
204 t = inf_ptrace_target ();
205 t->to_fetch_registers = ppcfbsd_fetch_inferior_registers;
206 t->to_store_registers = ppcfbsd_store_inferior_registers;
207 fbsd_nat_add_target (t);
208
209 /* Support debugging kernel virtual memory images. */
210 bsd_kvm_add_target (ppcfbsd_supply_pcb);
211 }
gdbarch
Definition: gdbarch.c:127
fbsd_nat_add_target
void fbsd_nat_add_target(struct target_ops *t)
Definition: fbsd-nat.c:1180
pid
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
Definition: gnu-nat.c:1824
fill_fpregset
void fill_fpregset(const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regno)
Definition: ppc-fbsd-nat.c:81
gdbarch_tdep::ppc_lr_regnum
int ppc_lr_regnum
Definition: ppc-tdep.h:231
ppc_num_fprs
Definition: ppc-tdep.h:284
ppc_supply_fpregset
void ppc_supply_fpregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *fpregs, size_t len)
Definition: rs6000-tdep.c:561
gdbarch_tdep::ppc_fpscr_regnum
int ppc_fpscr_regnum
Definition: ppc-tdep.h:241
regcache_get_ptid
ptid_t regcache_get_ptid(const struct regcache *regcache)
Definition: regcache.c:229
ppc-tdep.h
fill_gregset
void fill_gregset(const struct regcache *regcache, gdb_gregset_t *gregsetp, int regno)
Definition: ppc-fbsd-nat.c:55
memset
void * memset(T *s, int c, size_t n)=delete
gdbarch_tdep
Definition: aarch64-tdep.h:55
_
#define _(String)
Definition: gdb_locale.h:35
inf_ptrace_target
struct target_ops * inf_ptrace_target(void)
Definition: inf-ptrace.c:676
ppc_fbsd_fpregset
const struct regset * ppc_fbsd_fpregset(void)
Definition: ppc-fbsd-tdep.c:127
defs.h
gdbarch_tdep::ppc_cr_regnum
int ppc_cr_regnum
Definition: ppc-tdep.h:230
gdbarch_tdep
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1491
ptrace
PTRACE_TYPE_RET ptrace()
ppc_fbsd_gregset
const struct regset * ppc_fbsd_gregset(int wordsize)
Definition: ppc-fbsd-tdep.c:121
regset
Definition: regset.h:34
ppc_collect_gregset
void ppc_collect_gregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *gregs, size_t len)
Definition: rs6000-tdep.c:675
inf-ptrace.h
gdbarch_sp_regnum
int gdbarch_sp_regnum(struct gdbarch *gdbarch)
Definition: gdbarch.c:2146
target_ops
Definition: target.h:412
gdb_gregset_t
GDB_GREGSET_T gdb_gregset_t
Definition: gregset.h:34
regcache.h
fbsd-nat.h
bsd-kvm.h
gdbarch_tdep::ppc_gp0_regnum
int ppc_gp0_regnum
Definition: ppc-tdep.h:227
gdb_fpregset_t
GDB_FPREGSET_T gdb_fpregset_t
Definition: gregset.h:35
inferior.h
ppcfbsd_store_inferior_registers
static void ppcfbsd_store_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regno)
Definition: ppc-fbsd-nat.c:146
ppc_collect_fpregset
void ppc_collect_fpregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *fpregs, size_t len)
Definition: rs6000-tdep.c:726
regnum
int regnum
Definition: aarch64-tdep.c:77
ptid_get_lwp
long ptid_get_lwp(const ptid_t &ptid)
Definition: ptid.c:55
gregset.h
ppcfbsd_supply_pcb
static int ppcfbsd_supply_pcb(struct regcache *regcache, struct pcb *pcb)
Definition: ppc-fbsd-nat.c:179
gdb_assert
#define gdb_assert(expr)
Definition: gdb_assert.h:32
ppc-fbsd-tdep.h
supply_fpregset
void supply_fpregset(struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
Definition: ppc-fbsd-nat.c:69
target_ops::to_fetch_registers
void(* to_fetch_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_IGNORE()
Definition: target.h:457
perror_with_name
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
Definition: utils.c:692
gdbcore.h
regcache::arch
gdbarch * arch() const
Definition: regcache.c:221
gdbarch_tdep::regs
struct m32c_reg regs[M32C_MAX_NUM_REGS]
Definition: m32c-tdep.c:110
regcache_raw_supply
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1004
regcache
Definition: regcache.h:232
PTRACE_TYPE_ARG3
#define PTRACE_TYPE_ARG3
Definition: config.h:642
bsd_kvm_add_target
void bsd_kvm_add_target(int(*supply_pcb)(struct regcache *, struct pcb *))
Definition: bsd-kvm.c:354
target_ops::to_store_registers
void(* to_store_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:459
ppcfbsd_fetch_inferior_registers
static void ppcfbsd_fetch_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regno)
Definition: ppc-fbsd-nat.c:119
ppc_floating_point_unit_p
int ppc_floating_point_unit_p(struct gdbarch *gdbarch)
Definition: rs6000-tdep.c:218
supply_gregset
void supply_gregset(struct regcache *regcache, const gdb_gregset_t *gregsetp)
Definition: ppc-fbsd-nat.c:44
gdbarch_tdep::ppc_fp0_regnum
int ppc_fp0_regnum
Definition: ppc-tdep.h:240
ppc_supply_gregset
void ppc_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
Definition: rs6000-tdep.c:511
getfpregs_supplies
static int getfpregs_supplies(struct gdbarch *gdbarch, int regno)
Definition: ppc-fbsd-nat.c:93
_initialize_ppcfbsd_nat
void _initialize_ppcfbsd_nat(void)
Definition: ppc-fbsd-nat.c:199