1 /* Target-dependent code for FreeBSD, architecture-independent.
3 Copyright (C) 2002-2025 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"
29 #include "xml-syscall.h"
30 #include <sys/socket.h>
31 #include <arpa/inet.h>
34 #include "fbsd-tdep.h"
35 #include "gcore-elf.h"
36 #include "arch-utils.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
)
643 return (info
->stop_signal () != GDB_SIGNAL_0
644 && info
->ptid
.pid () == inferior_ptid
.pid ());
647 /* Return a byte_vector containing the contents of a core dump note
648 for the target object of type OBJECT. If STRUCTSIZE is non-zero,
649 the data is prefixed with a 32-bit integer size to match the format
650 used in FreeBSD NT_PROCSTAT_* notes. */
652 static std::optional
<gdb::byte_vector
>
653 fbsd_make_note_desc (enum target_object object
, uint32_t structsize
)
655 std::optional
<gdb::byte_vector
> buf
=
656 target_read_alloc (current_inferior ()->top_target (), object
, NULL
);
657 if (!buf
|| buf
->empty ())
663 gdb::byte_vector
desc (sizeof (structsize
) + buf
->size ());
664 memcpy (desc
.data (), &structsize
, sizeof (structsize
));
665 std::copy (buf
->begin (), buf
->end (), desc
.data () + sizeof (structsize
));
669 /* Create appropriate note sections for a corefile, returning them in
672 static gdb::unique_xmalloc_ptr
<char>
673 fbsd_make_corefile_notes (struct gdbarch
*gdbarch
, bfd
*obfd
, int *note_size
)
675 gdb::unique_xmalloc_ptr
<char> note_data
;
676 Elf_Internal_Ehdr
*i_ehdrp
;
677 struct thread_info
*curr_thr
, *signalled_thr
;
679 /* Put a "FreeBSD" label in the ELF header. */
680 i_ehdrp
= elf_elfheader (obfd
);
681 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_FREEBSD
;
683 gdb_assert (gdbarch_iterate_over_regset_sections_p (gdbarch
));
685 if (current_program_space
->exec_filename () != nullptr)
687 const char *fname
= lbasename (current_program_space
->exec_filename ());
688 std::string psargs
= fname
;
690 const std::string
&infargs
= current_inferior ()->args ();
691 if (!infargs
.empty ())
692 psargs
+= ' ' + infargs
;
694 note_data
.reset (elfcore_write_prpsinfo (obfd
, note_data
.release (),
699 /* Thread register information. */
702 update_thread_list ();
704 catch (const gdb_exception_error
&e
)
706 exception_print (gdb_stderr
, e
);
709 /* Like the kernel, prefer dumping the signalled thread first.
710 "First thread" is what tools use to infer the signalled thread.
711 In case there's more than one signalled thread, prefer the
712 current thread, if it is signalled. */
713 curr_thr
= inferior_thread ();
714 if (curr_thr
->stop_signal () != GDB_SIGNAL_0
)
715 signalled_thr
= curr_thr
;
718 signalled_thr
= iterate_over_threads (find_signalled_thread
);
719 if (signalled_thr
== NULL
)
720 signalled_thr
= curr_thr
;
723 enum gdb_signal stop_signal
= signalled_thr
->stop_signal ();
724 gcore_elf_build_thread_register_notes (gdbarch
, signalled_thr
, stop_signal
,
725 obfd
, ¬e_data
, note_size
);
726 for (thread_info
*thr
: current_inferior ()->non_exited_threads ())
728 if (thr
== signalled_thr
)
731 gcore_elf_build_thread_register_notes (gdbarch
, thr
, stop_signal
,
732 obfd
, ¬e_data
, note_size
);
735 /* Auxiliary vector. */
736 uint32_t structsize
= gdbarch_ptr_bit (gdbarch
) / 4; /* Elf_Auxinfo */
737 std::optional
<gdb::byte_vector
> note_desc
=
738 fbsd_make_note_desc (TARGET_OBJECT_AUXV
, structsize
);
739 if (note_desc
&& !note_desc
->empty ())
741 note_data
.reset (elfcore_write_note (obfd
, note_data
.release (),
742 note_size
, "FreeBSD",
743 NT_FREEBSD_PROCSTAT_AUXV
,
745 note_desc
->size ()));
750 /* Virtual memory mappings. */
751 note_desc
= fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_VMMAP
, 0);
752 if (note_desc
&& !note_desc
->empty ())
754 note_data
.reset (elfcore_write_note (obfd
, note_data
.release (),
755 note_size
, "FreeBSD",
756 NT_FREEBSD_PROCSTAT_VMMAP
,
758 note_desc
->size ()));
763 note_desc
= fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_PS_STRINGS
, 0);
764 if (note_desc
&& !note_desc
->empty ())
766 note_data
.reset (elfcore_write_note (obfd
, note_data
.release (),
767 note_size
, "FreeBSD",
768 NT_FREEBSD_PROCSTAT_PSSTRINGS
,
770 note_desc
->size ()));
775 /* Include the target description when possible. Some architectures
776 allow for per-thread gdbarch so we should really be emitting a tdesc
777 per-thread, however, we don't currently support reading in a
778 per-thread tdesc, so just emit the tdesc for the signalled thread. */
779 gdbarch
= target_thread_architecture (signalled_thr
->ptid
);
780 gcore_elf_make_tdesc_note (gdbarch
, obfd
, ¬e_data
, note_size
);
785 /* Helper function to generate the file descriptor description for a
786 single open file in 'info proc files'. */
789 fbsd_file_fd (int kf_fd
)
793 case KINFO_FILE_FD_TYPE_CWD
:
795 case KINFO_FILE_FD_TYPE_ROOT
:
797 case KINFO_FILE_FD_TYPE_JAIL
:
799 case KINFO_FILE_FD_TYPE_TRACE
:
801 case KINFO_FILE_FD_TYPE_TEXT
:
803 case KINFO_FILE_FD_TYPE_CTTY
:
806 return int_string (kf_fd
, 10, 1, 0, 0);
810 /* Helper function to generate the file type for a single open file in
811 'info proc files'. */
814 fbsd_file_type (int kf_type
, int kf_vnode_type
)
818 case KINFO_FILE_TYPE_VNODE
:
819 switch (kf_vnode_type
)
821 case KINFO_FILE_VTYPE_VREG
:
823 case KINFO_FILE_VTYPE_VDIR
:
825 case KINFO_FILE_VTYPE_VCHR
:
827 case KINFO_FILE_VTYPE_VLNK
:
829 case KINFO_FILE_VTYPE_VSOCK
:
831 case KINFO_FILE_VTYPE_VFIFO
:
835 char *str
= get_print_cell ();
837 xsnprintf (str
, PRINT_CELL_SIZE
, "vn:%d", kf_vnode_type
);
841 case KINFO_FILE_TYPE_SOCKET
:
843 case KINFO_FILE_TYPE_PIPE
:
845 case KINFO_FILE_TYPE_FIFO
:
847 case KINFO_FILE_TYPE_KQUEUE
:
849 case KINFO_FILE_TYPE_CRYPTO
:
851 case KINFO_FILE_TYPE_MQUEUE
:
853 case KINFO_FILE_TYPE_SHM
:
855 case KINFO_FILE_TYPE_SEM
:
857 case KINFO_FILE_TYPE_PTS
:
859 case KINFO_FILE_TYPE_PROCDESC
:
862 return int_string (kf_type
, 10, 1, 0, 0);
866 /* Helper function to generate the file flags for a single open file in
867 'info proc files'. */
870 fbsd_file_flags (int kf_flags
)
872 static char file_flags
[10];
874 file_flags
[0] = (kf_flags
& KINFO_FILE_FLAG_READ
) ? 'r' : '-';
875 file_flags
[1] = (kf_flags
& KINFO_FILE_FLAG_WRITE
) ? 'w' : '-';
876 file_flags
[2] = (kf_flags
& KINFO_FILE_FLAG_EXEC
) ? 'x' : '-';
877 file_flags
[3] = (kf_flags
& KINFO_FILE_FLAG_APPEND
) ? 'a' : '-';
878 file_flags
[4] = (kf_flags
& KINFO_FILE_FLAG_ASYNC
) ? 's' : '-';
879 file_flags
[5] = (kf_flags
& KINFO_FILE_FLAG_FSYNC
) ? 'f' : '-';
880 file_flags
[6] = (kf_flags
& KINFO_FILE_FLAG_NONBLOCK
) ? 'n' : '-';
881 file_flags
[7] = (kf_flags
& KINFO_FILE_FLAG_DIRECT
) ? 'd' : '-';
882 file_flags
[8] = (kf_flags
& KINFO_FILE_FLAG_HASLOCK
) ? 'l' : '-';
883 file_flags
[9] = '\0';
888 /* Helper function to generate the name of an IP protocol. */
891 fbsd_ipproto (int protocol
)
895 case FBSD_IPPROTO_ICMP
:
897 case FBSD_IPPROTO_TCP
:
899 case FBSD_IPPROTO_UDP
:
901 case FBSD_IPPROTO_SCTP
:
905 char *str
= get_print_cell ();
907 xsnprintf (str
, PRINT_CELL_SIZE
, "ip<%d>", protocol
);
913 /* Helper function to print out an IPv4 socket address. */
916 fbsd_print_sockaddr_in (const void *sockaddr
)
918 const struct fbsd_sockaddr_in
*sin
=
919 reinterpret_cast<const struct fbsd_sockaddr_in
*> (sockaddr
);
920 char buf
[INET_ADDRSTRLEN
];
922 if (inet_ntop (AF_INET
, sin
->sin_addr
, buf
, sizeof buf
) == nullptr)
923 error (_("Failed to format IPv4 address"));
924 gdb_printf ("%s:%u", buf
,
925 (sin
->sin_port
[0] << 8) | sin
->sin_port
[1]);
928 /* Helper function to print out an IPv6 socket address. */
931 fbsd_print_sockaddr_in6 (const void *sockaddr
)
933 const struct fbsd_sockaddr_in6
*sin6
=
934 reinterpret_cast<const struct fbsd_sockaddr_in6
*> (sockaddr
);
935 char buf
[INET6_ADDRSTRLEN
];
937 if (inet_ntop (AF_INET6
, sin6
->sin6_addr
, buf
, sizeof buf
) == nullptr)
938 error (_("Failed to format IPv6 address"));
939 gdb_printf ("%s.%u", buf
,
940 (sin6
->sin6_port
[0] << 8) | sin6
->sin6_port
[1]);
943 /* See fbsd-tdep.h. */
946 fbsd_info_proc_files_header ()
948 gdb_printf (_("Open files:\n\n"));
949 gdb_printf (" %6s %6s %10s %9s %s\n",
950 "FD", "Type", "Offset", "Flags ", "Name");
953 /* See fbsd-tdep.h. */
956 fbsd_info_proc_files_entry (int kf_type
, int kf_fd
, int kf_flags
,
957 LONGEST kf_offset
, int kf_vnode_type
,
958 int kf_sock_domain
, int kf_sock_type
,
959 int kf_sock_protocol
, const void *kf_sa_local
,
960 const void *kf_sa_peer
, const void *kf_path
)
962 gdb_printf (" %6s %6s %10s %8s ",
963 fbsd_file_fd (kf_fd
),
964 fbsd_file_type (kf_type
, kf_vnode_type
),
965 kf_offset
> -1 ? hex_string (kf_offset
) : "-",
966 fbsd_file_flags (kf_flags
));
967 if (kf_type
== KINFO_FILE_TYPE_SOCKET
)
969 switch (kf_sock_domain
)
973 switch (kf_sock_type
)
975 case FBSD_SOCK_STREAM
:
976 gdb_printf ("unix stream:");
978 case FBSD_SOCK_DGRAM
:
979 gdb_printf ("unix dgram:");
981 case FBSD_SOCK_SEQPACKET
:
982 gdb_printf ("unix seqpacket:");
985 gdb_printf ("unix <%d>:", kf_sock_type
);
989 /* For local sockets, print out the first non-nul path
990 rather than both paths. */
991 const struct fbsd_sockaddr_un
*saddr_un
992 = reinterpret_cast<const struct fbsd_sockaddr_un
*> (kf_sa_local
);
993 if (saddr_un
->sun_path
[0] == 0)
994 saddr_un
= reinterpret_cast<const struct fbsd_sockaddr_un
*>
996 gdb_printf ("%s", saddr_un
->sun_path
);
1000 gdb_printf ("%s4 ", fbsd_ipproto (kf_sock_protocol
));
1001 fbsd_print_sockaddr_in (kf_sa_local
);
1002 gdb_printf (" -> ");
1003 fbsd_print_sockaddr_in (kf_sa_peer
);
1006 gdb_printf ("%s6 ", fbsd_ipproto (kf_sock_protocol
));
1007 fbsd_print_sockaddr_in6 (kf_sa_local
);
1008 gdb_printf (" -> ");
1009 fbsd_print_sockaddr_in6 (kf_sa_peer
);
1014 gdb_printf ("%s", reinterpret_cast<const char *> (kf_path
));
1018 /* Implement "info proc files" for a corefile. */
1021 fbsd_core_info_proc_files (struct gdbarch
*gdbarch
)
1023 bfd
*cbfd
= current_program_space
->core_bfd ();
1024 asection
*section
= bfd_get_section_by_name (cbfd
, ".note.freebsdcore.files");
1025 if (section
== NULL
)
1027 warning (_("unable to find open files in core file"));
1031 size_t note_size
= bfd_section_size (section
);
1033 error (_("malformed core note - too short for header"));
1035 gdb::def_vector
<unsigned char> contents (note_size
);
1036 if (!bfd_get_section_contents (cbfd
, section
, contents
.data (),
1038 error (_("could not get core note contents"));
1040 unsigned char *descdata
= contents
.data ();
1041 unsigned char *descend
= descdata
+ note_size
;
1043 /* Skip over the structure size. */
1046 fbsd_info_proc_files_header ();
1048 while (descdata
+ KF_PATH
< descend
)
1050 ULONGEST structsize
= bfd_get_32 (cbfd
, descdata
+ KF_STRUCTSIZE
);
1051 if (structsize
< KF_PATH
)
1052 error (_("malformed core note - file structure too small"));
1054 LONGEST type
= bfd_get_signed_32 (cbfd
, descdata
+ KF_TYPE
);
1055 LONGEST fd
= bfd_get_signed_32 (cbfd
, descdata
+ KF_FD
);
1056 LONGEST flags
= bfd_get_signed_32 (cbfd
, descdata
+ KF_FLAGS
);
1057 LONGEST offset
= bfd_get_signed_64 (cbfd
, descdata
+ KF_OFFSET
);
1058 LONGEST vnode_type
= bfd_get_signed_32 (cbfd
, descdata
+ KF_VNODE_TYPE
);
1059 LONGEST sock_domain
= bfd_get_signed_32 (cbfd
, descdata
+ KF_SOCK_DOMAIN
);
1060 LONGEST sock_type
= bfd_get_signed_32 (cbfd
, descdata
+ KF_SOCK_TYPE
);
1061 LONGEST sock_protocol
= bfd_get_signed_32 (cbfd
,
1062 descdata
+ KF_SOCK_PROTOCOL
);
1063 fbsd_info_proc_files_entry (type
, fd
, flags
, offset
, vnode_type
,
1064 sock_domain
, sock_type
, sock_protocol
,
1065 descdata
+ KF_SA_LOCAL
, descdata
+ KF_SA_PEER
,
1066 descdata
+ KF_PATH
);
1068 descdata
+= structsize
;
1072 /* Helper function to generate mappings flags for a single VM map
1073 entry in 'info proc mappings'. */
1076 fbsd_vm_map_entry_flags (int kve_flags
, int kve_protection
)
1078 static char vm_flags
[9];
1080 vm_flags
[0] = (kve_protection
& KINFO_VME_PROT_READ
) ? 'r' : '-';
1081 vm_flags
[1] = (kve_protection
& KINFO_VME_PROT_WRITE
) ? 'w' : '-';
1082 vm_flags
[2] = (kve_protection
& KINFO_VME_PROT_EXEC
) ? 'x' : '-';
1084 vm_flags
[4] = (kve_flags
& KINFO_VME_FLAG_COW
) ? 'C' : '-';
1085 vm_flags
[5] = (kve_flags
& KINFO_VME_FLAG_NEEDS_COPY
) ? 'N' : '-';
1086 vm_flags
[6] = (kve_flags
& KINFO_VME_FLAG_SUPER
) ? 'S' : '-';
1087 vm_flags
[7] = (kve_flags
& KINFO_VME_FLAG_GROWS_UP
) ? 'U'
1088 : (kve_flags
& KINFO_VME_FLAG_GROWS_DOWN
) ? 'D' : '-';
1094 /* See fbsd-tdep.h. */
1097 fbsd_info_proc_mappings_header (int addr_bit
)
1099 gdb_printf (_("Mapped address spaces:\n\n"));
1102 gdb_printf (" %18s %18s %10s %10s %9s %s\n",
1105 " Size", " Offset", "Flags ", "File");
1109 gdb_printf ("\t%10s %10s %10s %10s %9s %s\n",
1112 " Size", " Offset", "Flags ", "File");
1116 /* See fbsd-tdep.h. */
1119 fbsd_info_proc_mappings_entry (int addr_bit
, ULONGEST kve_start
,
1120 ULONGEST kve_end
, ULONGEST kve_offset
,
1121 int kve_flags
, int kve_protection
,
1122 const void *kve_path
)
1126 gdb_printf (" %18s %18s %10s %10s %9s %s\n",
1127 hex_string (kve_start
),
1128 hex_string (kve_end
),
1129 hex_string (kve_end
- kve_start
),
1130 hex_string (kve_offset
),
1131 fbsd_vm_map_entry_flags (kve_flags
, kve_protection
),
1132 reinterpret_cast<const char *> (kve_path
));
1136 gdb_printf ("\t%10s %10s %10s %10s %9s %s\n",
1137 hex_string (kve_start
),
1138 hex_string (kve_end
),
1139 hex_string (kve_end
- kve_start
),
1140 hex_string (kve_offset
),
1141 fbsd_vm_map_entry_flags (kve_flags
, kve_protection
),
1142 reinterpret_cast<const char *> (kve_path
));
1146 /* Implement "info proc mappings" for a corefile. */
1149 fbsd_core_info_proc_mappings (struct gdbarch
*gdbarch
)
1152 unsigned char *descdata
, *descend
;
1154 bfd
*cbfd
= current_program_space
->core_bfd ();
1156 section
= bfd_get_section_by_name (cbfd
, ".note.freebsdcore.vmmap");
1157 if (section
== NULL
)
1159 warning (_("unable to find mappings in core file"));
1163 note_size
= bfd_section_size (section
);
1165 error (_("malformed core note - too short for header"));
1167 gdb::def_vector
<unsigned char> contents (note_size
);
1168 if (!bfd_get_section_contents (cbfd
, section
, contents
.data (), 0, note_size
))
1169 error (_("could not get core note contents"));
1171 descdata
= contents
.data ();
1172 descend
= descdata
+ note_size
;
1174 /* Skip over the structure size. */
1177 fbsd_info_proc_mappings_header (gdbarch_addr_bit (gdbarch
));
1178 while (descdata
+ KVE_PATH
< descend
)
1180 ULONGEST structsize
= bfd_get_32 (cbfd
, descdata
+ KVE_STRUCTSIZE
);
1181 if (structsize
< KVE_PATH
)
1182 error (_("malformed core note - vmmap entry too small"));
1184 ULONGEST start
= bfd_get_64 (cbfd
, descdata
+ KVE_START
);
1185 ULONGEST end
= bfd_get_64 (cbfd
, descdata
+ KVE_END
);
1186 ULONGEST offset
= bfd_get_64 (cbfd
, descdata
+ KVE_OFFSET
);
1187 LONGEST flags
= bfd_get_signed_32 (cbfd
, descdata
+ KVE_FLAGS
);
1188 LONGEST prot
= bfd_get_signed_32 (cbfd
, descdata
+ KVE_PROTECTION
);
1189 fbsd_info_proc_mappings_entry (gdbarch_addr_bit (gdbarch
), start
, end
,
1190 offset
, flags
, prot
, descdata
+ KVE_PATH
);
1192 descdata
+= structsize
;
1196 /* Fetch the pathname of a vnode for a single file descriptor from the
1197 file table core note. */
1199 static gdb::unique_xmalloc_ptr
<char>
1200 fbsd_core_vnode_path (struct gdbarch
*gdbarch
, int fd
)
1203 unsigned char *descdata
, *descend
;
1205 bfd
*cbfd
= current_program_space
->core_bfd ();
1207 section
= bfd_get_section_by_name (cbfd
, ".note.freebsdcore.files");
1208 if (section
== NULL
)
1211 note_size
= bfd_section_size (section
);
1213 error (_("malformed core note - too short for header"));
1215 gdb::def_vector
<unsigned char> contents (note_size
);
1216 if (!bfd_get_section_contents (cbfd
, section
, contents
.data (), 0, note_size
))
1217 error (_("could not get core note contents"));
1219 descdata
= contents
.data ();
1220 descend
= descdata
+ note_size
;
1222 /* Skip over the structure size. */
1225 while (descdata
+ KF_PATH
< descend
)
1227 ULONGEST structsize
;
1229 structsize
= bfd_get_32 (cbfd
, descdata
+ KF_STRUCTSIZE
);
1230 if (structsize
< KF_PATH
)
1231 error (_("malformed core note - file structure too small"));
1233 if (bfd_get_32 (cbfd
, descdata
+ KF_TYPE
) == KINFO_FILE_TYPE_VNODE
1234 && bfd_get_signed_32 (cbfd
, descdata
+ KF_FD
) == fd
)
1236 char *path
= (char *) descdata
+ KF_PATH
;
1237 return make_unique_xstrdup (path
);
1240 descdata
+= structsize
;
1245 /* Helper function to read a struct timeval. */
1248 fbsd_core_fetch_timeval (struct gdbarch
*gdbarch
, unsigned char *data
,
1249 LONGEST
&sec
, ULONGEST
&usec
)
1251 bfd
*cbfd
= current_program_space
->core_bfd ();
1253 if (gdbarch_addr_bit (gdbarch
) == 64)
1255 sec
= bfd_get_signed_64 (cbfd
, data
);
1256 usec
= bfd_get_64 (cbfd
, data
+ 8);
1258 else if (bfd_get_arch (cbfd
) == bfd_arch_i386
)
1260 sec
= bfd_get_signed_32 (cbfd
, data
);
1261 usec
= bfd_get_32 (cbfd
, data
+ 4);
1265 sec
= bfd_get_signed_64 (cbfd
, data
);
1266 usec
= bfd_get_32 (cbfd
, data
+ 8);
1270 /* Print out the contents of a signal set. */
1273 fbsd_print_sigset (const char *descr
, unsigned char *sigset
)
1275 bfd
*cbfd
= current_program_space
->core_bfd ();
1276 gdb_printf ("%s: ", descr
);
1277 for (int i
= 0; i
< SIG_WORDS
; i
++)
1278 gdb_printf ("%08x ",
1279 (unsigned int) bfd_get_32 (cbfd
, sigset
+ i
* 4));
1283 /* Implement "info proc status" for a corefile. */
1286 fbsd_core_info_proc_status (struct gdbarch
*gdbarch
)
1288 const struct kinfo_proc_layout
*kp
;
1290 unsigned char *descdata
;
1291 int addr_bit
, long_bit
;
1295 bfd
*cbfd
= current_program_space
->core_bfd ();
1297 section
= bfd_get_section_by_name (cbfd
, ".note.freebsdcore.proc");
1298 if (section
== NULL
)
1300 warning (_("unable to find process info in core file"));
1304 addr_bit
= gdbarch_addr_bit (gdbarch
);
1306 kp
= &kinfo_proc_layout_64
;
1307 else if (bfd_get_arch (cbfd
) == bfd_arch_i386
)
1308 kp
= &kinfo_proc_layout_i386
;
1310 kp
= &kinfo_proc_layout_32
;
1311 long_bit
= gdbarch_long_bit (gdbarch
);
1314 * Ensure that the note is large enough for all of the fields fetched
1315 * by this function. In particular, the note must contain the 32-bit
1316 * structure size, then it must be long enough to access the last
1317 * field used (ki_rusage_ch.ru_majflt) which is the size of a long.
1319 note_size
= bfd_section_size (section
);
1320 if (note_size
< (4 + kp
->ki_rusage_ch
+ kp
->ru_majflt
1321 + long_bit
/ TARGET_CHAR_BIT
))
1322 error (_("malformed core note - too short"));
1324 gdb::def_vector
<unsigned char> contents (note_size
);
1325 if (!bfd_get_section_contents (cbfd
, section
, contents
.data (), 0, note_size
))
1326 error (_("could not get core note contents"));
1328 descdata
= contents
.data ();
1330 /* Skip over the structure size. */
1333 /* Verify 'ki_layout' is 0. */
1334 if (bfd_get_32 (cbfd
, descdata
+ kp
->ki_layout
) != 0)
1336 warning (_("unsupported process information in core file"));
1340 gdb_printf ("Name: %.19s\n", descdata
+ kp
->ki_comm
);
1341 gdb_printf ("Process ID: %s\n",
1342 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_pid
)));
1343 gdb_printf ("Parent process: %s\n",
1344 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_ppid
)));
1345 gdb_printf ("Process group: %s\n",
1346 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_pgid
)));
1347 gdb_printf ("Session id: %s\n",
1348 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_sid
)));
1350 /* FreeBSD 12.0 and later store a 64-bit dev_t at 'ki_tdev'. Older
1351 kernels store a 32-bit dev_t at 'ki_tdev_freebsd11'. In older
1352 kernels the 64-bit 'ki_tdev' field is in a reserved section of
1353 the structure that is cleared to zero. Assume that a zero value
1354 in ki_tdev indicates a core dump from an older kernel and use the
1355 value in 'ki_tdev_freebsd11' instead. */
1356 value
= bfd_get_64 (cbfd
, descdata
+ kp
->ki_tdev
);
1358 value
= bfd_get_32 (cbfd
, descdata
+ kp
->ki_tdev_freebsd11
);
1359 gdb_printf ("TTY: %s\n", pulongest (value
));
1360 gdb_printf ("TTY owner process group: %s\n",
1361 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_tpgid
)));
1362 gdb_printf ("User IDs (real, effective, saved): %s %s %s\n",
1363 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_ruid
)),
1364 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_uid
)),
1365 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_svuid
)));
1366 gdb_printf ("Group IDs (real, effective, saved): %s %s %s\n",
1367 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_rgid
)),
1368 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_groups
)),
1369 pulongest (bfd_get_32 (cbfd
, descdata
+ kp
->ki_svgid
)));
1370 gdb_printf ("Groups: ");
1371 uint16_t ngroups
= bfd_get_16 (cbfd
, descdata
+ kp
->ki_ngroups
);
1372 for (int i
= 0; i
< ngroups
; i
++)
1374 pulongest (bfd_get_32 (cbfd
,
1375 descdata
+ kp
->ki_groups
+ i
* 4)));
1377 value
= bfd_get (long_bit
, cbfd
,
1378 descdata
+ kp
->ki_rusage
+ kp
->ru_minflt
);
1379 gdb_printf ("Minor faults (no memory page): %s\n", pulongest (value
));
1380 value
= bfd_get (long_bit
, cbfd
,
1381 descdata
+ kp
->ki_rusage_ch
+ kp
->ru_minflt
);
1382 gdb_printf ("Minor faults, children: %s\n", pulongest (value
));
1383 value
= bfd_get (long_bit
, cbfd
,
1384 descdata
+ kp
->ki_rusage
+ kp
->ru_majflt
);
1385 gdb_printf ("Major faults (memory page faults): %s\n",
1387 value
= bfd_get (long_bit
, cbfd
,
1388 descdata
+ kp
->ki_rusage_ch
+ kp
->ru_majflt
);
1389 gdb_printf ("Major faults, children: %s\n", pulongest (value
));
1390 fbsd_core_fetch_timeval (gdbarch
,
1391 descdata
+ kp
->ki_rusage
+ kp
->ru_utime
,
1393 gdb_printf ("utime: %s.%06d\n", plongest (sec
), (int) value
);
1394 fbsd_core_fetch_timeval (gdbarch
,
1395 descdata
+ kp
->ki_rusage
+ kp
->ru_stime
,
1397 gdb_printf ("stime: %s.%06d\n", plongest (sec
), (int) value
);
1398 fbsd_core_fetch_timeval (gdbarch
,
1399 descdata
+ kp
->ki_rusage_ch
+ kp
->ru_utime
,
1401 gdb_printf ("utime, children: %s.%06d\n", plongest (sec
), (int) value
);
1402 fbsd_core_fetch_timeval (gdbarch
,
1403 descdata
+ kp
->ki_rusage_ch
+ kp
->ru_stime
,
1405 gdb_printf ("stime, children: %s.%06d\n", plongest (sec
), (int) value
);
1406 gdb_printf ("'nice' value: %d\n",
1407 (int) bfd_get_signed_8 (core_bfd
, descdata
+ kp
->ki_nice
));
1408 fbsd_core_fetch_timeval (gdbarch
, descdata
+ kp
->ki_start
, sec
, value
);
1409 gdb_printf ("Start time: %s.%06d\n", plongest (sec
), (int) value
);
1410 gdb_printf ("Virtual memory size: %s kB\n",
1411 pulongest (bfd_get (addr_bit
, cbfd
,
1412 descdata
+ kp
->ki_size
) / 1024));
1413 gdb_printf ("Data size: %s pages\n",
1414 pulongest (bfd_get (addr_bit
, cbfd
,
1415 descdata
+ kp
->ki_dsize
)));
1416 gdb_printf ("Stack size: %s pages\n",
1417 pulongest (bfd_get (addr_bit
, cbfd
,
1418 descdata
+ kp
->ki_ssize
)));
1419 gdb_printf ("Text size: %s pages\n",
1420 pulongest (bfd_get (addr_bit
, cbfd
,
1421 descdata
+ kp
->ki_tsize
)));
1422 gdb_printf ("Resident set size: %s pages\n",
1423 pulongest (bfd_get (addr_bit
, cbfd
,
1424 descdata
+ kp
->ki_rssize
)));
1425 gdb_printf ("Maximum RSS: %s pages\n",
1426 pulongest (bfd_get (long_bit
, cbfd
,
1427 descdata
+ kp
->ki_rusage
1429 fbsd_print_sigset ("Ignored Signals", descdata
+ kp
->ki_sigignore
);
1430 fbsd_print_sigset ("Caught Signals", descdata
+ kp
->ki_sigcatch
);
1433 /* Implement the "core_info_proc" gdbarch method. */
1436 fbsd_core_info_proc (struct gdbarch
*gdbarch
, const char *args
,
1437 enum info_proc_what what
)
1439 bool do_cmdline
= false;
1440 bool do_cwd
= false;
1441 bool do_exe
= false;
1442 bool do_files
= false;
1443 bool do_mappings
= false;
1444 bool do_status
= false;
1485 bfd
*cbfd
= current_program_space
->core_bfd ();
1486 pid
= bfd_core_file_pid (cbfd
);
1488 gdb_printf (_("process %d\n"), pid
);
1492 const char *cmdline
;
1494 cmdline
= bfd_core_file_failing_command (cbfd
);
1496 gdb_printf ("cmdline = '%s'\n", cmdline
);
1498 warning (_("Command line unavailable"));
1502 gdb::unique_xmalloc_ptr
<char> cwd
=
1503 fbsd_core_vnode_path (gdbarch
, KINFO_FILE_FD_TYPE_CWD
);
1505 gdb_printf ("cwd = '%s'\n", cwd
.get ());
1507 warning (_("unable to read current working directory"));
1511 gdb::unique_xmalloc_ptr
<char> exe
=
1512 fbsd_core_vnode_path (gdbarch
, KINFO_FILE_FD_TYPE_TEXT
);
1514 gdb_printf ("exe = '%s'\n", exe
.get ());
1516 warning (_("unable to read executable path name"));
1519 fbsd_core_info_proc_files (gdbarch
);
1521 fbsd_core_info_proc_mappings (gdbarch
);
1523 fbsd_core_info_proc_status (gdbarch
);
1526 /* Print descriptions of FreeBSD-specific AUXV entries to FILE. */
1529 fbsd_print_auxv_entry (struct gdbarch
*gdbarch
, struct ui_file
*file
,
1530 CORE_ADDR type
, CORE_ADDR val
)
1532 const char *name
= "???";
1533 const char *description
= "";
1534 enum auxv_format format
= AUXV_FORMAT_HEX
;
1553 default_print_auxv_entry (gdbarch
, file
, type
, val
);
1555 #define _TAGNAME(tag) #tag
1556 #define TAGNAME(tag) _TAGNAME(AT_##tag)
1557 #define TAG(tag, text, kind) \
1558 case AT_FREEBSD_##tag: name = TAGNAME(tag); description = text; format = kind; break
1559 TAG (EXECPATH
, _("Executable path"), AUXV_FORMAT_STR
);
1560 TAG (CANARY
, _("Canary for SSP"), AUXV_FORMAT_HEX
);
1561 TAG (CANARYLEN
, ("Length of the SSP canary"), AUXV_FORMAT_DEC
);
1562 TAG (OSRELDATE
, _("OSRELDATE"), AUXV_FORMAT_DEC
);
1563 TAG (NCPUS
, _("Number of CPUs"), AUXV_FORMAT_DEC
);
1564 TAG (PAGESIZES
, _("Pagesizes"), AUXV_FORMAT_HEX
);
1565 TAG (PAGESIZESLEN
, _("Number of pagesizes"), AUXV_FORMAT_DEC
);
1566 TAG (TIMEKEEP
, _("Pointer to timehands"), AUXV_FORMAT_HEX
);
1567 TAG (STACKPROT
, _("Initial stack protection"), AUXV_FORMAT_HEX
);
1568 TAG (EHDRFLAGS
, _("ELF header e_flags"), AUXV_FORMAT_HEX
);
1569 TAG (HWCAP
, _("Machine-dependent CPU capability hints"), AUXV_FORMAT_HEX
);
1570 TAG (HWCAP2
, _("Extension of AT_HWCAP"), AUXV_FORMAT_HEX
);
1571 TAG (BSDFLAGS
, _("ELF BSD flags"), AUXV_FORMAT_HEX
);
1572 TAG (ARGC
, _("Argument count"), AUXV_FORMAT_DEC
);
1573 TAG (ARGV
, _("Argument vector"), AUXV_FORMAT_HEX
);
1574 TAG (ENVC
, _("Environment count"), AUXV_FORMAT_DEC
);
1575 TAG (ENVV
, _("Environment vector"), AUXV_FORMAT_HEX
);
1576 TAG (PS_STRINGS
, _("Pointer to ps_strings"), AUXV_FORMAT_HEX
);
1577 TAG (FXRNG
, _("Pointer to root RNG seed version"), AUXV_FORMAT_HEX
);
1578 TAG (KPRELOAD
, _("Base address of vDSO"), AUXV_FORMAT_HEX
);
1579 TAG (USRSTACKBASE
, _("Top of user stack"), AUXV_FORMAT_HEX
);
1580 TAG (USRSTACKLIM
, _("Grow limit of user stack"), AUXV_FORMAT_HEX
);
1583 fprint_auxv_entry (file
, name
, description
, format
, type
, val
);
1586 /* Implement the "get_siginfo_type" gdbarch method. */
1588 static struct type
*
1589 fbsd_get_siginfo_type (struct gdbarch
*gdbarch
)
1591 struct fbsd_gdbarch_data
*fbsd_gdbarch_data
;
1592 struct type
*int_type
, *int32_type
, *uint32_type
, *long_type
, *void_ptr_type
;
1593 struct type
*uid_type
, *pid_type
;
1594 struct type
*sigval_type
, *reason_type
;
1595 struct type
*siginfo_type
;
1598 fbsd_gdbarch_data
= get_fbsd_gdbarch_data (gdbarch
);
1599 if (fbsd_gdbarch_data
->siginfo_type
!= NULL
)
1600 return fbsd_gdbarch_data
->siginfo_type
;
1602 type_allocator
alloc (gdbarch
);
1603 int_type
= init_integer_type (alloc
, gdbarch_int_bit (gdbarch
),
1605 int32_type
= init_integer_type (alloc
, 32, 0, "int32_t");
1606 uint32_type
= init_integer_type (alloc
, 32, 1, "uint32_t");
1607 long_type
= init_integer_type (alloc
, gdbarch_long_bit (gdbarch
),
1609 void_ptr_type
= lookup_pointer_type (builtin_type (gdbarch
)->builtin_void
);
1612 sigval_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
1613 sigval_type
->set_name (xstrdup ("sigval"));
1614 append_composite_type_field (sigval_type
, "sival_int", int_type
);
1615 append_composite_type_field (sigval_type
, "sival_ptr", void_ptr_type
);
1618 pid_type
= alloc
.new_type (TYPE_CODE_TYPEDEF
,
1619 int32_type
->length () * TARGET_CHAR_BIT
,
1621 pid_type
->set_target_type (int32_type
);
1622 pid_type
->set_target_is_stub (true);
1625 uid_type
= alloc
.new_type (TYPE_CODE_TYPEDEF
,
1626 uint32_type
->length () * TARGET_CHAR_BIT
,
1628 uid_type
->set_target_type (uint32_type
);
1629 pid_type
->set_target_is_stub (true);
1632 reason_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
1635 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1636 append_composite_type_field (type
, "si_trapno", int_type
);
1637 append_composite_type_field (reason_type
, "_fault", type
);
1640 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1641 append_composite_type_field (type
, "si_timerid", int_type
);
1642 append_composite_type_field (type
, "si_overrun", int_type
);
1643 append_composite_type_field (reason_type
, "_timer", type
);
1646 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1647 append_composite_type_field (type
, "si_mqd", int_type
);
1648 append_composite_type_field (reason_type
, "_mesgq", type
);
1651 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1652 append_composite_type_field (type
, "si_band", long_type
);
1653 append_composite_type_field (reason_type
, "_poll", type
);
1656 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1657 append_composite_type_field (type
, "__spare1__", long_type
);
1658 append_composite_type_field (type
, "__spare2__",
1659 init_vector_type (int_type
, 7));
1660 append_composite_type_field (reason_type
, "__spare__", type
);
1662 /* struct siginfo */
1663 siginfo_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1664 siginfo_type
->set_name (xstrdup ("siginfo"));
1665 append_composite_type_field (siginfo_type
, "si_signo", int_type
);
1666 append_composite_type_field (siginfo_type
, "si_errno", int_type
);
1667 append_composite_type_field (siginfo_type
, "si_code", int_type
);
1668 append_composite_type_field (siginfo_type
, "si_pid", pid_type
);
1669 append_composite_type_field (siginfo_type
, "si_uid", uid_type
);
1670 append_composite_type_field (siginfo_type
, "si_status", int_type
);
1671 append_composite_type_field (siginfo_type
, "si_addr", void_ptr_type
);
1672 append_composite_type_field (siginfo_type
, "si_value", sigval_type
);
1673 append_composite_type_field (siginfo_type
, "_reason", reason_type
);
1675 fbsd_gdbarch_data
->siginfo_type
= siginfo_type
;
1677 return siginfo_type
;
1680 /* Implement the "gdb_signal_from_target" gdbarch method. */
1682 static enum gdb_signal
1683 fbsd_gdb_signal_from_target (struct gdbarch
*gdbarch
, int signal
)
1688 return GDB_SIGNAL_0
;
1690 case FREEBSD_SIGHUP
:
1691 return GDB_SIGNAL_HUP
;
1693 case FREEBSD_SIGINT
:
1694 return GDB_SIGNAL_INT
;
1696 case FREEBSD_SIGQUIT
:
1697 return GDB_SIGNAL_QUIT
;
1699 case FREEBSD_SIGILL
:
1700 return GDB_SIGNAL_ILL
;
1702 case FREEBSD_SIGTRAP
:
1703 return GDB_SIGNAL_TRAP
;
1705 case FREEBSD_SIGABRT
:
1706 return GDB_SIGNAL_ABRT
;
1708 case FREEBSD_SIGEMT
:
1709 return GDB_SIGNAL_EMT
;
1711 case FREEBSD_SIGFPE
:
1712 return GDB_SIGNAL_FPE
;
1714 case FREEBSD_SIGKILL
:
1715 return GDB_SIGNAL_KILL
;
1717 case FREEBSD_SIGBUS
:
1718 return GDB_SIGNAL_BUS
;
1720 case FREEBSD_SIGSEGV
:
1721 return GDB_SIGNAL_SEGV
;
1723 case FREEBSD_SIGSYS
:
1724 return GDB_SIGNAL_SYS
;
1726 case FREEBSD_SIGPIPE
:
1727 return GDB_SIGNAL_PIPE
;
1729 case FREEBSD_SIGALRM
:
1730 return GDB_SIGNAL_ALRM
;
1732 case FREEBSD_SIGTERM
:
1733 return GDB_SIGNAL_TERM
;
1735 case FREEBSD_SIGURG
:
1736 return GDB_SIGNAL_URG
;
1738 case FREEBSD_SIGSTOP
:
1739 return GDB_SIGNAL_STOP
;
1741 case FREEBSD_SIGTSTP
:
1742 return GDB_SIGNAL_TSTP
;
1744 case FREEBSD_SIGCONT
:
1745 return GDB_SIGNAL_CONT
;
1747 case FREEBSD_SIGCHLD
:
1748 return GDB_SIGNAL_CHLD
;
1750 case FREEBSD_SIGTTIN
:
1751 return GDB_SIGNAL_TTIN
;
1753 case FREEBSD_SIGTTOU
:
1754 return GDB_SIGNAL_TTOU
;
1757 return GDB_SIGNAL_IO
;
1759 case FREEBSD_SIGXCPU
:
1760 return GDB_SIGNAL_XCPU
;
1762 case FREEBSD_SIGXFSZ
:
1763 return GDB_SIGNAL_XFSZ
;
1765 case FREEBSD_SIGVTALRM
:
1766 return GDB_SIGNAL_VTALRM
;
1768 case FREEBSD_SIGPROF
:
1769 return GDB_SIGNAL_PROF
;
1771 case FREEBSD_SIGWINCH
:
1772 return GDB_SIGNAL_WINCH
;
1774 case FREEBSD_SIGINFO
:
1775 return GDB_SIGNAL_INFO
;
1777 case FREEBSD_SIGUSR1
:
1778 return GDB_SIGNAL_USR1
;
1780 case FREEBSD_SIGUSR2
:
1781 return GDB_SIGNAL_USR2
;
1783 /* SIGTHR is the same as SIGLWP on FreeBSD. */
1784 case FREEBSD_SIGTHR
:
1785 return GDB_SIGNAL_LWP
;
1787 case FREEBSD_SIGLIBRT
:
1788 return GDB_SIGNAL_LIBRT
;
1791 if (signal
>= FREEBSD_SIGRTMIN
&& signal
<= FREEBSD_SIGRTMAX
)
1793 int offset
= signal
- FREEBSD_SIGRTMIN
;
1795 return (enum gdb_signal
) ((int) GDB_SIGNAL_REALTIME_65
+ offset
);
1798 return GDB_SIGNAL_UNKNOWN
;
1801 /* Implement the "gdb_signal_to_target" gdbarch method. */
1804 fbsd_gdb_signal_to_target (struct gdbarch
*gdbarch
,
1805 enum gdb_signal signal
)
1812 case GDB_SIGNAL_HUP
:
1813 return FREEBSD_SIGHUP
;
1815 case GDB_SIGNAL_INT
:
1816 return FREEBSD_SIGINT
;
1818 case GDB_SIGNAL_QUIT
:
1819 return FREEBSD_SIGQUIT
;
1821 case GDB_SIGNAL_ILL
:
1822 return FREEBSD_SIGILL
;
1824 case GDB_SIGNAL_TRAP
:
1825 return FREEBSD_SIGTRAP
;
1827 case GDB_SIGNAL_ABRT
:
1828 return FREEBSD_SIGABRT
;
1830 case GDB_SIGNAL_EMT
:
1831 return FREEBSD_SIGEMT
;
1833 case GDB_SIGNAL_FPE
:
1834 return FREEBSD_SIGFPE
;
1836 case GDB_SIGNAL_KILL
:
1837 return FREEBSD_SIGKILL
;
1839 case GDB_SIGNAL_BUS
:
1840 return FREEBSD_SIGBUS
;
1842 case GDB_SIGNAL_SEGV
:
1843 return FREEBSD_SIGSEGV
;
1845 case GDB_SIGNAL_SYS
:
1846 return FREEBSD_SIGSYS
;
1848 case GDB_SIGNAL_PIPE
:
1849 return FREEBSD_SIGPIPE
;
1851 case GDB_SIGNAL_ALRM
:
1852 return FREEBSD_SIGALRM
;
1854 case GDB_SIGNAL_TERM
:
1855 return FREEBSD_SIGTERM
;
1857 case GDB_SIGNAL_URG
:
1858 return FREEBSD_SIGURG
;
1860 case GDB_SIGNAL_STOP
:
1861 return FREEBSD_SIGSTOP
;
1863 case GDB_SIGNAL_TSTP
:
1864 return FREEBSD_SIGTSTP
;
1866 case GDB_SIGNAL_CONT
:
1867 return FREEBSD_SIGCONT
;
1869 case GDB_SIGNAL_CHLD
:
1870 return FREEBSD_SIGCHLD
;
1872 case GDB_SIGNAL_TTIN
:
1873 return FREEBSD_SIGTTIN
;
1875 case GDB_SIGNAL_TTOU
:
1876 return FREEBSD_SIGTTOU
;
1879 return FREEBSD_SIGIO
;
1881 case GDB_SIGNAL_XCPU
:
1882 return FREEBSD_SIGXCPU
;
1884 case GDB_SIGNAL_XFSZ
:
1885 return FREEBSD_SIGXFSZ
;
1887 case GDB_SIGNAL_VTALRM
:
1888 return FREEBSD_SIGVTALRM
;
1890 case GDB_SIGNAL_PROF
:
1891 return FREEBSD_SIGPROF
;
1893 case GDB_SIGNAL_WINCH
:
1894 return FREEBSD_SIGWINCH
;
1896 case GDB_SIGNAL_INFO
:
1897 return FREEBSD_SIGINFO
;
1899 case GDB_SIGNAL_USR1
:
1900 return FREEBSD_SIGUSR1
;
1902 case GDB_SIGNAL_USR2
:
1903 return FREEBSD_SIGUSR2
;
1905 case GDB_SIGNAL_LWP
:
1906 return FREEBSD_SIGTHR
;
1908 case GDB_SIGNAL_LIBRT
:
1909 return FREEBSD_SIGLIBRT
;
1912 if (signal
>= GDB_SIGNAL_REALTIME_65
1913 && signal
<= GDB_SIGNAL_REALTIME_126
)
1915 int offset
= signal
- GDB_SIGNAL_REALTIME_65
;
1917 return FREEBSD_SIGRTMIN
+ offset
;
1923 /* Implement the "get_syscall_number" gdbarch method. */
1926 fbsd_get_syscall_number (struct gdbarch
*gdbarch
, thread_info
*thread
)
1929 /* FreeBSD doesn't use gdbarch_get_syscall_number since FreeBSD
1930 native targets fetch the system call number from the
1931 'pl_syscall_code' member of struct ptrace_lwpinfo in fbsd_wait.
1932 However, system call catching requires this function to be
1935 internal_error (_("fbsd_get_sycall_number called"));
1938 /* Read an integer symbol value from the current target. */
1941 fbsd_read_integer_by_name (struct gdbarch
*gdbarch
, const char *name
)
1943 bound_minimal_symbol ms
1944 = lookup_minimal_symbol (current_program_space
, name
);
1945 if (ms
.minsym
== NULL
)
1946 error (_("Unable to resolve symbol '%s'"), name
);
1949 if (target_read_memory (ms
.value_address (), buf
, sizeof buf
) != 0)
1950 error (_("Unable to read value of '%s'"), name
);
1952 return extract_signed_integer (buf
, gdbarch_byte_order (gdbarch
));
1955 /* Lookup offsets of fields in the runtime linker's 'Obj_Entry'
1956 structure needed to determine the TLS index of an object file. */
1959 fbsd_fetch_rtld_offsets (struct gdbarch
*gdbarch
, struct fbsd_pspace_data
*data
)
1963 /* Fetch offsets from debug symbols in rtld. */
1964 struct symbol
*obj_entry_sym
1965 = lookup_symbol_in_language ("Struct_Obj_Entry", nullptr,
1966 SEARCH_STRUCT_DOMAIN
,
1967 language_c
, nullptr).symbol
;
1968 if (obj_entry_sym
== NULL
)
1969 error (_("Unable to find Struct_Obj_Entry symbol"));
1970 data
->off_linkmap
= lookup_struct_elt (obj_entry_sym
->type (),
1971 "linkmap", 0).offset
/ 8;
1972 data
->off_tlsindex
= lookup_struct_elt (obj_entry_sym
->type (),
1973 "tlsindex", 0).offset
/ 8;
1974 data
->rtld_offsets_valid
= true;
1977 catch (const gdb_exception_error
&e
)
1979 data
->off_linkmap
= -1;
1984 /* Fetch offsets from global variables in libthr. Note that
1985 this does not work for single-threaded processes that are not
1986 linked against libthr. */
1987 data
->off_linkmap
= fbsd_read_integer_by_name (gdbarch
,
1988 "_thread_off_linkmap");
1989 data
->off_tlsindex
= fbsd_read_integer_by_name (gdbarch
,
1990 "_thread_off_tlsindex");
1991 data
->rtld_offsets_valid
= true;
1994 catch (const gdb_exception_error
&e
)
1996 data
->off_linkmap
= -1;
2000 /* Helper function to read the TLS index of an object file associated
2001 with a link map entry at LM_ADDR. */
2004 fbsd_get_tls_index (struct gdbarch
*gdbarch
, CORE_ADDR lm_addr
)
2006 struct fbsd_pspace_data
*data
= get_fbsd_pspace_data (current_program_space
);
2008 if (!data
->rtld_offsets_valid
)
2009 fbsd_fetch_rtld_offsets (gdbarch
, data
);
2011 if (data
->off_linkmap
== -1)
2012 throw_error (TLS_GENERIC_ERROR
,
2013 _("Cannot fetch runtime linker structure offsets"));
2015 /* Simulate container_of to convert from LM_ADDR to the Obj_Entry
2016 pointer and then compute the offset of the tlsindex member. */
2017 CORE_ADDR tlsindex_addr
= lm_addr
- data
->off_linkmap
+ data
->off_tlsindex
;
2020 if (target_read_memory (tlsindex_addr
, buf
, sizeof buf
) != 0)
2021 throw_error (TLS_GENERIC_ERROR
,
2022 _("Cannot find thread-local variables on this target"));
2024 return extract_signed_integer (buf
, gdbarch_byte_order (gdbarch
));
2027 /* See fbsd-tdep.h. */
2030 fbsd_get_thread_local_address (struct gdbarch
*gdbarch
, CORE_ADDR dtv_addr
,
2031 CORE_ADDR lm_addr
, CORE_ADDR offset
)
2033 LONGEST tls_index
= fbsd_get_tls_index (gdbarch
, lm_addr
);
2035 gdb::byte_vector
buf (gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
);
2036 if (target_read_memory (dtv_addr
, buf
.data (), buf
.size ()) != 0)
2037 throw_error (TLS_GENERIC_ERROR
,
2038 _("Cannot find thread-local variables on this target"));
2040 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
2042 = gdbarch_pointer_to_address (gdbarch
, builtin
->builtin_data_ptr
,
2045 addr
+= (tls_index
+ 1) * builtin
->builtin_data_ptr
->length ();
2046 if (target_read_memory (addr
, buf
.data (), buf
.size ()) != 0)
2047 throw_error (TLS_GENERIC_ERROR
,
2048 _("Cannot find thread-local variables on this target"));
2050 addr
= gdbarch_pointer_to_address (gdbarch
, builtin
->builtin_data_ptr
,
2052 return addr
+ offset
;
2055 /* See fbsd-tdep.h. */
2058 fbsd_skip_solib_resolver (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
2060 bound_minimal_symbol msym
2061 = lookup_minimal_symbol (current_program_space
, "_rtld_bind");
2062 if (msym
.minsym
!= nullptr && msym
.value_address () == pc
)
2063 return frame_unwind_caller_pc (get_current_frame ());
2068 /* Return description of signal code or nullptr. */
2071 fbsd_signal_cause (enum gdb_signal siggnal
, int code
)
2073 /* Signal-independent causes. */
2077 return _("Sent by kill()");
2079 return _("Sent by sigqueue()");
2081 return _("Timer expired");
2082 case FBSD_SI_ASYNCIO
:
2083 return _("Asynchronous I/O request completed");
2085 return _("Message arrived on empty message queue");
2086 case FBSD_SI_KERNEL
:
2087 return _("Sent by kernel");
2089 return _("Sent by thr_kill()");
2094 case GDB_SIGNAL_ILL
:
2097 case FBSD_ILL_ILLOPC
:
2098 return _("Illegal opcode");
2099 case FBSD_ILL_ILLOPN
:
2100 return _("Illegal operand");
2101 case FBSD_ILL_ILLADR
:
2102 return _("Illegal addressing mode");
2103 case FBSD_ILL_ILLTRP
:
2104 return _("Illegal trap");
2105 case FBSD_ILL_PRVOPC
:
2106 return _("Privileged opcode");
2107 case FBSD_ILL_PRVREG
:
2108 return _("Privileged register");
2109 case FBSD_ILL_COPROC
:
2110 return _("Coprocessor error");
2111 case FBSD_ILL_BADSTK
:
2112 return _("Internal stack error");
2115 case GDB_SIGNAL_BUS
:
2118 case FBSD_BUS_ADRALN
:
2119 return _("Invalid address alignment");
2120 case FBSD_BUS_ADRERR
:
2121 return _("Address not present");
2122 case FBSD_BUS_OBJERR
:
2123 return _("Object-specific hardware error");
2124 case FBSD_BUS_OOMERR
:
2125 return _("Out of memory");
2128 case GDB_SIGNAL_SEGV
:
2131 case FBSD_SEGV_MAPERR
:
2132 return _("Address not mapped to object");
2133 case FBSD_SEGV_ACCERR
:
2134 return _("Invalid permissions for mapped object");
2135 case FBSD_SEGV_PKUERR
:
2136 return _("PKU violation");
2139 case GDB_SIGNAL_FPE
:
2142 case FBSD_FPE_INTOVF
:
2143 return _("Integer overflow");
2144 case FBSD_FPE_INTDIV
:
2145 return _("Integer divide by zero");
2146 case FBSD_FPE_FLTDIV
:
2147 return _("Floating point divide by zero");
2148 case FBSD_FPE_FLTOVF
:
2149 return _("Floating point overflow");
2150 case FBSD_FPE_FLTUND
:
2151 return _("Floating point underflow");
2152 case FBSD_FPE_FLTRES
:
2153 return _("Floating point inexact result");
2154 case FBSD_FPE_FLTINV
:
2155 return _("Invalid floating point operation");
2156 case FBSD_FPE_FLTSUB
:
2157 return _("Subscript out of range");
2160 case GDB_SIGNAL_TRAP
:
2163 case FBSD_TRAP_BRKPT
:
2164 return _("Breakpoint");
2165 case FBSD_TRAP_TRACE
:
2166 return _("Trace trap");
2167 case FBSD_TRAP_DTRACE
:
2168 return _("DTrace-induced trap");
2170 return _("Capability violation");
2173 case GDB_SIGNAL_CHLD
:
2176 case FBSD_CLD_EXITED
:
2177 return _("Child has exited");
2178 case FBSD_CLD_KILLED
:
2179 return _("Child has terminated abnormally");
2180 case FBSD_CLD_DUMPED
:
2181 return _("Child has dumped core");
2182 case FBSD_CLD_TRAPPED
:
2183 return _("Traced child has trapped");
2184 case FBSD_CLD_STOPPED
:
2185 return _("Child has stopped");
2186 case FBSD_CLD_CONTINUED
:
2187 return _("Stopped child has continued");
2190 case GDB_SIGNAL_POLL
:
2194 return _("Data input available");
2196 return _("Output buffers available");
2198 return _("Input message available");
2200 return _("I/O error");
2202 return _("High priority input available");
2204 return _("Device disconnected");
2212 /* Report additional details for a signal stop. */
2215 fbsd_report_signal_info (struct gdbarch
*gdbarch
, struct ui_out
*uiout
,
2216 enum gdb_signal siggnal
)
2218 LONGEST code
, mqd
, pid
, status
, timerid
, uid
;
2222 code
= parse_and_eval_long ("$_siginfo.si_code");
2223 pid
= parse_and_eval_long ("$_siginfo.si_pid");
2224 uid
= parse_and_eval_long ("$_siginfo.si_uid");
2225 status
= parse_and_eval_long ("$_siginfo.si_status");
2226 timerid
= parse_and_eval_long ("$_siginfo._reason._timer.si_timerid");
2227 mqd
= parse_and_eval_long ("$_siginfo._reason._mesgq.si_mqd");
2229 catch (const gdb_exception_error
&e
)
2234 const char *meaning
= fbsd_signal_cause (siggnal
, code
);
2235 if (meaning
== nullptr)
2238 uiout
->text (".\n");
2239 uiout
->field_string ("sigcode-meaning", meaning
);
2246 uiout
->text (" from pid ");
2247 uiout
->field_string ("sending-pid", plongest (pid
));
2248 uiout
->text (" and user ");
2249 uiout
->field_string ("sending-uid", plongest (uid
));
2252 uiout
->text (": timerid ");
2253 uiout
->field_string ("timerid", plongest (timerid
));
2256 uiout
->text (": message queue ");
2257 uiout
->field_string ("message-queue", plongest (mqd
));
2259 case FBSD_SI_ASYNCIO
:
2263 if (siggnal
== GDB_SIGNAL_CHLD
)
2265 uiout
->text (": pid ");
2266 uiout
->field_string ("child-pid", plongest (pid
));
2267 uiout
->text (", uid ");
2268 uiout
->field_string ("child-uid", plongest (uid
));
2269 if (code
== FBSD_CLD_EXITED
)
2271 uiout
->text (", exit status ");
2272 uiout
->field_string ("exit-status", plongest (status
));
2276 uiout
->text (", signal ");
2277 uiout
->field_string ("signal", plongest (status
));
2282 /* Search a list of struct kinfo_vmmap entries in the ENTRIES buffer
2283 of LEN bytes to find the length of the entry starting at ADDR.
2284 Returns the length of the entry or zero if no entry was found. */
2287 fbsd_vmmap_length (struct gdbarch
*gdbarch
, unsigned char *entries
, size_t len
,
2290 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2291 unsigned char *descdata
= entries
;
2292 unsigned char *descend
= descdata
+ len
;
2294 /* Skip over the structure size. */
2297 while (descdata
+ KVE_PATH
< descend
)
2299 ULONGEST structsize
= extract_unsigned_integer (descdata
2300 + KVE_STRUCTSIZE
, 4,
2302 if (structsize
< KVE_PATH
)
2305 ULONGEST start
= extract_unsigned_integer (descdata
+ KVE_START
, 8,
2307 ULONGEST end
= extract_unsigned_integer (descdata
+ KVE_END
, 8,
2312 descdata
+= structsize
;
2317 /* Helper for fbsd_vsyscall_range that does the real work of finding
2318 the vDSO's address range. */
2321 fbsd_vdso_range (struct gdbarch
*gdbarch
, struct mem_range
*range
)
2323 if (target_auxv_search (AT_FREEBSD_KPRELOAD
, &range
->start
) <= 0)
2326 if (!target_has_execution ())
2328 /* Search for the ending address in the NT_PROCSTAT_VMMAP note. */
2329 bfd
*cbfd
= current_program_space
->core_bfd ();
2330 asection
*section
= bfd_get_section_by_name (cbfd
,
2331 ".note.freebsdcore.vmmap");
2332 if (section
== nullptr)
2335 size_t note_size
= bfd_section_size (section
);
2339 gdb::def_vector
<unsigned char> contents (note_size
);
2340 if (!bfd_get_section_contents (cbfd
, section
, contents
.data (),
2344 range
->length
= fbsd_vmmap_length (gdbarch
, contents
.data (), note_size
,
2349 /* Fetch the list of address space entries from the running target. */
2350 std::optional
<gdb::byte_vector
> buf
=
2351 target_read_alloc (current_inferior ()->top_target (),
2352 TARGET_OBJECT_FREEBSD_VMMAP
, nullptr);
2353 if (!buf
|| buf
->empty ())
2356 range
->length
= fbsd_vmmap_length (gdbarch
, buf
->data (), buf
->size (),
2359 return range
->length
!= 0;
2362 /* Try to extract the inferior arguments, environment, and executable name
2365 static core_file_exec_context
2366 fbsd_corefile_parse_exec_context_1 (struct gdbarch
*gdbarch
, bfd
*cbfd
)
2368 gdb_assert (gdbarch
!= nullptr);
2370 /* If there's no core file loaded then we're done. */
2371 if (cbfd
== nullptr)
2374 int ptr_bytes
= gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
;
2376 /* Find the .auxv section in the core file. The BFD library creates this
2377 for us from the AUXV note when the BFD is opened. If the section
2378 can't be found then there's nothing more we can do. */
2379 struct bfd_section
* section
= bfd_get_section_by_name (cbfd
, ".auxv");
2380 if (section
== nullptr)
2383 /* Grab the contents of the .auxv section. If we can't get the contents
2384 then there's nothing more we can do. */
2385 bfd_size_type size
= bfd_section_size (section
);
2386 if (bfd_section_size_insane (cbfd
, section
))
2388 gdb::byte_vector
contents (size
);
2389 if (!bfd_get_section_contents (cbfd
, section
, contents
.data (), 0, size
))
2392 /* Read AT_FREEBSD_ARGV, the address of the argument string vector. */
2393 CORE_ADDR argv_addr
;
2394 if (target_auxv_search (contents
, current_inferior ()->top_target (),
2395 gdbarch
, AT_FREEBSD_ARGV
, &argv_addr
) != 1)
2398 /* Read AT_FREEBSD_ARGV, the address of the environment string vector. */
2399 CORE_ADDR envv_addr
;
2400 if (target_auxv_search (contents
, current_inferior ()->top_target (),
2401 gdbarch
, AT_FREEBSD_ENVV
, &envv_addr
) != 1)
2404 /* Read the AT_EXECPATH string. It's OK if we can't get this
2406 gdb::unique_xmalloc_ptr
<char> execpath
;
2407 CORE_ADDR execpath_string_addr
;
2408 if (target_auxv_search (contents
, current_inferior ()->top_target (),
2409 gdbarch
, AT_FREEBSD_EXECPATH
,
2410 &execpath_string_addr
) == 1)
2411 execpath
= target_read_string (execpath_string_addr
, INT_MAX
);
2413 /* The byte order. */
2414 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2416 /* On FreeBSD the command the user ran is found in argv[0]. When we
2417 read the first argument we place it into EXECFN. */
2418 gdb::unique_xmalloc_ptr
<char> execfn
;
2420 /* Read strings from AT_FREEBSD_ARGV until we find a NULL marker. The
2421 first argument is placed into EXECFN as the command name. */
2422 std::vector
<gdb::unique_xmalloc_ptr
<char>> arguments
;
2425 = (CORE_ADDR
) read_memory_unsigned_integer (argv_addr
, ptr_bytes
,
2428 gdb::unique_xmalloc_ptr
<char> str
2429 = target_read_string (str_addr
, INT_MAX
);
2433 if (execfn
== nullptr)
2434 execfn
= std::move (str
);
2436 arguments
.emplace_back (std::move (str
));
2438 argv_addr
+= ptr_bytes
;
2441 /* Read strings from AT_FREEBSD_ENVV until we find a NULL marker. */
2442 std::vector
<gdb::unique_xmalloc_ptr
<char>> environment
;
2444 = (uint64_t) read_memory_unsigned_integer (envv_addr
, ptr_bytes
,
2447 gdb::unique_xmalloc_ptr
<char> str
2448 = target_read_string (str_addr
, INT_MAX
);
2452 environment
.emplace_back (std::move (str
));
2453 envv_addr
+= ptr_bytes
;
2456 return core_file_exec_context (std::move (execfn
),
2457 std::move (execpath
),
2458 std::move (arguments
),
2459 std::move (environment
));
2462 /* See elf-corelow.h. */
2464 static core_file_exec_context
2465 fbsd_corefile_parse_exec_context (struct gdbarch
*gdbarch
, bfd
*cbfd
)
2467 /* Catch and discard memory errors.
2469 If the core file format is not as we expect then we can easily trigger
2470 a memory error while parsing the core file. We don't want this to
2471 prevent the user from opening the core file; the information provided
2472 by this function is helpful, but not critical, debugging can continue
2473 without it. Instead just give a warning and return an empty context
2477 return fbsd_corefile_parse_exec_context_1 (gdbarch
, cbfd
);
2479 catch (const gdb_exception_error
&ex
)
2481 if (ex
.error
== MEMORY_ERROR
)
2484 (_("failed to parse execution context from corefile: %s"),
2485 ex
.message
->c_str ());
2493 /* Return the address range of the vDSO for the current inferior. */
2496 fbsd_vsyscall_range (struct gdbarch
*gdbarch
, struct mem_range
*range
)
2498 struct fbsd_pspace_data
*data
= get_fbsd_pspace_data (current_program_space
);
2500 if (data
->vdso_range_p
== 0)
2502 if (fbsd_vdso_range (gdbarch
, &data
->vdso_range
))
2503 data
->vdso_range_p
= 1;
2505 data
->vdso_range_p
= -1;
2508 if (data
->vdso_range_p
< 0)
2511 *range
= data
->vdso_range
;
2515 /* To be called from GDB_OSABI_FREEBSD handlers. */
2518 fbsd_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
2520 set_gdbarch_core_pid_to_str (gdbarch
, fbsd_core_pid_to_str
);
2521 set_gdbarch_core_thread_name (gdbarch
, fbsd_core_thread_name
);
2522 set_gdbarch_core_xfer_siginfo (gdbarch
, fbsd_core_xfer_siginfo
);
2523 set_gdbarch_make_corefile_notes (gdbarch
, fbsd_make_corefile_notes
);
2524 set_gdbarch_core_info_proc (gdbarch
, fbsd_core_info_proc
);
2525 set_gdbarch_print_auxv_entry (gdbarch
, fbsd_print_auxv_entry
);
2526 set_gdbarch_get_siginfo_type (gdbarch
, fbsd_get_siginfo_type
);
2527 set_gdbarch_gdb_signal_from_target (gdbarch
, fbsd_gdb_signal_from_target
);
2528 set_gdbarch_gdb_signal_to_target (gdbarch
, fbsd_gdb_signal_to_target
);
2529 set_gdbarch_report_signal_info (gdbarch
, fbsd_report_signal_info
);
2530 set_gdbarch_skip_solib_resolver (gdbarch
, fbsd_skip_solib_resolver
);
2531 set_gdbarch_vsyscall_range (gdbarch
, fbsd_vsyscall_range
);
2533 /* `catch syscall' */
2534 set_xml_syscall_file_name (gdbarch
, "syscalls/freebsd.xml");
2535 set_gdbarch_get_syscall_number (gdbarch
, fbsd_get_syscall_number
);
2536 set_gdbarch_core_parse_exec_context (gdbarch
,
2537 fbsd_corefile_parse_exec_context
);