]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/vaxobsd-tdep.c
* breakpoint.c:
[thirdparty/binutils-gdb.git] / gdb / vaxobsd-tdep.c
1 /* Target-dependent code for OpenBSD/vax.
2
3 Copyright (C) 2005 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 2 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, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
21
22 #include "defs.h"
23 #include "arch-utils.h"
24 #include "frame.h"
25 #include "frame-unwind.h"
26 #include "osabi.h"
27 #include "symtab.h"
28 #include "trad-frame.h"
29
30 #include "vax-tdep.h"
31
32 #include "gdb_string.h"
33
34 /* Signal trampolines. */
35
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
42 release to release.
43
44 By the way, the mapping mentioned above is read-only, so you cannot
45 place a breakpoint in the signal trampoline. */
46
47 /* Default page size. */
48 static const int vaxobsd_page_size = 4096;
49
50 /* Offset for sigreturn(2). */
51 static const int vaxobsd_sigreturn_offset = 0x11;
52
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 */
59 };
60
61 static int
62 vaxobsd_sigtramp_p (struct frame_info *next_frame)
63 {
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;
67 gdb_byte *buf;
68 char *name;
69
70 find_pc_partial_function (pc, &name, NULL, NULL);
71 if (name)
72 return 0;
73
74 buf = alloca(sizeof vaxobsd_sigreturn);
75 if (!safe_frame_unwind_memory (next_frame, sigreturn_addr,
76 buf, sizeof vaxobsd_sigreturn))
77 return 0;
78
79 if (memcmp(buf, vaxobsd_sigreturn, sizeof vaxobsd_sigreturn) == 0)
80 return 1;
81
82 return 0;
83 }
84
85 static struct trad_frame_cache *
86 vaxobsd_sigtramp_frame_cache (struct frame_info *next_frame, void **this_cache)
87 {
88 struct trad_frame_cache *cache;
89 CORE_ADDR addr, base, func;
90
91 if (*this_cache)
92 return *this_cache;
93
94 cache = trad_frame_cache_zalloc (next_frame);
95 *this_cache = cache;
96
97 func = frame_pc_unwind (next_frame);
98 func &= ~(vaxobsd_page_size - 1);
99
100 base = frame_unwind_register_unsigned (next_frame, VAX_SP_REGNUM);
101 addr = get_frame_memory_unsigned (next_frame, base - 4, 4);
102
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);
108
109 /* Construct the frame ID using the function start. */
110 trad_frame_set_id (cache, frame_id_build (base, func));
111
112 return cache;
113 }
114
115 static void
116 vaxobsd_sigtramp_frame_this_id (struct frame_info *next_frame,
117 void **this_cache, struct frame_id *this_id)
118 {
119 struct trad_frame_cache *cache =
120 vaxobsd_sigtramp_frame_cache (next_frame, this_cache);
121
122 trad_frame_get_id (cache, this_id);
123 }
124
125 static void
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,
130 gdb_byte *valuep)
131 {
132 struct trad_frame_cache *cache =
133 vaxobsd_sigtramp_frame_cache (next_frame, this_cache);
134
135 trad_frame_get_register (cache, next_frame, regnum,
136 optimizedp, lvalp, addrp, realnump, valuep);
137 }
138
139 static const struct frame_unwind vaxobsd_sigtramp_frame_unwind = {
140 SIGTRAMP_FRAME,
141 vaxobsd_sigtramp_frame_this_id,
142 vaxobsd_sigtramp_frame_prev_register
143 };
144
145 static const struct frame_unwind *
146 vaxobsd_sigtramp_frame_sniffer (struct frame_info *next_frame)
147 {
148 if (vaxobsd_sigtramp_p (next_frame))
149 return &vaxobsd_sigtramp_frame_unwind;
150
151 return NULL;
152 }
153 \f
154
155 /* OpenBSD a.out. */
156
157 static void
158 vaxobsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
159 {
160 frame_unwind_append_sniffer (gdbarch, vaxobsd_sigtramp_frame_sniffer);
161 }
162
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
166 expected. */
167 #define GDB_OSABI_OPENBSD_AOUT GDB_OSABI_NETBSD_AOUT
168
169 static enum gdb_osabi
170 vaxobsd_aout_osabi_sniffer (bfd *abfd)
171 {
172 if (strcmp (bfd_get_target (abfd), "a.out-vax-netbsd") == 0)
173 return GDB_OSABI_OPENBSD_AOUT;
174
175 return GDB_OSABI_UNKNOWN;
176 }
177 \f
178
179 /* Provide a prototype to silence -Wmissing-prototypes. */
180 void _initialize_vaxobsd_tdep (void);
181
182 void
183 _initialize_vaxobsd_tdep (void)
184 {
185 gdbarch_register_osabi_sniffer (bfd_arch_vax, bfd_target_aout_flavour,
186 vaxobsd_aout_osabi_sniffer);
187
188 gdbarch_register_osabi (bfd_arch_vax, 0, GDB_OSABI_OPENBSD_AOUT,
189 vaxobsd_init_abi);
190 }