GDB: Fix the overflow in addr/line_is_displayed()
[deliverable/binutils-gdb.git] / gdb / obsd-tdep.c
CommitLineData
fb08a90b
MK
1/* Target-dependent code for OpenBSD.
2
b811d2c2 3 Copyright (C) 2005-2020 Free Software Foundation, Inc.
fb08a90b
MK
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
fb08a90b
MK
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
fb08a90b
MK
19
20#include "defs.h"
21#include "frame.h"
22#include "symtab.h"
77e371c0 23#include "objfiles.h"
fb08a90b
MK
24
25#include "obsd-tdep.h"
26
27CORE_ADDR
28obsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
29{
3b7344d5 30 struct bound_minimal_symbol msym;
fb08a90b
MK
31
32 msym = lookup_minimal_symbol("_dl_bind", NULL, NULL);
77e371c0 33 if (msym.minsym && BMSYMBOL_VALUE_ADDRESS (msym) == pc)
c7ce8faa 34 return frame_unwind_caller_pc (get_current_frame ());
fb08a90b 35 else
52f729a7 36 return find_solib_trampoline_target (get_current_frame (), pc);
fb08a90b 37}
93ffa5b9
MK
38
39/* OpenBSD signal numbers. From <sys/signal.h>. */
40
41enum
42 {
43 OBSD_SIGHUP = 1,
44 OBSD_SIGINT = 2,
45 OBSD_SIGQUIT = 3,
46 OBSD_SIGILL = 4,
47 OBSD_SIGTRAP = 5,
48 OBSD_SIGABRT = 6,
49 OBSD_SIGEMT = 7,
50 OBSD_SIGFPE = 8,
51 OBSD_SIGKILL = 9,
52 OBSD_SIGBUS = 10,
53 OBSD_SIGSEGV = 11,
54 OBSD_SIGSYS = 12,
55 OBSD_SIGPIPE = 13,
56 OBSD_SIGALRM = 14,
57 OBSD_SIGTERM = 15,
58 OBSD_SIGURG = 16,
59 OBSD_SIGSTOP = 17,
60 OBSD_SIGTSTP = 18,
61 OBSD_SIGCONT = 19,
62 OBSD_SIGCHLD = 20,
63 OBSD_SIGTTIN = 21,
64 OBSD_SIGTTOU = 22,
65 OBSD_SIGIO = 23,
66 OBSD_SIGXCPU = 24,
67 OBSD_SIGXFSZ = 25,
68 OBSD_SIGVTALRM = 26,
69 OBSD_SIGPROF = 27,
70 OBSD_SIGWINCH = 28,
71 OBSD_SIGINFO = 29,
72 OBSD_SIGUSR1 = 30,
73 OBSD_SIGUSR2 = 31,
74 OBSD_SIGTHR = 32,
75 };
76
77/* Implement the "gdb_signal_from_target" gdbarch method. */
78
79static enum gdb_signal
80obsd_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
81{
82 switch (signal)
83 {
84 case 0:
85 return GDB_SIGNAL_0;
86
87 case OBSD_SIGHUP:
88 return GDB_SIGNAL_HUP;
89
90 case OBSD_SIGINT:
91 return GDB_SIGNAL_INT;
92
93 case OBSD_SIGQUIT:
94 return GDB_SIGNAL_QUIT;
95
96 case OBSD_SIGILL:
97 return GDB_SIGNAL_ILL;
98
99 case OBSD_SIGTRAP:
100 return GDB_SIGNAL_TRAP;
101
102 case OBSD_SIGABRT:
103 return GDB_SIGNAL_ABRT;
104
105 case OBSD_SIGEMT:
106 return GDB_SIGNAL_EMT;
107
108 case OBSD_SIGFPE:
109 return GDB_SIGNAL_FPE;
110
111 case OBSD_SIGKILL:
112 return GDB_SIGNAL_KILL;
113
114 case OBSD_SIGBUS:
115 return GDB_SIGNAL_BUS;
116
117 case OBSD_SIGSEGV:
118 return GDB_SIGNAL_SEGV;
119
120 case OBSD_SIGSYS:
121 return GDB_SIGNAL_SYS;
122
123 case OBSD_SIGPIPE:
124 return GDB_SIGNAL_PIPE;
125
126 case OBSD_SIGALRM:
127 return GDB_SIGNAL_ALRM;
128
129 case OBSD_SIGTERM:
130 return GDB_SIGNAL_TERM;
131
132 case OBSD_SIGURG:
133 return GDB_SIGNAL_URG;
134
135 case OBSD_SIGSTOP:
136 return GDB_SIGNAL_STOP;
137
138 case OBSD_SIGTSTP:
139 return GDB_SIGNAL_TSTP;
140
141 case OBSD_SIGCONT:
142 return GDB_SIGNAL_CONT;
143
144 case OBSD_SIGCHLD:
145 return GDB_SIGNAL_CHLD;
146
147 case OBSD_SIGTTIN:
148 return GDB_SIGNAL_TTIN;
149
150 case OBSD_SIGTTOU:
151 return GDB_SIGNAL_TTOU;
152
153 case OBSD_SIGIO:
154 return GDB_SIGNAL_IO;
155
156 case OBSD_SIGXCPU:
157 return GDB_SIGNAL_XCPU;
158
159 case OBSD_SIGXFSZ:
160 return GDB_SIGNAL_XFSZ;
161
162 case OBSD_SIGVTALRM:
163 return GDB_SIGNAL_VTALRM;
164
165 case OBSD_SIGPROF:
166 return GDB_SIGNAL_PROF;
167
168 case OBSD_SIGWINCH:
169 return GDB_SIGNAL_WINCH;
170
171 case OBSD_SIGINFO:
172 return GDB_SIGNAL_INFO;
173
174 case OBSD_SIGUSR1:
175 return GDB_SIGNAL_USR1;
176
177 case OBSD_SIGUSR2:
178 return GDB_SIGNAL_USR2;
179 }
180
181 return GDB_SIGNAL_UNKNOWN;
182}
183
184/* Implement the "gdb_signal_to_target" gdbarch method. */
185
186static int
187obsd_gdb_signal_to_target (struct gdbarch *gdbarch,
188 enum gdb_signal signal)
189{
190 switch (signal)
191 {
192 case GDB_SIGNAL_0:
193 return 0;
194
195 case GDB_SIGNAL_HUP:
196 return OBSD_SIGHUP;
197
198 case GDB_SIGNAL_INT:
199 return OBSD_SIGINT;
200
201 case GDB_SIGNAL_QUIT:
202 return OBSD_SIGQUIT;
203
204 case GDB_SIGNAL_ILL:
205 return OBSD_SIGILL;
206
207 case GDB_SIGNAL_TRAP:
208 return OBSD_SIGTRAP;
209
210 case GDB_SIGNAL_ABRT:
211 return OBSD_SIGABRT;
212
213 case GDB_SIGNAL_EMT:
214 return OBSD_SIGEMT;
215
216 case GDB_SIGNAL_FPE:
217 return OBSD_SIGFPE;
218
219 case GDB_SIGNAL_KILL:
220 return OBSD_SIGKILL;
221
222 case GDB_SIGNAL_BUS:
223 return OBSD_SIGBUS;
224
225 case GDB_SIGNAL_SEGV:
226 return OBSD_SIGSEGV;
227
228 case GDB_SIGNAL_SYS:
229 return OBSD_SIGSYS;
230
231 case GDB_SIGNAL_PIPE:
232 return OBSD_SIGPIPE;
233
234 case GDB_SIGNAL_ALRM:
235 return OBSD_SIGALRM;
236
237 case GDB_SIGNAL_TERM:
238 return OBSD_SIGTERM;
239
240 case GDB_SIGNAL_URG:
241 return OBSD_SIGURG;
242
243 case GDB_SIGNAL_STOP:
244 return OBSD_SIGSTOP;
245
246 case GDB_SIGNAL_TSTP:
247 return OBSD_SIGTSTP;
248
249 case GDB_SIGNAL_CONT:
250 return OBSD_SIGCONT;
251
252 case GDB_SIGNAL_CHLD:
253 return OBSD_SIGCHLD;
254
255 case GDB_SIGNAL_TTIN:
256 return OBSD_SIGTTIN;
257
258 case GDB_SIGNAL_TTOU:
259 return OBSD_SIGTTOU;
260
261 case GDB_SIGNAL_IO:
262 return OBSD_SIGIO;
263
264 case GDB_SIGNAL_XCPU:
265 return OBSD_SIGXCPU;
266
267 case GDB_SIGNAL_XFSZ:
268 return OBSD_SIGXFSZ;
269
270 case GDB_SIGNAL_VTALRM:
271 return OBSD_SIGVTALRM;
272
273 case GDB_SIGNAL_PROF:
274 return OBSD_SIGPROF;
275
276 case GDB_SIGNAL_WINCH:
277 return OBSD_SIGWINCH;
278
279 case GDB_SIGNAL_USR1:
280 return OBSD_SIGUSR1;
281
282 case GDB_SIGNAL_USR2:
283 return OBSD_SIGUSR2;
284
285 case GDB_SIGNAL_INFO:
286 return OBSD_SIGINFO;
287 }
288
289 return -1;
290}
291
bee30a64
MK
292static int
293obsd_auxv_parse (struct gdbarch *gdbarch, gdb_byte **readptr,
294 gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
295{
296 struct type *int_type = builtin_type (gdbarch)->builtin_int;
297 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
298 const int sizeof_auxv_type = TYPE_LENGTH (int_type);
299 const int sizeof_auxv_val = TYPE_LENGTH (ptr_type);
300 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
301 gdb_byte *ptr = *readptr;
302
303 if (endptr == ptr)
304 return 0;
305
306 if (endptr - ptr < 2 * sizeof_auxv_val)
307 return -1;
308
309 *typep = extract_unsigned_integer (ptr, sizeof_auxv_type, byte_order);
310 ptr += sizeof_auxv_val; /* Alignment. */
311 *valp = extract_unsigned_integer (ptr, sizeof_auxv_val, byte_order);
312 ptr += sizeof_auxv_val;
313
314 *readptr = ptr;
315 return 1;
316}
93ffa5b9
MK
317
318void
319obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
320{
321 set_gdbarch_gdb_signal_from_target (gdbarch,
322 obsd_gdb_signal_from_target);
323 set_gdbarch_gdb_signal_to_target (gdbarch,
324 obsd_gdb_signal_to_target);
bee30a64
MK
325
326 /* Unlike Linux, OpenBSD actually follows the ELF standard. */
327 set_gdbarch_auxv_parse (gdbarch, obsd_auxv_parse);
93ffa5b9 328}
This page took 1.54297 seconds and 4 git commands to generate.