GDB (xrefs)
/tmp/gdb-8.1/gdb/tilegx-linux-nat.c
Go to the documentation of this file.
1 /* Native-dependent code for GNU/Linux TILE-Gx.
2 
3  Copyright (C) 2012-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 "inferior.h"
22 #include "gdbcore.h"
23 #include "regcache.h"
24 #include "linux-nat.h"
25 #include "inf-ptrace.h"
26 
27 #include "nat/gdb_ptrace.h"
28 
29 #include <sys/procfs.h>
30 
31 /* Defines ps_err_e, struct ps_prochandle. */
32 #include "gdb_proc_service.h"
33 
34 /* Prototypes for supply_gregset etc. */
35 #include "gregset.h"
36 
37 /* The register sets used in GNU/Linux ELF core-dumps are identical to
38  the register sets in `struct user' that is used for a.out
39  core-dumps, and is also used by `ptrace'. The corresponding types
40  are `elf_gregset_t' for the general-purpose registers (with
41  `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
42  for the floating-point registers.
43 
44  Those types used to be available under the names `gregset_t' and
45  `fpregset_t' too, and this file used those names in the past. But
46  those names are now used for the register sets used in the
47  `mcontext_t' type, and have a different size and layout. */
48 
49 /* Mapping between the general-purpose registers in `struct user'
50  format and GDB's register array layout. Note that we map the
51  first 56 registers (0 thru 55) one-to-one. GDB maps the pc to
52  slot 64, but ptrace returns it in slot 56. */
53 static const int regmap[] =
54 {
55  0, 1, 2, 3, 4, 5, 6, 7,
56  8, 9, 10, 11, 12, 13, 14, 15,
57  16, 17, 18, 19, 20, 21, 22, 23,
58  24, 25, 26, 27, 28, 29, 30, 31,
59  32, 33, 34, 35, 36, 37, 38, 39,
60  40, 41, 42, 43, 44, 45, 46, 47,
61  48, 49, 50, 51, 52, 53, 54, 55,
62  -1, -1, -1, -1, -1, -1, -1, -1,
63  56, 58
64 };
65 
66 /* Transfering the general-purpose registers between GDB, inferiors
67  and core files. */
68 
69 /* Fill GDB's register array with the general-purpose register values
70  in *GREGSETP. */
71 
72 void
74  const elf_gregset_t *gregsetp)
75 {
76  elf_greg_t *regp = (elf_greg_t *) gregsetp;
77  int i;
78 
79  for (i = 0; i < sizeof (regmap) / sizeof (regmap[0]); i++)
80  if (regmap[i] >= 0)
81  regcache_raw_supply (regcache, i, regp + regmap[i]);
82 }
83 
84 /* Fill registers in *GREGSETPS with the values in GDB's
85  register array. */
86 
87 void
89  elf_gregset_t *gregsetp, int regno)
90 {
91  elf_greg_t *regp = (elf_greg_t *) gregsetp;
92  int i;
93 
94  for (i = 0; i < sizeof (regmap) / sizeof (regmap[0]); i++)
95  if (regmap[i] >= 0)
96  regcache_raw_collect (regcache, i, regp + regmap[i]);
97 }
98 
99 /* Transfering floating-point registers between GDB, inferiors and cores. */
100 
101 /* Fill GDB's register array with the floating-point register values in
102  *FPREGSETP. */
103 
104 void
106  const elf_fpregset_t *fpregsetp)
107 {
108  /* NOTE: There are no floating-point registers for TILE-Gx. */
109 }
110 
111 /* Fill register REGNO (if it is a floating-point register) in
112  *FPREGSETP with the value in GDB's register array. If REGNO is -1,
113  do this for all registers. */
114 
115 void
117  elf_fpregset_t *fpregsetp, int regno)
118 {
119  /* NOTE: There are no floating-point registers for TILE-Gx. */
120 }
121 
122 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
123  for all registers. */
124 
125 static void
127  struct regcache *regcache, int regnum)
128 {
129  elf_gregset_t regs;
131 
132  if (ptrace (PTRACE_GETREGS, tid, 0, (PTRACE_TYPE_ARG3) &regs) < 0)
133  perror_with_name (_("Couldn't get registers"));
134 
135  supply_gregset (regcache, (const elf_gregset_t *)&regs);
136 }
137 
138 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
139  this for all registers. */
140 
141 static void
143  struct regcache *regcache, int regnum)
144 {
145  elf_gregset_t regs;
147 
148  if (ptrace (PTRACE_GETREGS, tid, 0, (PTRACE_TYPE_ARG3) &regs) < 0)
149  perror_with_name (_("Couldn't get registers"));
150 
151  fill_gregset (regcache, &regs, regnum);
152 
153  if (ptrace (PTRACE_SETREGS, tid, 0, (PTRACE_TYPE_ARG3) &regs) < 0)
154  perror_with_name (_("Couldn't write registers"));
155 }
156 
157 void
159 {
160  struct target_ops *t;
161 
162  /* Fill in the generic GNU/Linux methods. */
163  t = linux_target ();
164 
165  /* Add our register access methods. */
168 
169  /* Register the target. */
171 }
static constexpr ptid_t tid
void fill_fpregset(const struct regcache *regcache, elf_fpregset_t *fpregsetp, int regno)
ptid_t regcache_get_ptid(const struct regcache *regcache)
Definition: regcache.c:229
void _initialize_tile_linux_nat(void)
#define _(String)
Definition: gdb_locale.h:35
void fill_gregset(const struct regcache *regcache, elf_gregset_t *gregsetp, int regno)
PTRACE_TYPE_RET ptrace()
void supply_gregset(struct regcache *regcache, const elf_gregset_t *gregsetp)
void supply_fpregset(struct regcache *regcache, const elf_fpregset_t *fpregsetp)
void linux_nat_add_target(struct target_ops *t)
Definition: linux-nat.c:4804
int regnum
Definition: aarch64-tdep.c:77
struct target_ops * linux_target(void)
Definition: linux-nat.c:4377
static const int regmap[]
void(* to_fetch_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_IGNORE()
Definition: target.h:457
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
Definition: utils.c:692
static void fetch_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regnum)
static void store_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regnum)
#define PTRACE_SETREGS
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1004
void regcache_raw_collect(const struct regcache *regcache, int regnum, void *buf)
Definition: regcache.c:1085
#define PTRACE_TYPE_ARG3
Definition: config.h:642
pid_t get_ptrace_pid(ptid_t ptid)
Definition: inf-ptrace.c:320
void(* to_store_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:459
#define PTRACE_GETREGS