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"
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 /* FIXME: kettenis/20060115: We should really eliminate the next two
47 functions completely. */
49 struct link_map_offsets
*
50 nbsd_ilp32_solib_svr4_fetch_link_map_offsets (void)
52 return svr4_ilp32_fetch_link_map_offsets ();
55 struct link_map_offsets
*
56 nbsd_lp64_solib_svr4_fetch_link_map_offsets (void)
58 return svr4_lp64_fetch_link_map_offsets ();
62 nbsd_pc_in_sigtramp (CORE_ADDR pc
, const char *func_name
)
64 /* Check for libc-provided signal trampoline. All such trampolines
65 have function names which begin with "__sigtramp". */
67 return (func_name
!= NULL
68 && startswith (func_name
, "__sigtramp"));
71 /* This enum is derived from NETBSD's <sys/signal.h>. */
111 /* Implement the "gdb_signal_from_target" gdbarch method. */
113 static enum gdb_signal
114 nbsd_gdb_signal_from_target (struct gdbarch
*gdbarch
, int signal
)
122 return GDB_SIGNAL_HUP
;
125 return GDB_SIGNAL_INT
;
128 return GDB_SIGNAL_QUIT
;
131 return GDB_SIGNAL_ILL
;
134 return GDB_SIGNAL_TRAP
;
137 return GDB_SIGNAL_ABRT
;
140 return GDB_SIGNAL_EMT
;
143 return GDB_SIGNAL_FPE
;
146 return GDB_SIGNAL_KILL
;
149 return GDB_SIGNAL_BUS
;
152 return GDB_SIGNAL_SEGV
;
155 return GDB_SIGNAL_SYS
;
158 return GDB_SIGNAL_PIPE
;
161 return GDB_SIGNAL_ALRM
;
164 return GDB_SIGNAL_TERM
;
167 return GDB_SIGNAL_URG
;
170 return GDB_SIGNAL_STOP
;
173 return GDB_SIGNAL_TSTP
;
176 return GDB_SIGNAL_CONT
;
179 return GDB_SIGNAL_CHLD
;
182 return GDB_SIGNAL_TTIN
;
185 return GDB_SIGNAL_TTOU
;
188 return GDB_SIGNAL_IO
;
191 return GDB_SIGNAL_XCPU
;
194 return GDB_SIGNAL_XFSZ
;
197 return GDB_SIGNAL_VTALRM
;
200 return GDB_SIGNAL_PROF
;
203 return GDB_SIGNAL_WINCH
;
206 return GDB_SIGNAL_INFO
;
209 return GDB_SIGNAL_USR1
;
212 return GDB_SIGNAL_USR2
;
215 return GDB_SIGNAL_PWR
;
217 /* SIGRTMIN and SIGRTMAX are not continuous in <gdb/signals.def>,
218 therefore we have to handle them here. */
220 return GDB_SIGNAL_REALTIME_33
;
223 return GDB_SIGNAL_REALTIME_63
;
226 if (signal
>= NBSD_SIGRTMIN
+ 1 && signal
<= NBSD_SIGRTMAX
- 1)
228 int offset
= signal
- NBSD_SIGRTMIN
+ 1;
230 return (enum gdb_signal
) ((int) GDB_SIGNAL_REALTIME_34
+ offset
);
233 return GDB_SIGNAL_UNKNOWN
;
236 /* Implement the "gdb_signal_to_target" gdbarch method. */
239 nbsd_gdb_signal_to_target (struct gdbarch
*gdbarch
,
240 enum gdb_signal signal
)
253 case GDB_SIGNAL_QUIT
:
259 case GDB_SIGNAL_TRAP
:
262 case GDB_SIGNAL_ABRT
:
271 case GDB_SIGNAL_KILL
:
277 case GDB_SIGNAL_SEGV
:
283 case GDB_SIGNAL_PIPE
:
286 case GDB_SIGNAL_ALRM
:
289 case GDB_SIGNAL_TERM
:
295 case GDB_SIGNAL_TSTP
:
298 case GDB_SIGNAL_CONT
:
301 case GDB_SIGNAL_CHLD
:
304 case GDB_SIGNAL_TTIN
:
307 case GDB_SIGNAL_TTOU
:
313 case GDB_SIGNAL_XCPU
:
316 case GDB_SIGNAL_XFSZ
:
319 case GDB_SIGNAL_VTALRM
:
320 return NBSD_SIGVTALRM
;
322 case GDB_SIGNAL_PROF
:
325 case GDB_SIGNAL_WINCH
:
326 return NBSD_SIGWINCH
;
328 case GDB_SIGNAL_INFO
:
331 case GDB_SIGNAL_USR1
:
334 case GDB_SIGNAL_USR2
:
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
;
345 /* Same comment applies to _64. */
346 case GDB_SIGNAL_REALTIME_63
:
347 return NBSD_SIGRTMAX
;
350 if (signal
>= GDB_SIGNAL_REALTIME_34
351 && signal
<= GDB_SIGNAL_REALTIME_62
)
353 int offset
= signal
- GDB_SIGNAL_REALTIME_32
;
355 return NBSD_SIGRTMIN
+ 1 + offset
;
361 /* Shared library resolver handling. */
364 nbsd_skip_solib_resolver (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
366 struct bound_minimal_symbol msym
;
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 ());
372 return find_solib_trampoline_target (get_current_frame (), pc
);
375 /* See nbsd-tdep.h. */
378 nbsd_info_proc_mappings_header (int addr_bit
)
380 printf_filtered (_("Mapped address spaces:\n\n"));
383 printf_filtered (" %18s %18s %10s %10s %9s %s\n",
386 " Size", " Offset", "Flags ", "File");
390 printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
393 " Size", " Offset", "Flags ", "File");
397 /* Helper function to generate mappings flags for a single VM map
398 entry in 'info proc mappings'. */
401 nbsd_vm_map_entry_flags (int kve_flags
, int kve_protection
)
403 static char vm_flags
[9];
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' : '-';
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' : '-';
420 nbsd_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
)
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
),
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
),
447 /* See nbsd-tdep.h. */
450 nbsd_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
452 set_gdbarch_gdb_signal_from_target (gdbarch
, nbsd_gdb_signal_from_target
);
453 set_gdbarch_gdb_signal_to_target (gdbarch
, nbsd_gdb_signal_to_target
);
454 set_gdbarch_skip_solib_resolver (gdbarch
, nbsd_skip_solib_resolver
);
455 set_gdbarch_auxv_parse (gdbarch
, svr4_auxv_parse
);