1 /* Target-dependent code for FreeBSD, architecture-independent.
3 Copyright (C) 2002-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "exceptions.h"
22 #include "extract-store-integer.h"
28 #include "gdbthread.h"
30 #include "xml-syscall.h"
31 #include <sys/socket.h>
32 #include <arpa/inet.h>
35 #include "fbsd-tdep.h"
36 #include "gcore-elf.h"
38 /* This enum is derived from FreeBSD's <sys/signal.h>. */
67 FREEBSD_SIGVTALRM
= 26,
69 FREEBSD_SIGWINCH
= 28,
74 FREEBSD_SIGLIBRT
= 33,
75 FREEBSD_SIGRTMIN
= 65,
76 FREEBSD_SIGRTMAX
= 126,
79 /* Constants for values of si_code as defined in FreeBSD's
82 #define FBSD_SI_USER 0x10001
83 #define FBSD_SI_QUEUE 0x10002
84 #define FBSD_SI_TIMER 0x10003
85 #define FBSD_SI_ASYNCIO 0x10004
86 #define FBSD_SI_MESGQ 0x10005
87 #define FBSD_SI_KERNEL 0x10006
88 #define FBSD_SI_LWP 0x10007
90 #define FBSD_ILL_ILLOPC 1
91 #define FBSD_ILL_ILLOPN 2
92 #define FBSD_ILL_ILLADR 3
93 #define FBSD_ILL_ILLTRP 4
94 #define FBSD_ILL_PRVOPC 5
95 #define FBSD_ILL_PRVREG 6
96 #define FBSD_ILL_COPROC 7
97 #define FBSD_ILL_BADSTK 8
99 #define FBSD_BUS_ADRALN 1
100 #define FBSD_BUS_ADRERR 2
101 #define FBSD_BUS_OBJERR 3
102 #define FBSD_BUS_OOMERR 100
104 #define FBSD_SEGV_MAPERR 1
105 #define FBSD_SEGV_ACCERR 2
106 #define FBSD_SEGV_PKUERR 100
108 #define FBSD_FPE_INTOVF 1
109 #define FBSD_FPE_INTDIV 2
110 #define FBSD_FPE_FLTDIV 3
111 #define FBSD_FPE_FLTOVF 4
112 #define FBSD_FPE_FLTUND 5
113 #define FBSD_FPE_FLTRES 6
114 #define FBSD_FPE_FLTINV 7
115 #define FBSD_FPE_FLTSUB 8
117 #define FBSD_TRAP_BRKPT 1
118 #define FBSD_TRAP_TRACE 2
119 #define FBSD_TRAP_DTRACE 3
120 #define FBSD_TRAP_CAP 4
122 #define FBSD_CLD_EXITED 1
123 #define FBSD_CLD_KILLED 2
124 #define FBSD_CLD_DUMPED 3
125 #define FBSD_CLD_TRAPPED 4
126 #define FBSD_CLD_STOPPED 5
127 #define FBSD_CLD_CONTINUED 6
129 #define FBSD_POLL_IN 1
130 #define FBSD_POLL_OUT 2
131 #define FBSD_POLL_MSG 3
132 #define FBSD_POLL_ERR 4
133 #define FBSD_POLL_PRI 5
134 #define FBSD_POLL_HUP 6
136 /* FreeBSD kernels 12.0 and later include a copy of the
137 'ptrace_lwpinfo' structure returned by the PT_LWPINFO ptrace
138 operation in an ELF core note (NT_FREEBSD_PTLWPINFO) for each LWP.
139 The constants below define the offset of field members and flags in
140 this structure used by methods in this file. Note that the
141 'ptrace_lwpinfo' struct in the note is preceded by a 4 byte integer
142 containing the size of the structure. */
144 #define LWPINFO_OFFSET 0x4
146 /* Offsets in ptrace_lwpinfo. */
147 #define LWPINFO_PL_FLAGS 0x8
148 #define LWPINFO64_PL_SIGINFO 0x30
149 #define LWPINFO32_PL_SIGINFO 0x2c
151 /* Flags in pl_flags. */
152 #define PL_FLAG_SI 0x20 /* siginfo is valid */
154 /* Sizes of siginfo_t. */
155 #define SIZE64_SIGINFO_T 80
156 #define SIZE32_SIGINFO_T 64
158 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_VMMAP core
159 dump notes. See <sys/user.h> for the definition of struct
160 kinfo_vmentry. This data structure should have the same layout on
163 Note that FreeBSD 7.0 used an older version of this structure
164 (struct kinfo_vmentry), but the NT_FREEBSD_PROCSTAT_VMMAP core
165 dump note wasn't introduced until FreeBSD 9.2. As a result, the
166 core dump note has always used the 7.1 and later structure
169 #define KVE_STRUCTSIZE 0x0
170 #define KVE_START 0x8
172 #define KVE_OFFSET 0x18
173 #define KVE_FLAGS 0x2c
174 #define KVE_PROTECTION 0x38
175 #define KVE_PATH 0x88
177 /* Flags in the 'kve_protection' field in struct kinfo_vmentry. These
178 match the KVME_PROT_* constants in <sys/user.h>. */
180 #define KINFO_VME_PROT_READ 0x00000001
181 #define KINFO_VME_PROT_WRITE 0x00000002
182 #define KINFO_VME_PROT_EXEC 0x00000004
184 /* Flags in the 'kve_flags' field in struct kinfo_vmentry. These
185 match the KVME_FLAG_* constants in <sys/user.h>. */
187 #define KINFO_VME_FLAG_COW 0x00000001
188 #define KINFO_VME_FLAG_NEEDS_COPY 0x00000002
189 #define KINFO_VME_FLAG_NOCOREDUMP 0x00000004
190 #define KINFO_VME_FLAG_SUPER 0x00000008
191 #define KINFO_VME_FLAG_GROWS_UP 0x00000010
192 #define KINFO_VME_FLAG_GROWS_DOWN 0x00000020
194 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_FILES core
195 dump notes. See <sys/user.h> for the definition of struct
196 kinfo_file. This data structure should have the same layout on all
199 Note that FreeBSD 7.0 used an older version of this structure
200 (struct kinfo_ofile), but the NT_FREEBSD_PROCSTAT_FILES core dump
201 note wasn't introduced until FreeBSD 9.2. As a result, the core
202 dump note has always used the 7.1 and later structure format. */
204 #define KF_STRUCTSIZE 0x0
207 #define KF_FLAGS 0x10
208 #define KF_OFFSET 0x18
209 #define KF_VNODE_TYPE 0x20
210 #define KF_SOCK_DOMAIN 0x24
211 #define KF_SOCK_TYPE 0x28
212 #define KF_SOCK_PROTOCOL 0x2c
213 #define KF_SA_LOCAL 0x30
214 #define KF_SA_PEER 0xb0
215 #define KF_PATH 0x170
217 /* Constants for the 'kf_type' field in struct kinfo_file. These
218 match the KF_TYPE_* constants in <sys/user.h>. */
220 #define KINFO_FILE_TYPE_VNODE 1
221 #define KINFO_FILE_TYPE_SOCKET 2
222 #define KINFO_FILE_TYPE_PIPE 3
223 #define KINFO_FILE_TYPE_FIFO 4
224 #define KINFO_FILE_TYPE_KQUEUE 5
225 #define KINFO_FILE_TYPE_CRYPTO 6
226 #define KINFO_FILE_TYPE_MQUEUE 7
227 #define KINFO_FILE_TYPE_SHM 8
228 #define KINFO_FILE_TYPE_SEM 9
229 #define KINFO_FILE_TYPE_PTS 10
230 #define KINFO_FILE_TYPE_PROCDESC 11
232 /* Special values for the 'kf_fd' field in struct kinfo_file. These
233 match the KF_FD_TYPE_* constants in <sys/user.h>. */
235 #define KINFO_FILE_FD_TYPE_CWD -1
236 #define KINFO_FILE_FD_TYPE_ROOT -2
237 #define KINFO_FILE_FD_TYPE_JAIL -3
238 #define KINFO_FILE_FD_TYPE_TRACE -4
239 #define KINFO_FILE_FD_TYPE_TEXT -5
240 #define KINFO_FILE_FD_TYPE_CTTY -6
242 /* Flags in the 'kf_flags' field in struct kinfo_file. These match
243 the KF_FLAG_* constants in <sys/user.h>. */
245 #define KINFO_FILE_FLAG_READ 0x00000001
246 #define KINFO_FILE_FLAG_WRITE 0x00000002
247 #define KINFO_FILE_FLAG_APPEND 0x00000004
248 #define KINFO_FILE_FLAG_ASYNC 0x00000008
249 #define KINFO_FILE_FLAG_FSYNC 0x00000010
250 #define KINFO_FILE_FLAG_NONBLOCK 0x00000020
251 #define KINFO_FILE_FLAG_DIRECT 0x00000040
252 #define KINFO_FILE_FLAG_HASLOCK 0x00000080
253 #define KINFO_FILE_FLAG_EXEC 0x00004000
255 /* Constants for the 'kf_vnode_type' field in struct kinfo_file.
256 These match the KF_VTYPE_* constants in <sys/user.h>. */
258 #define KINFO_FILE_VTYPE_VREG 1
259 #define KINFO_FILE_VTYPE_VDIR 2
260 #define KINFO_FILE_VTYPE_VCHR 4
261 #define KINFO_FILE_VTYPE_VLNK 5
262 #define KINFO_FILE_VTYPE_VSOCK 6
263 #define KINFO_FILE_VTYPE_VFIFO 7
265 /* Constants for socket address families. These match AF_* constants
266 in <sys/socket.h>. */
268 #define FBSD_AF_UNIX 1
269 #define FBSD_AF_INET 2
270 #define FBSD_AF_INET6 28
272 /* Constants for socket types. These match SOCK_* constants in
275 #define FBSD_SOCK_STREAM 1
276 #define FBSD_SOCK_DGRAM 2
277 #define FBSD_SOCK_SEQPACKET 5
279 /* Constants for IP protocols. These match IPPROTO_* constants in
282 #define FBSD_IPPROTO_ICMP 1
283 #define FBSD_IPPROTO_TCP 6
284 #define FBSD_IPPROTO_UDP 17
285 #define FBSD_IPPROTO_SCTP 132
287 /* Socket address structures. These have the same layout on all
288 FreeBSD architectures. In addition, multibyte fields such as IP
289 addresses are always stored in network byte order. */
291 struct fbsd_sockaddr_in
300 struct fbsd_sockaddr_in6
304 uint8_t sin6_port
[2];
305 uint32_t sin6_flowinfo
;
306 uint8_t sin6_addr
[16];
307 uint32_t sin6_scope_id
;
310 struct fbsd_sockaddr_un
317 /* Number of 32-bit words in a signal set. This matches _SIG_WORDS in
318 <sys/_sigset.h> and is the same value on all architectures. */
322 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_PROC core
323 dump notes. See <sys/user.h> for the definition of struct
324 kinfo_proc. This data structure has different layouts on different
325 architectures mostly due to ILP32 vs LP64. However, FreeBSD/i386
326 uses a 32-bit time_t while all other architectures use a 64-bit
329 The core dump note actually contains one kinfo_proc structure for
330 each thread, but all of the process-wide data can be obtained from
331 the first structure. One result of this note's format is that some
332 of the process-wide status available in the native target method
333 from the kern.proc.pid.<pid> sysctl such as ki_stat and ki_siglist
334 is not available from a core dump. Instead, the per-thread data
335 structures contain the value of these fields for individual
338 struct kinfo_proc_layout
340 /* Offsets of struct kinfo_proc members. */
347 int ki_tdev_freebsd11
;
369 /* Offsets of struct rusage members. */
377 const struct kinfo_proc_layout kinfo_proc_layout_32
=
385 .ki_tdev_freebsd11
= 0x44,
386 .ki_sigignore
= 0x68,
405 .ki_rusage_ch
= 0x278,
414 const struct kinfo_proc_layout kinfo_proc_layout_i386
=
422 .ki_tdev_freebsd11
= 0x44,
423 .ki_sigignore
= 0x68,
442 .ki_rusage_ch
= 0x258,
451 const struct kinfo_proc_layout kinfo_proc_layout_64
=
459 .ki_tdev_freebsd11
= 0x64,
460 .ki_sigignore
= 0x88,
479 .ki_rusage_ch
= 0x2f0,
488 struct fbsd_gdbarch_data
490 struct type
*siginfo_type
= nullptr;
493 static const registry
<gdbarch
>::key
<fbsd_gdbarch_data
>
494 fbsd_gdbarch_data_handle
;
496 static struct fbsd_gdbarch_data
*
497 get_fbsd_gdbarch_data (struct gdbarch
*gdbarch
)
499 struct fbsd_gdbarch_data
*result
= fbsd_gdbarch_data_handle
.get (gdbarch
);
500 if (result
== nullptr)
501 result
= fbsd_gdbarch_data_handle
.emplace (gdbarch
);
505 struct fbsd_pspace_data
507 /* Offsets in the runtime linker's 'Obj_Entry' structure. */
508 LONGEST off_linkmap
= 0;
509 LONGEST off_tlsindex
= 0;
510 bool rtld_offsets_valid
= false;
512 /* vDSO mapping range. */
513 struct mem_range vdso_range
{};
515 /* Zero if the range hasn't been searched for, > 0 if a range was
516 found, or < 0 if a range was not found. */
517 int vdso_range_p
= 0;
520 /* Per-program-space data for FreeBSD architectures. */
521 static const registry
<program_space
>::key
<fbsd_pspace_data
>
522 fbsd_pspace_data_handle
;
524 static struct fbsd_pspace_data
*
525 get_fbsd_pspace_data (struct program_space
*pspace
)
527 struct fbsd_pspace_data
*data
;
529 data
= fbsd_pspace_data_handle
.get (pspace
);
531 data
= fbsd_pspace_data_handle
.emplace (pspace
);
536 /* This is how we want PTIDs from core files to be printed. */
539 fbsd_core_pid_to_str (struct gdbarch
*gdbarch
, ptid_t ptid
)
541 if (ptid
.lwp () != 0)
542 return string_printf ("LWP %ld", ptid
.lwp ());
544 return normal_pid_to_str (ptid
);
547 /* Extract the name assigned to a thread from a core. Returns the
548 string in a static buffer. */
551 fbsd_core_thread_name (struct gdbarch
*gdbarch
, struct thread_info
*thr
)
554 struct bfd_section
*section
;
557 if (thr
->ptid
.lwp () != 0)
559 /* FreeBSD includes a NT_FREEBSD_THRMISC note for each thread
560 whose contents are defined by a "struct thrmisc" declared in
561 <sys/procfs.h> on FreeBSD. The per-thread name is stored as
562 a null-terminated string as the first member of the
563 structure. Rather than define the full structure here, just
564 extract the null-terminated name from the start of the
566 thread_section_name
section_name (".thrmisc", thr
->ptid
);
567 bfd
*cbfd
= current_program_space
->core_bfd ();
569 section
= bfd_get_section_by_name (cbfd
, section_name
.c_str ());
570 if (section
!= NULL
&& bfd_section_size (section
) > 0)
572 /* Truncate the name if it is longer than "buf". */
573 size
= bfd_section_size (section
);
574 if (size
> sizeof buf
- 1)
575 size
= sizeof buf
- 1;
576 if (bfd_get_section_contents (cbfd
, section
, buf
, (file_ptr
) 0, size
)
581 /* Note that each thread will report the process command
582 as its thread name instead of an empty name if a name
583 has not been set explicitly. Return a NULL name in
585 if (strcmp (buf
, elf_tdata (cbfd
)->core
->program
) != 0)
594 /* Implement the "core_xfer_siginfo" gdbarch method. */
597 fbsd_core_xfer_siginfo (struct gdbarch
*gdbarch
, gdb_byte
*readbuf
,
598 ULONGEST offset
, ULONGEST len
)
602 if (gdbarch_long_bit (gdbarch
) == 32)
603 siginfo_size
= SIZE32_SIGINFO_T
;
605 siginfo_size
= SIZE64_SIGINFO_T
;
606 if (offset
> siginfo_size
)
609 thread_section_name
section_name (".note.freebsdcore.lwpinfo", inferior_ptid
);
610 bfd
*cbfd
= current_program_space
->core_bfd ();
611 asection
*section
= bfd_get_section_by_name (cbfd
, section_name
.c_str ());
616 if (!bfd_get_section_contents (cbfd
, section
, buf
,
617 LWPINFO_OFFSET
+ LWPINFO_PL_FLAGS
, 4))
620 int pl_flags
= extract_signed_integer (buf
, gdbarch_byte_order (gdbarch
));
621 if (!(pl_flags
& PL_FLAG_SI
))
624 if (offset
+ len
> siginfo_size
)
625 len
= siginfo_size
- offset
;
627 ULONGEST siginfo_offset
;
628 if (gdbarch_long_bit (gdbarch
) == 32)
629 siginfo_offset
= LWPINFO_OFFSET
+ LWPINFO32_PL_SIGINFO
;
631 siginfo_offset
= LWPINFO_OFFSET
+ LWPINFO64_PL_SIGINFO
;
633 if (!bfd_get_section_contents (cbfd
, section
, readbuf
,
634 siginfo_offset
+ offset
, len
))
641 find_signalled_thread (struct thread_info
*info
, void *data
)
643 if (info
->stop_signal () != GDB_SIGNAL_0
644 && info
->ptid
.pid () == inferior_ptid
.pid ())
650 /* Return a byte_vector containing the contents of a core dump note
651 for the target object of type OBJECT. If STRUCTSIZE is non-zero,
652 the data is prefixed with a 32-bit integer size to match the format
653 used in FreeBSD NT_PROCSTAT_* notes. */
655 static std::optional
<gdb::byte_vector
>
656 fbsd_make_note_desc (enum target_object object
, uint32_t structsize
)
658 std::optional
<gdb::byte_vector
> buf
=
659 target_read_alloc (current_inferior ()->top_target (), object
, NULL
);
660 if (!buf
|| buf
->empty ())
666 gdb::byte_vector
desc (sizeof (structsize
) + buf
->size ());
667 memcpy (desc
.data (), &structsize
, sizeof (structsize
));
668 std::copy (buf
->begin (), buf
->end (), desc
.data () + sizeof (structsize
));
672 /* Create appropriate note sections for a corefile, returning them in
675 static gdb::unique_xmalloc_ptr
<char>
676 fbsd_make_corefile_notes (struct gdbarch
*gdbarch
, bfd
*obfd
, int *note_size
)
678 gdb::unique_xmalloc_ptr
<char> note_data
;
679 Elf_Internal_Ehdr
*i_ehdrp
;
680 struct thread_info
*curr_thr
, *signalled_thr
;
682 /* Put a "FreeBSD" label in the ELF header. */
683 i_ehdrp
= elf_elfheader (obfd
);
684 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_FREEBSD
;
686 gdb_assert (gdbarch_iterate_over_regset_sections_p (gdbarch
));
688 if (current_program_space
->exec_filename () != nullptr)
690 const char *fname
= lbasename (current_program_space
->exec_filename ());
691 std::string psargs
= fname
;
693 const std::string
&infargs
= current_inferior ()->args ();
694 if (!infargs
.empty ())
695 psargs
+= ' ' + infargs
;
697 note_data
.reset (elfcore_write_prpsinfo (obfd
, note_data
.release (),
702 /* Thread register information. */
705 update_thread_list ();
707 catch (const gdb_exception_error
&e
)
709 exception_print (gdb_stderr
, e
);
712 /* Like the kernel, prefer dumping the signalled thread first.
713 "First thread" is what tools use to infer the signalled thread.
714 In case there's more than one signalled thread, prefer the
715 current thread, if it is signalled. */
716 curr_thr
= inferior_thread ();
717 if (curr_thr
->stop_signal () != GDB_SIGNAL_0
)
718 signalled_thr
= curr_thr
;
721 signalled_thr
= iterate_over_threads (find_signalled_thread
, NULL
);
722 if (signalled_thr
== NULL
)
723 signalled_thr
= curr_thr
;
726 enum gdb_signal stop_signal
= signalled_thr
->stop_signal ();
727 gcore_elf_build_thread_register_notes (gdbarch
, signalled_thr
, stop_signal
,
728 obfd
, ¬e_data
, note_size
);
729 for (thread_info
*thr
: current_inferior ()->non_exited_threads ())
731 if (thr
== signalled_thr
)
734 gcore_elf_build_thread_register_notes (gdbarch
, thr
, stop_signal
,
735 obfd
, ¬e_data
, note_size
);
738 /* Auxiliary vector. */
739 uint32_t structsize
= gdbarch_ptr_bit (gdbarch
) / 4; /* Elf_Auxinfo */
740 std::optional
<gdb::byte_vector
> note_desc
=
741 fbsd_make_note_desc (TARGET_OBJECT_AUXV
, structsize
);
742 if (note_desc
&& !note_desc
->empty ())
744 note_data
.reset (elfcore_write_note (obfd
, note_data
.release (),
745 note_size
, "FreeBSD",
746 NT_FREEBSD_PROCSTAT_AUXV
,
748 note_desc
->size ()));
753 /* Virtual memory mappings. */
754 note_desc
= fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_VMMAP
, 0);
755 if (note_desc
&& !note_desc
->empty ())
757 note_data
.reset (elfcore_write_note (obfd
, note_data
.release (),
758 note_size
, "FreeBSD",
759 NT_FREEBSD_PROCSTAT_VMMAP
,
761 note_desc
->size ()));
766 note_desc
= fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_PS_STRINGS
, 0);
767 if (note_desc
&& !note_desc
->empty ())
769 note_data
.reset (elfcore_write_note (obfd
, note_data
.release (),
770 note_size
, "FreeBSD",
771 NT_FREEBSD_PROCSTAT_PSSTRINGS
,
773 note_desc
->size ()));
778 /* Include the target description when possible. Some architectures
779 allow for per-thread gdbarch so we should really be emitting a tdesc
780 per-thread, however, we don't currently support reading in a
781 per-thread tdesc, so just emit the tdesc for the signalled thread. */
782 gdbarch
= target_thread_architecture (signalled_thr
->ptid
);
783 gcore_elf_make_tdesc_note (gdbarch
, obfd
, ¬e_data
, note_size
);
788 /* Helper function to generate the file descriptor description for a
789 single open file in 'info proc files'. */
792 fbsd_file_fd (int kf_fd
)
796 case KINFO_FILE_FD_TYPE_CWD
:
798 case KINFO_FILE_FD_TYPE_ROOT
:
800 case KINFO_FILE_FD_TYPE_JAIL
:
802 case KINFO_FILE_FD_TYPE_TRACE
:
804 case KINFO_FILE_FD_TYPE_TEXT
:
806 case KINFO_FILE_FD_TYPE_CTTY
:
809 return int_string (kf_fd
, 10, 1, 0, 0);
813 /* Helper function to generate the file type for a single open file in
814 'info proc files'. */
817 fbsd_file_type (int kf_type
, int kf_vnode_type
)
821 case KINFO_FILE_TYPE_VNODE
:
822 switch (kf_vnode_type
)
824 case KINFO_FILE_VTYPE_VREG
:
826 case KINFO_FILE_VTYPE_VDIR
:
828 case KINFO_FILE_VTYPE_VCHR
:
830 case KINFO_FILE_VTYPE_VLNK
:
832 case KINFO_FILE_VTYPE_VSOCK
:
834 case KINFO_FILE_VTYPE_VFIFO
:
838 char *str
= get_print_cell ();
840 xsnprintf (str
, PRINT_CELL_SIZE
, "vn:%d", kf_vnode_type
);
844 case KINFO_FILE_TYPE_SOCKET
:
846 case KINFO_FILE_TYPE_PIPE
:
848 case KINFO_FILE_TYPE_FIFO
:
850 case KINFO_FILE_TYPE_KQUEUE
:
852 case KINFO_FILE_TYPE_CRYPTO
:
854 case KINFO_FILE_TYPE_MQUEUE
:
856 case KINFO_FILE_TYPE_SHM
:
858 case KINFO_FILE_TYPE_SEM
:
860 case KINFO_FILE_TYPE_PTS
:
862 case KINFO_FILE_TYPE_PROCDESC
:
865 return int_string (kf_type
, 10, 1, 0, 0);
869 /* Helper function to generate the file flags for a single open file in
870 'info proc files'. */
873 fbsd_file_flags (int kf_flags
)
875 static char file_flags
[10];
877 file_flags
[0] = (kf_flags
& KINFO_FILE_FLAG_READ
) ? 'r' : '-';
878 file_flags
[1] = (kf_flags
& KINFO_FILE_FLAG_WRITE
) ? 'w' : '-';
879 file_flags
[2] = (kf_flags
& KINFO_FILE_FLAG_EXEC
) ? 'x' : '-';
880 file_flags
[3] = (kf_flags
& KINFO_FILE_FLAG_APPEND
) ? 'a' : '-';
881 file_flags
[4] = (kf_flags
& KINFO_FILE_FLAG_ASYNC
) ? 's' : '-';
882 file_flags
[5] = (kf_flags
& KINFO_FILE_FLAG_FSYNC
) ? 'f' : '-';
883 file_flags
[6] = (kf_flags
& KINFO_FILE_FLAG_NONBLOCK
) ? 'n' : '-';
884 file_flags
[7] = (kf_flags
& KINFO_FILE_FLAG_DIRECT
) ? 'd' : '-';
885 file_flags
[8] = (kf_flags
& KINFO_FILE_FLAG_HASLOCK
) ? 'l' : '-';
886 file_flags
[9] = '\0';
891 /* Helper function to generate the name of an IP protocol. */
894 fbsd_ipproto (int protocol
)
898 case FBSD_IPPROTO_ICMP
:
900 case FBSD_IPPROTO_TCP
:
902 case FBSD_IPPROTO_UDP
:
904 case FBSD_IPPROTO_SCTP
:
908 char *str
= get_print_cell ();
910 xsnprintf (str
, PRINT_CELL_SIZE
, "ip<%d>", protocol
);
916 /* Helper function to print out an IPv4 socket address. */
919 fbsd_print_sockaddr_in (const void *sockaddr
)
921 const struct fbsd_sockaddr_in
*sin
=
922 reinterpret_cast<const struct fbsd_sockaddr_in
*> (sockaddr
);
923 char buf
[INET_ADDRSTRLEN
];
925 if (inet_ntop (AF_INET
, sin
->sin_addr
, buf
, sizeof buf
) == nullptr)
926 error (_("Failed to format IPv4 address"));
927 gdb_printf ("%s:%u", buf
,
928 (sin
->sin_port
[0] << 8) | sin
->sin_port
[1]);
931 /* Helper function to print out an IPv6 socket address. */
934 fbsd_print_sockaddr_in6 (const void *sockaddr
)
936 const struct fbsd_sockaddr_in6
*sin6
=
937 reinterpret_cast<const struct fbsd_sockaddr_in6
*> (sockaddr
);
938 char buf
[INET6_ADDRSTRLEN
];
940 if (inet_ntop (AF_INET6
, sin6
->sin6_addr
, buf
, sizeof buf
) == nullptr)
941 error (_("Failed to format IPv6 address"));
942 gdb_printf ("%s.%u", buf
,
943 (sin6
->sin6_port
[0] << 8) | sin6
->sin6_port
[1]);
946 /* See fbsd-tdep.h. */
949 fbsd_info_proc_files_header ()
951 gdb_printf (_("Open files:\n\n"));
952 gdb_printf (" %6s %6s %10s %9s %s\n",
953 "FD", "Type", "Offset", "Flags ", "Name");
956 /* See fbsd-tdep.h. */
959 fbsd_info_proc_files_entry (int kf_type
, int kf_fd
, int kf_flags
,
960 LONGEST kf_offset
, int kf_vnode_type
,
961 int kf_sock_domain
, int kf_sock_type
,
962 int kf_sock_protocol
, const void *kf_sa_local
,
963 const void *kf_sa_peer
, const void *kf_path
)
965 gdb_printf (" %6s %6s %10s %8s ",
966 fbsd_file_fd (kf_fd
),
967 fbsd_file_type (kf_type
, kf_vnode_type
),
968 kf_offset
> -1 ? hex_string (kf_offset
) : "-",
969 fbsd_file_flags (kf_flags
));
970 if (kf_type
== KINFO_FILE_TYPE_SOCKET
)
972 switch (kf_sock_domain
)
976 switch (kf_sock_type
)
978 case FBSD_SOCK_STREAM
:
979 gdb_printf ("unix stream:");
981 case FBSD_SOCK_DGRAM
:
982 gdb_printf ("unix dgram:");
984 case FBSD_SOCK_SEQPACKET
:
985 gdb_printf ("unix seqpacket:");
988 gdb_printf ("unix <%d>:", kf_sock_type
);
992 /* For local sockets, print out the first non-nul path
993 rather than both paths. */
994 const struct fbsd_sockaddr_un
*saddr_un
995 = reinterpret_cast<const struct fbsd_sockaddr_un
*> (kf_sa_local
);
996 if (saddr_un
->sun_path
[0] == 0)
997 saddr_un
= reinterpret_cast<const struct fbsd_sockaddr_un
*>
999 gdb_printf ("%s", saddr_un
->sun_path
);
1003 gdb_printf ("%s4 ", fbsd_ipproto (kf_sock_protocol
));
1004 fbsd_print_sockaddr_in (kf_sa_local
);
1005 gdb_printf (" -> ");
1006 fbsd_print_sockaddr_in (kf_sa_peer
);
1009 gdb_printf ("%s6 ", fbsd_ipproto (kf_sock_protocol
));
1010 fbsd_print_sockaddr_in6 (kf_sa_local
);
1011 gdb_printf (" -> ");
1012 fbsd_print_sockaddr_in6 (kf_sa_peer
);
1017 gdb_printf ("%s", reinterpret_cast<const char *> (kf_path
));
1021 /* Implement "info proc files" for a corefile. */
1024 fbsd_core_info_proc_files (struct gdbarch
*gdbarch
)
1026 bfd
*cbfd
= current_program_space
->core_bfd ();
1027 asection
*section
= bfd_get_section_by_name (cbfd
, ".note.freebsdcore.files");
1028 if (section
== NULL
)
1030 warning (_("unable to find open files in core file"));
1034 size_t note_size
= bfd_section_size (section
);
1036 error (_("malformed core note - too short for header"));
1038 gdb::def_vector
<unsigned char> contents (note_size
);
1039 if (!bfd_get_section_contents (cbfd
, section
, contents
.data (),
1041 error (_("could not get core note contents"));
1043 unsigned char *descdata
= contents
.data ();
1044 unsigned char *descend
= descdata
+ note_size
;
1046 /* Skip over the structure size. */
1049 fbsd_info_proc_files_header ();
1051 while (descdata
+ KF_PATH
< descend
)
1053 ULONGEST structsize
= bfd_get_32 (cbfd
, descdata
+ KF_STRUCTSIZE
);
1054 if (structsize
< KF_PATH
)
1055 error (_("malformed core note - file structure too small"));
1057 LONGEST type
= bfd_get_signed_32 (cbfd
, descdata
+ KF_TYPE
);
1058 LONGEST fd
= bfd_get_signed_32 (cbfd
, descdata
+ KF_FD
);
1059 LONGEST flags
= bfd_get_signed_32 (cbfd
, descdata
+ KF_FLAGS
);
1060 LONGEST offset
= bfd_get_signed_64 (cbfd
, descdata
+ KF_OFFSET
);
1061 LONGEST vnode_type
= bfd_get_signed_32 (cbfd
, descdata
+ KF_VNODE_TYPE
);
1062 LONGEST sock_domain
= bfd_get_signed_32 (cbfd
, descdata
+ KF_SOCK_DOMAIN
);
1063 LONGEST sock_type
= bfd_get_signed_32 (cbfd
, descdata
+ KF_SOCK_TYPE
);
1064 LONGEST sock_protocol
= bfd_get_signed_32 (cbfd
,
1065 descdata
+ KF_SOCK_PROTOCOL
);
1066 fbsd_info_proc_files_entry (type
, fd
, flags
, offset
, vnode_type
,
1067 sock_domain
, sock_type
, sock_protocol
,
1068 descdata
+ KF_SA_LOCAL
, descdata
+ KF_SA_PEER
,
1069 descdata
+ KF_PATH
);
1071 descdata
+= structsize
;
1075 /* Helper function to generate mappings flags for a single VM map
1076 entry in 'info proc mappings'. */
1079 fbsd_vm_map_entry_flags (int kve_flags
, int kve_protection
)
1081 static char vm_flags
[9];
1083 vm_flags
[0] = (kve_protection
& KINFO_VME_PROT_READ
) ? 'r' : '-';
1084 vm_flags
[1] = (kve_protection
& KINFO_VME_PROT_WRITE
) ? 'w' : '-';
1085 vm_flags
[2] = (kve_protection
& KINFO_VME_PROT_EXEC
) ? 'x' : '-';
1087 vm_flags
[4] = (kve_flags
& KINFO_VME_FLAG_COW
) ? 'C' : '-';
1088 vm_flags
[5] = (kve_flags
& KINFO_VME_FLAG_NEEDS_COPY
) ? 'N' : '-';
1089 vm_flags
[6] = (kve_flags
& KINFO_VME_FLAG_SUPER
) ? 'S' : '-';
1090 vm_flags
[7] = (kve_flags
& KINFO_VME_FLAG_GROWS_UP
) ? 'U'
1091 : (kve_flags
& KINFO_VME_FLAG_GROWS_DOWN
) ? 'D' : '-';
1097 /* See fbsd-tdep.h. */
1100 fbsd_info_proc_mappings_header (int addr_bit
)
1102 gdb_printf (_("Mapped address spaces:\n\n"));
1105 gdb_printf (" %18s %18s %10s %10s %9s %s\n",
1108 " Size", " Offset", "Flags ", "File");
1112 gdb_printf ("\t%10s %10s %10s %10s %9s %s\n",
1115 " Size", " Offset", "Flags ", "File");
1119 /* See fbsd-tdep.h. */
1122 fbsd_info_proc_mappings_entry (int addr_bit
, ULONGEST kve_start
,
1123 ULONGEST kve_end
, ULONGEST kve_offset
,
1124 int kve_flags
, int kve_protection
,
1125 const void *kve_path
)
1129 gdb_printf (" %18s %18s %10s %10s %9s %s\n",
1130 hex_string (kve_start
),
1131 hex_string (kve_end
),
1132 hex_string (kve_end
- kve_start
),
1133 hex_string (kve_offset
),
1134 fbsd_vm_map_entry_flags (kve_flags
, kve_protection
),
1135 reinterpret_cast<const char *> (kve_path
));
1139 gdb_printf ("\t%10s %10s %10s %10s %9s %s\n",
1140 hex_string (kve_start
),
1141 hex_string (kve_end
),
1142 hex_string (kve_end
- kve_start
),
1143 hex_string (kve_offset
),
1144 fbsd_vm_map_entry_flags (kve_flags
, kve_protection
),
1145 reinterpret_cast<const char *> (kve_path
));
1149 /* Implement "info proc mappings" for a corefile. */
1152 fbsd_core_info_proc_mappings (struct gdbarch
*gdbarch
)
1155 unsigned char *descdata
, *descend
;
1157 bfd
*cbfd
= current_program_space
->core_bfd ();
1159 section
= bfd_get_section_by_name (cbfd
, ".note.freebsdcore.vmmap");
1160 if (section
== NULL
)
1162 warning (_("unable to find mappings in core file"));
1166 note_size
= bfd_section_size (section
);
1168 error (_("malformed core note - too short for header"));
1170 gdb::def_vector
<unsigned char> contents (note_size
);
1171 if (!bfd_get_section_contents (cbfd
, section
, contents
.data (), 0, note_size
))
1172 error (_("could not get core note contents"));
1174 descdata
= contents
.data ();
1175 descend
= descdata
+ note_size
;
1177 /* Skip over the structure size. */
1180 fbsd_info_proc_mappings_header (gdbarch_addr_bit (gdbarch
));
1181 while (descdata
+ KVE_PATH
< descend
)
1183 ULONGEST structsize
= bfd_get_32 (cbfd
, descdata
+ KVE_STRUCTSIZE
);
1184 if (structsize
< KVE_PATH
)
1185 error (_("malformed core note - vmmap entry too small"));
1187 ULONGEST start
= bfd_get_64 (cbfd
, descdata
+ KVE_START
);
1188 ULONGEST end
= bfd_get_64 (cbfd
, descdata
+ KVE_END
);
1189 ULONGEST offset
= bfd_get_64 (cbfd
, descdata
+ KVE_OFFSET
);
1190 LONGEST flags
= bfd_get_signed_32 (cbfd
, descdata
+ KVE_FLAGS
);
1191 LONGEST prot
= bfd_get_signed_32 (cbfd
, descdata
+ KVE_PROTECTION
);
1192 fbsd_info_proc_mappings_entry (gdbarch_addr_bit (gdbarch
), start
, end
,
1193 offset
, flags
, prot
, descdata
+ KVE_PATH
);
1195 descdata
+= structsize
;
1199 /* Fetch the pathname of a vnode for a single file descriptor from the
1200 file table core note. */
1202 static gdb::unique_xmalloc_ptr
<char>
1203 fbsd_core_vnode_path (struct gdbarch
*gdbarch
, int fd
)
1206 unsigned char *descdata
, *descend
;
1208 bfd
*cbfd
= current_program_space
->core_bfd ();
1210 section
= bfd_get_section_by_name (cbfd
, ".note.freebsdcore.files");
1211 if (section
== NULL
)
1214 note_size
= bfd_section_size (section
);
1216 error (_("malformed core note - too short for header"));
1218 gdb::def_vector
<unsigned char> contents (note_size
);
1219 if (!bfd_get_section_contents (cbfd
, section
, contents
.data (), 0, note_size
))
1220 error (_("could not get core note contents"));
1222 descdata
= contents
.data ();
1223 descend
= descdata
+ note_size
;
1225 /* Skip over the structure size. */
1228 while (descdata
+ KF_PATH
< descend
)
1230 ULONGEST structsize
;
1232 structsize
= bfd_get_32 (cbfd
, descdata
+ KF_STRUCTSIZE
);
1233 if (structsize
< KF_PATH
)
1234 error (_("malformed core note - file structure too small"));
1236 if (bfd_get_32 (cbfd
, descdata
+ KF_TYPE
) == KINFO_FILE_TYPE_VNODE
1237 && bfd_get_signed_32 (cbfd
, descdata
+ KF_FD
) == fd
)
1239 char *path
= (char *) descdata
+ KF_PATH
;
1240 return make_unique_xstrdup (path
);
1243 descdata
+= structsize
;
1248 /* Helper function to read a struct timeval. */
1251 fbsd_core_fetch_timeval (struct gdbarch
*gdbarch
, unsigned char *data
,
1252 LONGEST
&sec
, ULONGEST
&usec
)
1254 bfd
*cbfd
= current_program_space
->core_bfd ();
1256 if (gdbarch_addr_bit (gdbarch
) == 64)
1258 sec
= bfd_get_signed_64 (cbfd
, data
);
1259 usec
= bfd_get_64 (cbfd
, data
+ 8);
1261 else if (bfd_get_arch (cbfd
) == bfd_arch_i386
)
1263 sec
= bfd_get_signed_32 (cbfd
, data
);
1264 usec
= bfd_get_32 (cbfd
, data
+ 4);
1268 sec
= bfd_get_signed_64 (cbfd
, data
);
1269 usec
= bfd_get_32 (cbfd
, data
+ 8);
1273 /* Print out the contents of a signal set. */
1276 fbsd_print_sigset (const char *descr
, unsigned char *sigset
)
1278 bfd
*cbfd
= current_program_space
->core_bfd ();
1279 gdb_printf ("%s: ", descr
);
1280 for (int i
= 0; i
< SIG_WORDS
; i
++)
1281 gdb_printf ("%08x ",
1282 (unsigned int) bfd_get_32 (cbfd
, sigset
+ i
* 4));
1286 /* Implement "info proc status" for a corefile. */
1289 fbsd_core_info_proc_status (struct gdbarch
*gdbarch
)
1291 const struct kinfo_proc_layout
*kp
;
1293 unsigned char *descdata
;
1294 int addr_bit
, long_bit
;
1298 bfd
*cbfd
= current_program_space
->core_bfd ();
1300 section
= bfd_get_section_by_name (cbfd
, ".note.freebsdcore.proc");
1301 if (section
== NULL
)
1303 warning (_("unable to find process info in core file"));
1307 addr_bit
= gdbarch_addr_bit (gdbarch
);
1309 kp
= &kinfo_proc_layout_64
;
1310 else if (bfd_get_arch (cbfd
) == bfd_arch_i386
)
1311 kp
= &kinfo_proc_layout_i386
;
1313 kp
= &kinfo_proc_layout_32
;
1314 long_bit
= gdbarch_long_bit (gdbarch
);
1317 * Ensure that the note is large enough for all of the fields fetched
1318 * by this function. In particular, the note must contain the 32-bit
1319 * structure size, then it must be long enough to access the last
1320 * field used (ki_rusage_ch.ru_majflt) which is the size of a long.
1322 note_size
= bfd_section_size (section
);
1323 if (note_size
< (4 + kp
->ki_rusage_ch
+ kp
->ru_majflt
1324 + long_bit
/ TARGET_CHAR_BIT
))
1325 error (_("malformed core note - too short"));
1327 gdb::def_vector
<unsigned char> contents (note_size
);
1328 if (!bfd_get_section_contents (cbfd
, section
, contents
.data (), 0, note_size
))
1329 error (_("could not get core note contents"));
1331 descdata
= contents
.data ();
1333 /* Skip over the structure size. */
1336 /* Verify 'ki_layout' is 0. */
1337 if (bfd_get_32 (cbfd
, descdata
+ kp
->ki_layout
) != 0)
1339 warning (_("unsupported process information in core file"));
1343 gdb_printf ("Name: %.19s\n", descdata
+ kp
->ki_comm
);
1344 gdb_printf ("Process ID: %s\n",
1345 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_pid
)));
1346 gdb_printf ("Parent process: %s\n",
1347 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_ppid
)));
1348 gdb_printf ("Process group: %s\n",
1349 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_pgid
)));
1350 gdb_printf ("Session id: %s\n",
1351 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_sid
)));
1353 /* FreeBSD 12.0 and later store a 64-bit dev_t at 'ki_tdev'. Older
1354 kernels store a 32-bit dev_t at 'ki_tdev_freebsd11'. In older
1355 kernels the 64-bit 'ki_tdev' field is in a reserved section of
1356 the structure that is cleared to zero. Assume that a zero value
1357 in ki_tdev indicates a core dump from an older kernel and use the
1358 value in 'ki_tdev_freebsd11' instead. */
1359 value
= bfd_get_64 (cbfd
, descdata
+ kp
->ki_tdev
);
1361 value
= bfd_get_32 (cbfd
, descdata
+ kp
->ki_tdev_freebsd11
);
1362 gdb_printf ("TTY: %s\n", pulongest (value
));
1363 gdb_printf ("TTY owner process group: %s\n",
1364 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_tpgid
)));
1365 gdb_printf ("User IDs (real, effective, saved): %s %s %s\n",
1366 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_ruid
)),
1367 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_uid
)),
1368 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_svuid
)));
1369 gdb_printf ("Group IDs (real, effective, saved): %s %s %s\n",
1370 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_rgid
)),
1371 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_groups
)),
1372 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_svgid
)));
1373 gdb_printf ("Groups: ");
1374 uint16_t ngroups
= bfd_get_16 (cbfd
, descdata
+ kp
->ki_ngroups
);
1375 for (int i
= 0; i
< ngroups
; i
++)
1377 pulongest (bfd_get_32 (cbfd
,
1378 descdata
+ kp
->ki_groups
+ i
* 4)));
1380 value
= bfd_get (long_bit
, cbfd
,
1381 descdata
+ kp
->ki_rusage
+ kp
->ru_minflt
);
1382 gdb_printf ("Minor faults (no memory page): %s\n", pulongest (value
));
1383 value
= bfd_get (long_bit
, cbfd
,
1384 descdata
+ kp
->ki_rusage_ch
+ kp
->ru_minflt
);
1385 gdb_printf ("Minor faults, children: %s\n", pulongest (value
));
1386 value
= bfd_get (long_bit
, cbfd
,
1387 descdata
+ kp
->ki_rusage
+ kp
->ru_majflt
);
1388 gdb_printf ("Major faults (memory page faults): %s\n",
1390 value
= bfd_get (long_bit
, cbfd
,
1391 descdata
+ kp
->ki_rusage_ch
+ kp
->ru_majflt
);
1392 gdb_printf ("Major faults, children: %s\n", pulongest (value
));
1393 fbsd_core_fetch_timeval (gdbarch
,
1394 descdata
+ kp
->ki_rusage
+ kp
->ru_utime
,
1396 gdb_printf ("utime: %s.%06d\n", plongest (sec
), (int) value
);
1397 fbsd_core_fetch_timeval (gdbarch
,
1398 descdata
+ kp
->ki_rusage
+ kp
->ru_stime
,
1400 gdb_printf ("stime: %s.%06d\n", plongest (sec
), (int) value
);
1401 fbsd_core_fetch_timeval (gdbarch
,
1402 descdata
+ kp
->ki_rusage_ch
+ kp
->ru_utime
,
1404 gdb_printf ("utime, children: %s.%06d\n", plongest (sec
), (int) value
);
1405 fbsd_core_fetch_timeval (gdbarch
,
1406 descdata
+ kp
->ki_rusage_ch
+ kp
->ru_stime
,
1408 gdb_printf ("stime, children: %s.%06d\n", plongest (sec
), (int) value
);
1409 gdb_printf ("'nice' value: %d\n",
1410 (int) bfd_get_signed_8 (core_bfd
, descdata
+ kp
->ki_nice
));
1411 fbsd_core_fetch_timeval (gdbarch
, descdata
+ kp
->ki_start
, sec
, value
);
1412 gdb_printf ("Start time: %s.%06d\n", plongest (sec
), (int) value
);
1413 gdb_printf ("Virtual memory size: %s kB\n",
1414 pulongest (bfd_get (addr_bit
, cbfd
,
1415 descdata
+ kp
->ki_size
) / 1024));
1416 gdb_printf ("Data size: %s pages\n",
1417 pulongest (bfd_get (addr_bit
, cbfd
,
1418 descdata
+ kp
->ki_dsize
)));
1419 gdb_printf ("Stack size: %s pages\n",
1420 pulongest (bfd_get (addr_bit
, cbfd
,
1421 descdata
+ kp
->ki_ssize
)));
1422 gdb_printf ("Text size: %s pages\n",
1423 pulongest (bfd_get (addr_bit
, cbfd
,
1424 descdata
+ kp
->ki_tsize
)));
1425 gdb_printf ("Resident set size: %s pages\n",
1426 pulongest (bfd_get (addr_bit
, cbfd
,
1427 descdata
+ kp
->ki_rssize
)));
1428 gdb_printf ("Maximum RSS: %s pages\n",
1429 pulongest (bfd_get (long_bit
, cbfd
,
1430 descdata
+ kp
->ki_rusage
1432 fbsd_print_sigset ("Ignored Signals", descdata
+ kp
->ki_sigignore
);
1433 fbsd_print_sigset ("Caught Signals", descdata
+ kp
->ki_sigcatch
);
1436 /* Implement the "core_info_proc" gdbarch method. */
1439 fbsd_core_info_proc (struct gdbarch
*gdbarch
, const char *args
,
1440 enum info_proc_what what
)
1442 bool do_cmdline
= false;
1443 bool do_cwd
= false;
1444 bool do_exe
= false;
1445 bool do_files
= false;
1446 bool do_mappings
= false;
1447 bool do_status
= false;
1488 bfd
*cbfd
= current_program_space
->core_bfd ();
1489 pid
= bfd_core_file_pid (cbfd
);
1491 gdb_printf (_("process %d\n"), pid
);
1495 const char *cmdline
;
1497 cmdline
= bfd_core_file_failing_command (cbfd
);
1499 gdb_printf ("cmdline = '%s'\n", cmdline
);
1501 warning (_("Command line unavailable"));
1505 gdb::unique_xmalloc_ptr
<char> cwd
=
1506 fbsd_core_vnode_path (gdbarch
, KINFO_FILE_FD_TYPE_CWD
);
1508 gdb_printf ("cwd = '%s'\n", cwd
.get ());
1510 warning (_("unable to read current working directory"));
1514 gdb::unique_xmalloc_ptr
<char> exe
=
1515 fbsd_core_vnode_path (gdbarch
, KINFO_FILE_FD_TYPE_TEXT
);
1517 gdb_printf ("exe = '%s'\n", exe
.get ());
1519 warning (_("unable to read executable path name"));
1522 fbsd_core_info_proc_files (gdbarch
);
1524 fbsd_core_info_proc_mappings (gdbarch
);
1526 fbsd_core_info_proc_status (gdbarch
);
1529 /* Print descriptions of FreeBSD-specific AUXV entries to FILE. */
1532 fbsd_print_auxv_entry (struct gdbarch
*gdbarch
, struct ui_file
*file
,
1533 CORE_ADDR type
, CORE_ADDR val
)
1535 const char *name
= "???";
1536 const char *description
= "";
1537 enum auxv_format format
= AUXV_FORMAT_HEX
;
1556 default_print_auxv_entry (gdbarch
, file
, type
, val
);
1558 #define _TAGNAME(tag) #tag
1559 #define TAGNAME(tag) _TAGNAME(AT_##tag)
1560 #define TAG(tag, text, kind) \
1561 case AT_FREEBSD_##tag: name = TAGNAME(tag); description = text; format = kind; break
1562 TAG (EXECPATH
, _("Executable path"), AUXV_FORMAT_STR
);
1563 TAG (CANARY
, _("Canary for SSP"), AUXV_FORMAT_HEX
);
1564 TAG (CANARYLEN
, ("Length of the SSP canary"), AUXV_FORMAT_DEC
);
1565 TAG (OSRELDATE
, _("OSRELDATE"), AUXV_FORMAT_DEC
);
1566 TAG (NCPUS
, _("Number of CPUs"), AUXV_FORMAT_DEC
);
1567 TAG (PAGESIZES
, _("Pagesizes"), AUXV_FORMAT_HEX
);
1568 TAG (PAGESIZESLEN
, _("Number of pagesizes"), AUXV_FORMAT_DEC
);
1569 TAG (TIMEKEEP
, _("Pointer to timehands"), AUXV_FORMAT_HEX
);
1570 TAG (STACKPROT
, _("Initial stack protection"), AUXV_FORMAT_HEX
);
1571 TAG (EHDRFLAGS
, _("ELF header e_flags"), AUXV_FORMAT_HEX
);
1572 TAG (HWCAP
, _("Machine-dependent CPU capability hints"), AUXV_FORMAT_HEX
);
1573 TAG (HWCAP2
, _("Extension of AT_HWCAP"), AUXV_FORMAT_HEX
);
1574 TAG (BSDFLAGS
, _("ELF BSD flags"), AUXV_FORMAT_HEX
);
1575 TAG (ARGC
, _("Argument count"), AUXV_FORMAT_DEC
);
1576 TAG (ARGV
, _("Argument vector"), AUXV_FORMAT_HEX
);
1577 TAG (ENVC
, _("Environment count"), AUXV_FORMAT_DEC
);
1578 TAG (ENVV
, _("Environment vector"), AUXV_FORMAT_HEX
);
1579 TAG (PS_STRINGS
, _("Pointer to ps_strings"), AUXV_FORMAT_HEX
);
1580 TAG (FXRNG
, _("Pointer to root RNG seed version"), AUXV_FORMAT_HEX
);
1581 TAG (KPRELOAD
, _("Base address of vDSO"), AUXV_FORMAT_HEX
);
1582 TAG (USRSTACKBASE
, _("Top of user stack"), AUXV_FORMAT_HEX
);
1583 TAG (USRSTACKLIM
, _("Grow limit of user stack"), AUXV_FORMAT_HEX
);
1586 fprint_auxv_entry (file
, name
, description
, format
, type
, val
);
1589 /* Implement the "get_siginfo_type" gdbarch method. */
1591 static struct type
*
1592 fbsd_get_siginfo_type (struct gdbarch
*gdbarch
)
1594 struct fbsd_gdbarch_data
*fbsd_gdbarch_data
;
1595 struct type
*int_type
, *int32_type
, *uint32_type
, *long_type
, *void_ptr_type
;
1596 struct type
*uid_type
, *pid_type
;
1597 struct type
*sigval_type
, *reason_type
;
1598 struct type
*siginfo_type
;
1601 fbsd_gdbarch_data
= get_fbsd_gdbarch_data (gdbarch
);
1602 if (fbsd_gdbarch_data
->siginfo_type
!= NULL
)
1603 return fbsd_gdbarch_data
->siginfo_type
;
1605 type_allocator
alloc (gdbarch
);
1606 int_type
= init_integer_type (alloc
, gdbarch_int_bit (gdbarch
),
1608 int32_type
= init_integer_type (alloc
, 32, 0, "int32_t");
1609 uint32_type
= init_integer_type (alloc
, 32, 1, "uint32_t");
1610 long_type
= init_integer_type (alloc
, gdbarch_long_bit (gdbarch
),
1612 void_ptr_type
= lookup_pointer_type (builtin_type (gdbarch
)->builtin_void
);
1615 sigval_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
1616 sigval_type
->set_name (xstrdup ("sigval"));
1617 append_composite_type_field (sigval_type
, "sival_int", int_type
);
1618 append_composite_type_field (sigval_type
, "sival_ptr", void_ptr_type
);
1621 pid_type
= alloc
.new_type (TYPE_CODE_TYPEDEF
,
1622 int32_type
->length () * TARGET_CHAR_BIT
,
1624 pid_type
->set_target_type (int32_type
);
1625 pid_type
->set_target_is_stub (true);
1628 uid_type
= alloc
.new_type (TYPE_CODE_TYPEDEF
,
1629 uint32_type
->length () * TARGET_CHAR_BIT
,
1631 uid_type
->set_target_type (uint32_type
);
1632 pid_type
->set_target_is_stub (true);
1635 reason_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
1638 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1639 append_composite_type_field (type
, "si_trapno", int_type
);
1640 append_composite_type_field (reason_type
, "_fault", type
);
1643 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1644 append_composite_type_field (type
, "si_timerid", int_type
);
1645 append_composite_type_field (type
, "si_overrun", int_type
);
1646 append_composite_type_field (reason_type
, "_timer", type
);
1649 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1650 append_composite_type_field (type
, "si_mqd", int_type
);
1651 append_composite_type_field (reason_type
, "_mesgq", type
);
1654 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1655 append_composite_type_field (type
, "si_band", long_type
);
1656 append_composite_type_field (reason_type
, "_poll", type
);
1659 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1660 append_composite_type_field (type
, "__spare1__", long_type
);
1661 append_composite_type_field (type
, "__spare2__",
1662 init_vector_type (int_type
, 7));
1663 append_composite_type_field (reason_type
, "__spare__", type
);
1665 /* struct siginfo */
1666 siginfo_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1667 siginfo_type
->set_name (xstrdup ("siginfo"));
1668 append_composite_type_field (siginfo_type
, "si_signo", int_type
);
1669 append_composite_type_field (siginfo_type
, "si_errno", int_type
);
1670 append_composite_type_field (siginfo_type
, "si_code", int_type
);
1671 append_composite_type_field (siginfo_type
, "si_pid", pid_type
);
1672 append_composite_type_field (siginfo_type
, "si_uid", uid_type
);
1673 append_composite_type_field (siginfo_type
, "si_status", int_type
);
1674 append_composite_type_field (siginfo_type
, "si_addr", void_ptr_type
);
1675 append_composite_type_field (siginfo_type
, "si_value", sigval_type
);
1676 append_composite_type_field (siginfo_type
, "_reason", reason_type
);
1678 fbsd_gdbarch_data
->siginfo_type
= siginfo_type
;
1680 return siginfo_type
;
1683 /* Implement the "gdb_signal_from_target" gdbarch method. */
1685 static enum gdb_signal
1686 fbsd_gdb_signal_from_target (struct gdbarch
*gdbarch
, int signal
)
1691 return GDB_SIGNAL_0
;
1693 case FREEBSD_SIGHUP
:
1694 return GDB_SIGNAL_HUP
;
1696 case FREEBSD_SIGINT
:
1697 return GDB_SIGNAL_INT
;
1699 case FREEBSD_SIGQUIT
:
1700 return GDB_SIGNAL_QUIT
;
1702 case FREEBSD_SIGILL
:
1703 return GDB_SIGNAL_ILL
;
1705 case FREEBSD_SIGTRAP
:
1706 return GDB_SIGNAL_TRAP
;
1708 case FREEBSD_SIGABRT
:
1709 return GDB_SIGNAL_ABRT
;
1711 case FREEBSD_SIGEMT
:
1712 return GDB_SIGNAL_EMT
;
1714 case FREEBSD_SIGFPE
:
1715 return GDB_SIGNAL_FPE
;
1717 case FREEBSD_SIGKILL
:
1718 return GDB_SIGNAL_KILL
;
1720 case FREEBSD_SIGBUS
:
1721 return GDB_SIGNAL_BUS
;
1723 case FREEBSD_SIGSEGV
:
1724 return GDB_SIGNAL_SEGV
;
1726 case FREEBSD_SIGSYS
:
1727 return GDB_SIGNAL_SYS
;
1729 case FREEBSD_SIGPIPE
:
1730 return GDB_SIGNAL_PIPE
;
1732 case FREEBSD_SIGALRM
:
1733 return GDB_SIGNAL_ALRM
;
1735 case FREEBSD_SIGTERM
:
1736 return GDB_SIGNAL_TERM
;
1738 case FREEBSD_SIGURG
:
1739 return GDB_SIGNAL_URG
;
1741 case FREEBSD_SIGSTOP
:
1742 return GDB_SIGNAL_STOP
;
1744 case FREEBSD_SIGTSTP
:
1745 return GDB_SIGNAL_TSTP
;
1747 case FREEBSD_SIGCONT
:
1748 return GDB_SIGNAL_CONT
;
1750 case FREEBSD_SIGCHLD
:
1751 return GDB_SIGNAL_CHLD
;
1753 case FREEBSD_SIGTTIN
:
1754 return GDB_SIGNAL_TTIN
;
1756 case FREEBSD_SIGTTOU
:
1757 return GDB_SIGNAL_TTOU
;
1760 return GDB_SIGNAL_IO
;
1762 case FREEBSD_SIGXCPU
:
1763 return GDB_SIGNAL_XCPU
;
1765 case FREEBSD_SIGXFSZ
:
1766 return GDB_SIGNAL_XFSZ
;
1768 case FREEBSD_SIGVTALRM
:
1769 return GDB_SIGNAL_VTALRM
;
1771 case FREEBSD_SIGPROF
:
1772 return GDB_SIGNAL_PROF
;
1774 case FREEBSD_SIGWINCH
:
1775 return GDB_SIGNAL_WINCH
;
1777 case FREEBSD_SIGINFO
:
1778 return GDB_SIGNAL_INFO
;
1780 case FREEBSD_SIGUSR1
:
1781 return GDB_SIGNAL_USR1
;
1783 case FREEBSD_SIGUSR2
:
1784 return GDB_SIGNAL_USR2
;
1786 /* SIGTHR is the same as SIGLWP on FreeBSD. */
1787 case FREEBSD_SIGTHR
:
1788 return GDB_SIGNAL_LWP
;
1790 case FREEBSD_SIGLIBRT
:
1791 return GDB_SIGNAL_LIBRT
;
1794 if (signal
>= FREEBSD_SIGRTMIN
&& signal
<= FREEBSD_SIGRTMAX
)
1796 int offset
= signal
- FREEBSD_SIGRTMIN
;
1798 return (enum gdb_signal
) ((int) GDB_SIGNAL_REALTIME_65
+ offset
);
1801 return GDB_SIGNAL_UNKNOWN
;
1804 /* Implement the "gdb_signal_to_target" gdbarch method. */
1807 fbsd_gdb_signal_to_target (struct gdbarch
*gdbarch
,
1808 enum gdb_signal signal
)
1815 case GDB_SIGNAL_HUP
:
1816 return FREEBSD_SIGHUP
;
1818 case GDB_SIGNAL_INT
:
1819 return FREEBSD_SIGINT
;
1821 case GDB_SIGNAL_QUIT
:
1822 return FREEBSD_SIGQUIT
;
1824 case GDB_SIGNAL_ILL
:
1825 return FREEBSD_SIGILL
;
1827 case GDB_SIGNAL_TRAP
:
1828 return FREEBSD_SIGTRAP
;
1830 case GDB_SIGNAL_ABRT
:
1831 return FREEBSD_SIGABRT
;
1833 case GDB_SIGNAL_EMT
:
1834 return FREEBSD_SIGEMT
;
1836 case GDB_SIGNAL_FPE
:
1837 return FREEBSD_SIGFPE
;
1839 case GDB_SIGNAL_KILL
:
1840 return FREEBSD_SIGKILL
;
1842 case GDB_SIGNAL_BUS
:
1843 return FREEBSD_SIGBUS
;
1845 case GDB_SIGNAL_SEGV
:
1846 return FREEBSD_SIGSEGV
;
1848 case GDB_SIGNAL_SYS
:
1849 return FREEBSD_SIGSYS
;
1851 case GDB_SIGNAL_PIPE
:
1852 return FREEBSD_SIGPIPE
;
1854 case GDB_SIGNAL_ALRM
:
1855 return FREEBSD_SIGALRM
;
1857 case GDB_SIGNAL_TERM
:
1858 return FREEBSD_SIGTERM
;
1860 case GDB_SIGNAL_URG
:
1861 return FREEBSD_SIGURG
;
1863 case GDB_SIGNAL_STOP
:
1864 return FREEBSD_SIGSTOP
;
1866 case GDB_SIGNAL_TSTP
:
1867 return FREEBSD_SIGTSTP
;
1869 case GDB_SIGNAL_CONT
:
1870 return FREEBSD_SIGCONT
;
1872 case GDB_SIGNAL_CHLD
:
1873 return FREEBSD_SIGCHLD
;
1875 case GDB_SIGNAL_TTIN
:
1876 return FREEBSD_SIGTTIN
;
1878 case GDB_SIGNAL_TTOU
:
1879 return FREEBSD_SIGTTOU
;
1882 return FREEBSD_SIGIO
;
1884 case GDB_SIGNAL_XCPU
:
1885 return FREEBSD_SIGXCPU
;
1887 case GDB_SIGNAL_XFSZ
:
1888 return FREEBSD_SIGXFSZ
;
1890 case GDB_SIGNAL_VTALRM
:
1891 return FREEBSD_SIGVTALRM
;
1893 case GDB_SIGNAL_PROF
:
1894 return FREEBSD_SIGPROF
;
1896 case GDB_SIGNAL_WINCH
:
1897 return FREEBSD_SIGWINCH
;
1899 case GDB_SIGNAL_INFO
:
1900 return FREEBSD_SIGINFO
;
1902 case GDB_SIGNAL_USR1
:
1903 return FREEBSD_SIGUSR1
;
1905 case GDB_SIGNAL_USR2
:
1906 return FREEBSD_SIGUSR2
;
1908 case GDB_SIGNAL_LWP
:
1909 return FREEBSD_SIGTHR
;
1911 case GDB_SIGNAL_LIBRT
:
1912 return FREEBSD_SIGLIBRT
;
1915 if (signal
>= GDB_SIGNAL_REALTIME_65
1916 && signal
<= GDB_SIGNAL_REALTIME_126
)
1918 int offset
= signal
- GDB_SIGNAL_REALTIME_65
;
1920 return FREEBSD_SIGRTMIN
+ offset
;
1926 /* Implement the "get_syscall_number" gdbarch method. */
1929 fbsd_get_syscall_number (struct gdbarch
*gdbarch
, thread_info
*thread
)
1932 /* FreeBSD doesn't use gdbarch_get_syscall_number since FreeBSD
1933 native targets fetch the system call number from the
1934 'pl_syscall_code' member of struct ptrace_lwpinfo in fbsd_wait.
1935 However, system call catching requires this function to be
1938 internal_error (_("fbsd_get_sycall_number called"));
1941 /* Read an integer symbol value from the current target. */
1944 fbsd_read_integer_by_name (struct gdbarch
*gdbarch
, const char *name
)
1946 bound_minimal_symbol ms
1947 = lookup_minimal_symbol (current_program_space
, name
);
1948 if (ms
.minsym
== NULL
)
1949 error (_("Unable to resolve symbol '%s'"), name
);
1952 if (target_read_memory (ms
.value_address (), buf
, sizeof buf
) != 0)
1953 error (_("Unable to read value of '%s'"), name
);
1955 return extract_signed_integer (buf
, gdbarch_byte_order (gdbarch
));
1958 /* Lookup offsets of fields in the runtime linker's 'Obj_Entry'
1959 structure needed to determine the TLS index of an object file. */
1962 fbsd_fetch_rtld_offsets (struct gdbarch
*gdbarch
, struct fbsd_pspace_data
*data
)
1966 /* Fetch offsets from debug symbols in rtld. */
1967 struct symbol
*obj_entry_sym
1968 = lookup_symbol_in_language ("Struct_Obj_Entry", nullptr,
1969 SEARCH_STRUCT_DOMAIN
,
1970 language_c
, nullptr).symbol
;
1971 if (obj_entry_sym
== NULL
)
1972 error (_("Unable to find Struct_Obj_Entry symbol"));
1973 data
->off_linkmap
= lookup_struct_elt (obj_entry_sym
->type (),
1974 "linkmap", 0).offset
/ 8;
1975 data
->off_tlsindex
= lookup_struct_elt (obj_entry_sym
->type (),
1976 "tlsindex", 0).offset
/ 8;
1977 data
->rtld_offsets_valid
= true;
1980 catch (const gdb_exception_error
&e
)
1982 data
->off_linkmap
= -1;
1987 /* Fetch offsets from global variables in libthr. Note that
1988 this does not work for single-threaded processes that are not
1989 linked against libthr. */
1990 data
->off_linkmap
= fbsd_read_integer_by_name (gdbarch
,
1991 "_thread_off_linkmap");
1992 data
->off_tlsindex
= fbsd_read_integer_by_name (gdbarch
,
1993 "_thread_off_tlsindex");
1994 data
->rtld_offsets_valid
= true;
1997 catch (const gdb_exception_error
&e
)
1999 data
->off_linkmap
= -1;
2003 /* Helper function to read the TLS index of an object file associated
2004 with a link map entry at LM_ADDR. */
2007 fbsd_get_tls_index (struct gdbarch
*gdbarch
, CORE_ADDR lm_addr
)
2009 struct fbsd_pspace_data
*data
= get_fbsd_pspace_data (current_program_space
);
2011 if (!data
->rtld_offsets_valid
)
2012 fbsd_fetch_rtld_offsets (gdbarch
, data
);
2014 if (data
->off_linkmap
== -1)
2015 throw_error (TLS_GENERIC_ERROR
,
2016 _("Cannot fetch runtime linker structure offsets"));
2018 /* Simulate container_of to convert from LM_ADDR to the Obj_Entry
2019 pointer and then compute the offset of the tlsindex member. */
2020 CORE_ADDR tlsindex_addr
= lm_addr
- data
->off_linkmap
+ data
->off_tlsindex
;
2023 if (target_read_memory (tlsindex_addr
, buf
, sizeof buf
) != 0)
2024 throw_error (TLS_GENERIC_ERROR
,
2025 _("Cannot find thread-local variables on this target"));
2027 return extract_signed_integer (buf
, gdbarch_byte_order (gdbarch
));
2030 /* See fbsd-tdep.h. */
2033 fbsd_get_thread_local_address (struct gdbarch
*gdbarch
, CORE_ADDR dtv_addr
,
2034 CORE_ADDR lm_addr
, CORE_ADDR offset
)
2036 LONGEST tls_index
= fbsd_get_tls_index (gdbarch
, lm_addr
);
2038 gdb::byte_vector
buf (gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
);
2039 if (target_read_memory (dtv_addr
, buf
.data (), buf
.size ()) != 0)
2040 throw_error (TLS_GENERIC_ERROR
,
2041 _("Cannot find thread-local variables on this target"));
2043 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
2045 = gdbarch_pointer_to_address (gdbarch
, builtin
->builtin_data_ptr
,
2048 addr
+= (tls_index
+ 1) * builtin
->builtin_data_ptr
->length ();
2049 if (target_read_memory (addr
, buf
.data (), buf
.size ()) != 0)
2050 throw_error (TLS_GENERIC_ERROR
,
2051 _("Cannot find thread-local variables on this target"));
2053 addr
= gdbarch_pointer_to_address (gdbarch
, builtin
->builtin_data_ptr
,
2055 return addr
+ offset
;
2058 /* See fbsd-tdep.h. */
2061 fbsd_skip_solib_resolver (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
2063 bound_minimal_symbol msym
2064 = lookup_minimal_symbol (current_program_space
, "_rtld_bind");
2065 if (msym
.minsym
!= nullptr && msym
.value_address () == pc
)
2066 return frame_unwind_caller_pc (get_current_frame ());
2071 /* Return description of signal code or nullptr. */
2074 fbsd_signal_cause (enum gdb_signal siggnal
, int code
)
2076 /* Signal-independent causes. */
2080 return _("Sent by kill()");
2082 return _("Sent by sigqueue()");
2084 return _("Timer expired");
2085 case FBSD_SI_ASYNCIO
:
2086 return _("Asynchronous I/O request completed");
2088 return _("Message arrived on empty message queue");
2089 case FBSD_SI_KERNEL
:
2090 return _("Sent by kernel");
2092 return _("Sent by thr_kill()");
2097 case GDB_SIGNAL_ILL
:
2100 case FBSD_ILL_ILLOPC
:
2101 return _("Illegal opcode");
2102 case FBSD_ILL_ILLOPN
:
2103 return _("Illegal operand");
2104 case FBSD_ILL_ILLADR
:
2105 return _("Illegal addressing mode");
2106 case FBSD_ILL_ILLTRP
:
2107 return _("Illegal trap");
2108 case FBSD_ILL_PRVOPC
:
2109 return _("Privileged opcode");
2110 case FBSD_ILL_PRVREG
:
2111 return _("Privileged register");
2112 case FBSD_ILL_COPROC
:
2113 return _("Coprocessor error");
2114 case FBSD_ILL_BADSTK
:
2115 return _("Internal stack error");
2118 case GDB_SIGNAL_BUS
:
2121 case FBSD_BUS_ADRALN
:
2122 return _("Invalid address alignment");
2123 case FBSD_BUS_ADRERR
:
2124 return _("Address not present");
2125 case FBSD_BUS_OBJERR
:
2126 return _("Object-specific hardware error");
2127 case FBSD_BUS_OOMERR
:
2128 return _("Out of memory");
2131 case GDB_SIGNAL_SEGV
:
2134 case FBSD_SEGV_MAPERR
:
2135 return _("Address not mapped to object");
2136 case FBSD_SEGV_ACCERR
:
2137 return _("Invalid permissions for mapped object");
2138 case FBSD_SEGV_PKUERR
:
2139 return _("PKU violation");
2142 case GDB_SIGNAL_FPE
:
2145 case FBSD_FPE_INTOVF
:
2146 return _("Integer overflow");
2147 case FBSD_FPE_INTDIV
:
2148 return _("Integer divide by zero");
2149 case FBSD_FPE_FLTDIV
:
2150 return _("Floating point divide by zero");
2151 case FBSD_FPE_FLTOVF
:
2152 return _("Floating point overflow");
2153 case FBSD_FPE_FLTUND
:
2154 return _("Floating point underflow");
2155 case FBSD_FPE_FLTRES
:
2156 return _("Floating point inexact result");
2157 case FBSD_FPE_FLTINV
:
2158 return _("Invalid floating point operation");
2159 case FBSD_FPE_FLTSUB
:
2160 return _("Subscript out of range");
2163 case GDB_SIGNAL_TRAP
:
2166 case FBSD_TRAP_BRKPT
:
2167 return _("Breakpoint");
2168 case FBSD_TRAP_TRACE
:
2169 return _("Trace trap");
2170 case FBSD_TRAP_DTRACE
:
2171 return _("DTrace-induced trap");
2173 return _("Capability violation");
2176 case GDB_SIGNAL_CHLD
:
2179 case FBSD_CLD_EXITED
:
2180 return _("Child has exited");
2181 case FBSD_CLD_KILLED
:
2182 return _("Child has terminated abnormally");
2183 case FBSD_CLD_DUMPED
:
2184 return _("Child has dumped core");
2185 case FBSD_CLD_TRAPPED
:
2186 return _("Traced child has trapped");
2187 case FBSD_CLD_STOPPED
:
2188 return _("Child has stopped");
2189 case FBSD_CLD_CONTINUED
:
2190 return _("Stopped child has continued");
2193 case GDB_SIGNAL_POLL
:
2197 return _("Data input available");
2199 return _("Output buffers available");
2201 return _("Input message available");
2203 return _("I/O error");
2205 return _("High priority input available");
2207 return _("Device disconnected");
2215 /* Report additional details for a signal stop. */
2218 fbsd_report_signal_info (struct gdbarch
*gdbarch
, struct ui_out
*uiout
,
2219 enum gdb_signal siggnal
)
2221 LONGEST code
, mqd
, pid
, status
, timerid
, uid
;
2225 code
= parse_and_eval_long ("$_siginfo.si_code");
2226 pid
= parse_and_eval_long ("$_siginfo.si_pid");
2227 uid
= parse_and_eval_long ("$_siginfo.si_uid");
2228 status
= parse_and_eval_long ("$_siginfo.si_status");
2229 timerid
= parse_and_eval_long ("$_siginfo._reason._timer.si_timerid");
2230 mqd
= parse_and_eval_long ("$_siginfo._reason._mesgq.si_mqd");
2232 catch (const gdb_exception_error
&e
)
2237 const char *meaning
= fbsd_signal_cause (siggnal
, code
);
2238 if (meaning
== nullptr)
2241 uiout
->text (".\n");
2242 uiout
->field_string ("sigcode-meaning", meaning
);
2249 uiout
->text (" from pid ");
2250 uiout
->field_string ("sending-pid", plongest (pid
));
2251 uiout
->text (" and user ");
2252 uiout
->field_string ("sending-uid", plongest (uid
));
2255 uiout
->text (": timerid ");
2256 uiout
->field_string ("timerid", plongest (timerid
));
2259 uiout
->text (": message queue ");
2260 uiout
->field_string ("message-queue", plongest (mqd
));
2262 case FBSD_SI_ASYNCIO
:
2266 if (siggnal
== GDB_SIGNAL_CHLD
)
2268 uiout
->text (": pid ");
2269 uiout
->field_string ("child-pid", plongest (pid
));
2270 uiout
->text (", uid ");
2271 uiout
->field_string ("child-uid", plongest (uid
));
2272 if (code
== FBSD_CLD_EXITED
)
2274 uiout
->text (", exit status ");
2275 uiout
->field_string ("exit-status", plongest (status
));
2279 uiout
->text (", signal ");
2280 uiout
->field_string ("signal", plongest (status
));
2285 /* Search a list of struct kinfo_vmmap entries in the ENTRIES buffer
2286 of LEN bytes to find the length of the entry starting at ADDR.
2287 Returns the length of the entry or zero if no entry was found. */
2290 fbsd_vmmap_length (struct gdbarch
*gdbarch
, unsigned char *entries
, size_t len
,
2293 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2294 unsigned char *descdata
= entries
;
2295 unsigned char *descend
= descdata
+ len
;
2297 /* Skip over the structure size. */
2300 while (descdata
+ KVE_PATH
< descend
)
2302 ULONGEST structsize
= extract_unsigned_integer (descdata
2303 + KVE_STRUCTSIZE
, 4,
2305 if (structsize
< KVE_PATH
)
2308 ULONGEST start
= extract_unsigned_integer (descdata
+ KVE_START
, 8,
2310 ULONGEST end
= extract_unsigned_integer (descdata
+ KVE_END
, 8,
2315 descdata
+= structsize
;
2320 /* Helper for fbsd_vsyscall_range that does the real work of finding
2321 the vDSO's address range. */
2324 fbsd_vdso_range (struct gdbarch
*gdbarch
, struct mem_range
*range
)
2326 if (target_auxv_search (AT_FREEBSD_KPRELOAD
, &range
->start
) <= 0)
2329 if (!target_has_execution ())
2331 /* Search for the ending address in the NT_PROCSTAT_VMMAP note. */
2332 bfd
*cbfd
= current_program_space
->core_bfd ();
2333 asection
*section
= bfd_get_section_by_name (cbfd
,
2334 ".note.freebsdcore.vmmap");
2335 if (section
== nullptr)
2338 size_t note_size
= bfd_section_size (section
);
2342 gdb::def_vector
<unsigned char> contents (note_size
);
2343 if (!bfd_get_section_contents (cbfd
, section
, contents
.data (),
2347 range
->length
= fbsd_vmmap_length (gdbarch
, contents
.data (), note_size
,
2352 /* Fetch the list of address space entries from the running target. */
2353 std::optional
<gdb::byte_vector
> buf
=
2354 target_read_alloc (current_inferior ()->top_target (),
2355 TARGET_OBJECT_FREEBSD_VMMAP
, nullptr);
2356 if (!buf
|| buf
->empty ())
2359 range
->length
= fbsd_vmmap_length (gdbarch
, buf
->data (), buf
->size (),
2362 return range
->length
!= 0;
2365 /* Return the address range of the vDSO for the current inferior. */
2368 fbsd_vsyscall_range (struct gdbarch
*gdbarch
, struct mem_range
*range
)
2370 struct fbsd_pspace_data
*data
= get_fbsd_pspace_data (current_program_space
);
2372 if (data
->vdso_range_p
== 0)
2374 if (fbsd_vdso_range (gdbarch
, &data
->vdso_range
))
2375 data
->vdso_range_p
= 1;
2377 data
->vdso_range_p
= -1;
2380 if (data
->vdso_range_p
< 0)
2383 *range
= data
->vdso_range
;
2387 /* To be called from GDB_OSABI_FREEBSD handlers. */
2390 fbsd_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
2392 set_gdbarch_core_pid_to_str (gdbarch
, fbsd_core_pid_to_str
);
2393 set_gdbarch_core_thread_name (gdbarch
, fbsd_core_thread_name
);
2394 set_gdbarch_core_xfer_siginfo (gdbarch
, fbsd_core_xfer_siginfo
);
2395 set_gdbarch_make_corefile_notes (gdbarch
, fbsd_make_corefile_notes
);
2396 set_gdbarch_core_info_proc (gdbarch
, fbsd_core_info_proc
);
2397 set_gdbarch_print_auxv_entry (gdbarch
, fbsd_print_auxv_entry
);
2398 set_gdbarch_get_siginfo_type (gdbarch
, fbsd_get_siginfo_type
);
2399 set_gdbarch_gdb_signal_from_target (gdbarch
, fbsd_gdb_signal_from_target
);
2400 set_gdbarch_gdb_signal_to_target (gdbarch
, fbsd_gdb_signal_to_target
);
2401 set_gdbarch_report_signal_info (gdbarch
, fbsd_report_signal_info
);
2402 set_gdbarch_skip_solib_resolver (gdbarch
, fbsd_skip_solib_resolver
);
2403 set_gdbarch_vsyscall_range (gdbarch
, fbsd_vsyscall_range
);
2405 /* `catch syscall' */
2406 set_xml_syscall_file_name (gdbarch
, "syscalls/freebsd.xml");
2407 set_gdbarch_get_syscall_number (gdbarch
, fbsd_get_syscall_number
);