Add basic event handling in the NetBSD target
[deliverable/binutils-gdb.git] / gdb / nbsd-tdep.c
CommitLineData
ea5bc2a6 1/* Common target-dependent code for NetBSD systems.
76a9d10f 2
b811d2c2 3 Copyright (C) 2002-2020 Free Software Foundation, Inc.
76a9d10f 4
ea5bc2a6
JT
5 Contributed by Wasabi Systems, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
ea5bc2a6 12 (at your option) any later version.
a9762ec7 13
ea5bc2a6
JT
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
a9762ec7 18
ea5bc2a6 19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
ea5bc2a6
JT
21
22#include "defs.h"
206c98a6 23#include "auxv.h"
ea5bc2a6 24#include "solib-svr4.h"
63807e1d 25#include "nbsd-tdep.h"
79743962 26#include "gdbarch.h"
063f8e80 27#include "objfiles.h"
ea5bc2a6 28
54b8cbd0
KR
29/* Flags in the 'kve_protection' field in struct kinfo_vmentry. These
30 match the KVME_PROT_* constants in <sys/sysctl.h>. */
31
32#define KINFO_VME_PROT_READ 0x00000001
33#define KINFO_VME_PROT_WRITE 0x00000002
34#define KINFO_VME_PROT_EXEC 0x00000004
35
36/* Flags in the 'kve_flags' field in struct kinfo_vmentry. These
37 match the KVME_FLAG_* constants in <sys/sysctl.h>. */
38
39#define KINFO_VME_FLAG_COW 0x00000001
40#define KINFO_VME_FLAG_NEEDS_COPY 0x00000002
41#define KINFO_VME_FLAG_NOCOREDUMP 0x00000004
42#define KINFO_VME_FLAG_PAGEABLE 0x00000008
43#define KINFO_VME_FLAG_GROWS_UP 0x00000010
44#define KINFO_VME_FLAG_GROWS_DOWN 0x00000020
45
76a9d10f
MK
46/* FIXME: kettenis/20060115: We should really eliminate the next two
47 functions completely. */
ea5bc2a6 48
ea5bc2a6
JT
49struct link_map_offsets *
50nbsd_ilp32_solib_svr4_fetch_link_map_offsets (void)
51{
76a9d10f 52 return svr4_ilp32_fetch_link_map_offsets ();
ea5bc2a6
JT
53}
54
55struct link_map_offsets *
56nbsd_lp64_solib_svr4_fetch_link_map_offsets (void)
57{
76a9d10f 58 return svr4_lp64_fetch_link_map_offsets ();
ea5bc2a6 59}
3d9b49b0
JT
60
61int
2c02bd72 62nbsd_pc_in_sigtramp (CORE_ADDR pc, const char *func_name)
3d9b49b0
JT
63{
64 /* Check for libc-provided signal trampoline. All such trampolines
65 have function names which begin with "__sigtramp". */
66
67 return (func_name != NULL
61012eef 68 && startswith (func_name, "__sigtramp"));
3d9b49b0 69}
79743962
KR
70
71/* This enum is derived from NETBSD's <sys/signal.h>. */
72
73enum
74 {
75 NBSD_SIGHUP = 1,
76 NBSD_SIGINT = 2,
77 NBSD_SIGQUIT = 3,
78 NBSD_SIGILL = 4,
79 NBSD_SIGTRAP = 5,
80 NBSD_SIGABRT = 6,
81 NBSD_SIGEMT = 7,
82 NBSD_SIGFPE = 8,
83 NBSD_SIGKILL = 9,
84 NBSD_SIGBUS = 10,
85 NBSD_SIGSEGV = 11,
86 NBSD_SIGSYS = 12,
87 NBSD_SIGPIPE = 13,
88 NBSD_SIGALRM = 14,
89 NBSD_SIGTERM = 15,
90 NBSD_SIGURG = 16,
91 NBSD_SIGSTOP = 17,
92 NBSD_SIGTSTP = 18,
93 NBSD_SIGCONT = 19,
94 NBSD_SIGCHLD = 20,
95 NBSD_SIGTTIN = 21,
96 NBSD_SIGTTOU = 22,
97 NBSD_SIGIO = 23,
98 NBSD_SIGXCPU = 24,
99 NBSD_SIGXFSZ = 25,
100 NBSD_SIGVTALRM = 26,
101 NBSD_SIGPROF = 27,
102 NBSD_SIGWINCH = 28,
103 NBSD_SIGINFO = 29,
104 NBSD_SIGUSR1 = 30,
105 NBSD_SIGUSR2 = 31,
106 NBSD_SIGPWR = 32,
107 NBSD_SIGRTMIN = 33,
108 NBSD_SIGRTMAX = 63,
109 };
110
111/* Implement the "gdb_signal_from_target" gdbarch method. */
112
113static enum gdb_signal
114nbsd_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
115{
116 switch (signal)
117 {
118 case 0:
119 return GDB_SIGNAL_0;
120
121 case NBSD_SIGHUP:
122 return GDB_SIGNAL_HUP;
123
124 case NBSD_SIGINT:
125 return GDB_SIGNAL_INT;
126
127 case NBSD_SIGQUIT:
128 return GDB_SIGNAL_QUIT;
129
130 case NBSD_SIGILL:
131 return GDB_SIGNAL_ILL;
132
133 case NBSD_SIGTRAP:
134 return GDB_SIGNAL_TRAP;
135
136 case NBSD_SIGABRT:
137 return GDB_SIGNAL_ABRT;
138
139 case NBSD_SIGEMT:
140 return GDB_SIGNAL_EMT;
141
142 case NBSD_SIGFPE:
143 return GDB_SIGNAL_FPE;
144
145 case NBSD_SIGKILL:
146 return GDB_SIGNAL_KILL;
147
148 case NBSD_SIGBUS:
149 return GDB_SIGNAL_BUS;
150
151 case NBSD_SIGSEGV:
152 return GDB_SIGNAL_SEGV;
153
154 case NBSD_SIGSYS:
155 return GDB_SIGNAL_SYS;
156
157 case NBSD_SIGPIPE:
158 return GDB_SIGNAL_PIPE;
159
160 case NBSD_SIGALRM:
161 return GDB_SIGNAL_ALRM;
162
163 case NBSD_SIGTERM:
164 return GDB_SIGNAL_TERM;
165
166 case NBSD_SIGURG:
167 return GDB_SIGNAL_URG;
168
169 case NBSD_SIGSTOP:
170 return GDB_SIGNAL_STOP;
171
172 case NBSD_SIGTSTP:
173 return GDB_SIGNAL_TSTP;
174
175 case NBSD_SIGCONT:
176 return GDB_SIGNAL_CONT;
177
178 case NBSD_SIGCHLD:
179 return GDB_SIGNAL_CHLD;
180
181 case NBSD_SIGTTIN:
182 return GDB_SIGNAL_TTIN;
183
184 case NBSD_SIGTTOU:
185 return GDB_SIGNAL_TTOU;
186
187 case NBSD_SIGIO:
188 return GDB_SIGNAL_IO;
189
190 case NBSD_SIGXCPU:
191 return GDB_SIGNAL_XCPU;
192
193 case NBSD_SIGXFSZ:
194 return GDB_SIGNAL_XFSZ;
195
196 case NBSD_SIGVTALRM:
197 return GDB_SIGNAL_VTALRM;
198
199 case NBSD_SIGPROF:
200 return GDB_SIGNAL_PROF;
201
202 case NBSD_SIGWINCH:
203 return GDB_SIGNAL_WINCH;
204
205 case NBSD_SIGINFO:
206 return GDB_SIGNAL_INFO;
207
208 case NBSD_SIGUSR1:
209 return GDB_SIGNAL_USR1;
210
211 case NBSD_SIGUSR2:
212 return GDB_SIGNAL_USR2;
213
214 case NBSD_SIGPWR:
215 return GDB_SIGNAL_PWR;
216
217 /* SIGRTMIN and SIGRTMAX are not continuous in <gdb/signals.def>,
218 therefore we have to handle them here. */
219 case NBSD_SIGRTMIN:
220 return GDB_SIGNAL_REALTIME_33;
221
222 case NBSD_SIGRTMAX:
223 return GDB_SIGNAL_REALTIME_63;
224 }
225
226 if (signal >= NBSD_SIGRTMIN + 1 && signal <= NBSD_SIGRTMAX - 1)
227 {
228 int offset = signal - NBSD_SIGRTMIN + 1;
229
230 return (enum gdb_signal) ((int) GDB_SIGNAL_REALTIME_34 + offset);
231 }
232
233 return GDB_SIGNAL_UNKNOWN;
234}
235
236/* Implement the "gdb_signal_to_target" gdbarch method. */
237
238static int
239nbsd_gdb_signal_to_target (struct gdbarch *gdbarch,
240 enum gdb_signal signal)
241{
242 switch (signal)
243 {
244 case GDB_SIGNAL_0:
245 return 0;
246
247 case GDB_SIGNAL_HUP:
248 return NBSD_SIGHUP;
249
250 case GDB_SIGNAL_INT:
251 return NBSD_SIGINT;
252
253 case GDB_SIGNAL_QUIT:
254 return NBSD_SIGQUIT;
255
256 case GDB_SIGNAL_ILL:
257 return NBSD_SIGILL;
258
259 case GDB_SIGNAL_TRAP:
260 return NBSD_SIGTRAP;
261
262 case GDB_SIGNAL_ABRT:
263 return NBSD_SIGABRT;
264
265 case GDB_SIGNAL_EMT:
266 return NBSD_SIGEMT;
267
268 case GDB_SIGNAL_FPE:
269 return NBSD_SIGFPE;
270
271 case GDB_SIGNAL_KILL:
272 return NBSD_SIGKILL;
273
274 case GDB_SIGNAL_BUS:
275 return NBSD_SIGBUS;
276
277 case GDB_SIGNAL_SEGV:
278 return NBSD_SIGSEGV;
279
280 case GDB_SIGNAL_SYS:
281 return NBSD_SIGSYS;
282
283 case GDB_SIGNAL_PIPE:
284 return NBSD_SIGPIPE;
285
286 case GDB_SIGNAL_ALRM:
287 return NBSD_SIGALRM;
288
289 case GDB_SIGNAL_TERM:
290 return NBSD_SIGTERM;
291
292 case GDB_SIGNAL_URG:
293 return NBSD_SIGSTOP;
294
295 case GDB_SIGNAL_TSTP:
296 return NBSD_SIGTSTP;
297
298 case GDB_SIGNAL_CONT:
299 return NBSD_SIGCONT;
300
301 case GDB_SIGNAL_CHLD:
302 return NBSD_SIGCHLD;
303
304 case GDB_SIGNAL_TTIN:
305 return NBSD_SIGTTIN;
306
307 case GDB_SIGNAL_TTOU:
308 return NBSD_SIGTTOU;
309
310 case GDB_SIGNAL_IO:
311 return NBSD_SIGIO;
312
313 case GDB_SIGNAL_XCPU:
314 return NBSD_SIGXCPU;
315
316 case GDB_SIGNAL_XFSZ:
317 return NBSD_SIGXFSZ;
318
319 case GDB_SIGNAL_VTALRM:
320 return NBSD_SIGVTALRM;
321
322 case GDB_SIGNAL_PROF:
323 return NBSD_SIGPROF;
324
325 case GDB_SIGNAL_WINCH:
326 return NBSD_SIGWINCH;
327
328 case GDB_SIGNAL_INFO:
329 return NBSD_SIGINFO;
330
331 case GDB_SIGNAL_USR1:
332 return NBSD_SIGUSR1;
333
334 case GDB_SIGNAL_USR2:
335 return NBSD_SIGUSR2;
336
337 case GDB_SIGNAL_PWR:
338 return NBSD_SIGPWR;
339
340 /* GDB_SIGNAL_REALTIME_33 is not continuous in <gdb/signals.def>,
341 therefore we have to handle it here. */
342 case GDB_SIGNAL_REALTIME_33:
343 return NBSD_SIGRTMIN;
344
345 /* Same comment applies to _64. */
346 case GDB_SIGNAL_REALTIME_63:
347 return NBSD_SIGRTMAX;
348 }
349
350 if (signal >= GDB_SIGNAL_REALTIME_34
351 && signal <= GDB_SIGNAL_REALTIME_62)
352 {
353 int offset = signal - GDB_SIGNAL_REALTIME_32;
354
355 return NBSD_SIGRTMIN + 1 + offset;
356 }
357
358 return -1;
359}
360
063f8e80
KR
361/* Shared library resolver handling. */
362
363static CORE_ADDR
364nbsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
365{
366 struct bound_minimal_symbol msym;
367
368 msym = lookup_minimal_symbol ("_rtld_bind_start", NULL, NULL);
369 if (msym.minsym && BMSYMBOL_VALUE_ADDRESS (msym) == pc)
370 return frame_unwind_caller_pc (get_current_frame ());
371 else
372 return find_solib_trampoline_target (get_current_frame (), pc);
373}
374
79743962
KR
375/* See nbsd-tdep.h. */
376
54b8cbd0
KR
377void
378nbsd_info_proc_mappings_header (int addr_bit)
379{
380 printf_filtered (_("Mapped address spaces:\n\n"));
381 if (addr_bit == 64)
382 {
383 printf_filtered (" %18s %18s %10s %10s %9s %s\n",
384 "Start Addr",
385 " End Addr",
386 " Size", " Offset", "Flags ", "File");
387 }
388 else
389 {
390 printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
391 "Start Addr",
392 " End Addr",
393 " Size", " Offset", "Flags ", "File");
394 }
395}
396
397/* Helper function to generate mappings flags for a single VM map
398 entry in 'info proc mappings'. */
399
400static const char *
401nbsd_vm_map_entry_flags (int kve_flags, int kve_protection)
402{
403 static char vm_flags[9];
404
405 vm_flags[0] = (kve_protection & KINFO_VME_PROT_READ) ? 'r' : '-';
406 vm_flags[1] = (kve_protection & KINFO_VME_PROT_WRITE) ? 'w' : '-';
407 vm_flags[2] = (kve_protection & KINFO_VME_PROT_EXEC) ? 'x' : '-';
408 vm_flags[3] = ' ';
409 vm_flags[4] = (kve_flags & KINFO_VME_FLAG_COW) ? 'C' : '-';
410 vm_flags[5] = (kve_flags & KINFO_VME_FLAG_NEEDS_COPY) ? 'N' : '-';
411 vm_flags[6] = (kve_flags & KINFO_VME_FLAG_PAGEABLE) ? 'P' : '-';
412 vm_flags[7] = (kve_flags & KINFO_VME_FLAG_GROWS_UP) ? 'U'
413 : (kve_flags & KINFO_VME_FLAG_GROWS_DOWN) ? 'D' : '-';
414 vm_flags[8] = '\0';
415
416 return vm_flags;
417}
418
419void
420nbsd_info_proc_mappings_entry (int addr_bit, ULONGEST kve_start,
421 ULONGEST kve_end, ULONGEST kve_offset,
422 int kve_flags, int kve_protection,
423 const char *kve_path)
424{
425 if (addr_bit == 64)
426 {
427 printf_filtered (" %18s %18s %10s %10s %9s %s\n",
428 hex_string (kve_start),
429 hex_string (kve_end),
430 hex_string (kve_end - kve_start),
431 hex_string (kve_offset),
432 nbsd_vm_map_entry_flags (kve_flags, kve_protection),
433 kve_path);
434 }
435 else
436 {
437 printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
438 hex_string (kve_start),
439 hex_string (kve_end),
440 hex_string (kve_end - kve_start),
441 hex_string (kve_offset),
442 nbsd_vm_map_entry_flags (kve_flags, kve_protection),
443 kve_path);
444 }
445}
446
f94b2e03
KR
447/* Implement the "get_syscall_number" gdbarch method. */
448
449static LONGEST
450nbsd_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread)
451{
452
453 /* NetBSD doesn't use gdbarch_get_syscall_number since NetBSD
454 native targets fetch the system call number from the
455 'si_sysnum' member of siginfo_t in nbsd_nat_target::wait.
456 However, system call catching requires this function to be
457 set. */
458
459 internal_error (__FILE__, __LINE__, _("nbsd_get_sycall_number called"));
460}
461
54b8cbd0
KR
462/* See nbsd-tdep.h. */
463
79743962
KR
464void
465nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
466{
467 set_gdbarch_gdb_signal_from_target (gdbarch, nbsd_gdb_signal_from_target);
468 set_gdbarch_gdb_signal_to_target (gdbarch, nbsd_gdb_signal_to_target);
063f8e80 469 set_gdbarch_skip_solib_resolver (gdbarch, nbsd_skip_solib_resolver);
206c98a6 470 set_gdbarch_auxv_parse (gdbarch, svr4_auxv_parse);
f94b2e03
KR
471
472 /* `catch syscall' */
473 set_gdbarch_get_syscall_number (gdbarch, nbsd_get_syscall_number);
79743962 474}
This page took 1.674093 seconds and 4 git commands to generate.