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