GDB (xrefs)
Loading...
Searching...
No Matches
alpha-linux-tdep.c
Go to the documentation of this file.
1/* Target-dependent code for GNU/Linux on Alpha.
2 Copyright (C) 2002-2023 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#include "defs.h"
20#include "frame.h"
21#include "osabi.h"
22#include "solib-svr4.h"
23#include "symtab.h"
24#include "regset.h"
25#include "regcache.h"
26#include "linux-tdep.h"
27#include "alpha-tdep.h"
28#include "gdbarch.h"
29
30/* This enum represents the signals' numbers on the Alpha
31 architecture. It just contains the signal definitions which are
32 different from the generic implementation.
33
34 It is derived from the file <arch/alpha/include/uapi/asm/signal.h>,
35 from the Linux kernel tree. */
36
37enum
38 {
39 /* SIGABRT is the same as in the generic implementation, but is
40 defined here because SIGIOT depends on it. */
57 };
58
59/* Under GNU/Linux, signal handler invocations can be identified by
60 the designated code sequence that is used to return from a signal
61 handler. In particular, the return address of a signal handler
62 points to a sequence that copies $sp to $16, loads $0 with the
63 appropriate syscall number, and finally enters the kernel.
64
65 This is somewhat complicated in that:
66 (1) the expansion of the "mov" assembler macro has changed over
67 time, from "bis src,src,dst" to "bis zero,src,dst",
68 (2) the kernel has changed from using "addq" to "lda" to load the
69 syscall number,
70 (3) there is a "normal" sigreturn and an "rt" sigreturn which
71 has a different stack layout. */
72
73static long
75{
76 switch (alpha_read_insn (gdbarch, pc))
77 {
78 case 0x47de0410: /* bis $30,$30,$16 */
79 case 0x47fe0410: /* bis $31,$30,$16 */
80 return 0;
81
82 case 0x43ecf400: /* addq $31,103,$0 */
83 case 0x201f0067: /* lda $0,103($31) */
84 case 0x201f015f: /* lda $0,351($31) */
85 return 4;
86
87 case 0x00000083: /* call_pal callsys */
88 return 8;
89
90 default:
91 return -1;
92 }
93}
94
95static LONGEST
97{
98 long i, off;
99
100 if (pc & 3)
101 return -1;
102
103 /* Guess where we might be in the sequence. */
105 if (off < 0)
106 return -1;
107
108 /* Verify that the other two insns of the sequence are as we expect. */
109 pc -= off;
110 for (i = 0; i < 12; i += 4)
111 {
112 if (i == off)
113 continue;
114 if (alpha_linux_sigtramp_offset_1 (gdbarch, pc + i) != i)
115 return -1;
116 }
117
118 return off;
119}
120
121static int
123 CORE_ADDR pc, const char *func_name)
124{
125 return alpha_linux_sigtramp_offset (gdbarch, pc) >= 0;
126}
127
128static CORE_ADDR
130{
131 struct gdbarch *gdbarch = get_frame_arch (this_frame);
132 CORE_ADDR pc;
133 ULONGEST sp;
134 long off;
135
136 pc = get_frame_pc (this_frame);
138
140 gdb_assert (off >= 0);
141
142 /* __NR_rt_sigreturn has a couple of structures on the stack. This is:
143
144 struct rt_sigframe {
145 struct siginfo info;
146 struct ucontext uc;
147 };
148
149 offsetof (struct rt_sigframe, uc.uc_mcontext); */
150
151 if (alpha_read_insn (gdbarch, pc - off + 4) == 0x201f015f)
152 return sp + 176;
153
154 /* __NR_sigreturn has the sigcontext structure at the top of the stack. */
155 return sp;
156}
157
158/* Supply register REGNUM from the buffer specified by GREGS and LEN
159 in the general-purpose register set REGSET to register cache
160 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
161
162static void
164 struct regcache *regcache,
165 int regnum, const void *gregs, size_t len)
166{
167 const gdb_byte *regs = (const gdb_byte *) gregs;
168
169 gdb_assert (len >= 32 * 8);
170 alpha_supply_int_regs (regcache, regnum, regs, regs + 31 * 8,
171 len >= 33 * 8 ? regs + 32 * 8 : NULL);
172}
173
174/* Collect register REGNUM from the register cache REGCACHE and store
175 it in the buffer specified by GREGS and LEN as described by the
176 general-purpose register set REGSET. If REGNUM is -1, do this for
177 all registers in REGSET. */
178
179static void
181 const struct regcache *regcache,
182 int regnum, void *gregs, size_t len)
183{
184 gdb_byte *regs = (gdb_byte *) gregs;
185
186 gdb_assert (len >= 32 * 8);
187 alpha_fill_int_regs (regcache, regnum, regs, regs + 31 * 8,
188 len >= 33 * 8 ? regs + 32 * 8 : NULL);
189}
190
191/* Supply register REGNUM from the buffer specified by FPREGS and LEN
192 in the floating-point register set REGSET to register cache
193 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
194
195static void
197 struct regcache *regcache,
198 int regnum, const void *fpregs, size_t len)
199{
200 const gdb_byte *regs = (const gdb_byte *) fpregs;
201
202 gdb_assert (len >= 32 * 8);
203 alpha_supply_fp_regs (regcache, regnum, regs, regs + 31 * 8);
204}
205
206/* Collect register REGNUM from the register cache REGCACHE and store
207 it in the buffer specified by FPREGS and LEN as described by the
208 general-purpose register set REGSET. If REGNUM is -1, do this for
209 all registers in REGSET. */
210
211static void
213 const struct regcache *regcache,
214 int regnum, void *fpregs, size_t len)
215{
216 gdb_byte *regs = (gdb_byte *) fpregs;
217
218 gdb_assert (len >= 32 * 8);
219 alpha_fill_fp_regs (regcache, regnum, regs, regs + 31 * 8);
220}
221
227
233
234/* Iterate over core file register note sections. */
235
236static void
239 void *cb_data,
240 const struct regcache *regcache)
241{
242 cb (".reg", 32 * 8, 32 * 8, &alpha_linux_gregset, NULL, cb_data);
243 cb (".reg2", 32 * 8, 32 * 8, &alpha_linux_fpregset, NULL, cb_data);
244}
245
246/* Implementation of `gdbarch_gdb_signal_from_target', as defined in
247 gdbarch.h. */
248
249static enum gdb_signal
251 int signal)
252{
253 switch (signal)
254 {
256 return GDB_SIGNAL_EMT;
257
259 return GDB_SIGNAL_BUS;
260
262 return GDB_SIGNAL_SYS;
263
265 return GDB_SIGNAL_URG;
266
268 return GDB_SIGNAL_STOP;
269
271 return GDB_SIGNAL_TSTP;
272
274 return GDB_SIGNAL_CONT;
275
277 return GDB_SIGNAL_CHLD;
278
279 /* No way to differentiate between SIGIO and SIGPOLL.
280 Therefore, we just handle the first one. */
282 return GDB_SIGNAL_IO;
283
284 /* No way to differentiate between SIGINFO and SIGPWR.
285 Therefore, we just handle the first one. */
287 return GDB_SIGNAL_INFO;
288
290 return GDB_SIGNAL_USR1;
291
293 return GDB_SIGNAL_USR2;
294 }
295
296 return linux_gdb_signal_from_target (gdbarch, signal);
297}
298
299/* Implementation of `gdbarch_gdb_signal_to_target', as defined in
300 gdbarch.h. */
301
302static int
304 enum gdb_signal signal)
305{
306 switch (signal)
307 {
308 case GDB_SIGNAL_EMT:
309 return ALPHA_LINUX_SIGEMT;
310
311 case GDB_SIGNAL_BUS:
312 return ALPHA_LINUX_SIGBUS;
313
314 case GDB_SIGNAL_SYS:
315 return ALPHA_LINUX_SIGSYS;
316
317 case GDB_SIGNAL_URG:
318 return ALPHA_LINUX_SIGURG;
319
320 case GDB_SIGNAL_STOP:
321 return ALPHA_LINUX_SIGSTOP;
322
323 case GDB_SIGNAL_TSTP:
324 return ALPHA_LINUX_SIGTSTP;
325
326 case GDB_SIGNAL_CONT:
327 return ALPHA_LINUX_SIGCONT;
328
329 case GDB_SIGNAL_CHLD:
330 return ALPHA_LINUX_SIGCHLD;
331
332 case GDB_SIGNAL_IO:
333 return ALPHA_LINUX_SIGIO;
334
335 case GDB_SIGNAL_INFO:
336 return ALPHA_LINUX_SIGINFO;
337
338 case GDB_SIGNAL_USR1:
339 return ALPHA_LINUX_SIGUSR1;
340
341 case GDB_SIGNAL_USR2:
342 return ALPHA_LINUX_SIGUSR2;
343
344 case GDB_SIGNAL_POLL:
345 return ALPHA_LINUX_SIGPOLL;
346
347 case GDB_SIGNAL_PWR:
348 return ALPHA_LINUX_SIGPWR;
349 }
350
351 return linux_gdb_signal_to_target (gdbarch, signal);
352}
353
354static void
389
391void
int regnum
static void alpha_linux_collect_gregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *gregs, size_t len)
static const struct regset alpha_linux_fpregset
static int alpha_linux_pc_in_sigtramp(struct gdbarch *gdbarch, CORE_ADDR pc, const char *func_name)
void _initialize_alpha_linux_tdep()
static const struct regset alpha_linux_gregset
static int alpha_linux_gdb_signal_to_target(struct gdbarch *gdbarch, enum gdb_signal signal)
@ ALPHA_LINUX_SIGEMT
@ ALPHA_LINUX_SIGUSR1
@ ALPHA_LINUX_SIGABRT
@ ALPHA_LINUX_SIGPWR
@ ALPHA_LINUX_SIGBUS
@ ALPHA_LINUX_SIGCONT
@ ALPHA_LINUX_SIGPOLL
@ ALPHA_LINUX_SIGURG
@ ALPHA_LINUX_SIGIO
@ ALPHA_LINUX_SIGTSTP
@ ALPHA_LINUX_SIGSYS
@ ALPHA_LINUX_SIGCHLD
@ ALPHA_LINUX_SIGUSR2
@ ALPHA_LINUX_SIGSTOP
@ ALPHA_LINUX_SIGIOT
@ ALPHA_LINUX_SIGINFO
static void alpha_linux_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
static void alpha_linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
static long alpha_linux_sigtramp_offset_1(struct gdbarch *gdbarch, CORE_ADDR pc)
static LONGEST alpha_linux_sigtramp_offset(struct gdbarch *gdbarch, CORE_ADDR pc)
static CORE_ADDR alpha_linux_sigcontext_addr(frame_info_ptr this_frame)
static void alpha_linux_supply_fpregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *fpregs, size_t len)
static void alpha_linux_collect_fpregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *fpregs, size_t len)
static void alpha_linux_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
static enum gdb_signal alpha_linux_gdb_signal_from_target(struct gdbarch *gdbarch, int signal)
void alpha_mdebug_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
unsigned int alpha_read_insn(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition alpha-tdep.c:670
void alpha_supply_int_regs(struct regcache *regcache, int regno, const void *r0_r30, const void *pc, const void *unique)
void alpha_supply_fp_regs(struct regcache *regcache, int regno, const void *f0_f30, const void *fpcr)
void alpha_dwarf2_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
void alpha_fill_fp_regs(const struct regcache *regcache, int regno, void *f0_f30, void *fpcr)
void alpha_fill_int_regs(const struct regcache *regcache, int regno, void *r0_r30, void *pc, void *unique)
#define ALPHA_SP_REGNUM
Definition alpha-tdep.h:47
ULONGEST get_frame_register_unsigned(frame_info_ptr frame, int regnum)
Definition frame.c:1399
CORE_ADDR get_frame_pc(frame_info_ptr frame)
Definition frame.c:2712
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
Definition frame.c:3027
void set_gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype *skip_trampoline_code)
void set_gdbarch_gdb_signal_from_target(struct gdbarch *gdbarch, gdbarch_gdb_signal_from_target_ftype *gdb_signal_from_target)
void set_gdbarch_gdb_signal_to_target(struct gdbarch *gdbarch, gdbarch_gdb_signal_to_target_ftype *gdb_signal_to_target)
void set_gdbarch_fetch_tls_load_module_address(struct gdbarch *gdbarch, gdbarch_fetch_tls_load_module_address_ftype *fetch_tls_load_module_address)
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype *iterate_over_regset_sections)
void iterate_over_regset_sections_cb(const char *sect_name, int supply_size, int collect_size, const struct regset *regset, const char *human_name, void *cb_data)
Definition gdbarch.h:104
link_map_offsets * linux_lp64_fetch_link_map_offsets()
int linux_gdb_signal_to_target(struct gdbarch *gdbarch, enum gdb_signal signal)
enum gdb_signal linux_gdb_signal_from_target(struct gdbarch *gdbarch, int signal)
void linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch, int num_disp_step_buffers)
CORE_ADDR find_solib_trampoline_target(frame_info_ptr frame, CORE_ADDR pc)
Definition minsyms.c:1554
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:146
@ GDB_OSABI_LINUX
Definition osabi.h:32
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
CORE_ADDR svr4_fetch_objfile_link_map(struct objfile *objfile)
CORE_ADDR(* sigcontext_addr)(frame_info_ptr)
Definition alpha-tdep.h:84
int(* pc_in_sigtramp)(struct gdbarch *gdbarch, CORE_ADDR pc, const char *name)
Definition alpha-tdep.h:90
LONGEST(* dynamic_sigtramp_offset)(struct gdbarch *, CORE_ADDR)
Definition alpha-tdep.h:80