Fix RELOC_FOR_GLOBAL_SYMBOLS macro so that it can cope with user defined symbols...
[binutils-gdb.git] / gdb / alpha-obsd-tdep.c
blob8602e21c64aaffb247baf434fa782ec6cdd2b7c4
1 /* Target-dependent code for OpenBSD/alpha.
3 Copyright (C) 2006-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #include "frame.h"
21 #include "gdbcore.h"
22 #include "osabi.h"
24 #include "obsd-tdep.h"
25 #include "alpha-tdep.h"
26 #include "alpha-bsd-tdep.h"
27 #include "solib-svr4.h"
29 /* Signal trampolines. */
31 /* The OpenBSD kernel maps the signal trampoline at some random
32 location in user space, which means that the traditional BSD way of
33 detecting it won't work.
35 The signal trampoline will be mapped at an address that is page
36 aligned. We recognize the signal trampoline by looking for the
37 sigreturn system call. */
39 static const int alphaobsd_page_size = 8192;
41 static LONGEST
42 alphaobsd_sigtramp_offset (struct gdbarch *gdbarch, CORE_ADDR pc)
44 return (pc & (alphaobsd_page_size - 1));
47 static int
48 alphaobsd_pc_in_sigtramp (struct gdbarch *gdbarch,
49 CORE_ADDR pc, const char *name)
51 CORE_ADDR start_pc = (pc & ~(alphaobsd_page_size - 1));
52 unsigned insn;
54 if (name)
55 return 0;
57 /* Check for "". */
58 insn = alpha_read_insn (gdbarch, start_pc + 5 * ALPHA_INSN_SIZE);
59 if (insn != 0x201f0067)
60 return 0;
62 /* Check for "". */
63 insn = alpha_read_insn (gdbarch, start_pc + 6 * ALPHA_INSN_SIZE);
64 if (insn != 0x00000083)
65 return 0;
67 return 1;
70 static CORE_ADDR
71 alphaobsd_sigcontext_addr (const frame_info_ptr &this_frame)
73 struct gdbarch *gdbarch = get_frame_arch (this_frame);
74 CORE_ADDR pc = get_frame_pc (this_frame);
76 if (alphaobsd_sigtramp_offset (gdbarch, pc) < 3 * ALPHA_INSN_SIZE)
78 /* On entry, a pointer the `struct sigcontext' is passed in %a2. */
79 return get_frame_register_unsigned (this_frame, ALPHA_A0_REGNUM + 2);
81 else if (alphaobsd_sigtramp_offset (gdbarch, pc) < 4 * ALPHA_INSN_SIZE)
83 /* It is stored on the stack Before calling the signal handler. */
84 CORE_ADDR sp;
85 sp = get_frame_register_unsigned (this_frame, ALPHA_SP_REGNUM);
86 return get_frame_memory_unsigned (this_frame, sp, 8);
88 else
90 /* It is reloaded into %a0 for the sigreturn(2) call. */
91 return get_frame_register_unsigned (this_frame, ALPHA_A0_REGNUM);
96 static void
97 alphaobsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
99 alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
101 /* Hook into the DWARF CFI frame unwinder. */
102 alpha_dwarf2_init_abi (info, gdbarch);
104 /* Hook into the MDEBUG frame unwinder. */
105 alpha_mdebug_init_abi (info, gdbarch);
107 /* OpenBSD/alpha 3.0 and earlier does not provide single step
108 support via ptrace(2); use software single-stepping for now. */
109 set_gdbarch_software_single_step (gdbarch, alpha_software_single_step);
111 /* OpenBSD/alpha has SVR4-style shared libraries. */
112 set_solib_svr4_fetch_link_map_offsets
113 (gdbarch, svr4_lp64_fetch_link_map_offsets);
114 set_gdbarch_skip_solib_resolver (gdbarch, obsd_skip_solib_resolver);
116 tdep->dynamic_sigtramp_offset = alphaobsd_sigtramp_offset;
117 tdep->pc_in_sigtramp = alphaobsd_pc_in_sigtramp;
118 tdep->sigcontext_addr = alphaobsd_sigcontext_addr;
120 tdep->jb_pc = 2;
121 tdep->jb_elt_size = 8;
123 set_gdbarch_iterate_over_regset_sections
124 (gdbarch, alphanbsd_iterate_over_regset_sections);
128 void _initialize_alphaobsd_tdep ();
129 void
130 _initialize_alphaobsd_tdep ()
132 gdbarch_register_osabi (bfd_arch_alpha, 0, GDB_OSABI_OPENBSD,
133 alphaobsd_init_abi);