1 /* Common target-dependent code for NetBSD systems.
3 Copyright (C) 2002-2020 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/>. */
24 #include "solib-svr4.h"
25 #include "nbsd-tdep.h"
28 #include "xml-syscall.h"
30 /* Flags in the 'kve_protection' field in struct kinfo_vmentry. These
31 match the KVME_PROT_* constants in <sys/sysctl.h>. */
33 #define KINFO_VME_PROT_READ 0x00000001
34 #define KINFO_VME_PROT_WRITE 0x00000002
35 #define KINFO_VME_PROT_EXEC 0x00000004
37 /* Flags in the 'kve_flags' field in struct kinfo_vmentry. These
38 match the KVME_FLAG_* constants in <sys/sysctl.h>. */
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
47 /* FIXME: kettenis/20060115: We should really eliminate the next two
48 functions completely. */
50 struct link_map_offsets
*
51 nbsd_ilp32_solib_svr4_fetch_link_map_offsets (void)
53 return svr4_ilp32_fetch_link_map_offsets ();
56 struct link_map_offsets
*
57 nbsd_lp64_solib_svr4_fetch_link_map_offsets (void)
59 return svr4_lp64_fetch_link_map_offsets ();
63 nbsd_pc_in_sigtramp (CORE_ADDR pc
, const char *func_name
)
65 /* Check for libc-provided signal trampoline. All such trampolines
66 have function names which begin with "__sigtramp". */
68 return (func_name
!= NULL
69 && startswith (func_name
, "__sigtramp"));
72 /* This enum is derived from NETBSD's <sys/signal.h>. */
112 /* Implement the "gdb_signal_from_target" gdbarch method. */
114 static enum gdb_signal
115 nbsd_gdb_signal_from_target (struct gdbarch
*gdbarch
, int signal
)
123 return GDB_SIGNAL_HUP
;
126 return GDB_SIGNAL_INT
;
129 return GDB_SIGNAL_QUIT
;
132 return GDB_SIGNAL_ILL
;
135 return GDB_SIGNAL_TRAP
;
138 return GDB_SIGNAL_ABRT
;
141 return GDB_SIGNAL_EMT
;
144 return GDB_SIGNAL_FPE
;
147 return GDB_SIGNAL_KILL
;
150 return GDB_SIGNAL_BUS
;
153 return GDB_SIGNAL_SEGV
;
156 return GDB_SIGNAL_SYS
;
159 return GDB_SIGNAL_PIPE
;
162 return GDB_SIGNAL_ALRM
;
165 return GDB_SIGNAL_TERM
;
168 return GDB_SIGNAL_URG
;
171 return GDB_SIGNAL_STOP
;
174 return GDB_SIGNAL_TSTP
;
177 return GDB_SIGNAL_CONT
;
180 return GDB_SIGNAL_CHLD
;
183 return GDB_SIGNAL_TTIN
;
186 return GDB_SIGNAL_TTOU
;
189 return GDB_SIGNAL_IO
;
192 return GDB_SIGNAL_XCPU
;
195 return GDB_SIGNAL_XFSZ
;
198 return GDB_SIGNAL_VTALRM
;
201 return GDB_SIGNAL_PROF
;
204 return GDB_SIGNAL_WINCH
;
207 return GDB_SIGNAL_INFO
;
210 return GDB_SIGNAL_USR1
;
213 return GDB_SIGNAL_USR2
;
216 return GDB_SIGNAL_PWR
;
218 /* SIGRTMIN and SIGRTMAX are not continuous in <gdb/signals.def>,
219 therefore we have to handle them here. */
221 return GDB_SIGNAL_REALTIME_33
;
224 return GDB_SIGNAL_REALTIME_63
;
227 if (signal
>= NBSD_SIGRTMIN
+ 1 && signal
<= NBSD_SIGRTMAX
- 1)
229 int offset
= signal
- NBSD_SIGRTMIN
+ 1;
231 return (enum gdb_signal
) ((int) GDB_SIGNAL_REALTIME_34
+ offset
);
234 return GDB_SIGNAL_UNKNOWN
;
237 /* Implement the "gdb_signal_to_target" gdbarch method. */
240 nbsd_gdb_signal_to_target (struct gdbarch
*gdbarch
,
241 enum gdb_signal signal
)
254 case GDB_SIGNAL_QUIT
:
260 case GDB_SIGNAL_TRAP
:
263 case GDB_SIGNAL_ABRT
:
272 case GDB_SIGNAL_KILL
:
278 case GDB_SIGNAL_SEGV
:
284 case GDB_SIGNAL_PIPE
:
287 case GDB_SIGNAL_ALRM
:
290 case GDB_SIGNAL_TERM
:
296 case GDB_SIGNAL_TSTP
:
299 case GDB_SIGNAL_CONT
:
302 case GDB_SIGNAL_CHLD
:
305 case GDB_SIGNAL_TTIN
:
308 case GDB_SIGNAL_TTOU
:
314 case GDB_SIGNAL_XCPU
:
317 case GDB_SIGNAL_XFSZ
:
320 case GDB_SIGNAL_VTALRM
:
321 return NBSD_SIGVTALRM
;
323 case GDB_SIGNAL_PROF
:
326 case GDB_SIGNAL_WINCH
:
327 return NBSD_SIGWINCH
;
329 case GDB_SIGNAL_INFO
:
332 case GDB_SIGNAL_USR1
:
335 case GDB_SIGNAL_USR2
:
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
;
346 /* Same comment applies to _64. */
347 case GDB_SIGNAL_REALTIME_63
:
348 return NBSD_SIGRTMAX
;
351 if (signal
>= GDB_SIGNAL_REALTIME_34
352 && signal
<= GDB_SIGNAL_REALTIME_62
)
354 int offset
= signal
- GDB_SIGNAL_REALTIME_32
;
356 return NBSD_SIGRTMIN
+ 1 + offset
;
362 /* Shared library resolver handling. */
365 nbsd_skip_solib_resolver (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
367 struct bound_minimal_symbol msym
;
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 ());
373 return find_solib_trampoline_target (get_current_frame (), pc
);
376 /* See nbsd-tdep.h. */
379 nbsd_info_proc_mappings_header (int addr_bit
)
381 printf_filtered (_("Mapped address spaces:\n\n"));
384 printf_filtered (" %18s %18s %10s %10s %9s %s\n",
387 " Size", " Offset", "Flags ", "File");
391 printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
394 " Size", " Offset", "Flags ", "File");
398 /* Helper function to generate mappings flags for a single VM map
399 entry in 'info proc mappings'. */
402 nbsd_vm_map_entry_flags (int kve_flags
, int kve_protection
)
404 static char vm_flags
[9];
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' : '-';
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' : '-';
421 nbsd_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
)
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
),
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
),
448 /* Implement the "get_syscall_number" gdbarch method. */
451 nbsd_get_syscall_number (struct gdbarch
*gdbarch
, thread_info
*thread
)
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
460 internal_error (__FILE__
, __LINE__
, _("nbsd_get_sycall_number called"));
463 /* See nbsd-tdep.h. */
466 nbsd_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
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
);
470 set_gdbarch_skip_solib_resolver (gdbarch
, nbsd_skip_solib_resolver
);
471 set_gdbarch_auxv_parse (gdbarch
, svr4_auxv_parse
);
473 /* `catch syscall' */
474 set_xml_syscall_file_name (gdbarch
, "syscalls/netbsd.xml");
475 set_gdbarch_get_syscall_number (gdbarch
, nbsd_get_syscall_number
);