1 /* Target-dependent code for FreeBSD, architecture-independent.
3 Copyright (C) 2002-2021 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/>. */
27 #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"
37 /* This enum is derived from FreeBSD's <sys/signal.h>. */
66 FREEBSD_SIGVTALRM
= 26,
68 FREEBSD_SIGWINCH
= 28,
73 FREEBSD_SIGLIBRT
= 33,
74 FREEBSD_SIGRTMIN
= 65,
75 FREEBSD_SIGRTMAX
= 126,
78 /* Constants for values of si_code as defined in FreeBSD's
81 #define FBSD_SI_USER 0x10001
82 #define FBSD_SI_QUEUE 0x10002
83 #define FBSD_SI_TIMER 0x10003
84 #define FBSD_SI_ASYNCIO 0x10004
85 #define FBSD_SI_MESGQ 0x10005
86 #define FBSD_SI_KERNEL 0x10006
87 #define FBSD_SI_LWP 0x10007
89 #define FBSD_ILL_ILLOPC 1
90 #define FBSD_ILL_ILLOPN 2
91 #define FBSD_ILL_ILLADR 3
92 #define FBSD_ILL_ILLTRP 4
93 #define FBSD_ILL_PRVOPC 5
94 #define FBSD_ILL_PRVREG 6
95 #define FBSD_ILL_COPROC 7
96 #define FBSD_ILL_BADSTK 8
98 #define FBSD_BUS_ADRALN 1
99 #define FBSD_BUS_ADRERR 2
100 #define FBSD_BUS_OBJERR 3
101 #define FBSD_BUS_OOMERR 100
103 #define FBSD_SEGV_MAPERR 1
104 #define FBSD_SEGV_ACCERR 2
105 #define FBSD_SEGV_PKUERR 100
107 #define FBSD_FPE_INTOVF 1
108 #define FBSD_FPE_INTDIV 2
109 #define FBSD_FPE_FLTDIV 3
110 #define FBSD_FPE_FLTOVF 4
111 #define FBSD_FPE_FLTUND 5
112 #define FBSD_FPE_FLTRES 6
113 #define FBSD_FPE_FLTINV 7
114 #define FBSD_FPE_FLTSUB 8
116 #define FBSD_TRAP_BRKPT 1
117 #define FBSD_TRAP_TRACE 2
118 #define FBSD_TRAP_DTRACE 3
119 #define FBSD_TRAP_CAP 4
121 #define FBSD_CLD_EXITED 1
122 #define FBSD_CLD_KILLED 2
123 #define FBSD_CLD_DUMPED 3
124 #define FBSD_CLD_TRAPPED 4
125 #define FBSD_CLD_STOPPED 5
126 #define FBSD_CLD_CONTINUED 6
128 #define FBSD_POLL_IN 1
129 #define FBSD_POLL_OUT 2
130 #define FBSD_POLL_MSG 3
131 #define FBSD_POLL_ERR 4
132 #define FBSD_POLL_PRI 5
133 #define FBSD_POLL_HUP 6
135 /* FreeBSD kernels 12.0 and later include a copy of the
136 'ptrace_lwpinfo' structure returned by the PT_LWPINFO ptrace
137 operation in an ELF core note (NT_FREEBSD_PTLWPINFO) for each LWP.
138 The constants below define the offset of field members and flags in
139 this structure used by methods in this file. Note that the
140 'ptrace_lwpinfo' struct in the note is preceded by a 4 byte integer
141 containing the size of the structure. */
143 #define LWPINFO_OFFSET 0x4
145 /* Offsets in ptrace_lwpinfo. */
146 #define LWPINFO_PL_FLAGS 0x8
147 #define LWPINFO64_PL_SIGINFO 0x30
148 #define LWPINFO32_PL_SIGINFO 0x2c
150 /* Flags in pl_flags. */
151 #define PL_FLAG_SI 0x20 /* siginfo is valid */
153 /* Sizes of siginfo_t. */
154 #define SIZE64_SIGINFO_T 80
155 #define SIZE32_SIGINFO_T 64
157 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_VMMAP core
158 dump notes. See <sys/user.h> for the definition of struct
159 kinfo_vmentry. This data structure should have the same layout on
162 Note that FreeBSD 7.0 used an older version of this structure
163 (struct kinfo_vmentry), but the NT_FREEBSD_PROCSTAT_VMMAP core
164 dump note wasn't introduced until FreeBSD 9.2. As a result, the
165 core dump note has always used the 7.1 and later structure
168 #define KVE_STRUCTSIZE 0x0
169 #define KVE_START 0x8
171 #define KVE_OFFSET 0x18
172 #define KVE_FLAGS 0x2c
173 #define KVE_PROTECTION 0x38
174 #define KVE_PATH 0x88
176 /* Flags in the 'kve_protection' field in struct kinfo_vmentry. These
177 match the KVME_PROT_* constants in <sys/user.h>. */
179 #define KINFO_VME_PROT_READ 0x00000001
180 #define KINFO_VME_PROT_WRITE 0x00000002
181 #define KINFO_VME_PROT_EXEC 0x00000004
183 /* Flags in the 'kve_flags' field in struct kinfo_vmentry. These
184 match the KVME_FLAG_* constants in <sys/user.h>. */
186 #define KINFO_VME_FLAG_COW 0x00000001
187 #define KINFO_VME_FLAG_NEEDS_COPY 0x00000002
188 #define KINFO_VME_FLAG_NOCOREDUMP 0x00000004
189 #define KINFO_VME_FLAG_SUPER 0x00000008
190 #define KINFO_VME_FLAG_GROWS_UP 0x00000010
191 #define KINFO_VME_FLAG_GROWS_DOWN 0x00000020
193 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_FILES core
194 dump notes. See <sys/user.h> for the definition of struct
195 kinfo_file. This data structure should have the same layout on all
198 Note that FreeBSD 7.0 used an older version of this structure
199 (struct kinfo_ofile), but the NT_FREEBSD_PROCSTAT_FILES core dump
200 note wasn't introduced until FreeBSD 9.2. As a result, the core
201 dump note has always used the 7.1 and later structure format. */
203 #define KF_STRUCTSIZE 0x0
206 #define KF_FLAGS 0x10
207 #define KF_OFFSET 0x18
208 #define KF_VNODE_TYPE 0x20
209 #define KF_SOCK_DOMAIN 0x24
210 #define KF_SOCK_TYPE 0x28
211 #define KF_SOCK_PROTOCOL 0x2c
212 #define KF_SA_LOCAL 0x30
213 #define KF_SA_PEER 0xb0
214 #define KF_PATH 0x170
216 /* Constants for the 'kf_type' field in struct kinfo_file. These
217 match the KF_TYPE_* constants in <sys/user.h>. */
219 #define KINFO_FILE_TYPE_VNODE 1
220 #define KINFO_FILE_TYPE_SOCKET 2
221 #define KINFO_FILE_TYPE_PIPE 3
222 #define KINFO_FILE_TYPE_FIFO 4
223 #define KINFO_FILE_TYPE_KQUEUE 5
224 #define KINFO_FILE_TYPE_CRYPTO 6
225 #define KINFO_FILE_TYPE_MQUEUE 7
226 #define KINFO_FILE_TYPE_SHM 8
227 #define KINFO_FILE_TYPE_SEM 9
228 #define KINFO_FILE_TYPE_PTS 10
229 #define KINFO_FILE_TYPE_PROCDESC 11
231 /* Special values for the 'kf_fd' field in struct kinfo_file. These
232 match the KF_FD_TYPE_* constants in <sys/user.h>. */
234 #define KINFO_FILE_FD_TYPE_CWD -1
235 #define KINFO_FILE_FD_TYPE_ROOT -2
236 #define KINFO_FILE_FD_TYPE_JAIL -3
237 #define KINFO_FILE_FD_TYPE_TRACE -4
238 #define KINFO_FILE_FD_TYPE_TEXT -5
239 #define KINFO_FILE_FD_TYPE_CTTY -6
241 /* Flags in the 'kf_flags' field in struct kinfo_file. These match
242 the KF_FLAG_* constants in <sys/user.h>. */
244 #define KINFO_FILE_FLAG_READ 0x00000001
245 #define KINFO_FILE_FLAG_WRITE 0x00000002
246 #define KINFO_FILE_FLAG_APPEND 0x00000004
247 #define KINFO_FILE_FLAG_ASYNC 0x00000008
248 #define KINFO_FILE_FLAG_FSYNC 0x00000010
249 #define KINFO_FILE_FLAG_NONBLOCK 0x00000020
250 #define KINFO_FILE_FLAG_DIRECT 0x00000040
251 #define KINFO_FILE_FLAG_HASLOCK 0x00000080
252 #define KINFO_FILE_FLAG_EXEC 0x00004000
254 /* Constants for the 'kf_vnode_type' field in struct kinfo_file.
255 These match the KF_VTYPE_* constants in <sys/user.h>. */
257 #define KINFO_FILE_VTYPE_VREG 1
258 #define KINFO_FILE_VTYPE_VDIR 2
259 #define KINFO_FILE_VTYPE_VCHR 4
260 #define KINFO_FILE_VTYPE_VLNK 5
261 #define KINFO_FILE_VTYPE_VSOCK 6
262 #define KINFO_FILE_VTYPE_VFIFO 7
264 /* Constants for socket address families. These match AF_* constants
265 in <sys/socket.h>. */
267 #define FBSD_AF_UNIX 1
268 #define FBSD_AF_INET 2
269 #define FBSD_AF_INET6 28
271 /* Constants for socket types. These match SOCK_* constants in
274 #define FBSD_SOCK_STREAM 1
275 #define FBSD_SOCK_DGRAM 2
276 #define FBSD_SOCK_SEQPACKET 5
278 /* Constants for IP protocols. These match IPPROTO_* constants in
281 #define FBSD_IPPROTO_ICMP 1
282 #define FBSD_IPPROTO_TCP 6
283 #define FBSD_IPPROTO_UDP 17
284 #define FBSD_IPPROTO_SCTP 132
286 /* Socket address structures. These have the same layout on all
287 FreeBSD architectures. In addition, multibyte fields such as IP
288 addresses are always stored in network byte order. */
290 struct fbsd_sockaddr_in
299 struct fbsd_sockaddr_in6
303 uint8_t sin6_port
[2];
304 uint32_t sin6_flowinfo
;
305 uint8_t sin6_addr
[16];
306 uint32_t sin6_scope_id
;
309 struct fbsd_sockaddr_un
316 /* Number of 32-bit words in a signal set. This matches _SIG_WORDS in
317 <sys/_sigset.h> and is the same value on all architectures. */
321 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_PROC core
322 dump notes. See <sys/user.h> for the definition of struct
323 kinfo_proc. This data structure has different layouts on different
324 architectures mostly due to ILP32 vs LP64. However, FreeBSD/i386
325 uses a 32-bit time_t while all other architectures use a 64-bit
328 The core dump note actually contains one kinfo_proc structure for
329 each thread, but all of the process-wide data can be obtained from
330 the first structure. One result of this note's format is that some
331 of the process-wide status available in the native target method
332 from the kern.proc.pid.<pid> sysctl such as ki_stat and ki_siglist
333 is not available from a core dump. Instead, the per-thread data
334 structures contain the value of these fields for individual
337 struct kinfo_proc_layout
339 /* Offsets of struct kinfo_proc members. */
346 int ki_tdev_freebsd11
;
368 /* Offsets of struct rusage members. */
376 const struct kinfo_proc_layout kinfo_proc_layout_32
=
384 .ki_tdev_freebsd11
= 0x44,
385 .ki_sigignore
= 0x68,
404 .ki_rusage_ch
= 0x278,
413 const struct kinfo_proc_layout kinfo_proc_layout_i386
=
421 .ki_tdev_freebsd11
= 0x44,
422 .ki_sigignore
= 0x68,
441 .ki_rusage_ch
= 0x258,
450 const struct kinfo_proc_layout kinfo_proc_layout_64
=
458 .ki_tdev_freebsd11
= 0x64,
459 .ki_sigignore
= 0x88,
478 .ki_rusage_ch
= 0x2f0,
487 static struct gdbarch_data
*fbsd_gdbarch_data_handle
;
489 struct fbsd_gdbarch_data
491 struct type
*siginfo_type
;
495 init_fbsd_gdbarch_data (struct gdbarch
*gdbarch
)
497 return GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct fbsd_gdbarch_data
);
500 static struct fbsd_gdbarch_data
*
501 get_fbsd_gdbarch_data (struct gdbarch
*gdbarch
)
503 return ((struct fbsd_gdbarch_data
*)
504 gdbarch_data (gdbarch
, fbsd_gdbarch_data_handle
));
507 struct fbsd_pspace_data
509 /* Offsets in the runtime linker's 'Obj_Entry' structure. */
510 LONGEST off_linkmap
= 0;
511 LONGEST off_tlsindex
= 0;
512 bool rtld_offsets_valid
= false;
515 /* Per-program-space data for FreeBSD architectures. */
516 static const struct program_space_key
<fbsd_pspace_data
>
517 fbsd_pspace_data_handle
;
519 static struct fbsd_pspace_data
*
520 get_fbsd_pspace_data (struct program_space
*pspace
)
522 struct fbsd_pspace_data
*data
;
524 data
= fbsd_pspace_data_handle
.get (pspace
);
526 data
= fbsd_pspace_data_handle
.emplace (pspace
);
531 /* This is how we want PTIDs from core files to be printed. */
534 fbsd_core_pid_to_str (struct gdbarch
*gdbarch
, ptid_t ptid
)
536 if (ptid
.lwp () != 0)
537 return string_printf ("LWP %ld", ptid
.lwp ());
539 return normal_pid_to_str (ptid
);
542 /* Extract the name assigned to a thread from a core. Returns the
543 string in a static buffer. */
546 fbsd_core_thread_name (struct gdbarch
*gdbarch
, struct thread_info
*thr
)
549 struct bfd_section
*section
;
552 if (thr
->ptid
.lwp () != 0)
554 /* FreeBSD includes a NT_FREEBSD_THRMISC note for each thread
555 whose contents are defined by a "struct thrmisc" declared in
556 <sys/procfs.h> on FreeBSD. The per-thread name is stored as
557 a null-terminated string as the first member of the
558 structure. Rather than define the full structure here, just
559 extract the null-terminated name from the start of the
561 thread_section_name
section_name (".thrmisc", thr
->ptid
);
563 section
= bfd_get_section_by_name (core_bfd
, section_name
.c_str ());
564 if (section
!= NULL
&& bfd_section_size (section
) > 0)
566 /* Truncate the name if it is longer than "buf". */
567 size
= bfd_section_size (section
);
568 if (size
> sizeof buf
- 1)
569 size
= sizeof buf
- 1;
570 if (bfd_get_section_contents (core_bfd
, section
, buf
, (file_ptr
) 0,
576 /* Note that each thread will report the process command
577 as its thread name instead of an empty name if a name
578 has not been set explicitly. Return a NULL name in
580 if (strcmp (buf
, elf_tdata (core_bfd
)->core
->program
) != 0)
589 /* Implement the "core_xfer_siginfo" gdbarch method. */
592 fbsd_core_xfer_siginfo (struct gdbarch
*gdbarch
, gdb_byte
*readbuf
,
593 ULONGEST offset
, ULONGEST len
)
597 if (gdbarch_long_bit (gdbarch
) == 32)
598 siginfo_size
= SIZE32_SIGINFO_T
;
600 siginfo_size
= SIZE64_SIGINFO_T
;
601 if (offset
> siginfo_size
)
604 thread_section_name
section_name (".note.freebsdcore.lwpinfo", inferior_ptid
);
605 asection
*section
= bfd_get_section_by_name (core_bfd
, section_name
.c_str ());
610 if (!bfd_get_section_contents (core_bfd
, section
, buf
,
611 LWPINFO_OFFSET
+ LWPINFO_PL_FLAGS
, 4))
614 int pl_flags
= extract_signed_integer (buf
, 4, gdbarch_byte_order (gdbarch
));
615 if (!(pl_flags
& PL_FLAG_SI
))
618 if (offset
+ len
> siginfo_size
)
619 len
= siginfo_size
- offset
;
621 ULONGEST siginfo_offset
;
622 if (gdbarch_long_bit (gdbarch
) == 32)
623 siginfo_offset
= LWPINFO_OFFSET
+ LWPINFO32_PL_SIGINFO
;
625 siginfo_offset
= LWPINFO_OFFSET
+ LWPINFO64_PL_SIGINFO
;
627 if (!bfd_get_section_contents (core_bfd
, section
, readbuf
,
628 siginfo_offset
+ offset
, len
))
635 find_signalled_thread (struct thread_info
*info
, void *data
)
637 if (info
->suspend
.stop_signal
!= GDB_SIGNAL_0
638 && info
->ptid
.pid () == inferior_ptid
.pid ())
644 /* Return a byte_vector containing the contents of a core dump note
645 for the target object of type OBJECT. If STRUCTSIZE is non-zero,
646 the data is prefixed with a 32-bit integer size to match the format
647 used in FreeBSD NT_PROCSTAT_* notes. */
649 static gdb::optional
<gdb::byte_vector
>
650 fbsd_make_note_desc (enum target_object object
, uint32_t structsize
)
652 gdb::optional
<gdb::byte_vector
> buf
=
653 target_read_alloc (current_inferior ()->top_target (), object
, NULL
);
654 if (!buf
|| buf
->empty ())
660 gdb::byte_vector
desc (sizeof (structsize
) + buf
->size ());
661 memcpy (desc
.data (), &structsize
, sizeof (structsize
));
662 memcpy (desc
.data () + sizeof (structsize
), buf
->data (), buf
->size ());
666 /* Create appropriate note sections for a corefile, returning them in
669 static gdb::unique_xmalloc_ptr
<char>
670 fbsd_make_corefile_notes (struct gdbarch
*gdbarch
, bfd
*obfd
, int *note_size
)
672 gdb::unique_xmalloc_ptr
<char> note_data
;
673 Elf_Internal_Ehdr
*i_ehdrp
;
674 struct thread_info
*curr_thr
, *signalled_thr
;
676 /* Put a "FreeBSD" label in the ELF header. */
677 i_ehdrp
= elf_elfheader (obfd
);
678 i_ehdrp
->e_ident
[EI_OSABI
] = ELFOSABI_FREEBSD
;
680 gdb_assert (gdbarch_iterate_over_regset_sections_p (gdbarch
));
682 if (get_exec_file (0))
684 const char *fname
= lbasename (get_exec_file (0));
685 std::string psargs
= fname
;
687 const char *infargs
= get_inferior_args ();
689 psargs
= psargs
+ " " + infargs
;
691 note_data
.reset (elfcore_write_prpsinfo (obfd
, note_data
.release (),
696 /* Thread register information. */
699 update_thread_list ();
701 catch (const gdb_exception_error
&e
)
703 exception_print (gdb_stderr
, e
);
706 /* Like the kernel, prefer dumping the signalled thread first.
707 "First thread" is what tools use to infer the signalled thread.
708 In case there's more than one signalled thread, prefer the
709 current thread, if it is signalled. */
710 curr_thr
= inferior_thread ();
711 if (curr_thr
->suspend
.stop_signal
!= GDB_SIGNAL_0
)
712 signalled_thr
= curr_thr
;
715 signalled_thr
= iterate_over_threads (find_signalled_thread
, NULL
);
716 if (signalled_thr
== NULL
)
717 signalled_thr
= curr_thr
;
720 enum gdb_signal stop_signal
= signalled_thr
->suspend
.stop_signal
;
721 gcore_elf_build_thread_register_notes (gdbarch
, signalled_thr
, stop_signal
,
722 obfd
, ¬e_data
, note_size
);
723 for (thread_info
*thr
: current_inferior ()->non_exited_threads ())
725 if (thr
== signalled_thr
)
728 gcore_elf_build_thread_register_notes (gdbarch
, thr
, stop_signal
,
729 obfd
, ¬e_data
, note_size
);
732 /* Auxiliary vector. */
733 uint32_t structsize
= gdbarch_ptr_bit (gdbarch
) / 4; /* Elf_Auxinfo */
734 gdb::optional
<gdb::byte_vector
> note_desc
=
735 fbsd_make_note_desc (TARGET_OBJECT_AUXV
, structsize
);
736 if (note_desc
&& !note_desc
->empty ())
738 note_data
.reset (elfcore_write_note (obfd
, note_data
.release (),
739 note_size
, "FreeBSD",
740 NT_FREEBSD_PROCSTAT_AUXV
,
742 note_desc
->size ()));
747 /* Virtual memory mappings. */
748 note_desc
= fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_VMMAP
, 0);
749 if (note_desc
&& !note_desc
->empty ())
751 note_data
.reset (elfcore_write_note (obfd
, note_data
.release (),
752 note_size
, "FreeBSD",
753 NT_FREEBSD_PROCSTAT_VMMAP
,
755 note_desc
->size ()));
760 note_desc
= fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_PS_STRINGS
, 0);
761 if (note_desc
&& !note_desc
->empty ())
763 note_data
.reset (elfcore_write_note (obfd
, note_data
.release (),
764 note_size
, "FreeBSD",
765 NT_FREEBSD_PROCSTAT_PSSTRINGS
,
767 note_desc
->size ()));
772 /* Include the target description when possible. */
773 gcore_elf_make_tdesc_note (obfd
, ¬e_data
, note_size
);
778 /* Helper function to generate the file descriptor description for a
779 single open file in 'info proc files'. */
782 fbsd_file_fd (int kf_fd
)
786 case KINFO_FILE_FD_TYPE_CWD
:
788 case KINFO_FILE_FD_TYPE_ROOT
:
790 case KINFO_FILE_FD_TYPE_JAIL
:
792 case KINFO_FILE_FD_TYPE_TRACE
:
794 case KINFO_FILE_FD_TYPE_TEXT
:
796 case KINFO_FILE_FD_TYPE_CTTY
:
799 return int_string (kf_fd
, 10, 1, 0, 0);
803 /* Helper function to generate the file type for a single open file in
804 'info proc files'. */
807 fbsd_file_type (int kf_type
, int kf_vnode_type
)
811 case KINFO_FILE_TYPE_VNODE
:
812 switch (kf_vnode_type
)
814 case KINFO_FILE_VTYPE_VREG
:
816 case KINFO_FILE_VTYPE_VDIR
:
818 case KINFO_FILE_VTYPE_VCHR
:
820 case KINFO_FILE_VTYPE_VLNK
:
822 case KINFO_FILE_VTYPE_VSOCK
:
824 case KINFO_FILE_VTYPE_VFIFO
:
828 char *str
= get_print_cell ();
830 xsnprintf (str
, PRINT_CELL_SIZE
, "vn:%d", kf_vnode_type
);
834 case KINFO_FILE_TYPE_SOCKET
:
836 case KINFO_FILE_TYPE_PIPE
:
838 case KINFO_FILE_TYPE_FIFO
:
840 case KINFO_FILE_TYPE_KQUEUE
:
842 case KINFO_FILE_TYPE_CRYPTO
:
844 case KINFO_FILE_TYPE_MQUEUE
:
846 case KINFO_FILE_TYPE_SHM
:
848 case KINFO_FILE_TYPE_SEM
:
850 case KINFO_FILE_TYPE_PTS
:
852 case KINFO_FILE_TYPE_PROCDESC
:
855 return int_string (kf_type
, 10, 1, 0, 0);
859 /* Helper function to generate the file flags for a single open file in
860 'info proc files'. */
863 fbsd_file_flags (int kf_flags
)
865 static char file_flags
[10];
867 file_flags
[0] = (kf_flags
& KINFO_FILE_FLAG_READ
) ? 'r' : '-';
868 file_flags
[1] = (kf_flags
& KINFO_FILE_FLAG_WRITE
) ? 'w' : '-';
869 file_flags
[2] = (kf_flags
& KINFO_FILE_FLAG_EXEC
) ? 'x' : '-';
870 file_flags
[3] = (kf_flags
& KINFO_FILE_FLAG_APPEND
) ? 'a' : '-';
871 file_flags
[4] = (kf_flags
& KINFO_FILE_FLAG_ASYNC
) ? 's' : '-';
872 file_flags
[5] = (kf_flags
& KINFO_FILE_FLAG_FSYNC
) ? 'f' : '-';
873 file_flags
[6] = (kf_flags
& KINFO_FILE_FLAG_NONBLOCK
) ? 'n' : '-';
874 file_flags
[7] = (kf_flags
& KINFO_FILE_FLAG_DIRECT
) ? 'd' : '-';
875 file_flags
[8] = (kf_flags
& KINFO_FILE_FLAG_HASLOCK
) ? 'l' : '-';
876 file_flags
[9] = '\0';
881 /* Helper function to generate the name of an IP protocol. */
884 fbsd_ipproto (int protocol
)
888 case FBSD_IPPROTO_ICMP
:
890 case FBSD_IPPROTO_TCP
:
892 case FBSD_IPPROTO_UDP
:
894 case FBSD_IPPROTO_SCTP
:
898 char *str
= get_print_cell ();
900 xsnprintf (str
, PRINT_CELL_SIZE
, "ip<%d>", protocol
);
906 /* Helper function to print out an IPv4 socket address. */
909 fbsd_print_sockaddr_in (const void *sockaddr
)
911 const struct fbsd_sockaddr_in
*sin
=
912 reinterpret_cast<const struct fbsd_sockaddr_in
*> (sockaddr
);
913 char buf
[INET_ADDRSTRLEN
];
915 if (inet_ntop (AF_INET
, sin
->sin_addr
, buf
, sizeof buf
) == nullptr)
916 error (_("Failed to format IPv4 address"));
917 printf_filtered ("%s:%u", buf
,
918 (sin
->sin_port
[0] << 8) | sin
->sin_port
[1]);
921 /* Helper function to print out an IPv6 socket address. */
924 fbsd_print_sockaddr_in6 (const void *sockaddr
)
926 const struct fbsd_sockaddr_in6
*sin6
=
927 reinterpret_cast<const struct fbsd_sockaddr_in6
*> (sockaddr
);
928 char buf
[INET6_ADDRSTRLEN
];
930 if (inet_ntop (AF_INET6
, sin6
->sin6_addr
, buf
, sizeof buf
) == nullptr)
931 error (_("Failed to format IPv6 address"));
932 printf_filtered ("%s.%u", buf
,
933 (sin6
->sin6_port
[0] << 8) | sin6
->sin6_port
[1]);
936 /* See fbsd-tdep.h. */
939 fbsd_info_proc_files_header ()
941 printf_filtered (_("Open files:\n\n"));
942 printf_filtered (" %6s %6s %10s %9s %s\n",
943 "FD", "Type", "Offset", "Flags ", "Name");
946 /* See fbsd-tdep.h. */
949 fbsd_info_proc_files_entry (int kf_type
, int kf_fd
, int kf_flags
,
950 LONGEST kf_offset
, int kf_vnode_type
,
951 int kf_sock_domain
, int kf_sock_type
,
952 int kf_sock_protocol
, const void *kf_sa_local
,
953 const void *kf_sa_peer
, const void *kf_path
)
955 printf_filtered (" %6s %6s %10s %8s ",
956 fbsd_file_fd (kf_fd
),
957 fbsd_file_type (kf_type
, kf_vnode_type
),
958 kf_offset
> -1 ? hex_string (kf_offset
) : "-",
959 fbsd_file_flags (kf_flags
));
960 if (kf_type
== KINFO_FILE_TYPE_SOCKET
)
962 switch (kf_sock_domain
)
966 switch (kf_sock_type
)
968 case FBSD_SOCK_STREAM
:
969 printf_filtered ("unix stream:");
971 case FBSD_SOCK_DGRAM
:
972 printf_filtered ("unix dgram:");
974 case FBSD_SOCK_SEQPACKET
:
975 printf_filtered ("unix seqpacket:");
978 printf_filtered ("unix <%d>:", kf_sock_type
);
982 /* For local sockets, print out the first non-nul path
983 rather than both paths. */
984 const struct fbsd_sockaddr_un
*saddr_un
985 = reinterpret_cast<const struct fbsd_sockaddr_un
*> (kf_sa_local
);
986 if (saddr_un
->sun_path
[0] == 0)
987 saddr_un
= reinterpret_cast<const struct fbsd_sockaddr_un
*>
989 printf_filtered ("%s", saddr_un
->sun_path
);
993 printf_filtered ("%s4 ", fbsd_ipproto (kf_sock_protocol
));
994 fbsd_print_sockaddr_in (kf_sa_local
);
995 printf_filtered (" -> ");
996 fbsd_print_sockaddr_in (kf_sa_peer
);
999 printf_filtered ("%s6 ", fbsd_ipproto (kf_sock_protocol
));
1000 fbsd_print_sockaddr_in6 (kf_sa_local
);
1001 printf_filtered (" -> ");
1002 fbsd_print_sockaddr_in6 (kf_sa_peer
);
1007 printf_filtered ("%s", reinterpret_cast<const char *> (kf_path
));
1008 printf_filtered ("\n");
1011 /* Implement "info proc files" for a corefile. */
1014 fbsd_core_info_proc_files (struct gdbarch
*gdbarch
)
1017 = bfd_get_section_by_name (core_bfd
, ".note.freebsdcore.files");
1018 if (section
== NULL
)
1020 warning (_("unable to find open files in core file"));
1024 size_t note_size
= bfd_section_size (section
);
1026 error (_("malformed core note - too short for header"));
1028 gdb::def_vector
<unsigned char> contents (note_size
);
1029 if (!bfd_get_section_contents (core_bfd
, section
, contents
.data (),
1031 error (_("could not get core note contents"));
1033 unsigned char *descdata
= contents
.data ();
1034 unsigned char *descend
= descdata
+ note_size
;
1036 /* Skip over the structure size. */
1039 fbsd_info_proc_files_header ();
1041 while (descdata
+ KF_PATH
< descend
)
1043 ULONGEST structsize
= bfd_get_32 (core_bfd
, descdata
+ KF_STRUCTSIZE
);
1044 if (structsize
< KF_PATH
)
1045 error (_("malformed core note - file structure too small"));
1047 LONGEST type
= bfd_get_signed_32 (core_bfd
, descdata
+ KF_TYPE
);
1048 LONGEST fd
= bfd_get_signed_32 (core_bfd
, descdata
+ KF_FD
);
1049 LONGEST flags
= bfd_get_signed_32 (core_bfd
, descdata
+ KF_FLAGS
);
1050 LONGEST offset
= bfd_get_signed_64 (core_bfd
, descdata
+ KF_OFFSET
);
1051 LONGEST vnode_type
= bfd_get_signed_32 (core_bfd
,
1052 descdata
+ KF_VNODE_TYPE
);
1053 LONGEST sock_domain
= bfd_get_signed_32 (core_bfd
,
1054 descdata
+ KF_SOCK_DOMAIN
);
1055 LONGEST sock_type
= bfd_get_signed_32 (core_bfd
, descdata
+ KF_SOCK_TYPE
);
1056 LONGEST sock_protocol
= bfd_get_signed_32 (core_bfd
,
1057 descdata
+ KF_SOCK_PROTOCOL
);
1058 fbsd_info_proc_files_entry (type
, fd
, flags
, offset
, vnode_type
,
1059 sock_domain
, sock_type
, sock_protocol
,
1060 descdata
+ KF_SA_LOCAL
, descdata
+ KF_SA_PEER
,
1061 descdata
+ KF_PATH
);
1063 descdata
+= structsize
;
1067 /* Helper function to generate mappings flags for a single VM map
1068 entry in 'info proc mappings'. */
1071 fbsd_vm_map_entry_flags (int kve_flags
, int kve_protection
)
1073 static char vm_flags
[9];
1075 vm_flags
[0] = (kve_protection
& KINFO_VME_PROT_READ
) ? 'r' : '-';
1076 vm_flags
[1] = (kve_protection
& KINFO_VME_PROT_WRITE
) ? 'w' : '-';
1077 vm_flags
[2] = (kve_protection
& KINFO_VME_PROT_EXEC
) ? 'x' : '-';
1079 vm_flags
[4] = (kve_flags
& KINFO_VME_FLAG_COW
) ? 'C' : '-';
1080 vm_flags
[5] = (kve_flags
& KINFO_VME_FLAG_NEEDS_COPY
) ? 'N' : '-';
1081 vm_flags
[6] = (kve_flags
& KINFO_VME_FLAG_SUPER
) ? 'S' : '-';
1082 vm_flags
[7] = (kve_flags
& KINFO_VME_FLAG_GROWS_UP
) ? 'U'
1083 : (kve_flags
& KINFO_VME_FLAG_GROWS_DOWN
) ? 'D' : '-';
1089 /* See fbsd-tdep.h. */
1092 fbsd_info_proc_mappings_header (int addr_bit
)
1094 printf_filtered (_("Mapped address spaces:\n\n"));
1097 printf_filtered (" %18s %18s %10s %10s %9s %s\n",
1100 " Size", " Offset", "Flags ", "File");
1104 printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
1107 " Size", " Offset", "Flags ", "File");
1111 /* See fbsd-tdep.h. */
1114 fbsd_info_proc_mappings_entry (int addr_bit
, ULONGEST kve_start
,
1115 ULONGEST kve_end
, ULONGEST kve_offset
,
1116 int kve_flags
, int kve_protection
,
1117 const void *kve_path
)
1121 printf_filtered (" %18s %18s %10s %10s %9s %s\n",
1122 hex_string (kve_start
),
1123 hex_string (kve_end
),
1124 hex_string (kve_end
- kve_start
),
1125 hex_string (kve_offset
),
1126 fbsd_vm_map_entry_flags (kve_flags
, kve_protection
),
1127 reinterpret_cast<const char *> (kve_path
));
1131 printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
1132 hex_string (kve_start
),
1133 hex_string (kve_end
),
1134 hex_string (kve_end
- kve_start
),
1135 hex_string (kve_offset
),
1136 fbsd_vm_map_entry_flags (kve_flags
, kve_protection
),
1137 reinterpret_cast<const char *> (kve_path
));
1141 /* Implement "info proc mappings" for a corefile. */
1144 fbsd_core_info_proc_mappings (struct gdbarch
*gdbarch
)
1147 unsigned char *descdata
, *descend
;
1150 section
= bfd_get_section_by_name (core_bfd
, ".note.freebsdcore.vmmap");
1151 if (section
== NULL
)
1153 warning (_("unable to find mappings in core file"));
1157 note_size
= bfd_section_size (section
);
1159 error (_("malformed core note - too short for header"));
1161 gdb::def_vector
<unsigned char> contents (note_size
);
1162 if (!bfd_get_section_contents (core_bfd
, section
, contents
.data (),
1164 error (_("could not get core note contents"));
1166 descdata
= contents
.data ();
1167 descend
= descdata
+ note_size
;
1169 /* Skip over the structure size. */
1172 fbsd_info_proc_mappings_header (gdbarch_addr_bit (gdbarch
));
1173 while (descdata
+ KVE_PATH
< descend
)
1175 ULONGEST structsize
= bfd_get_32 (core_bfd
, descdata
+ KVE_STRUCTSIZE
);
1176 if (structsize
< KVE_PATH
)
1177 error (_("malformed core note - vmmap entry too small"));
1179 ULONGEST start
= bfd_get_64 (core_bfd
, descdata
+ KVE_START
);
1180 ULONGEST end
= bfd_get_64 (core_bfd
, descdata
+ KVE_END
);
1181 ULONGEST offset
= bfd_get_64 (core_bfd
, descdata
+ KVE_OFFSET
);
1182 LONGEST flags
= bfd_get_signed_32 (core_bfd
, descdata
+ KVE_FLAGS
);
1183 LONGEST prot
= bfd_get_signed_32 (core_bfd
, descdata
+ KVE_PROTECTION
);
1184 fbsd_info_proc_mappings_entry (gdbarch_addr_bit (gdbarch
), start
, end
,
1185 offset
, flags
, prot
, descdata
+ KVE_PATH
);
1187 descdata
+= structsize
;
1191 /* Fetch the pathname of a vnode for a single file descriptor from the
1192 file table core note. */
1194 static gdb::unique_xmalloc_ptr
<char>
1195 fbsd_core_vnode_path (struct gdbarch
*gdbarch
, int fd
)
1198 unsigned char *descdata
, *descend
;
1201 section
= bfd_get_section_by_name (core_bfd
, ".note.freebsdcore.files");
1202 if (section
== NULL
)
1205 note_size
= bfd_section_size (section
);
1207 error (_("malformed core note - too short for header"));
1209 gdb::def_vector
<unsigned char> contents (note_size
);
1210 if (!bfd_get_section_contents (core_bfd
, section
, contents
.data (),
1212 error (_("could not get core note contents"));
1214 descdata
= contents
.data ();
1215 descend
= descdata
+ note_size
;
1217 /* Skip over the structure size. */
1220 while (descdata
+ KF_PATH
< descend
)
1222 ULONGEST structsize
;
1224 structsize
= bfd_get_32 (core_bfd
, descdata
+ KF_STRUCTSIZE
);
1225 if (structsize
< KF_PATH
)
1226 error (_("malformed core note - file structure too small"));
1228 if (bfd_get_32 (core_bfd
, descdata
+ KF_TYPE
) == KINFO_FILE_TYPE_VNODE
1229 && bfd_get_signed_32 (core_bfd
, descdata
+ KF_FD
) == fd
)
1231 char *path
= (char *) descdata
+ KF_PATH
;
1232 return make_unique_xstrdup (path
);
1235 descdata
+= structsize
;
1240 /* Helper function to read a struct timeval. */
1243 fbsd_core_fetch_timeval (struct gdbarch
*gdbarch
, unsigned char *data
,
1244 LONGEST
&sec
, ULONGEST
&usec
)
1246 if (gdbarch_addr_bit (gdbarch
) == 64)
1248 sec
= bfd_get_signed_64 (core_bfd
, data
);
1249 usec
= bfd_get_64 (core_bfd
, data
+ 8);
1251 else if (bfd_get_arch (core_bfd
) == bfd_arch_i386
)
1253 sec
= bfd_get_signed_32 (core_bfd
, data
);
1254 usec
= bfd_get_32 (core_bfd
, data
+ 4);
1258 sec
= bfd_get_signed_64 (core_bfd
, data
);
1259 usec
= bfd_get_32 (core_bfd
, data
+ 8);
1263 /* Print out the contents of a signal set. */
1266 fbsd_print_sigset (const char *descr
, unsigned char *sigset
)
1268 printf_filtered ("%s: ", descr
);
1269 for (int i
= 0; i
< SIG_WORDS
; i
++)
1270 printf_filtered ("%08x ",
1271 (unsigned int) bfd_get_32 (core_bfd
, sigset
+ i
* 4));
1272 printf_filtered ("\n");
1275 /* Implement "info proc status" for a corefile. */
1278 fbsd_core_info_proc_status (struct gdbarch
*gdbarch
)
1280 const struct kinfo_proc_layout
*kp
;
1282 unsigned char *descdata
;
1283 int addr_bit
, long_bit
;
1288 section
= bfd_get_section_by_name (core_bfd
, ".note.freebsdcore.proc");
1289 if (section
== NULL
)
1291 warning (_("unable to find process info in core file"));
1295 addr_bit
= gdbarch_addr_bit (gdbarch
);
1297 kp
= &kinfo_proc_layout_64
;
1298 else if (bfd_get_arch (core_bfd
) == bfd_arch_i386
)
1299 kp
= &kinfo_proc_layout_i386
;
1301 kp
= &kinfo_proc_layout_32
;
1302 long_bit
= gdbarch_long_bit (gdbarch
);
1305 * Ensure that the note is large enough for all of the fields fetched
1306 * by this function. In particular, the note must contain the 32-bit
1307 * structure size, then it must be long enough to access the last
1308 * field used (ki_rusage_ch.ru_majflt) which is the size of a long.
1310 note_size
= bfd_section_size (section
);
1311 if (note_size
< (4 + kp
->ki_rusage_ch
+ kp
->ru_majflt
1312 + long_bit
/ TARGET_CHAR_BIT
))
1313 error (_("malformed core note - too short"));
1315 gdb::def_vector
<unsigned char> contents (note_size
);
1316 if (!bfd_get_section_contents (core_bfd
, section
, contents
.data (),
1318 error (_("could not get core note contents"));
1320 descdata
= contents
.data ();
1322 /* Skip over the structure size. */
1325 /* Verify 'ki_layout' is 0. */
1326 if (bfd_get_32 (core_bfd
, descdata
+ kp
->ki_layout
) != 0)
1328 warning (_("unsupported process information in core file"));
1332 printf_filtered ("Name: %.19s\n", descdata
+ kp
->ki_comm
);
1333 printf_filtered ("Process ID: %s\n",
1334 pulongest (bfd_get_32 (core_bfd
, descdata
+ kp
->ki_pid
)));
1335 printf_filtered ("Parent process: %s\n",
1336 pulongest (bfd_get_32 (core_bfd
, descdata
+ kp
->ki_ppid
)));
1337 printf_filtered ("Process group: %s\n",
1338 pulongest (bfd_get_32 (core_bfd
, descdata
+ kp
->ki_pgid
)));
1339 printf_filtered ("Session id: %s\n",
1340 pulongest (bfd_get_32 (core_bfd
, descdata
+ kp
->ki_sid
)));
1342 /* FreeBSD 12.0 and later store a 64-bit dev_t at 'ki_tdev'. Older
1343 kernels store a 32-bit dev_t at 'ki_tdev_freebsd11'. In older
1344 kernels the 64-bit 'ki_tdev' field is in a reserved section of
1345 the structure that is cleared to zero. Assume that a zero value
1346 in ki_tdev indicates a core dump from an older kernel and use the
1347 value in 'ki_tdev_freebsd11' instead. */
1348 value
= bfd_get_64 (core_bfd
, descdata
+ kp
->ki_tdev
);
1350 value
= bfd_get_32 (core_bfd
, descdata
+ kp
->ki_tdev_freebsd11
);
1351 printf_filtered ("TTY: %s\n", pulongest (value
));
1352 printf_filtered ("TTY owner process group: %s\n",
1353 pulongest (bfd_get_32 (core_bfd
, descdata
+ kp
->ki_tpgid
)));
1354 printf_filtered ("User IDs (real, effective, saved): %s %s %s\n",
1355 pulongest (bfd_get_32 (core_bfd
, descdata
+ kp
->ki_ruid
)),
1356 pulongest (bfd_get_32 (core_bfd
, descdata
+ kp
->ki_uid
)),
1357 pulongest (bfd_get_32 (core_bfd
, descdata
+ kp
->ki_svuid
)));
1358 printf_filtered ("Group IDs (real, effective, saved): %s %s %s\n",
1359 pulongest (bfd_get_32 (core_bfd
, descdata
+ kp
->ki_rgid
)),
1360 pulongest (bfd_get_32 (core_bfd
, descdata
+ kp
->ki_groups
)),
1361 pulongest (bfd_get_32 (core_bfd
, descdata
+ kp
->ki_svgid
)));
1362 printf_filtered ("Groups: ");
1363 uint16_t ngroups
= bfd_get_16 (core_bfd
, descdata
+ kp
->ki_ngroups
);
1364 for (int i
= 0; i
< ngroups
; i
++)
1365 printf_filtered ("%s ",
1366 pulongest (bfd_get_32 (core_bfd
,
1367 descdata
+ kp
->ki_groups
+ i
* 4)));
1368 printf_filtered ("\n");
1369 value
= bfd_get (long_bit
, core_bfd
,
1370 descdata
+ kp
->ki_rusage
+ kp
->ru_minflt
);
1371 printf_filtered ("Minor faults (no memory page): %s\n", pulongest (value
));
1372 value
= bfd_get (long_bit
, core_bfd
,
1373 descdata
+ kp
->ki_rusage_ch
+ kp
->ru_minflt
);
1374 printf_filtered ("Minor faults, children: %s\n", pulongest (value
));
1375 value
= bfd_get (long_bit
, core_bfd
,
1376 descdata
+ kp
->ki_rusage
+ kp
->ru_majflt
);
1377 printf_filtered ("Major faults (memory page faults): %s\n",
1379 value
= bfd_get (long_bit
, core_bfd
,
1380 descdata
+ kp
->ki_rusage_ch
+ kp
->ru_majflt
);
1381 printf_filtered ("Major faults, children: %s\n", pulongest (value
));
1382 fbsd_core_fetch_timeval (gdbarch
,
1383 descdata
+ kp
->ki_rusage
+ kp
->ru_utime
,
1385 printf_filtered ("utime: %s.%06d\n", plongest (sec
), (int) value
);
1386 fbsd_core_fetch_timeval (gdbarch
,
1387 descdata
+ kp
->ki_rusage
+ kp
->ru_stime
,
1389 printf_filtered ("stime: %s.%06d\n", plongest (sec
), (int) value
);
1390 fbsd_core_fetch_timeval (gdbarch
,
1391 descdata
+ kp
->ki_rusage_ch
+ kp
->ru_utime
,
1393 printf_filtered ("utime, children: %s.%06d\n", plongest (sec
), (int) value
);
1394 fbsd_core_fetch_timeval (gdbarch
,
1395 descdata
+ kp
->ki_rusage_ch
+ kp
->ru_stime
,
1397 printf_filtered ("stime, children: %s.%06d\n", plongest (sec
), (int) value
);
1398 printf_filtered ("'nice' value: %d\n",
1399 (int) bfd_get_signed_8 (core_bfd
, descdata
+ kp
->ki_nice
));
1400 fbsd_core_fetch_timeval (gdbarch
, descdata
+ kp
->ki_start
, sec
, value
);
1401 printf_filtered ("Start time: %s.%06d\n", plongest (sec
), (int) value
);
1402 printf_filtered ("Virtual memory size: %s kB\n",
1403 pulongest (bfd_get (addr_bit
, core_bfd
,
1404 descdata
+ kp
->ki_size
) / 1024));
1405 printf_filtered ("Data size: %s pages\n",
1406 pulongest (bfd_get (addr_bit
, core_bfd
,
1407 descdata
+ kp
->ki_dsize
)));
1408 printf_filtered ("Stack size: %s pages\n",
1409 pulongest (bfd_get (addr_bit
, core_bfd
,
1410 descdata
+ kp
->ki_ssize
)));
1411 printf_filtered ("Text size: %s pages\n",
1412 pulongest (bfd_get (addr_bit
, core_bfd
,
1413 descdata
+ kp
->ki_tsize
)));
1414 printf_filtered ("Resident set size: %s pages\n",
1415 pulongest (bfd_get (addr_bit
, core_bfd
,
1416 descdata
+ kp
->ki_rssize
)));
1417 printf_filtered ("Maximum RSS: %s pages\n",
1418 pulongest (bfd_get (long_bit
, core_bfd
,
1419 descdata
+ kp
->ki_rusage
1421 fbsd_print_sigset ("Ignored Signals", descdata
+ kp
->ki_sigignore
);
1422 fbsd_print_sigset ("Caught Signals", descdata
+ kp
->ki_sigcatch
);
1425 /* Implement the "core_info_proc" gdbarch method. */
1428 fbsd_core_info_proc (struct gdbarch
*gdbarch
, const char *args
,
1429 enum info_proc_what what
)
1431 bool do_cmdline
= false;
1432 bool do_cwd
= false;
1433 bool do_exe
= false;
1434 bool do_files
= false;
1435 bool do_mappings
= false;
1436 bool do_status
= false;
1477 pid
= bfd_core_file_pid (core_bfd
);
1479 printf_filtered (_("process %d\n"), pid
);
1483 const char *cmdline
;
1485 cmdline
= bfd_core_file_failing_command (core_bfd
);
1487 printf_filtered ("cmdline = '%s'\n", cmdline
);
1489 warning (_("Command line unavailable"));
1493 gdb::unique_xmalloc_ptr
<char> cwd
=
1494 fbsd_core_vnode_path (gdbarch
, KINFO_FILE_FD_TYPE_CWD
);
1496 printf_filtered ("cwd = '%s'\n", cwd
.get ());
1498 warning (_("unable to read current working directory"));
1502 gdb::unique_xmalloc_ptr
<char> exe
=
1503 fbsd_core_vnode_path (gdbarch
, KINFO_FILE_FD_TYPE_TEXT
);
1505 printf_filtered ("exe = '%s'\n", exe
.get ());
1507 warning (_("unable to read executable path name"));
1510 fbsd_core_info_proc_files (gdbarch
);
1512 fbsd_core_info_proc_mappings (gdbarch
);
1514 fbsd_core_info_proc_status (gdbarch
);
1517 /* Print descriptions of FreeBSD-specific AUXV entries to FILE. */
1520 fbsd_print_auxv_entry (struct gdbarch
*gdbarch
, struct ui_file
*file
,
1521 CORE_ADDR type
, CORE_ADDR val
)
1523 const char *name
= "???";
1524 const char *description
= "";
1525 enum auxv_format format
= AUXV_FORMAT_HEX
;
1544 default_print_auxv_entry (gdbarch
, file
, type
, val
);
1546 #define _TAGNAME(tag) #tag
1547 #define TAGNAME(tag) _TAGNAME(AT_##tag)
1548 #define TAG(tag, text, kind) \
1549 case AT_FREEBSD_##tag: name = TAGNAME(tag); description = text; format = kind; break
1550 TAG (EXECPATH
, _("Executable path"), AUXV_FORMAT_STR
);
1551 TAG (CANARY
, _("Canary for SSP"), AUXV_FORMAT_HEX
);
1552 TAG (CANARYLEN
, ("Length of the SSP canary"), AUXV_FORMAT_DEC
);
1553 TAG (OSRELDATE
, _("OSRELDATE"), AUXV_FORMAT_DEC
);
1554 TAG (NCPUS
, _("Number of CPUs"), AUXV_FORMAT_DEC
);
1555 TAG (PAGESIZES
, _("Pagesizes"), AUXV_FORMAT_HEX
);
1556 TAG (PAGESIZESLEN
, _("Number of pagesizes"), AUXV_FORMAT_DEC
);
1557 TAG (TIMEKEEP
, _("Pointer to timehands"), AUXV_FORMAT_HEX
);
1558 TAG (STACKPROT
, _("Initial stack protection"), AUXV_FORMAT_HEX
);
1559 TAG (EHDRFLAGS
, _("ELF header e_flags"), AUXV_FORMAT_HEX
);
1560 TAG (HWCAP
, _("Machine-dependent CPU capability hints"), AUXV_FORMAT_HEX
);
1561 TAG (HWCAP2
, _("Extension of AT_HWCAP"), AUXV_FORMAT_HEX
);
1562 TAG (BSDFLAGS
, _("ELF BSD flags"), AUXV_FORMAT_HEX
);
1563 TAG (ARGC
, _("Argument count"), AUXV_FORMAT_DEC
);
1564 TAG (ARGV
, _("Argument vector"), AUXV_FORMAT_HEX
);
1565 TAG (ENVC
, _("Environment count"), AUXV_FORMAT_DEC
);
1566 TAG (ENVV
, _("Environment vector"), AUXV_FORMAT_HEX
);
1567 TAG (PS_STRINGS
, _("Pointer to ps_strings"), AUXV_FORMAT_HEX
);
1570 fprint_auxv_entry (file
, name
, description
, format
, type
, val
);
1573 /* Implement the "get_siginfo_type" gdbarch method. */
1575 static struct type
*
1576 fbsd_get_siginfo_type (struct gdbarch
*gdbarch
)
1578 struct fbsd_gdbarch_data
*fbsd_gdbarch_data
;
1579 struct type
*int_type
, *int32_type
, *uint32_type
, *long_type
, *void_ptr_type
;
1580 struct type
*uid_type
, *pid_type
;
1581 struct type
*sigval_type
, *reason_type
;
1582 struct type
*siginfo_type
;
1585 fbsd_gdbarch_data
= get_fbsd_gdbarch_data (gdbarch
);
1586 if (fbsd_gdbarch_data
->siginfo_type
!= NULL
)
1587 return fbsd_gdbarch_data
->siginfo_type
;
1589 int_type
= arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
1591 int32_type
= arch_integer_type (gdbarch
, 32, 0, "int32_t");
1592 uint32_type
= arch_integer_type (gdbarch
, 32, 1, "uint32_t");
1593 long_type
= arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
1595 void_ptr_type
= lookup_pointer_type (builtin_type (gdbarch
)->builtin_void
);
1598 sigval_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
1599 sigval_type
->set_name (xstrdup ("sigval"));
1600 append_composite_type_field (sigval_type
, "sival_int", int_type
);
1601 append_composite_type_field (sigval_type
, "sival_ptr", void_ptr_type
);
1604 pid_type
= arch_type (gdbarch
, TYPE_CODE_TYPEDEF
,
1605 TYPE_LENGTH (int32_type
) * TARGET_CHAR_BIT
, "__pid_t");
1606 TYPE_TARGET_TYPE (pid_type
) = int32_type
;
1607 pid_type
->set_target_is_stub (true);
1610 uid_type
= arch_type (gdbarch
, TYPE_CODE_TYPEDEF
,
1611 TYPE_LENGTH (uint32_type
) * TARGET_CHAR_BIT
,
1613 TYPE_TARGET_TYPE (uid_type
) = uint32_type
;
1614 pid_type
->set_target_is_stub (true);
1617 reason_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
1620 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1621 append_composite_type_field (type
, "si_trapno", int_type
);
1622 append_composite_type_field (reason_type
, "_fault", type
);
1625 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1626 append_composite_type_field (type
, "si_timerid", int_type
);
1627 append_composite_type_field (type
, "si_overrun", int_type
);
1628 append_composite_type_field (reason_type
, "_timer", type
);
1631 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1632 append_composite_type_field (type
, "si_mqd", int_type
);
1633 append_composite_type_field (reason_type
, "_mesgq", type
);
1636 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1637 append_composite_type_field (type
, "si_band", long_type
);
1638 append_composite_type_field (reason_type
, "_poll", type
);
1641 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1642 append_composite_type_field (type
, "__spare1__", long_type
);
1643 append_composite_type_field (type
, "__spare2__",
1644 init_vector_type (int_type
, 7));
1645 append_composite_type_field (reason_type
, "__spare__", type
);
1647 /* struct siginfo */
1648 siginfo_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
1649 siginfo_type
->set_name (xstrdup ("siginfo"));
1650 append_composite_type_field (siginfo_type
, "si_signo", int_type
);
1651 append_composite_type_field (siginfo_type
, "si_errno", int_type
);
1652 append_composite_type_field (siginfo_type
, "si_code", int_type
);
1653 append_composite_type_field (siginfo_type
, "si_pid", pid_type
);
1654 append_composite_type_field (siginfo_type
, "si_uid", uid_type
);
1655 append_composite_type_field (siginfo_type
, "si_status", int_type
);
1656 append_composite_type_field (siginfo_type
, "si_addr", void_ptr_type
);
1657 append_composite_type_field (siginfo_type
, "si_value", sigval_type
);
1658 append_composite_type_field (siginfo_type
, "_reason", reason_type
);
1660 fbsd_gdbarch_data
->siginfo_type
= siginfo_type
;
1662 return siginfo_type
;
1665 /* Implement the "gdb_signal_from_target" gdbarch method. */
1667 static enum gdb_signal
1668 fbsd_gdb_signal_from_target (struct gdbarch
*gdbarch
, int signal
)
1673 return GDB_SIGNAL_0
;
1675 case FREEBSD_SIGHUP
:
1676 return GDB_SIGNAL_HUP
;
1678 case FREEBSD_SIGINT
:
1679 return GDB_SIGNAL_INT
;
1681 case FREEBSD_SIGQUIT
:
1682 return GDB_SIGNAL_QUIT
;
1684 case FREEBSD_SIGILL
:
1685 return GDB_SIGNAL_ILL
;
1687 case FREEBSD_SIGTRAP
:
1688 return GDB_SIGNAL_TRAP
;
1690 case FREEBSD_SIGABRT
:
1691 return GDB_SIGNAL_ABRT
;
1693 case FREEBSD_SIGEMT
:
1694 return GDB_SIGNAL_EMT
;
1696 case FREEBSD_SIGFPE
:
1697 return GDB_SIGNAL_FPE
;
1699 case FREEBSD_SIGKILL
:
1700 return GDB_SIGNAL_KILL
;
1702 case FREEBSD_SIGBUS
:
1703 return GDB_SIGNAL_BUS
;
1705 case FREEBSD_SIGSEGV
:
1706 return GDB_SIGNAL_SEGV
;
1708 case FREEBSD_SIGSYS
:
1709 return GDB_SIGNAL_SYS
;
1711 case FREEBSD_SIGPIPE
:
1712 return GDB_SIGNAL_PIPE
;
1714 case FREEBSD_SIGALRM
:
1715 return GDB_SIGNAL_ALRM
;
1717 case FREEBSD_SIGTERM
:
1718 return GDB_SIGNAL_TERM
;
1720 case FREEBSD_SIGURG
:
1721 return GDB_SIGNAL_URG
;
1723 case FREEBSD_SIGSTOP
:
1724 return GDB_SIGNAL_STOP
;
1726 case FREEBSD_SIGTSTP
:
1727 return GDB_SIGNAL_TSTP
;
1729 case FREEBSD_SIGCONT
:
1730 return GDB_SIGNAL_CONT
;
1732 case FREEBSD_SIGCHLD
:
1733 return GDB_SIGNAL_CHLD
;
1735 case FREEBSD_SIGTTIN
:
1736 return GDB_SIGNAL_TTIN
;
1738 case FREEBSD_SIGTTOU
:
1739 return GDB_SIGNAL_TTOU
;
1742 return GDB_SIGNAL_IO
;
1744 case FREEBSD_SIGXCPU
:
1745 return GDB_SIGNAL_XCPU
;
1747 case FREEBSD_SIGXFSZ
:
1748 return GDB_SIGNAL_XFSZ
;
1750 case FREEBSD_SIGVTALRM
:
1751 return GDB_SIGNAL_VTALRM
;
1753 case FREEBSD_SIGPROF
:
1754 return GDB_SIGNAL_PROF
;
1756 case FREEBSD_SIGWINCH
:
1757 return GDB_SIGNAL_WINCH
;
1759 case FREEBSD_SIGINFO
:
1760 return GDB_SIGNAL_INFO
;
1762 case FREEBSD_SIGUSR1
:
1763 return GDB_SIGNAL_USR1
;
1765 case FREEBSD_SIGUSR2
:
1766 return GDB_SIGNAL_USR2
;
1768 /* SIGTHR is the same as SIGLWP on FreeBSD. */
1769 case FREEBSD_SIGTHR
:
1770 return GDB_SIGNAL_LWP
;
1772 case FREEBSD_SIGLIBRT
:
1773 return GDB_SIGNAL_LIBRT
;
1776 if (signal
>= FREEBSD_SIGRTMIN
&& signal
<= FREEBSD_SIGRTMAX
)
1778 int offset
= signal
- FREEBSD_SIGRTMIN
;
1780 return (enum gdb_signal
) ((int) GDB_SIGNAL_REALTIME_65
+ offset
);
1783 return GDB_SIGNAL_UNKNOWN
;
1786 /* Implement the "gdb_signal_to_target" gdbarch method. */
1789 fbsd_gdb_signal_to_target (struct gdbarch
*gdbarch
,
1790 enum gdb_signal signal
)
1797 case GDB_SIGNAL_HUP
:
1798 return FREEBSD_SIGHUP
;
1800 case GDB_SIGNAL_INT
:
1801 return FREEBSD_SIGINT
;
1803 case GDB_SIGNAL_QUIT
:
1804 return FREEBSD_SIGQUIT
;
1806 case GDB_SIGNAL_ILL
:
1807 return FREEBSD_SIGILL
;
1809 case GDB_SIGNAL_TRAP
:
1810 return FREEBSD_SIGTRAP
;
1812 case GDB_SIGNAL_ABRT
:
1813 return FREEBSD_SIGABRT
;
1815 case GDB_SIGNAL_EMT
:
1816 return FREEBSD_SIGEMT
;
1818 case GDB_SIGNAL_FPE
:
1819 return FREEBSD_SIGFPE
;
1821 case GDB_SIGNAL_KILL
:
1822 return FREEBSD_SIGKILL
;
1824 case GDB_SIGNAL_BUS
:
1825 return FREEBSD_SIGBUS
;
1827 case GDB_SIGNAL_SEGV
:
1828 return FREEBSD_SIGSEGV
;
1830 case GDB_SIGNAL_SYS
:
1831 return FREEBSD_SIGSYS
;
1833 case GDB_SIGNAL_PIPE
:
1834 return FREEBSD_SIGPIPE
;
1836 case GDB_SIGNAL_ALRM
:
1837 return FREEBSD_SIGALRM
;
1839 case GDB_SIGNAL_TERM
:
1840 return FREEBSD_SIGTERM
;
1842 case GDB_SIGNAL_URG
:
1843 return FREEBSD_SIGURG
;
1845 case GDB_SIGNAL_STOP
:
1846 return FREEBSD_SIGSTOP
;
1848 case GDB_SIGNAL_TSTP
:
1849 return FREEBSD_SIGTSTP
;
1851 case GDB_SIGNAL_CONT
:
1852 return FREEBSD_SIGCONT
;
1854 case GDB_SIGNAL_CHLD
:
1855 return FREEBSD_SIGCHLD
;
1857 case GDB_SIGNAL_TTIN
:
1858 return FREEBSD_SIGTTIN
;
1860 case GDB_SIGNAL_TTOU
:
1861 return FREEBSD_SIGTTOU
;
1864 return FREEBSD_SIGIO
;
1866 case GDB_SIGNAL_XCPU
:
1867 return FREEBSD_SIGXCPU
;
1869 case GDB_SIGNAL_XFSZ
:
1870 return FREEBSD_SIGXFSZ
;
1872 case GDB_SIGNAL_VTALRM
:
1873 return FREEBSD_SIGVTALRM
;
1875 case GDB_SIGNAL_PROF
:
1876 return FREEBSD_SIGPROF
;
1878 case GDB_SIGNAL_WINCH
:
1879 return FREEBSD_SIGWINCH
;
1881 case GDB_SIGNAL_INFO
:
1882 return FREEBSD_SIGINFO
;
1884 case GDB_SIGNAL_USR1
:
1885 return FREEBSD_SIGUSR1
;
1887 case GDB_SIGNAL_USR2
:
1888 return FREEBSD_SIGUSR2
;
1890 case GDB_SIGNAL_LWP
:
1891 return FREEBSD_SIGTHR
;
1893 case GDB_SIGNAL_LIBRT
:
1894 return FREEBSD_SIGLIBRT
;
1897 if (signal
>= GDB_SIGNAL_REALTIME_65
1898 && signal
<= GDB_SIGNAL_REALTIME_126
)
1900 int offset
= signal
- GDB_SIGNAL_REALTIME_65
;
1902 return FREEBSD_SIGRTMIN
+ offset
;
1908 /* Implement the "get_syscall_number" gdbarch method. */
1911 fbsd_get_syscall_number (struct gdbarch
*gdbarch
, thread_info
*thread
)
1914 /* FreeBSD doesn't use gdbarch_get_syscall_number since FreeBSD
1915 native targets fetch the system call number from the
1916 'pl_syscall_code' member of struct ptrace_lwpinfo in fbsd_wait.
1917 However, system call catching requires this function to be
1920 internal_error (__FILE__
, __LINE__
, _("fbsd_get_sycall_number called"));
1923 /* Read an integer symbol value from the current target. */
1926 fbsd_read_integer_by_name (struct gdbarch
*gdbarch
, const char *name
)
1928 bound_minimal_symbol ms
= lookup_minimal_symbol (name
, NULL
, NULL
);
1929 if (ms
.minsym
== NULL
)
1930 error (_("Unable to resolve symbol '%s'"), name
);
1933 if (target_read_memory (BMSYMBOL_VALUE_ADDRESS (ms
), buf
, sizeof buf
) != 0)
1934 error (_("Unable to read value of '%s'"), name
);
1936 return extract_signed_integer (buf
, sizeof buf
, gdbarch_byte_order (gdbarch
));
1939 /* Lookup offsets of fields in the runtime linker's 'Obj_Entry'
1940 structure needed to determine the TLS index of an object file. */
1943 fbsd_fetch_rtld_offsets (struct gdbarch
*gdbarch
, struct fbsd_pspace_data
*data
)
1947 /* Fetch offsets from debug symbols in rtld. */
1948 struct symbol
*obj_entry_sym
1949 = lookup_symbol_in_language ("Struct_Obj_Entry", NULL
, STRUCT_DOMAIN
,
1950 language_c
, NULL
).symbol
;
1951 if (obj_entry_sym
== NULL
)
1952 error (_("Unable to find Struct_Obj_Entry symbol"));
1953 data
->off_linkmap
= lookup_struct_elt (SYMBOL_TYPE (obj_entry_sym
),
1954 "linkmap", 0).offset
/ 8;
1955 data
->off_tlsindex
= lookup_struct_elt (SYMBOL_TYPE (obj_entry_sym
),
1956 "tlsindex", 0).offset
/ 8;
1957 data
->rtld_offsets_valid
= true;
1960 catch (const gdb_exception_error
&e
)
1962 data
->off_linkmap
= -1;
1967 /* Fetch offsets from global variables in libthr. Note that
1968 this does not work for single-threaded processes that are not
1969 linked against libthr. */
1970 data
->off_linkmap
= fbsd_read_integer_by_name (gdbarch
,
1971 "_thread_off_linkmap");
1972 data
->off_tlsindex
= fbsd_read_integer_by_name (gdbarch
,
1973 "_thread_off_tlsindex");
1974 data
->rtld_offsets_valid
= true;
1977 catch (const gdb_exception_error
&e
)
1979 data
->off_linkmap
= -1;
1983 /* Helper function to read the TLS index of an object file associated
1984 with a link map entry at LM_ADDR. */
1987 fbsd_get_tls_index (struct gdbarch
*gdbarch
, CORE_ADDR lm_addr
)
1989 struct fbsd_pspace_data
*data
= get_fbsd_pspace_data (current_program_space
);
1991 if (!data
->rtld_offsets_valid
)
1992 fbsd_fetch_rtld_offsets (gdbarch
, data
);
1994 if (data
->off_linkmap
== -1)
1995 throw_error (TLS_GENERIC_ERROR
,
1996 _("Cannot fetch runtime linker structure offsets"));
1998 /* Simulate container_of to convert from LM_ADDR to the Obj_Entry
1999 pointer and then compute the offset of the tlsindex member. */
2000 CORE_ADDR tlsindex_addr
= lm_addr
- data
->off_linkmap
+ data
->off_tlsindex
;
2003 if (target_read_memory (tlsindex_addr
, buf
, sizeof buf
) != 0)
2004 throw_error (TLS_GENERIC_ERROR
,
2005 _("Cannot find thread-local variables on this target"));
2007 return extract_signed_integer (buf
, sizeof buf
, gdbarch_byte_order (gdbarch
));
2010 /* See fbsd-tdep.h. */
2013 fbsd_get_thread_local_address (struct gdbarch
*gdbarch
, CORE_ADDR dtv_addr
,
2014 CORE_ADDR lm_addr
, CORE_ADDR offset
)
2016 LONGEST tls_index
= fbsd_get_tls_index (gdbarch
, lm_addr
);
2018 gdb_byte buf
[gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
];
2019 if (target_read_memory (dtv_addr
, buf
, sizeof buf
) != 0)
2020 throw_error (TLS_GENERIC_ERROR
,
2021 _("Cannot find thread-local variables on this target"));
2023 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
2024 CORE_ADDR addr
= gdbarch_pointer_to_address (gdbarch
,
2025 builtin
->builtin_data_ptr
, buf
);
2027 addr
+= (tls_index
+ 1) * TYPE_LENGTH (builtin
->builtin_data_ptr
);
2028 if (target_read_memory (addr
, buf
, sizeof buf
) != 0)
2029 throw_error (TLS_GENERIC_ERROR
,
2030 _("Cannot find thread-local variables on this target"));
2032 addr
= gdbarch_pointer_to_address (gdbarch
, builtin
->builtin_data_ptr
, buf
);
2033 return addr
+ offset
;
2036 /* See fbsd-tdep.h. */
2039 fbsd_skip_solib_resolver (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
2041 struct bound_minimal_symbol msym
= lookup_bound_minimal_symbol ("_rtld_bind");
2042 if (msym
.minsym
!= nullptr && BMSYMBOL_VALUE_ADDRESS (msym
) == pc
)
2043 return frame_unwind_caller_pc (get_current_frame ());
2048 /* Return description of signal code or nullptr. */
2051 fbsd_signal_cause (enum gdb_signal siggnal
, int code
)
2053 /* Signal-independent causes. */
2057 return _("Sent by kill()");
2059 return _("Sent by sigqueue()");
2061 return _("Timer expired");
2062 case FBSD_SI_ASYNCIO
:
2063 return _("Asynchronous I/O request completed");
2065 return _("Message arrived on empty message queue");
2066 case FBSD_SI_KERNEL
:
2067 return _("Sent by kernel");
2069 return _("Sent by thr_kill()");
2074 case GDB_SIGNAL_ILL
:
2077 case FBSD_ILL_ILLOPC
:
2078 return _("Illegal opcode");
2079 case FBSD_ILL_ILLOPN
:
2080 return _("Illegal operand");
2081 case FBSD_ILL_ILLADR
:
2082 return _("Illegal addressing mode");
2083 case FBSD_ILL_ILLTRP
:
2084 return _("Illegal trap");
2085 case FBSD_ILL_PRVOPC
:
2086 return _("Privileged opcode");
2087 case FBSD_ILL_PRVREG
:
2088 return _("Privileged register");
2089 case FBSD_ILL_COPROC
:
2090 return _("Coprocessor error");
2091 case FBSD_ILL_BADSTK
:
2092 return _("Internal stack error");
2095 case GDB_SIGNAL_BUS
:
2098 case FBSD_BUS_ADRALN
:
2099 return _("Invalid address alignment");
2100 case FBSD_BUS_ADRERR
:
2101 return _("Address not present");
2102 case FBSD_BUS_OBJERR
:
2103 return _("Object-specific hardware error");
2104 case FBSD_BUS_OOMERR
:
2105 return _("Out of memory");
2108 case GDB_SIGNAL_SEGV
:
2111 case FBSD_SEGV_MAPERR
:
2112 return _("Address not mapped to object");
2113 case FBSD_SEGV_ACCERR
:
2114 return _("Invalid permissions for mapped object");
2115 case FBSD_SEGV_PKUERR
:
2116 return _("PKU violation");
2119 case GDB_SIGNAL_FPE
:
2122 case FBSD_FPE_INTOVF
:
2123 return _("Integer overflow");
2124 case FBSD_FPE_INTDIV
:
2125 return _("Integer divide by zero");
2126 case FBSD_FPE_FLTDIV
:
2127 return _("Floating point divide by zero");
2128 case FBSD_FPE_FLTOVF
:
2129 return _("Floating point overflow");
2130 case FBSD_FPE_FLTUND
:
2131 return _("Floating point underflow");
2132 case FBSD_FPE_FLTRES
:
2133 return _("Floating point inexact result");
2134 case FBSD_FPE_FLTINV
:
2135 return _("Invalid floating point operation");
2136 case FBSD_FPE_FLTSUB
:
2137 return _("Subscript out of range");
2140 case GDB_SIGNAL_TRAP
:
2143 case FBSD_TRAP_BRKPT
:
2144 return _("Breakpoint");
2145 case FBSD_TRAP_TRACE
:
2146 return _("Trace trap");
2147 case FBSD_TRAP_DTRACE
:
2148 return _("DTrace-induced trap");
2150 return _("Capability violation");
2153 case GDB_SIGNAL_CHLD
:
2156 case FBSD_CLD_EXITED
:
2157 return _("Child has exited");
2158 case FBSD_CLD_KILLED
:
2159 return _("Child has terminated abnormally");
2160 case FBSD_CLD_DUMPED
:
2161 return _("Child has dumped core");
2162 case FBSD_CLD_TRAPPED
:
2163 return _("Traced child has trapped");
2164 case FBSD_CLD_STOPPED
:
2165 return _("Child has stopped");
2166 case FBSD_CLD_CONTINUED
:
2167 return _("Stopped child has continued");
2170 case GDB_SIGNAL_POLL
:
2174 return _("Data input available");
2176 return _("Output buffers available");
2178 return _("Input message available");
2180 return _("I/O error");
2182 return _("High priority input available");
2184 return _("Device disconnected");
2192 /* Report additional details for a signal stop. */
2195 fbsd_report_signal_info (struct gdbarch
*gdbarch
, struct ui_out
*uiout
,
2196 enum gdb_signal siggnal
)
2198 LONGEST code
, mqd
, pid
, status
, timerid
, uid
;
2202 code
= parse_and_eval_long ("$_siginfo.si_code");
2203 pid
= parse_and_eval_long ("$_siginfo.si_pid");
2204 uid
= parse_and_eval_long ("$_siginfo.si_uid");
2205 status
= parse_and_eval_long ("$_siginfo.si_status");
2206 timerid
= parse_and_eval_long ("$_siginfo._reason._timer.si_timerid");
2207 mqd
= parse_and_eval_long ("$_siginfo._reason._mesgq.si_mqd");
2209 catch (const gdb_exception_error
&e
)
2214 const char *meaning
= fbsd_signal_cause (siggnal
, code
);
2215 if (meaning
== nullptr)
2218 uiout
->text (".\n");
2219 uiout
->field_string ("sigcode-meaning", meaning
);
2226 uiout
->text (" from pid ");
2227 uiout
->field_string ("sending-pid", plongest (pid
));
2228 uiout
->text (" and user ");
2229 uiout
->field_string ("sending-uid", plongest (uid
));
2232 uiout
->text (": timerid ");
2233 uiout
->field_string ("timerid", plongest (timerid
));
2236 uiout
->text (": message queue ");
2237 uiout
->field_string ("message-queue", plongest (mqd
));
2239 case FBSD_SI_ASYNCIO
:
2243 if (siggnal
== GDB_SIGNAL_CHLD
)
2245 uiout
->text (": pid ");
2246 uiout
->field_string ("child-pid", plongest (pid
));
2247 uiout
->text (", uid ");
2248 uiout
->field_string ("child-uid", plongest (uid
));
2249 if (code
== FBSD_CLD_EXITED
)
2251 uiout
->text (", exit status ");
2252 uiout
->field_string ("exit-status", plongest (status
));
2256 uiout
->text (", signal ");
2257 uiout
->field_string ("signal", plongest (status
));
2262 /* To be called from GDB_OSABI_FREEBSD handlers. */
2265 fbsd_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
2267 set_gdbarch_core_pid_to_str (gdbarch
, fbsd_core_pid_to_str
);
2268 set_gdbarch_core_thread_name (gdbarch
, fbsd_core_thread_name
);
2269 set_gdbarch_core_xfer_siginfo (gdbarch
, fbsd_core_xfer_siginfo
);
2270 set_gdbarch_make_corefile_notes (gdbarch
, fbsd_make_corefile_notes
);
2271 set_gdbarch_core_info_proc (gdbarch
, fbsd_core_info_proc
);
2272 set_gdbarch_print_auxv_entry (gdbarch
, fbsd_print_auxv_entry
);
2273 set_gdbarch_get_siginfo_type (gdbarch
, fbsd_get_siginfo_type
);
2274 set_gdbarch_gdb_signal_from_target (gdbarch
, fbsd_gdb_signal_from_target
);
2275 set_gdbarch_gdb_signal_to_target (gdbarch
, fbsd_gdb_signal_to_target
);
2276 set_gdbarch_report_signal_info (gdbarch
, fbsd_report_signal_info
);
2277 set_gdbarch_skip_solib_resolver (gdbarch
, fbsd_skip_solib_resolver
);
2279 /* `catch syscall' */
2280 set_xml_syscall_file_name (gdbarch
, "syscalls/freebsd.xml");
2281 set_gdbarch_get_syscall_number (gdbarch
, fbsd_get_syscall_number
);
2284 void _initialize_fbsd_tdep ();
2286 _initialize_fbsd_tdep ()
2288 fbsd_gdbarch_data_handle
=
2289 gdbarch_data_register_post_init (init_fbsd_gdbarch_data
);