1 /* Target-dependent code for OpenBSD/vax.
3 Copyright (C) 2005 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 2 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, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
23 #include "arch-utils.h"
25 #include "frame-unwind.h"
28 #include "trad-frame.h"
32 #include "gdb_string.h"
34 /* Signal trampolines. */
36 /* Since OpenBSD 3.2, the sigtramp routine is mapped at a random page
37 in virtual memory. The randomness makes it somewhat tricky to
38 detect it, but fortunately we can rely on the fact that the start
39 of the sigtramp routine is page-aligned. We recognize the
40 trampoline by looking for the code that invokes the sigreturn
41 system call. The offset where we can find that code varies from
44 By the way, the mapping mentioned above is read-only, so you cannot
45 place a breakpoint in the signal trampoline. */
47 /* Default page size. */
48 static const int vaxobsd_page_size = 4096;
50 /* Offset for sigreturn(2). */
51 static const int vaxobsd_sigreturn_offset = 0x11;
53 /* Instruction sequence for sigreturn(2). VAX doesn't have
54 fixed-length instructions so we include the ensuing exit(2) to
55 reduce the chance of spurious matches. */
56 static const gdb_byte vaxobsd_sigreturn[] = {
57 0xbc, 0x8f, 0x67, 0x00, /* chmk $SYS_sigreturn */
58 0xbc, 0x01 /* chmk $SYS_exit */
62 vaxobsd_sigtramp_p (struct frame_info *next_frame)
64 CORE_ADDR pc = frame_pc_unwind (next_frame);
65 CORE_ADDR start_pc = (pc & ~(vaxobsd_page_size - 1));
66 CORE_ADDR sigreturn_addr = start_pc + vaxobsd_sigreturn_offset;
70 find_pc_partial_function (pc, &name, NULL, NULL);
74 buf = alloca(sizeof vaxobsd_sigreturn);
75 if (!safe_frame_unwind_memory (next_frame, sigreturn_addr,
76 buf, sizeof vaxobsd_sigreturn))
79 if (memcmp(buf, vaxobsd_sigreturn, sizeof vaxobsd_sigreturn) == 0)
85 static struct trad_frame_cache *
86 vaxobsd_sigtramp_frame_cache (struct frame_info *next_frame, void **this_cache)
88 struct trad_frame_cache *cache;
89 CORE_ADDR addr, base, func;
94 cache = trad_frame_cache_zalloc (next_frame);
97 func = frame_pc_unwind (next_frame);
98 func &= ~(vaxobsd_page_size - 1);
100 base = frame_unwind_register_unsigned (next_frame, VAX_SP_REGNUM);
101 addr = get_frame_memory_unsigned (next_frame, base - 4, 4);
103 trad_frame_set_reg_addr (cache, VAX_SP_REGNUM, addr + 8);
104 trad_frame_set_reg_addr (cache, VAX_FP_REGNUM, addr + 12);
105 trad_frame_set_reg_addr (cache, VAX_AP_REGNUM, addr + 16);
106 trad_frame_set_reg_addr (cache, VAX_PC_REGNUM, addr + 20);
107 trad_frame_set_reg_addr (cache, VAX_PS_REGNUM, addr + 24);
109 /* Construct the frame ID using the function start. */
110 trad_frame_set_id (cache, frame_id_build (base, func));
116 vaxobsd_sigtramp_frame_this_id (struct frame_info *next_frame,
117 void **this_cache, struct frame_id *this_id)
119 struct trad_frame_cache *cache =
120 vaxobsd_sigtramp_frame_cache (next_frame, this_cache);
122 trad_frame_get_id (cache, this_id);
126 vaxobsd_sigtramp_frame_prev_register (struct frame_info *next_frame,
127 void **this_cache, int regnum,
128 int *optimizedp, enum lval_type *lvalp,
129 CORE_ADDR *addrp, int *realnump,
132 struct trad_frame_cache *cache =
133 vaxobsd_sigtramp_frame_cache (next_frame, this_cache);
135 trad_frame_get_register (cache, next_frame, regnum,
136 optimizedp, lvalp, addrp, realnump, valuep);
139 static const struct frame_unwind vaxobsd_sigtramp_frame_unwind = {
141 vaxobsd_sigtramp_frame_this_id,
142 vaxobsd_sigtramp_frame_prev_register
145 static const struct frame_unwind *
146 vaxobsd_sigtramp_frame_sniffer (struct frame_info *next_frame)
148 if (vaxobsd_sigtramp_p (next_frame))
149 return &vaxobsd_sigtramp_frame_unwind;
158 vaxobsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
160 frame_unwind_append_sniffer (gdbarch, vaxobsd_sigtramp_frame_sniffer);
163 /* FIXME: kettenis/20050821: Since OpenBSD/vax binaries are
164 indistingushable from NetBSD/vax a.out binaries, building a GDB
165 that should support both these targets will probably not work as
167 #define GDB_OSABI_OPENBSD_AOUT GDB_OSABI_NETBSD_AOUT
169 static enum gdb_osabi
170 vaxobsd_aout_osabi_sniffer (bfd *abfd)
172 if (strcmp (bfd_get_target (abfd), "a.out-vax-netbsd") == 0)
173 return GDB_OSABI_OPENBSD_AOUT;
175 return GDB_OSABI_UNKNOWN;
179 /* Provide a prototype to silence -Wmissing-prototypes. */
180 void _initialize_vaxobsd_tdep (void);
183 _initialize_vaxobsd_tdep (void)
185 gdbarch_register_osabi_sniffer (bfd_arch_vax, bfd_target_aout_flavour,
186 vaxobsd_aout_osabi_sniffer);
188 gdbarch_register_osabi (bfd_arch_vax, 0, GDB_OSABI_OPENBSD_AOUT,