GDB (xrefs)
/tmp/gdb-7.10/gdb/shnbsd-nat.c
Go to the documentation of this file.
1 /* Native-dependent code for NetBSD/sh.
2 
3  Copyright (C) 2002-2015 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
46  struct regcache *regcache, int regno)
47 {
48  if (regno == -1 || GETREGS_SUPPLIES (get_regcache_arch (regcache), regno))
49  {
50  struct reg inferior_registers;
51 
52  if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
53  (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
54  perror_with_name (_("Couldn't get registers"));
55 
57  (char *) &inferior_registers,
59 
60  if (regno != -1)
61  return;
62  }
63 }
64 
65 static void
67  struct regcache *regcache, int regno)
68 {
69  if (regno == -1 || GETREGS_SUPPLIES (get_regcache_arch (regcache), regno))
70  {
71  struct reg inferior_registers;
72 
73  if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
74  (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
75  perror_with_name (_("Couldn't get registers"));
76 
78  (char *) &inferior_registers,
80 
81  if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
82  (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
83  perror_with_name (_("Couldn't set registers"));
84 
85  if (regno != -1)
86  return;
87  }
88 }
89 
90 /* Provide a prototype to silence -Wmissing-prototypes. */
91 void _initialize_shnbsd_nat (void);
92 
93 void
95 {
96  struct target_ops *t;
97 
98  t = inf_ptrace_target ();
101  add_target (t);
102 }
void add_target(struct target_ops *t)
Definition: target.c:395
struct gdbarch * get_regcache_arch(const struct regcache *regcache)
Definition: regcache.c:297
void sh_corefile_supply_regset(const struct regset *regset, struct regcache *regcache, int regnum, const void *regs, size_t len)
Definition: sh-tdep.c:2150
#define _(String)
Definition: gdb_locale.h:40
struct target_ops * inf_ptrace_target(void)
Definition: inf-ptrace.c:668
PTRACE_TYPE_RET ptrace()
static void shnbsd_fetch_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regno)
Definition: shnbsd-nat.c:45
Definition: regdef.h:22
#define GETREGS_SUPPLIES(gdbarch, regno)
Definition: shnbsd-nat.c:35
int ptid_get_pid(ptid_t ptid)
Definition: ptid.c:52
void sh_corefile_collect_regset(const struct regset *regset, const struct regcache *regcache, int regnum, void *regs, size_t len)
Definition: sh-tdep.c:2176
const struct regset sh_corefile_gregset
Definition: sh-tdep.c:2199
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
ptid_t inferior_ptid
Definition: infcmd.c:124
#define SHNBSD_SIZEOF_GREGS
Definition: shnbsd-nat.c:42
static void shnbsd_store_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regno)
Definition: shnbsd-nat.c:66
#define PTRACE_TYPE_ARG3
Definition: config.h:658
void(* to_store_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:474
void _initialize_shnbsd_nat(void)
Definition: shnbsd-nat.c:94