GDB (xrefs)

/tmp/gdb-8.1/gdb/alpha-nbsd-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for NetBSD/alpha.
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 "frame.h"
24 #include "gdbcore.h"
25 #include "osabi.h"
26 #include "regcache.h"
27 #include "regset.h"
28 #include "value.h"
29
30 #include "alpha-tdep.h"
31 #include "alpha-bsd-tdep.h"
32 #include "nbsd-tdep.h"
33 #include "solib-svr4.h"
34 #include "target.h"
35
36 /* Core file support. */
37
38 /* Sizeof `struct reg' in <machine/reg.h>. */
39 #define ALPHANBSD_SIZEOF_GREGS (32 * 8)
40
41 /* Sizeof `struct fpreg' in <machine/reg.h. */
42 #define ALPHANBSD_SIZEOF_FPREGS ((32 * 8) + 8)
43
44 /* Supply register REGNUM from the buffer specified by FPREGS and LEN
45 in the floating-point register set REGSET to register cache
46 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
47
48 static void
49 alphanbsd_supply_fpregset (const struct regset *regset,
50 struct regcache *regcache,
51 int regnum, const void *fpregs, size_t len)
52 {
53 const gdb_byte *regs = (const gdb_byte *) fpregs;
54 int i;
55
56 gdb_assert (len >= ALPHANBSD_SIZEOF_FPREGS);
57
58 for (i = ALPHA_FP0_REGNUM; i < ALPHA_FP0_REGNUM + 31; i++)
59 {
60 if (regnum == i || regnum == -1)
61 regcache_raw_supply (regcache, i, regs + (i - ALPHA_FP0_REGNUM) * 8);
62 }
63
64 if (regnum == ALPHA_FPCR_REGNUM || regnum == -1)
65 regcache_raw_supply (regcache, ALPHA_FPCR_REGNUM, regs + 32 * 8);
66 }
67
68 /* Supply register REGNUM from the buffer specified by GREGS and LEN
69 in the general-purpose register set REGSET to register cache
70 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
71
72 static void
73 alphanbsd_aout_supply_gregset (const struct regset *regset,
74 struct regcache *regcache,
75 int regnum, const void *gregs, size_t len)
76 {
77 const gdb_byte *regs = (const gdb_byte *) gregs;
78 int i;
79
80 /* Table to map a GDB register number to a trapframe register index. */
81 static const int regmap[] =
82 {
83 0, 1, 2, 3,
84 4, 5, 6, 7,
85 8, 9, 10, 11,
86 12, 13, 14, 15,
87 30, 31, 32, 16,
88 17, 18, 19, 20,
89 21, 22, 23, 24,
90 25, 29, 26
91 };
92
93 gdb_assert (len >= ALPHANBSD_SIZEOF_GREGS);
94
95 for (i = 0; i < ARRAY_SIZE(regmap); i++)
96 {
97 if (regnum == i || regnum == -1)
98 regcache_raw_supply (regcache, i, regs + regmap[i] * 8);
99 }
100
101 if (regnum == ALPHA_PC_REGNUM || regnum == -1)
102 regcache_raw_supply (regcache, ALPHA_PC_REGNUM, regs + 31 * 8);
103
104 if (len >= ALPHANBSD_SIZEOF_GREGS + ALPHANBSD_SIZEOF_FPREGS)
105 {
106 regs += ALPHANBSD_SIZEOF_GREGS;
107 len -= ALPHANBSD_SIZEOF_GREGS;
108 alphanbsd_supply_fpregset (regset, regcache, regnum, regs, len);
109 }
110 }
111
112 /* Supply register REGNUM from the buffer specified by GREGS and LEN
113 in the general-purpose register set REGSET to register cache
114 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
115
116 static void
117 alphanbsd_supply_gregset (const struct regset *regset,
118 struct regcache *regcache,
119 int regnum, const void *gregs, size_t len)
120 {
121 const gdb_byte *regs = (const gdb_byte *) gregs;
122 int i;
123
124 if (len >= ALPHANBSD_SIZEOF_GREGS + ALPHANBSD_SIZEOF_FPREGS)
125 {
126 alphanbsd_aout_supply_gregset (regset, regcache, regnum, gregs, len);
127 return;
128 }
129
130 for (i = 0; i < ALPHA_ZERO_REGNUM; i++)
131 {
132 if (regnum == i || regnum == -1)
133 regcache_raw_supply (regcache, i, regs + i * 8);
134 }
135
136 if (regnum == ALPHA_PC_REGNUM || regnum == -1)
137 regcache_raw_supply (regcache, ALPHA_PC_REGNUM, regs + 31 * 8);
138 }
139
140 /* NetBSD/alpha register sets. */
141
142 static const struct regset alphanbsd_gregset =
143 {
144 NULL,
145 alphanbsd_supply_gregset,
146 NULL,
147 REGSET_VARIABLE_SIZE
148 };
149
150 static const struct regset alphanbsd_fpregset =
151 {
152 NULL,
153 alphanbsd_supply_fpregset
154 };
155
156 /* Iterate over supported core file register note sections. */
157
158 void
159 alphanbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
160 iterate_over_regset_sections_cb *cb,
161 void *cb_data,
162 const struct regcache *regcache)
163 {
164 cb (".reg", ALPHANBSD_SIZEOF_GREGS, &alphanbsd_gregset, NULL, cb_data);
165 cb (".reg2", ALPHANBSD_SIZEOF_FPREGS, &alphanbsd_fpregset, NULL, cb_data);
166 }
167
168
169 /* Signal trampolines. */
170
171 /* Under NetBSD/alpha, signal handler invocations can be identified by the
172 designated code sequence that is used to return from a signal handler.
173 In particular, the return address of a signal handler points to the
174 following code sequence:
175
176 ldq a0, 0(sp)
177 lda sp, 16(sp)
178 lda v0, 295(zero) # __sigreturn14
179 call_pal callsys
180
181 Each instruction has a unique encoding, so we simply attempt to match
182 the instruction the PC is pointing to with any of the above instructions.
183 If there is a hit, we know the offset to the start of the designated
184 sequence and can then check whether we really are executing in the
185 signal trampoline. If not, -1 is returned, otherwise the offset from the
186 start of the return sequence is returned. */
187 static const gdb_byte sigtramp_retcode[] =
188 {
189 0x00, 0x00, 0x1e, 0xa6, /* ldq a0, 0(sp) */
190 0x10, 0x00, 0xde, 0x23, /* lda sp, 16(sp) */
191 0x27, 0x01, 0x1f, 0x20, /* lda v0, 295(zero) */
192 0x83, 0x00, 0x00, 0x00, /* call_pal callsys */
193 };
194 #define RETCODE_NWORDS 4
195 #define RETCODE_SIZE (RETCODE_NWORDS * 4)
196
197 static LONGEST
198 alphanbsd_sigtramp_offset (struct gdbarch *gdbarch, CORE_ADDR pc)
199 {
200 gdb_byte ret[RETCODE_SIZE], w[4];
201 LONGEST off;
202 int i;
203
204 if (target_read_memory (pc, w, 4) != 0)
205 return -1;
206
207 for (i = 0; i < RETCODE_NWORDS; i++)
208 {
209 if (memcmp (w, sigtramp_retcode + (i * 4), 4) == 0)
210 break;
211 }
212 if (i == RETCODE_NWORDS)
213 return (-1);
214
215 off = i * 4;
216 pc -= off;
217
218 if (target_read_memory (pc, ret, sizeof (ret)) != 0)
219 return -1;
220
221 if (memcmp (ret, sigtramp_retcode, RETCODE_SIZE) == 0)
222 return off;
223
224 return -1;
225 }
226
227 static int
228 alphanbsd_pc_in_sigtramp (struct gdbarch *gdbarch,
229 CORE_ADDR pc, const char *func_name)
230 {
231 return (nbsd_pc_in_sigtramp (pc, func_name)
232 || alphanbsd_sigtramp_offset (gdbarch, pc) >= 0);
233 }
234
235 static CORE_ADDR
236 alphanbsd_sigcontext_addr (struct frame_info *frame)
237 {
238 /* FIXME: This is not correct for all versions of NetBSD/alpha.
239 We will probably need to disassemble the trampoline to figure
240 out which trampoline frame type we have. */
241 if (!get_next_frame (frame))
242 return 0;
243 return get_frame_base (get_next_frame (frame));
244 }
245
246
247 static void
248 alphanbsd_init_abi (struct gdbarch_info info,
249 struct gdbarch *gdbarch)
250 {
251 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
252
253 /* Hook into the DWARF CFI frame unwinder. */
254 alpha_dwarf2_init_abi (info, gdbarch);
255
256 /* Hook into the MDEBUG frame unwinder. */
257 alpha_mdebug_init_abi (info, gdbarch);
258
259 /* NetBSD/alpha does not provide single step support via ptrace(2); we
260 must use software single-stepping. */
261 set_gdbarch_software_single_step (gdbarch, alpha_software_single_step);
262
263 /* NetBSD/alpha has SVR4-style shared libraries. */
264 set_solib_svr4_fetch_link_map_offsets
265 (gdbarch, svr4_lp64_fetch_link_map_offsets);
266
267 tdep->dynamic_sigtramp_offset = alphanbsd_sigtramp_offset;
268 tdep->pc_in_sigtramp = alphanbsd_pc_in_sigtramp;
269 tdep->sigcontext_addr = alphanbsd_sigcontext_addr;
270
271 tdep->jb_pc = 2;
272 tdep->jb_elt_size = 8;
273
274 set_gdbarch_iterate_over_regset_sections
275 (gdbarch, alphanbsd_iterate_over_regset_sections);
276 }
277
278
279 void
280 _initialize_alphanbsd_tdep (void)
281 {
282 /* Even though NetBSD/alpha used ELF since day one, it used the
283 traditional a.out-style core dump format before NetBSD 1.6, but
284 we don't support those. */
285 gdbarch_register_osabi (bfd_arch_alpha, 0, GDB_OSABI_NETBSD,
286 alphanbsd_init_abi);
287 }
gdbarch
Definition: gdbarch.c:127
alpha_mdebug_init_abi
void alpha_mdebug_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: alpha-mdebug-tdep.c:403
_initialize_alphanbsd_tdep
void _initialize_alphanbsd_tdep(void)
Definition: alpha-nbsd-tdep.c:280
alphanbsd_pc_in_sigtramp
static int alphanbsd_pc_in_sigtramp(struct gdbarch *gdbarch, CORE_ADDR pc, const char *func_name)
Definition: alpha-nbsd-tdep.c:228
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
svr4_lp64_fetch_link_map_offsets
struct link_map_offsets * svr4_lp64_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3214
ALPHA_FP0_REGNUM
#define ALPHA_FP0_REGNUM
Definition: alpha-tdep.h:47
gdbarch_tdep::dynamic_sigtramp_offset
LONGEST(* dynamic_sigtramp_offset)(struct gdbarch *, CORE_ADDR)
Definition: alpha-tdep.h:78
alpha_software_single_step
std::vector< CORE_ADDR > alpha_software_single_step(struct regcache *regcache)
Definition: alpha-tdep.c:1722
iterate_over_regset_sections_cb
void() iterate_over_regset_sections_cb(const char *sect_name, int size, const struct regset *regset, const char *human_name, void *cb_data)
Definition: gdbarch.h:99
alphanbsd_sigcontext_addr
static CORE_ADDR alphanbsd_sigcontext_addr(struct frame_info *frame)
Definition: alpha-nbsd-tdep.c:236
nbsd_pc_in_sigtramp
int nbsd_pc_in_sigtramp(CORE_ADDR pc, const char *func_name)
Definition: nbsd-tdep.c:42
ALPHANBSD_SIZEOF_GREGS
#define ALPHANBSD_SIZEOF_GREGS
Definition: alpha-nbsd-tdep.c:39
alpha_dwarf2_init_abi
void alpha_dwarf2_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: alpha-tdep.c:1850
gdbarch_tdep
Definition: aarch64-tdep.h:55
gdbarch_tdep::sigcontext_addr
CORE_ADDR(* sigcontext_addr)(struct frame_info *)
Definition: alpha-tdep.h:82
frame_info
Definition: frame.c:85
regmap
static int regmap[]
Definition: m32r-linux-nat.c:45
defs.h
gdbarch_tdep
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1491
alphanbsd_init_abi
static void alphanbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: alpha-nbsd-tdep.c:248
regset
Definition: regset.h:34
ALPHA_PC_REGNUM
#define ALPHA_PC_REGNUM
Definition: alpha-tdep.h:50
RETCODE_SIZE
#define RETCODE_SIZE
Definition: alpha-nbsd-tdep.c:195
solib-svr4.h
osabi.h
regcache.h
RETCODE_NWORDS
#define RETCODE_NWORDS
Definition: alpha-nbsd-tdep.c:194
alphanbsd_supply_gregset
static void alphanbsd_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
Definition: alpha-nbsd-tdep.c:117
frame.h
gdbarch_tdep::jb_pc
int jb_pc
Definition: aarch64-tdep.h:62
set_solib_svr4_fetch_link_map_offsets
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
Definition: solib-svr4.c:3137
REGSET_VARIABLE_SIZE
#define REGSET_VARIABLE_SIZE
Definition: regset.h:52
alpha-bsd-tdep.h
sigtramp_retcode
static const gdb_byte sigtramp_retcode[]
Definition: alpha-nbsd-tdep.c:187
ALPHA_FPCR_REGNUM
#define ALPHA_FPCR_REGNUM
Definition: alpha-tdep.h:49
regnum
int regnum
Definition: aarch64-tdep.c:77
alphanbsd_iterate_over_regset_sections
void alphanbsd_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
Definition: alpha-nbsd-tdep.c:159
gdbarch_register_osabi
void gdbarch_register_osabi(enum bfd_architecture arch, unsigned long machine, enum gdb_osabi osabi, void(*init_osabi)(struct gdbarch_info, struct gdbarch *))
Definition: osabi.c:143
nbsd-tdep.h
gdbarch_tdep::jb_elt_size
size_t jb_elt_size
Definition: aarch64-tdep.h:65
gdb_assert
#define gdb_assert(expr)
Definition: gdb_assert.h:32
ALPHA_ZERO_REGNUM
#define ALPHA_ZERO_REGNUM
Definition: alpha-tdep.h:46
ALPHANBSD_SIZEOF_FPREGS
#define ALPHANBSD_SIZEOF_FPREGS
Definition: alpha-nbsd-tdep.c:42
set_gdbarch_software_single_step
void set_gdbarch_software_single_step(struct gdbarch *gdbarch, gdbarch_software_single_step_ftype software_single_step)
Definition: gdbarch.c:3258
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
get_next_frame
struct frame_info * get_next_frame(struct frame_info *this_frame)
Definition: frame.c:1771
alphanbsd_gregset
static const struct regset alphanbsd_gregset
Definition: alpha-nbsd-tdep.c:142
gdbarch_tdep::pc_in_sigtramp
int(* pc_in_sigtramp)(struct gdbarch *gdbarch, CORE_ADDR pc, const char *name)
Definition: alpha-tdep.h:88
gdbcore.h
get_frame_base
CORE_ADDR get_frame_base(struct frame_info *fi)
Definition: frame.c:2544
target_read_memory
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: target.c:1370
alphanbsd_supply_fpregset
static void alphanbsd_supply_fpregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *fpregs, size_t len)
Definition: alpha-nbsd-tdep.c:49
GDB_OSABI_NETBSD
Definition: defs.h:519
target.h
gdbarch_tdep::regs
struct m32c_reg regs[M32C_MAX_NUM_REGS]
Definition: m32c-tdep.c:110
value.h
regcache_raw_supply
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1004
regcache
Definition: regcache.h:232
alphanbsd_sigtramp_offset
static LONGEST alphanbsd_sigtramp_offset(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition: alpha-nbsd-tdep.c:198
gdbarch_info
Definition: gdbarch.h:1626
regset.h
set_gdbarch_iterate_over_regset_sections
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype iterate_over_regset_sections)
Definition: gdbarch.c:3647
alpha-tdep.h
alphanbsd_fpregset
static const struct regset alphanbsd_fpregset
Definition: alpha-nbsd-tdep.c:150
LONGEST
long long LONGEST
Definition: common-types.h:52
alphanbsd_aout_supply_gregset
static void alphanbsd_aout_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
Definition: alpha-nbsd-tdep.c:73