GDB (xrefs)

/tmp/gdb-8.1/gdb/sh-nbsd-nat.c
Go to the documentation of this file.
1 /* Native-dependent code for NetBSD/sh.
2
3 Copyright (C) 2002-2018 Free Software Foundation, Inc.
4
5 Contributed by Wasabi Systems, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #include "defs.h"
23 #include "inferior.h"
24
25 #include <sys/types.h>
26 #include <sys/ptrace.h>
27 #include <machine/reg.h>
28
29 #include "sh-tdep.h"
30 #include "inf-ptrace.h"
31 #include "regcache.h"
32
33
34 /* Determine if PT_GETREGS fetches this register. */
35 #define GETREGS_SUPPLIES(gdbarch, regno) \
36 (((regno) >= R0_REGNUM && (regno) <= (R0_REGNUM + 15)) \
37 || (regno) == gdbarch_pc_regnum (gdbarch) || (regno) == PR_REGNUM \
38 || (regno) == MACH_REGNUM || (regno) == MACL_REGNUM \
39 || (regno) == SR_REGNUM)
40
41 /* Sizeof `struct reg' in <machine/reg.h>. */
42 #define SHNBSD_SIZEOF_GREGS (21 * 4)
43
44 static void
45 shnbsd_fetch_inferior_registers (struct target_ops *ops,
46 struct regcache *regcache, int regno)
47 {
48 pid_t pid = ptid_get_pid (regcache_get_ptid (regcache));
49
50 if (regno == -1 || GETREGS_SUPPLIES (regcache->arch (), regno))
51 {
52 struct reg inferior_registers;
53
54 if (ptrace (PT_GETREGS, pid,
55 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
56 perror_with_name (_("Couldn't get registers"));
57
58 sh_corefile_supply_regset (&sh_corefile_gregset, regcache, regno,
59 (char *) &inferior_registers,
60 SHNBSD_SIZEOF_GREGS);
61
62 if (regno != -1)
63 return;
64 }
65 }
66
67 static void
68 shnbsd_store_inferior_registers (struct target_ops *ops,
69 struct regcache *regcache, int regno)
70 {
71 pid_t pid = ptid_get_pid (regcache_get_ptid (regcache));
72
73 if (regno == -1 || GETREGS_SUPPLIES (regcache->arch (), regno))
74 {
75 struct reg inferior_registers;
76
77 if (ptrace (PT_GETREGS, pid,
78 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
79 perror_with_name (_("Couldn't get registers"));
80
81 sh_corefile_collect_regset (&sh_corefile_gregset, regcache, regno,
82 (char *) &inferior_registers,
83 SHNBSD_SIZEOF_GREGS);
84
85 if (ptrace (PT_SETREGS, pid,
86 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
87 perror_with_name (_("Couldn't set registers"));
88
89 if (regno != -1)
90 return;
91 }
92 }
93
94 void
95 _initialize_shnbsd_nat (void)
96 {
97 struct target_ops *t;
98
99 t = inf_ptrace_target ();
100 t->to_fetch_registers = shnbsd_fetch_inferior_registers;
101 t->to_store_registers = shnbsd_store_inferior_registers;
102 add_target (t);
103 }
add_target
void add_target(struct target_ops *t)
Definition: target.c:395
ptid_get_pid
int ptid_get_pid(const ptid_t &ptid)
Definition: ptid.c:47
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
sh_corefile_supply_regset
void sh_corefile_supply_regset(const struct regset *regset, struct regcache *regcache, int regnum, const void *regs, size_t len)
Definition: sh-tdep.c:2164
regcache_get_ptid
ptid_t regcache_get_ptid(const struct regcache *regcache)
Definition: regcache.c:229
SHNBSD_SIZEOF_GREGS
#define SHNBSD_SIZEOF_GREGS
Definition: sh-nbsd-nat.c:42
GETREGS_SUPPLIES
#define GETREGS_SUPPLIES(gdbarch, regno)
Definition: sh-nbsd-nat.c:35
_
#define _(String)
Definition: gdb_locale.h:35
inf_ptrace_target
struct target_ops * inf_ptrace_target(void)
Definition: inf-ptrace.c:676
defs.h
ptrace
PTRACE_TYPE_RET ptrace()
_initialize_shnbsd_nat
void _initialize_shnbsd_nat(void)
Definition: sh-nbsd-nat.c:95
inf-ptrace.h
target_ops
Definition: target.h:412
regcache.h
inferior.h
shnbsd_fetch_inferior_registers
static void shnbsd_fetch_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regno)
Definition: sh-nbsd-nat.c:45
reg
Definition: regdef.h:22
sh_corefile_collect_regset
void sh_corefile_collect_regset(const struct regset *regset, const struct regcache *regcache, int regnum, void *regs, size_t len)
Definition: sh-tdep.c:2190
sh_corefile_gregset
const struct regset sh_corefile_gregset
Definition: sh-tdep.c:2213
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
regcache::arch
gdbarch * arch() const
Definition: regcache.c:221
shnbsd_store_inferior_registers
static void shnbsd_store_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regno)
Definition: sh-nbsd-nat.c:68
regcache
Definition: regcache.h:232
sh-tdep.h
PTRACE_TYPE_ARG3
#define PTRACE_TYPE_ARG3
Definition: config.h:642
target_ops::to_store_registers
void(* to_store_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:459