GDB (xrefs)

/tmp/gdb-8.1/gdb/aarch64-fbsd-nat.c
Go to the documentation of this file.
1 /* Native-dependent code for FreeBSD/aarch64.
2
3 Copyright (C) 2017-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 "target.h"
22
23 #include <sys/types.h>
24 #include <sys/ptrace.h>
25 #include <machine/reg.h>
26
27 #include "fbsd-nat.h"
28 #include "aarch64-tdep.h"
29 #include "aarch64-fbsd-tdep.h"
30 #include "inf-ptrace.h"
31
32 /* Determine if PT_GETREGS fetches REGNUM. */
33
34 static bool
35 getregs_supplies (struct gdbarch *gdbarch, int regnum)
36 {
37 return (regnum >= AARCH64_X0_REGNUM && regnum <= AARCH64_CPSR_REGNUM);
38 }
39
40 /* Determine if PT_GETFPREGS fetches REGNUM. */
41
42 static bool
43 getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
44 {
45 return (regnum >= AARCH64_V0_REGNUM && regnum <= AARCH64_FPCR_REGNUM);
46 }
47
48 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
49 for all registers. */
50
51 static void
52 aarch64_fbsd_fetch_inferior_registers (struct target_ops *ops,
53 struct regcache *regcache, int regnum)
54 {
55 pid_t pid = get_ptrace_pid (regcache_get_ptid (regcache));
56
57 struct gdbarch *gdbarch = regcache->arch ();
58 if (regnum == -1 || getregs_supplies (gdbarch, regnum))
59 {
60 struct reg regs;
61
62 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
63 perror_with_name (_("Couldn't get registers"));
64
65 regcache->supply_regset (&aarch64_fbsd_gregset, regnum, &regs,
66 sizeof (regs));
67 }
68
69 if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
70 {
71 struct fpreg fpregs;
72
73 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
74 perror_with_name (_("Couldn't get floating point status"));
75
76 regcache->supply_regset (&aarch64_fbsd_fpregset, regnum, &fpregs,
77 sizeof (fpregs));
78 }
79 }
80
81 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
82 this for all registers. */
83
84 static void
85 aarch64_fbsd_store_inferior_registers (struct target_ops *ops,
86 struct regcache *regcache, int regnum)
87 {
88 pid_t pid = get_ptrace_pid (regcache_get_ptid (regcache));
89
90 struct gdbarch *gdbarch = regcache->arch ();
91 if (regnum == -1 || getregs_supplies (gdbarch, regnum))
92 {
93 struct reg regs;
94
95 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
96 perror_with_name (_("Couldn't get registers"));
97
98 regcache->collect_regset (&aarch64_fbsd_gregset, regnum, &regs,
99 sizeof (regs));
100
101 if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
102 perror_with_name (_("Couldn't write registers"));
103 }
104
105 if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
106 {
107 struct fpreg fpregs;
108
109 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
110 perror_with_name (_("Couldn't get floating point status"));
111
112 regcache->collect_regset (&aarch64_fbsd_fpregset, regnum, &fpregs,
113 sizeof (fpregs));
114
115 if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
116 perror_with_name (_("Couldn't write floating point status"));
117 }
118 }
119
120 void
121 _initialize_aarch64_fbsd_nat (void)
122 {
123 struct target_ops *t;
124
125 t = inf_ptrace_target ();
126 t->to_fetch_registers = aarch64_fbsd_fetch_inferior_registers;
127 t->to_store_registers = aarch64_fbsd_store_inferior_registers;
128 fbsd_nat_add_target (t);
129 }
gdbarch
Definition: gdbarch.c:127
_initialize_aarch64_fbsd_nat
void _initialize_aarch64_fbsd_nat(void)
Definition: aarch64-fbsd-nat.c:121
getregs_supplies
static bool getregs_supplies(struct gdbarch *gdbarch, int regnum)
Definition: aarch64-fbsd-nat.c:35
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
regcache::supply_regset
void supply_regset(const struct regset *regset, int regnum, const void *buf, size_t size)
Definition: regcache.c:1200
AARCH64_FPCR_REGNUM
Definition: aarch64.h:39
AARCH64_CPSR_REGNUM
Definition: aarch64.h:35
regcache_get_ptid
ptid_t regcache_get_ptid(const struct regcache *regcache)
Definition: regcache.c:229
_
#define _(String)
Definition: gdb_locale.h:35
inf_ptrace_target
struct target_ops * inf_ptrace_target(void)
Definition: inf-ptrace.c:676
defs.h
aarch64-tdep.h
ptrace
PTRACE_TYPE_RET ptrace()
getfpregs_supplies
static bool getfpregs_supplies(struct gdbarch *gdbarch, int regnum)
Definition: aarch64-fbsd-nat.c:43
inf-ptrace.h
target_ops
Definition: target.h:412
fbsd-nat.h
regnum
int regnum
Definition: aarch64-tdep.c:77
regcache::collect_regset
void collect_regset(const struct regset *regset, int regnum, void *buf, size_t size) const
Definition: regcache.c:1219
aarch64_fbsd_fpregset
const struct regset aarch64_fbsd_fpregset
Definition: aarch64-fbsd-tdep.c:158
reg
Definition: regdef.h:22
aarch64_fbsd_gregset
const struct regset aarch64_fbsd_gregset
Definition: aarch64-fbsd-tdep.c:152
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
AARCH64_V0_REGNUM
Definition: aarch64.h:36
regcache::arch
gdbarch * arch() const
Definition: regcache.c:221
target.h
aarch64_fbsd_store_inferior_registers
static void aarch64_fbsd_store_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regnum)
Definition: aarch64-fbsd-nat.c:85
regcache
Definition: regcache.h:232
PTRACE_TYPE_ARG3
#define PTRACE_TYPE_ARG3
Definition: config.h:642
get_ptrace_pid
pid_t get_ptrace_pid(ptid_t ptid)
Definition: inf-ptrace.c:320
target_ops::to_store_registers
void(* to_store_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:459
aarch64_fbsd_fetch_inferior_registers
static void aarch64_fbsd_fetch_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regnum)
Definition: aarch64-fbsd-nat.c:52
aarch64-fbsd-tdep.h
AARCH64_X0_REGNUM
Definition: aarch64.h:30