arm, objdump: print obsolote warning when 26-bit set in instructions
[binutils-gdb.git] / gdb / netbsd-tdep.c
blob415a7432787ede7fe6d8b29205bf172a14132742
1 /* Common target-dependent code for NetBSD systems.
3 Copyright (C) 2002-2024 Free Software Foundation, Inc.
5 Contributed by Wasabi Systems, Inc.
7 This file is part of GDB.
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
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "auxv.h"
23 #include "solib-svr4.h"
24 #include "netbsd-tdep.h"
25 #include "gdbarch.h"
26 #include "objfiles.h"
27 #include "xml-syscall.h"
29 /* Flags in the 'kve_protection' field in struct kinfo_vmentry. These
30 match the KVME_PROT_* constants in <sys/sysctl.h>. */
32 #define KINFO_VME_PROT_READ 0x00000001
33 #define KINFO_VME_PROT_WRITE 0x00000002
34 #define KINFO_VME_PROT_EXEC 0x00000004
36 /* Flags in the 'kve_flags' field in struct kinfo_vmentry. These
37 match the KVME_FLAG_* constants in <sys/sysctl.h>. */
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
46 int
47 nbsd_pc_in_sigtramp (CORE_ADDR pc, const char *func_name)
49 /* Check for libc-provided signal trampoline. All such trampolines
50 have function names which begin with "__sigtramp". */
52 return (func_name != NULL
53 && startswith (func_name, "__sigtramp"));
56 /* This enum is derived from NETBSD's <sys/signal.h>. */
58 enum
60 NBSD_SIGHUP = 1,
61 NBSD_SIGINT = 2,
62 NBSD_SIGQUIT = 3,
63 NBSD_SIGILL = 4,
64 NBSD_SIGTRAP = 5,
65 NBSD_SIGABRT = 6,
66 NBSD_SIGEMT = 7,
67 NBSD_SIGFPE = 8,
68 NBSD_SIGKILL = 9,
69 NBSD_SIGBUS = 10,
70 NBSD_SIGSEGV = 11,
71 NBSD_SIGSYS = 12,
72 NBSD_SIGPIPE = 13,
73 NBSD_SIGALRM = 14,
74 NBSD_SIGTERM = 15,
75 NBSD_SIGURG = 16,
76 NBSD_SIGSTOP = 17,
77 NBSD_SIGTSTP = 18,
78 NBSD_SIGCONT = 19,
79 NBSD_SIGCHLD = 20,
80 NBSD_SIGTTIN = 21,
81 NBSD_SIGTTOU = 22,
82 NBSD_SIGIO = 23,
83 NBSD_SIGXCPU = 24,
84 NBSD_SIGXFSZ = 25,
85 NBSD_SIGVTALRM = 26,
86 NBSD_SIGPROF = 27,
87 NBSD_SIGWINCH = 28,
88 NBSD_SIGINFO = 29,
89 NBSD_SIGUSR1 = 30,
90 NBSD_SIGUSR2 = 31,
91 NBSD_SIGPWR = 32,
92 NBSD_SIGRTMIN = 33,
93 NBSD_SIGRTMAX = 63,
96 /* Implement the "gdb_signal_from_target" gdbarch method. */
98 static enum gdb_signal
99 nbsd_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
101 switch (signal)
103 case 0:
104 return GDB_SIGNAL_0;
106 case NBSD_SIGHUP:
107 return GDB_SIGNAL_HUP;
109 case NBSD_SIGINT:
110 return GDB_SIGNAL_INT;
112 case NBSD_SIGQUIT:
113 return GDB_SIGNAL_QUIT;
115 case NBSD_SIGILL:
116 return GDB_SIGNAL_ILL;
118 case NBSD_SIGTRAP:
119 return GDB_SIGNAL_TRAP;
121 case NBSD_SIGABRT:
122 return GDB_SIGNAL_ABRT;
124 case NBSD_SIGEMT:
125 return GDB_SIGNAL_EMT;
127 case NBSD_SIGFPE:
128 return GDB_SIGNAL_FPE;
130 case NBSD_SIGKILL:
131 return GDB_SIGNAL_KILL;
133 case NBSD_SIGBUS:
134 return GDB_SIGNAL_BUS;
136 case NBSD_SIGSEGV:
137 return GDB_SIGNAL_SEGV;
139 case NBSD_SIGSYS:
140 return GDB_SIGNAL_SYS;
142 case NBSD_SIGPIPE:
143 return GDB_SIGNAL_PIPE;
145 case NBSD_SIGALRM:
146 return GDB_SIGNAL_ALRM;
148 case NBSD_SIGTERM:
149 return GDB_SIGNAL_TERM;
151 case NBSD_SIGURG:
152 return GDB_SIGNAL_URG;
154 case NBSD_SIGSTOP:
155 return GDB_SIGNAL_STOP;
157 case NBSD_SIGTSTP:
158 return GDB_SIGNAL_TSTP;
160 case NBSD_SIGCONT:
161 return GDB_SIGNAL_CONT;
163 case NBSD_SIGCHLD:
164 return GDB_SIGNAL_CHLD;
166 case NBSD_SIGTTIN:
167 return GDB_SIGNAL_TTIN;
169 case NBSD_SIGTTOU:
170 return GDB_SIGNAL_TTOU;
172 case NBSD_SIGIO:
173 return GDB_SIGNAL_IO;
175 case NBSD_SIGXCPU:
176 return GDB_SIGNAL_XCPU;
178 case NBSD_SIGXFSZ:
179 return GDB_SIGNAL_XFSZ;
181 case NBSD_SIGVTALRM:
182 return GDB_SIGNAL_VTALRM;
184 case NBSD_SIGPROF:
185 return GDB_SIGNAL_PROF;
187 case NBSD_SIGWINCH:
188 return GDB_SIGNAL_WINCH;
190 case NBSD_SIGINFO:
191 return GDB_SIGNAL_INFO;
193 case NBSD_SIGUSR1:
194 return GDB_SIGNAL_USR1;
196 case NBSD_SIGUSR2:
197 return GDB_SIGNAL_USR2;
199 case NBSD_SIGPWR:
200 return GDB_SIGNAL_PWR;
202 /* SIGRTMIN and SIGRTMAX are not continuous in <gdb/signals.def>,
203 therefore we have to handle them here. */
204 case NBSD_SIGRTMIN:
205 return GDB_SIGNAL_REALTIME_33;
207 case NBSD_SIGRTMAX:
208 return GDB_SIGNAL_REALTIME_63;
211 if (signal >= NBSD_SIGRTMIN + 1 && signal <= NBSD_SIGRTMAX - 1)
213 int offset = signal - NBSD_SIGRTMIN + 1;
215 return (enum gdb_signal) ((int) GDB_SIGNAL_REALTIME_34 + offset);
218 return GDB_SIGNAL_UNKNOWN;
221 /* Implement the "gdb_signal_to_target" gdbarch method. */
223 static int
224 nbsd_gdb_signal_to_target (struct gdbarch *gdbarch,
225 enum gdb_signal signal)
227 switch (signal)
229 case GDB_SIGNAL_0:
230 return 0;
232 case GDB_SIGNAL_HUP:
233 return NBSD_SIGHUP;
235 case GDB_SIGNAL_INT:
236 return NBSD_SIGINT;
238 case GDB_SIGNAL_QUIT:
239 return NBSD_SIGQUIT;
241 case GDB_SIGNAL_ILL:
242 return NBSD_SIGILL;
244 case GDB_SIGNAL_TRAP:
245 return NBSD_SIGTRAP;
247 case GDB_SIGNAL_ABRT:
248 return NBSD_SIGABRT;
250 case GDB_SIGNAL_EMT:
251 return NBSD_SIGEMT;
253 case GDB_SIGNAL_FPE:
254 return NBSD_SIGFPE;
256 case GDB_SIGNAL_KILL:
257 return NBSD_SIGKILL;
259 case GDB_SIGNAL_BUS:
260 return NBSD_SIGBUS;
262 case GDB_SIGNAL_SEGV:
263 return NBSD_SIGSEGV;
265 case GDB_SIGNAL_SYS:
266 return NBSD_SIGSYS;
268 case GDB_SIGNAL_PIPE:
269 return NBSD_SIGPIPE;
271 case GDB_SIGNAL_ALRM:
272 return NBSD_SIGALRM;
274 case GDB_SIGNAL_TERM:
275 return NBSD_SIGTERM;
277 case GDB_SIGNAL_URG:
278 return NBSD_SIGSTOP;
280 case GDB_SIGNAL_TSTP:
281 return NBSD_SIGTSTP;
283 case GDB_SIGNAL_CONT:
284 return NBSD_SIGCONT;
286 case GDB_SIGNAL_CHLD:
287 return NBSD_SIGCHLD;
289 case GDB_SIGNAL_TTIN:
290 return NBSD_SIGTTIN;
292 case GDB_SIGNAL_TTOU:
293 return NBSD_SIGTTOU;
295 case GDB_SIGNAL_IO:
296 return NBSD_SIGIO;
298 case GDB_SIGNAL_XCPU:
299 return NBSD_SIGXCPU;
301 case GDB_SIGNAL_XFSZ:
302 return NBSD_SIGXFSZ;
304 case GDB_SIGNAL_VTALRM:
305 return NBSD_SIGVTALRM;
307 case GDB_SIGNAL_PROF:
308 return NBSD_SIGPROF;
310 case GDB_SIGNAL_WINCH:
311 return NBSD_SIGWINCH;
313 case GDB_SIGNAL_INFO:
314 return NBSD_SIGINFO;
316 case GDB_SIGNAL_USR1:
317 return NBSD_SIGUSR1;
319 case GDB_SIGNAL_USR2:
320 return NBSD_SIGUSR2;
322 case GDB_SIGNAL_PWR:
323 return NBSD_SIGPWR;
325 /* GDB_SIGNAL_REALTIME_33 is not continuous in <gdb/signals.def>,
326 therefore we have to handle it here. */
327 case GDB_SIGNAL_REALTIME_33:
328 return NBSD_SIGRTMIN;
330 /* Same comment applies to _64. */
331 case GDB_SIGNAL_REALTIME_63:
332 return NBSD_SIGRTMAX;
335 if (signal >= GDB_SIGNAL_REALTIME_34
336 && signal <= GDB_SIGNAL_REALTIME_62)
338 int offset = signal - GDB_SIGNAL_REALTIME_32;
340 return NBSD_SIGRTMIN + 1 + offset;
343 return -1;
346 /* Shared library resolver handling. */
348 static CORE_ADDR
349 nbsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
351 bound_minimal_symbol msym
352 = lookup_minimal_symbol (current_program_space, "_rtld_bind_start");
353 if (msym.minsym && msym.value_address () == pc)
354 return frame_unwind_caller_pc (get_current_frame ());
355 else
356 return find_solib_trampoline_target (get_current_frame (), pc);
359 struct nbsd_gdbarch_data
361 struct type *siginfo_type = nullptr;
364 static const registry<gdbarch>::key<nbsd_gdbarch_data>
365 nbsd_gdbarch_data_handle;
367 static struct nbsd_gdbarch_data *
368 get_nbsd_gdbarch_data (struct gdbarch *gdbarch)
370 struct nbsd_gdbarch_data *result = nbsd_gdbarch_data_handle.get (gdbarch);
371 if (result == nullptr)
372 result = nbsd_gdbarch_data_handle.emplace (gdbarch);
373 return result;
376 /* Implement the "get_siginfo_type" gdbarch method. */
378 static struct type *
379 nbsd_get_siginfo_type (struct gdbarch *gdbarch)
381 nbsd_gdbarch_data *nbsd_gdbarch_data = get_nbsd_gdbarch_data (gdbarch);
382 if (nbsd_gdbarch_data->siginfo_type != NULL)
383 return nbsd_gdbarch_data->siginfo_type;
385 type *char_type = builtin_type (gdbarch)->builtin_char;
386 type *int_type = builtin_type (gdbarch)->builtin_int;
387 type *long_type = builtin_type (gdbarch)->builtin_long;
389 type *void_ptr_type
390 = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
392 type *int32_type = builtin_type (gdbarch)->builtin_int32;
393 type *uint32_type = builtin_type (gdbarch)->builtin_uint32;
394 type *uint64_type = builtin_type (gdbarch)->builtin_uint64;
396 bool lp64 = void_ptr_type->length () == 8;
397 size_t char_bits = gdbarch_addressable_memory_unit_size (gdbarch) * 8;
399 /* pid_t */
400 type_allocator alloc (gdbarch);
401 type *pid_type = alloc.new_type (TYPE_CODE_TYPEDEF,
402 int32_type->length () * char_bits,
403 "pid_t");
404 pid_type->set_target_type (int32_type);
406 /* uid_t */
407 type *uid_type = alloc.new_type (TYPE_CODE_TYPEDEF,
408 uint32_type->length () * char_bits,
409 "uid_t");
410 uid_type->set_target_type (uint32_type);
412 /* clock_t */
413 type *clock_type = alloc.new_type (TYPE_CODE_TYPEDEF,
414 int_type->length () * char_bits,
415 "clock_t");
416 clock_type->set_target_type (int_type);
418 /* lwpid_t */
419 type *lwpid_type = alloc.new_type (TYPE_CODE_TYPEDEF,
420 int32_type->length () * char_bits,
421 "lwpid_t");
422 lwpid_type->set_target_type (int32_type);
424 /* union sigval */
425 type *sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
426 sigval_type->set_name (gdbarch_obstack_strdup (gdbarch, "sigval"));
427 append_composite_type_field (sigval_type, "sival_int", int_type);
428 append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type);
430 /* union _option */
431 type *option_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
432 option_type->set_name (gdbarch_obstack_strdup (gdbarch, "_option"));
433 append_composite_type_field (option_type, "_pe_other_pid", pid_type);
434 append_composite_type_field (option_type, "_pe_lwp", lwpid_type);
436 /* union _reason */
437 type *reason_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
439 /* _rt */
440 type *t = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
441 append_composite_type_field (t, "_pid", pid_type);
442 append_composite_type_field (t, "_uid", uid_type);
443 append_composite_type_field (t, "_value", sigval_type);
444 append_composite_type_field (reason_type, "_rt", t);
446 /* _child */
447 t = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
448 append_composite_type_field (t, "_pid", pid_type);
449 append_composite_type_field (t, "_uid", uid_type);
450 append_composite_type_field (t, "_status", int_type);
451 append_composite_type_field (t, "_utime", clock_type);
452 append_composite_type_field (t, "_stime", clock_type);
453 append_composite_type_field (reason_type, "_child", t);
455 /* _fault */
456 t = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
457 append_composite_type_field (t, "_addr", void_ptr_type);
458 append_composite_type_field (t, "_trap", int_type);
459 append_composite_type_field (t, "_trap2", int_type);
460 append_composite_type_field (t, "_trap3", int_type);
461 append_composite_type_field (reason_type, "_fault", t);
463 /* _poll */
464 t = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
465 append_composite_type_field (t, "_band", long_type);
466 append_composite_type_field (t, "_fd", int_type);
467 append_composite_type_field (reason_type, "_poll", t);
469 /* _syscall */
470 t = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
471 append_composite_type_field (t, "_sysnum", int_type);
472 append_composite_type_field (t, "_retval",
473 init_vector_type (int_type, 2));
474 append_composite_type_field (t, "_error", int_type);
475 append_composite_type_field (t, "_args",
476 init_vector_type (uint64_type, 8));
477 append_composite_type_field (reason_type, "_syscall", t);
479 /* _ptrace_state */
480 t = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
481 append_composite_type_field (t, "_pe_report_event", int_type);
482 append_composite_type_field (t, "_option", option_type);
483 append_composite_type_field (reason_type, "_ptrace_state", t);
485 /* struct _ksiginfo */
486 type *ksiginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
487 ksiginfo_type->set_name (gdbarch_obstack_strdup (gdbarch, "_ksiginfo"));
488 append_composite_type_field (ksiginfo_type, "_signo", int_type);
489 append_composite_type_field (ksiginfo_type, "_code", int_type);
490 append_composite_type_field (ksiginfo_type, "_errno", int_type);
491 if (lp64)
492 append_composite_type_field (ksiginfo_type, "_pad", int_type);
493 append_composite_type_field (ksiginfo_type, "_reason", reason_type);
495 /* union siginfo */
496 type *siginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
497 siginfo_type->set_name (gdbarch_obstack_strdup (gdbarch, "siginfo"));
498 append_composite_type_field (siginfo_type, "si_pad",
499 init_vector_type (char_type, 128));
500 append_composite_type_field (siginfo_type, "_info", ksiginfo_type);
502 nbsd_gdbarch_data->siginfo_type = siginfo_type;
504 return siginfo_type;
507 /* See netbsd-tdep.h. */
509 void
510 nbsd_info_proc_mappings_header (int addr_bit)
512 gdb_printf (_("Mapped address spaces:\n\n"));
513 if (addr_bit == 64)
515 gdb_printf (" %18s %18s %10s %10s %9s %s\n",
516 "Start Addr",
517 " End Addr",
518 " Size", " Offset", "Flags ", "File");
520 else
522 gdb_printf ("\t%10s %10s %10s %10s %9s %s\n",
523 "Start Addr",
524 " End Addr",
525 " Size", " Offset", "Flags ", "File");
529 /* Helper function to generate mappings flags for a single VM map
530 entry in 'info proc mappings'. */
532 static const char *
533 nbsd_vm_map_entry_flags (int kve_flags, int kve_protection)
535 static char vm_flags[9];
537 vm_flags[0] = (kve_protection & KINFO_VME_PROT_READ) ? 'r' : '-';
538 vm_flags[1] = (kve_protection & KINFO_VME_PROT_WRITE) ? 'w' : '-';
539 vm_flags[2] = (kve_protection & KINFO_VME_PROT_EXEC) ? 'x' : '-';
540 vm_flags[3] = ' ';
541 vm_flags[4] = (kve_flags & KINFO_VME_FLAG_COW) ? 'C' : '-';
542 vm_flags[5] = (kve_flags & KINFO_VME_FLAG_NEEDS_COPY) ? 'N' : '-';
543 vm_flags[6] = (kve_flags & KINFO_VME_FLAG_PAGEABLE) ? 'P' : '-';
544 vm_flags[7] = (kve_flags & KINFO_VME_FLAG_GROWS_UP) ? 'U'
545 : (kve_flags & KINFO_VME_FLAG_GROWS_DOWN) ? 'D' : '-';
546 vm_flags[8] = '\0';
548 return vm_flags;
551 void
552 nbsd_info_proc_mappings_entry (int addr_bit, ULONGEST kve_start,
553 ULONGEST kve_end, ULONGEST kve_offset,
554 int kve_flags, int kve_protection,
555 const char *kve_path)
557 if (addr_bit == 64)
559 gdb_printf (" %18s %18s %10s %10s %9s %s\n",
560 hex_string (kve_start),
561 hex_string (kve_end),
562 hex_string (kve_end - kve_start),
563 hex_string (kve_offset),
564 nbsd_vm_map_entry_flags (kve_flags, kve_protection),
565 kve_path);
567 else
569 gdb_printf ("\t%10s %10s %10s %10s %9s %s\n",
570 hex_string (kve_start),
571 hex_string (kve_end),
572 hex_string (kve_end - kve_start),
573 hex_string (kve_offset),
574 nbsd_vm_map_entry_flags (kve_flags, kve_protection),
575 kve_path);
579 /* Implement the "get_syscall_number" gdbarch method. */
581 static LONGEST
582 nbsd_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread)
585 /* NetBSD doesn't use gdbarch_get_syscall_number since NetBSD
586 native targets fetch the system call number from the
587 'si_sysnum' member of siginfo_t in nbsd_nat_target::wait.
588 However, system call catching requires this function to be
589 set. */
591 internal_error (_("nbsd_get_sycall_number called"));
594 /* See netbsd-tdep.h. */
596 void
597 nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
599 set_gdbarch_gdb_signal_from_target (gdbarch, nbsd_gdb_signal_from_target);
600 set_gdbarch_gdb_signal_to_target (gdbarch, nbsd_gdb_signal_to_target);
601 set_gdbarch_skip_solib_resolver (gdbarch, nbsd_skip_solib_resolver);
602 set_gdbarch_auxv_parse (gdbarch, svr4_auxv_parse);
603 set_gdbarch_get_siginfo_type (gdbarch, nbsd_get_siginfo_type);
605 /* `catch syscall' */
606 set_xml_syscall_file_name (gdbarch, "syscalls/netbsd.xml");
607 set_gdbarch_get_syscall_number (gdbarch, nbsd_get_syscall_number);