1 /* Target-dependent code for FreeBSD, architecture-independent.
3 Copyright (C) 2002-2018 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/>. */
26 #include "gdbthread.h"
27 #include "xml-syscall.h"
28 #include <sys/socket.h>
29 #include <arpa/inet.h>
32 #include "fbsd-tdep.h"
35 /* FreeBSD kernels 12.0 and later include a copy of the
36 'ptrace_lwpinfo' structure returned by the PT_LWPINFO ptrace
37 operation in an ELF core note (NT_FREEBSD_PTLWPINFO) for each LWP.
38 The constants below define the offset of field members and flags in
39 this structure used by methods in this file. Note that the
40 'ptrace_lwpinfo' struct in the note is preceded by a 4 byte integer
41 containing the size of the structure. */
43 #define LWPINFO_OFFSET 0x4
45 /* Offsets in ptrace_lwpinfo. */
46 #define LWPINFO_PL_FLAGS 0x8
47 #define LWPINFO64_PL_SIGINFO 0x30
48 #define LWPINFO32_PL_SIGINFO 0x2c
50 /* Flags in pl_flags. */
51 #define PL_FLAG_SI 0x20 /* siginfo is valid */
53 /* Sizes of siginfo_t. */
54 #define SIZE64_SIGINFO_T 80
55 #define SIZE32_SIGINFO_T 64
57 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_VMMAP core
58 dump notes. See <sys/user.h> for the definition of struct
59 kinfo_vmentry. This data structure should have the same layout on
62 Note that FreeBSD 7.0 used an older version of this structure
63 (struct kinfo_ovmentry), but the NT_FREEBSD_PROCSTAT_VMMAP core
64 dump note wasn't introduced until FreeBSD 9.2. As a result, the
65 core dump note has always used the 7.1 and later structure
68 #define KVE_STRUCTSIZE 0x0
71 #define KVE_OFFSET 0x18
72 #define KVE_FLAGS 0x2c
73 #define KVE_PROTECTION 0x38
76 /* Flags in the 'kve_protection' field in struct kinfo_vmentry. These
77 match the KVME_PROT_* constants in <sys/user.h>. */
79 #define KINFO_VME_PROT_READ 0x00000001
80 #define KINFO_VME_PROT_WRITE 0x00000002
81 #define KINFO_VME_PROT_EXEC 0x00000004
83 /* Flags in the 'kve_flags' field in struct kinfo_vmentry. These
84 match the KVME_FLAG_* constants in <sys/user.h>. */
86 #define KINFO_VME_FLAG_COW 0x00000001
87 #define KINFO_VME_FLAG_NEEDS_COPY 0x00000002
88 #define KINFO_VME_FLAG_NOCOREDUMP 0x00000004
89 #define KINFO_VME_FLAG_SUPER 0x00000008
90 #define KINFO_VME_FLAG_GROWS_UP 0x00000010
91 #define KINFO_VME_FLAG_GROWS_DOWN 0x00000020
93 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_FILES core
94 dump notes. See <sys/user.h> for the definition of struct
95 kinfo_file. This data structure should have the same layout on all
98 Note that FreeBSD 7.0 used an older version of this structure
99 (struct kinfo_ofile), but the NT_FREEBSD_PROCSTAT_FILES core dump
100 note wasn't introduced until FreeBSD 9.2. As a result, the core
101 dump note has always used the 7.1 and later structure format. */
103 #define KF_STRUCTSIZE 0x0
106 #define KF_FLAGS 0x10
107 #define KF_OFFSET 0x18
108 #define KF_VNODE_TYPE 0x20
109 #define KF_SOCK_DOMAIN 0x24
110 #define KF_SOCK_TYPE 0x28
111 #define KF_SOCK_PROTOCOL 0x2c
112 #define KF_SA_LOCAL 0x30
113 #define KF_SA_PEER 0xb0
114 #define KF_PATH 0x170
116 /* Constants for the 'kf_type' field in struct kinfo_file. These
117 match the KF_TYPE_* constants in <sys/user.h>. */
119 #define KINFO_FILE_TYPE_VNODE 1
120 #define KINFO_FILE_TYPE_SOCKET 2
121 #define KINFO_FILE_TYPE_PIPE 3
122 #define KINFO_FILE_TYPE_FIFO 4
123 #define KINFO_FILE_TYPE_KQUEUE 5
124 #define KINFO_FILE_TYPE_CRYPTO 6
125 #define KINFO_FILE_TYPE_MQUEUE 7
126 #define KINFO_FILE_TYPE_SHM 8
127 #define KINFO_FILE_TYPE_SEM 9
128 #define KINFO_FILE_TYPE_PTS 10
129 #define KINFO_FILE_TYPE_PROCDESC 11
131 /* Special values for the 'kf_fd' field in struct kinfo_file. These
132 match the KF_FD_TYPE_* constants in <sys/user.h>. */
134 #define KINFO_FILE_FD_TYPE_CWD -1
135 #define KINFO_FILE_FD_TYPE_ROOT -2
136 #define KINFO_FILE_FD_TYPE_JAIL -3
137 #define KINFO_FILE_FD_TYPE_TRACE -4
138 #define KINFO_FILE_FD_TYPE_TEXT -5
139 #define KINFO_FILE_FD_TYPE_CTTY -6
141 /* Flags in the 'kf_flags' field in struct kinfo_file. These match
142 the KF_FLAG_* constants in <sys/user.h>. */
144 #define KINFO_FILE_FLAG_READ 0x00000001
145 #define KINFO_FILE_FLAG_WRITE 0x00000002
146 #define KINFO_FILE_FLAG_APPEND 0x00000004
147 #define KINFO_FILE_FLAG_ASYNC 0x00000008
148 #define KINFO_FILE_FLAG_FSYNC 0x00000010
149 #define KINFO_FILE_FLAG_NONBLOCK 0x00000020
150 #define KINFO_FILE_FLAG_DIRECT 0x00000040
151 #define KINFO_FILE_FLAG_HASLOCK 0x00000080
152 #define KINFO_FILE_FLAG_EXEC 0x00004000
154 /* Constants for the 'kf_vnode_type' field in struct kinfo_file.
155 These match the KF_VTYPE_* constants in <sys/user.h>. */
157 #define KINFO_FILE_VTYPE_VREG 1
158 #define KINFO_FILE_VTYPE_VDIR 2
159 #define KINFO_FILE_VTYPE_VCHR 4
160 #define KINFO_FILE_VTYPE_VLNK 5
161 #define KINFO_FILE_VTYPE_VSOCK 6
162 #define KINFO_FILE_VTYPE_VFIFO 7
164 /* Constants for socket address families. These match AF_* constants
165 in <sys/socket.h>. */
167 #define FBSD_AF_UNIX 1
168 #define FBSD_AF_INET 2
169 #define FBSD_AF_INET6 28
171 /* Constants for socket types. These match SOCK_* constants in
174 #define FBSD_SOCK_STREAM 1
175 #define FBSD_SOCK_DGRAM 2
176 #define FBSD_SOCK_SEQPACKET 5
178 /* Constants for IP protocols. These match IPPROTO_* constants in
181 #define FBSD_IPPROTO_ICMP 1
182 #define FBSD_IPPROTO_TCP 6
183 #define FBSD_IPPROTO_UDP 17
184 #define FBSD_IPPROTO_SCTP 132
186 /* Socket address structures. These have the same layout on all
187 FreeBSD architectures. In addition, multibyte fields such as IP
188 addresses are always stored in network byte order. */
190 struct fbsd_sockaddr_in
199 struct fbsd_sockaddr_in6
203 uint8_t sin6_port[2];
204 uint32_t sin6_flowinfo;
205 uint8_t sin6_addr[16];
206 uint32_t sin6_scope_id;
209 struct fbsd_sockaddr_un
216 /* Number of 32-bit words in a signal set. This matches _SIG_WORDS in
217 <sys/_sigset.h> and is the same value on all architectures. */
221 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_PROC core
222 dump notes. See <sys/user.h> for the definition of struct
223 kinfo_proc. This data structure has different layouts on different
224 architectures mostly due to ILP32 vs LP64. However, FreeBSD/i386
225 uses a 32-bit time_t while all other architectures use a 64-bit
228 The core dump note actually contains one kinfo_proc structure for
229 each thread, but all of the process-wide data can be obtained from
230 the first structure. One result of this note's format is that some
231 of the process-wide status available in the native target method
232 from the kern.proc.pid.<pid> sysctl such as ki_stat and ki_siglist
233 is not available from a core dump. Instead, the per-thread data
234 structures contain the value of these fields for individual
237 struct kinfo_proc_layout
239 /* Offsets of struct kinfo_proc members. */
246 int ki_tdev_freebsd11;
268 /* Offsets of struct rusage members. */
276 const struct kinfo_proc_layout kinfo_proc_layout_32 =
284 .ki_tdev_freebsd11 = 0x44,
285 .ki_sigignore = 0x68,
304 .ki_rusage_ch = 0x278,
313 const struct kinfo_proc_layout kinfo_proc_layout_i386 =
321 .ki_tdev_freebsd11 = 0x44,
322 .ki_sigignore = 0x68,
341 .ki_rusage_ch = 0x258,
350 const struct kinfo_proc_layout kinfo_proc_layout_64 =
358 .ki_tdev_freebsd11 = 0x64,
359 .ki_sigignore = 0x88,
378 .ki_rusage_ch = 0x2f0,
387 static struct gdbarch_data *fbsd_gdbarch_data_handle;
389 struct fbsd_gdbarch_data
391 struct type *siginfo_type;
395 init_fbsd_gdbarch_data (struct gdbarch *gdbarch)
397 return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct fbsd_gdbarch_data);
400 static struct fbsd_gdbarch_data *
401 get_fbsd_gdbarch_data (struct gdbarch *gdbarch)
403 return ((struct fbsd_gdbarch_data *)
404 gdbarch_data (gdbarch, fbsd_gdbarch_data_handle));
407 /* This is how we want PTIDs from core files to be printed. */
410 fbsd_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
414 if (ptid.lwp () != 0)
416 xsnprintf (buf, sizeof buf, "LWP %ld", ptid.lwp ());
420 return normal_pid_to_str (ptid);
423 /* Extract the name assigned to a thread from a core. Returns the
424 string in a static buffer. */
427 fbsd_core_thread_name (struct gdbarch *gdbarch, struct thread_info *thr)
430 struct bfd_section *section;
433 if (thr->ptid.lwp () != 0)
435 /* FreeBSD includes a NT_FREEBSD_THRMISC note for each thread
436 whose contents are defined by a "struct thrmisc" declared in
437 <sys/procfs.h> on FreeBSD. The per-thread name is stored as
438 a null-terminated string as the first member of the
439 structure. Rather than define the full structure here, just
440 extract the null-terminated name from the start of the
442 thread_section_name section_name (".thrmisc", thr->ptid);
444 section = bfd_get_section_by_name (core_bfd, section_name.c_str ());
445 if (section != NULL && bfd_section_size (core_bfd, section) > 0)
447 /* Truncate the name if it is longer than "buf". */
448 size = bfd_section_size (core_bfd, section);
449 if (size > sizeof buf - 1)
450 size = sizeof buf - 1;
451 if (bfd_get_section_contents (core_bfd, section, buf, (file_ptr) 0,
457 /* Note that each thread will report the process command
458 as its thread name instead of an empty name if a name
459 has not been set explicitly. Return a NULL name in
461 if (strcmp (buf, elf_tdata (core_bfd)->core->program) != 0)
470 /* Implement the "core_xfer_siginfo" gdbarch method. */
473 fbsd_core_xfer_siginfo (struct gdbarch *gdbarch, gdb_byte *readbuf,
474 ULONGEST offset, ULONGEST len)
478 if (gdbarch_long_bit (gdbarch) == 32)
479 siginfo_size = SIZE32_SIGINFO_T;
481 siginfo_size = SIZE64_SIGINFO_T;
482 if (offset > siginfo_size)
485 thread_section_name section_name (".note.freebsdcore.lwpinfo", inferior_ptid);
486 asection *section = bfd_get_section_by_name (core_bfd, section_name.c_str ());
491 if (!bfd_get_section_contents (core_bfd, section, buf,
492 LWPINFO_OFFSET + LWPINFO_PL_FLAGS, 4))
495 int pl_flags = extract_signed_integer (buf, 4, gdbarch_byte_order (gdbarch));
496 if (!(pl_flags & PL_FLAG_SI))
499 if (offset + len > siginfo_size)
500 len = siginfo_size - offset;
502 ULONGEST siginfo_offset;
503 if (gdbarch_long_bit (gdbarch) == 32)
504 siginfo_offset = LWPINFO_OFFSET + LWPINFO32_PL_SIGINFO;
506 siginfo_offset = LWPINFO_OFFSET + LWPINFO64_PL_SIGINFO;
508 if (!bfd_get_section_contents (core_bfd, section, readbuf,
509 siginfo_offset + offset, len))
516 find_signalled_thread (struct thread_info *info, void *data)
518 if (info->suspend.stop_signal != GDB_SIGNAL_0
519 && info->ptid.pid () == inferior_ptid.pid ())
525 /* Structure for passing information from
526 fbsd_collect_thread_registers via an iterator to
527 fbsd_collect_regset_section_cb. */
529 struct fbsd_collect_regset_section_cb_data
531 const struct regcache *regcache;
536 enum gdb_signal stop_signal;
541 fbsd_collect_regset_section_cb (const char *sect_name, int supply_size,
542 int collect_size, const struct regset *regset,
543 const char *human_name, void *cb_data)
546 struct fbsd_collect_regset_section_cb_data *data
547 = (struct fbsd_collect_regset_section_cb_data *) cb_data;
549 if (data->abort_iteration)
552 gdb_assert (regset->collect_regset);
554 buf = (char *) xmalloc (collect_size);
555 regset->collect_regset (regset, data->regcache, -1, buf, collect_size);
557 /* PRSTATUS still needs to be treated specially. */
558 if (strcmp (sect_name, ".reg") == 0)
559 data->note_data = (char *) elfcore_write_prstatus
560 (data->obfd, data->note_data, data->note_size, data->lwp,
561 gdb_signal_to_host (data->stop_signal), buf);
563 data->note_data = (char *) elfcore_write_register_note
564 (data->obfd, data->note_data, data->note_size,
565 sect_name, buf, collect_size);
568 if (data->note_data == NULL)
569 data->abort_iteration = 1;
572 /* Records the thread's register state for the corefile note
576 fbsd_collect_thread_registers (const struct regcache *regcache,
577 ptid_t ptid, bfd *obfd,
578 char *note_data, int *note_size,
579 enum gdb_signal stop_signal)
581 struct gdbarch *gdbarch = regcache->arch ();
582 struct fbsd_collect_regset_section_cb_data data;
584 data.regcache = regcache;
586 data.note_data = note_data;
587 data.note_size = note_size;
588 data.stop_signal = stop_signal;
589 data.abort_iteration = 0;
590 data.lwp = ptid.lwp ();
592 gdbarch_iterate_over_regset_sections (gdbarch,
593 fbsd_collect_regset_section_cb,
595 return data.note_data;
598 struct fbsd_corefile_thread_data
600 struct gdbarch *gdbarch;
604 enum gdb_signal stop_signal;
607 /* Records the thread's register state for the corefile note
611 fbsd_corefile_thread (struct thread_info *info,
612 struct fbsd_corefile_thread_data *args)
614 struct regcache *regcache;
616 regcache = get_thread_arch_regcache (info->ptid, args->gdbarch);
618 target_fetch_registers (regcache, -1);
620 args->note_data = fbsd_collect_thread_registers
621 (regcache, info->ptid, args->obfd, args->note_data,
622 args->note_size, args->stop_signal);
625 /* Return a byte_vector containing the contents of a core dump note
626 for the target object of type OBJECT. If STRUCTSIZE is non-zero,
627 the data is prefixed with a 32-bit integer size to match the format
628 used in FreeBSD NT_PROCSTAT_* notes. */
630 static gdb::optional<gdb::byte_vector>
631 fbsd_make_note_desc (enum target_object object, uint32_t structsize)
633 gdb::optional<gdb::byte_vector> buf =
634 target_read_alloc (current_top_target (), object, NULL);
635 if (!buf || buf->empty ())
641 gdb::byte_vector desc (sizeof (structsize) + buf->size ());
642 memcpy (desc.data (), &structsize, sizeof (structsize));
643 memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ());
647 /* Create appropriate note sections for a corefile, returning them in
651 fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
653 struct fbsd_corefile_thread_data thread_args;
654 char *note_data = NULL;
655 Elf_Internal_Ehdr *i_ehdrp;
656 struct thread_info *curr_thr, *signalled_thr, *thr;
658 /* Put a "FreeBSD" label in the ELF header. */
659 i_ehdrp = elf_elfheader (obfd);
660 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
662 gdb_assert (gdbarch_iterate_over_regset_sections_p (gdbarch));
664 if (get_exec_file (0))
666 const char *fname = lbasename (get_exec_file (0));
667 char *psargs = xstrdup (fname);
669 if (get_inferior_args ())
670 psargs = reconcat (psargs, psargs, " ", get_inferior_args (),
673 note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
677 /* Thread register information. */
680 update_thread_list ();
682 CATCH (e, RETURN_MASK_ERROR)
684 exception_print (gdb_stderr, e);
688 /* Like the kernel, prefer dumping the signalled thread first.
689 "First thread" is what tools use to infer the signalled thread.
690 In case there's more than one signalled thread, prefer the
691 current thread, if it is signalled. */
692 curr_thr = inferior_thread ();
693 if (curr_thr->suspend.stop_signal != GDB_SIGNAL_0)
694 signalled_thr = curr_thr;
697 signalled_thr = iterate_over_threads (find_signalled_thread, NULL);
698 if (signalled_thr == NULL)
699 signalled_thr = curr_thr;
702 thread_args.gdbarch = gdbarch;
703 thread_args.obfd = obfd;
704 thread_args.note_data = note_data;
705 thread_args.note_size = note_size;
706 thread_args.stop_signal = signalled_thr->suspend.stop_signal;
708 fbsd_corefile_thread (signalled_thr, &thread_args);
709 ALL_NON_EXITED_THREADS (thr)
711 if (thr == signalled_thr)
713 if (thr->ptid.pid () != inferior_ptid.pid ())
716 fbsd_corefile_thread (thr, &thread_args);
719 note_data = thread_args.note_data;
721 /* Auxiliary vector. */
722 uint32_t structsize = gdbarch_ptr_bit (gdbarch) / 4; /* Elf_Auxinfo */
723 gdb::optional<gdb::byte_vector> note_desc =
724 fbsd_make_note_desc (TARGET_OBJECT_AUXV, structsize);
725 if (note_desc && !note_desc->empty ())
727 note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
728 NT_FREEBSD_PROCSTAT_AUXV,
729 note_desc->data (), note_desc->size ());
734 /* Virtual memory mappings. */
735 note_desc = fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_VMMAP, 0);
736 if (note_desc && !note_desc->empty ())
738 note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
739 NT_FREEBSD_PROCSTAT_VMMAP,
740 note_desc->data (), note_desc->size ());
745 note_desc = fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_PS_STRINGS, 0);
746 if (note_desc && !note_desc->empty ())
748 note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
749 NT_FREEBSD_PROCSTAT_PSSTRINGS,
750 note_desc->data (), note_desc->size ());
758 /* Helper function to generate the file descriptor description for a
759 single open file in 'info proc files'. */
762 fbsd_file_fd (int kf_fd)
766 case KINFO_FILE_FD_TYPE_CWD:
768 case KINFO_FILE_FD_TYPE_ROOT:
770 case KINFO_FILE_FD_TYPE_JAIL:
772 case KINFO_FILE_FD_TYPE_TRACE:
774 case KINFO_FILE_FD_TYPE_TEXT:
776 case KINFO_FILE_FD_TYPE_CTTY:
779 return int_string (kf_fd, 10, 1, 0, 0);
783 /* Helper function to generate the file type for a single open file in
784 'info proc files'. */
787 fbsd_file_type (int kf_type, int kf_vnode_type)
791 case KINFO_FILE_TYPE_VNODE:
792 switch (kf_vnode_type)
794 case KINFO_FILE_VTYPE_VREG:
796 case KINFO_FILE_VTYPE_VDIR:
798 case KINFO_FILE_VTYPE_VCHR:
800 case KINFO_FILE_VTYPE_VLNK:
802 case KINFO_FILE_VTYPE_VSOCK:
804 case KINFO_FILE_VTYPE_VFIFO:
808 char *str = get_print_cell ();
810 xsnprintf (str, PRINT_CELL_SIZE, "vn:%d", kf_vnode_type);
814 case KINFO_FILE_TYPE_SOCKET:
816 case KINFO_FILE_TYPE_PIPE:
818 case KINFO_FILE_TYPE_FIFO:
820 case KINFO_FILE_TYPE_KQUEUE:
822 case KINFO_FILE_TYPE_CRYPTO:
824 case KINFO_FILE_TYPE_MQUEUE:
826 case KINFO_FILE_TYPE_SHM:
828 case KINFO_FILE_TYPE_SEM:
830 case KINFO_FILE_TYPE_PTS:
832 case KINFO_FILE_TYPE_PROCDESC:
835 return int_string (kf_type, 10, 1, 0, 0);
839 /* Helper function to generate the file flags for a single open file in
840 'info proc files'. */
843 fbsd_file_flags (int kf_flags)
845 static char file_flags[10];
847 file_flags[0] = (kf_flags & KINFO_FILE_FLAG_READ) ? 'r' : '-';
848 file_flags[1] = (kf_flags & KINFO_FILE_FLAG_WRITE) ? 'w' : '-';
849 file_flags[2] = (kf_flags & KINFO_FILE_FLAG_EXEC) ? 'x' : '-';
850 file_flags[3] = (kf_flags & KINFO_FILE_FLAG_APPEND) ? 'a' : '-';
851 file_flags[4] = (kf_flags & KINFO_FILE_FLAG_ASYNC) ? 's' : '-';
852 file_flags[5] = (kf_flags & KINFO_FILE_FLAG_FSYNC) ? 'f' : '-';
853 file_flags[6] = (kf_flags & KINFO_FILE_FLAG_NONBLOCK) ? 'n' : '-';
854 file_flags[7] = (kf_flags & KINFO_FILE_FLAG_DIRECT) ? 'd' : '-';
855 file_flags[8] = (kf_flags & KINFO_FILE_FLAG_HASLOCK) ? 'l' : '-';
856 file_flags[9] = '\0';
861 /* Helper function to generate the name of an IP protocol. */
864 fbsd_ipproto (int protocol)
868 case FBSD_IPPROTO_ICMP:
870 case FBSD_IPPROTO_TCP:
872 case FBSD_IPPROTO_UDP:
874 case FBSD_IPPROTO_SCTP:
878 char *str = get_print_cell ();
880 xsnprintf (str, PRINT_CELL_SIZE, "ip<%d>", protocol);
886 /* Helper function to print out an IPv4 socket address. */
889 fbsd_print_sockaddr_in (const void *sockaddr)
891 const struct fbsd_sockaddr_in *sin =
892 reinterpret_cast<const struct fbsd_sockaddr_in *> (sockaddr);
893 char buf[INET_ADDRSTRLEN];
895 if (inet_ntop(AF_INET, sin->sin_addr, buf, sizeof buf) == nullptr)
896 error (_("Failed to format IPv4 address"));
897 printf_filtered ("%s:%u", buf,
898 (sin->sin_port[0] << 8) | sin->sin_port[1]);
901 /* Helper function to print out an IPv6 socket address. */
904 fbsd_print_sockaddr_in6 (const void *sockaddr)
906 const struct fbsd_sockaddr_in6 *sin6 =
907 reinterpret_cast<const struct fbsd_sockaddr_in6 *> (sockaddr);
908 char buf[INET6_ADDRSTRLEN];
910 if (inet_ntop(AF_INET6, sin6->sin6_addr, buf, sizeof buf) == nullptr)
911 error (_("Failed to format IPv6 address"));
912 printf_filtered ("%s.%u", buf,
913 (sin6->sin6_port[0] << 8) | sin6->sin6_port[1]);
916 /* See fbsd-tdep.h. */
919 fbsd_info_proc_files_header ()
921 printf_filtered (_("Open files:\n\n"));
922 printf_filtered (" %6s %6s %10s %9s %s\n",
923 "FD", "Type", "Offset", "Flags ", "Name");
926 /* See fbsd-tdep.h. */
929 fbsd_info_proc_files_entry (int kf_type, int kf_fd, int kf_flags,
930 LONGEST kf_offset, int kf_vnode_type,
931 int kf_sock_domain, int kf_sock_type,
932 int kf_sock_protocol, const void *kf_sa_local,
933 const void *kf_sa_peer, const void *kf_path)
935 printf_filtered (" %6s %6s %10s %8s ",
936 fbsd_file_fd (kf_fd),
937 fbsd_file_type (kf_type, kf_vnode_type),
938 kf_offset > -1 ? hex_string (kf_offset) : "-",
939 fbsd_file_flags (kf_flags));
940 if (kf_type == KINFO_FILE_TYPE_SOCKET)
942 switch (kf_sock_domain)
946 switch (kf_sock_type)
948 case FBSD_SOCK_STREAM:
949 printf_filtered ("unix stream:");
951 case FBSD_SOCK_DGRAM:
952 printf_filtered ("unix dgram:");
954 case FBSD_SOCK_SEQPACKET:
955 printf_filtered ("unix seqpacket:");
958 printf_filtered ("unix <%d>:", kf_sock_type);
962 /* For local sockets, print out the first non-nul path
963 rather than both paths. */
964 const struct fbsd_sockaddr_un *sun
965 = reinterpret_cast<const struct fbsd_sockaddr_un *> (kf_sa_local);
966 if (sun->sun_path[0] == 0)
967 sun = reinterpret_cast<const struct fbsd_sockaddr_un *>
969 printf_filtered ("%s", sun->sun_path);
973 printf_filtered ("%s4 ", fbsd_ipproto (kf_sock_protocol));
974 fbsd_print_sockaddr_in (kf_sa_local);
975 printf_filtered (" -> ");
976 fbsd_print_sockaddr_in (kf_sa_peer);
979 printf_filtered ("%s6 ", fbsd_ipproto (kf_sock_protocol));
980 fbsd_print_sockaddr_in6 (kf_sa_local);
981 printf_filtered (" -> ");
982 fbsd_print_sockaddr_in6 (kf_sa_peer);
987 printf_filtered ("%s", reinterpret_cast<const char *> (kf_path));
988 printf_filtered ("\n");
991 /* Implement "info proc files" for a corefile. */
994 fbsd_core_info_proc_files (struct gdbarch *gdbarch)
997 = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files");
1000 warning (_("unable to find open files in core file"));
1004 size_t note_size = bfd_get_section_size (section);
1006 error (_("malformed core note - too short for header"));
1008 gdb::def_vector<unsigned char> contents (note_size);
1009 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
1011 error (_("could not get core note contents"));
1013 unsigned char *descdata = contents.data ();
1014 unsigned char *descend = descdata + note_size;
1016 /* Skip over the structure size. */
1019 fbsd_info_proc_files_header ();
1021 while (descdata + KF_PATH < descend)
1023 ULONGEST structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE);
1024 if (structsize < KF_PATH)
1025 error (_("malformed core note - file structure too small"));
1027 LONGEST type = bfd_get_signed_32 (core_bfd, descdata + KF_TYPE);
1028 LONGEST fd = bfd_get_signed_32 (core_bfd, descdata + KF_FD);
1029 LONGEST flags = bfd_get_signed_32 (core_bfd, descdata + KF_FLAGS);
1030 LONGEST offset = bfd_get_signed_64 (core_bfd, descdata + KF_OFFSET);
1031 LONGEST vnode_type = bfd_get_signed_32 (core_bfd,
1032 descdata + KF_VNODE_TYPE);
1033 LONGEST sock_domain = bfd_get_signed_32 (core_bfd,
1034 descdata + KF_SOCK_DOMAIN);
1035 LONGEST sock_type = bfd_get_signed_32 (core_bfd, descdata + KF_SOCK_TYPE);
1036 LONGEST sock_protocol = bfd_get_signed_32 (core_bfd,
1037 descdata + KF_SOCK_PROTOCOL);
1038 fbsd_info_proc_files_entry (type, fd, flags, offset, vnode_type,
1039 sock_domain, sock_type, sock_protocol,
1040 descdata + KF_SA_LOCAL, descdata + KF_SA_PEER,
1041 descdata + KF_PATH);
1043 descdata += structsize;
1047 /* Helper function to generate mappings flags for a single VM map
1048 entry in 'info proc mappings'. */
1051 fbsd_vm_map_entry_flags (int kve_flags, int kve_protection)
1053 static char vm_flags[9];
1055 vm_flags[0] = (kve_protection & KINFO_VME_PROT_READ) ? 'r' : '-';
1056 vm_flags[1] = (kve_protection & KINFO_VME_PROT_WRITE) ? 'w' : '-';
1057 vm_flags[2] = (kve_protection & KINFO_VME_PROT_EXEC) ? 'x' : '-';
1059 vm_flags[4] = (kve_flags & KINFO_VME_FLAG_COW) ? 'C' : '-';
1060 vm_flags[5] = (kve_flags & KINFO_VME_FLAG_NEEDS_COPY) ? 'N' : '-';
1061 vm_flags[6] = (kve_flags & KINFO_VME_FLAG_SUPER) ? 'S' : '-';
1062 vm_flags[7] = (kve_flags & KINFO_VME_FLAG_GROWS_UP) ? 'U'
1063 : (kve_flags & KINFO_VME_FLAG_GROWS_DOWN) ? 'D' : '-';
1069 /* Implement "info proc mappings" for a corefile. */
1072 fbsd_core_info_proc_mappings (struct gdbarch *gdbarch)
1075 unsigned char *descdata, *descend;
1078 section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.vmmap");
1079 if (section == NULL)
1081 warning (_("unable to find mappings in core file"));
1085 note_size = bfd_get_section_size (section);
1087 error (_("malformed core note - too short for header"));
1089 gdb::def_vector<unsigned char> contents (note_size);
1090 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
1092 error (_("could not get core note contents"));
1094 descdata = contents.data ();
1095 descend = descdata + note_size;
1097 /* Skip over the structure size. */
1100 printf_filtered (_("Mapped address spaces:\n\n"));
1101 if (gdbarch_addr_bit (gdbarch) == 64)
1103 printf_filtered (" %18s %18s %10s %10s %9s %s\n",
1106 " Size", " Offset", "Flags ", "File");
1110 printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
1113 " Size", " Offset", "Flags ", "File");
1116 while (descdata + KVE_PATH < descend)
1118 ULONGEST start, end, offset, flags, prot, structsize;
1120 structsize = bfd_get_32 (core_bfd, descdata + KVE_STRUCTSIZE);
1121 if (structsize < KVE_PATH)
1122 error (_("malformed core note - vmmap entry too small"));
1124 start = bfd_get_64 (core_bfd, descdata + KVE_START);
1125 end = bfd_get_64 (core_bfd, descdata + KVE_END);
1126 offset = bfd_get_64 (core_bfd, descdata + KVE_OFFSET);
1127 flags = bfd_get_32 (core_bfd, descdata + KVE_FLAGS);
1128 prot = bfd_get_32 (core_bfd, descdata + KVE_PROTECTION);
1129 if (gdbarch_addr_bit (gdbarch) == 64)
1131 printf_filtered (" %18s %18s %10s %10s %9s %s\n",
1132 paddress (gdbarch, start),
1133 paddress (gdbarch, end),
1134 hex_string (end - start),
1135 hex_string (offset),
1136 fbsd_vm_map_entry_flags (flags, prot),
1137 descdata + KVE_PATH);
1141 printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
1142 paddress (gdbarch, start),
1143 paddress (gdbarch, end),
1144 hex_string (end - start),
1145 hex_string (offset),
1146 fbsd_vm_map_entry_flags (flags, prot),
1147 descdata + KVE_PATH);
1150 descdata += structsize;
1154 /* Fetch the pathname of a vnode for a single file descriptor from the
1155 file table core note. */
1157 static gdb::unique_xmalloc_ptr<char>
1158 fbsd_core_vnode_path (struct gdbarch *gdbarch, int fd)
1161 unsigned char *descdata, *descend;
1164 section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files");
1165 if (section == NULL)
1168 note_size = bfd_get_section_size (section);
1170 error (_("malformed core note - too short for header"));
1172 gdb::def_vector<unsigned char> contents (note_size);
1173 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
1175 error (_("could not get core note contents"));
1177 descdata = contents.data ();
1178 descend = descdata + note_size;
1180 /* Skip over the structure size. */
1183 while (descdata + KF_PATH < descend)
1185 ULONGEST structsize;
1187 structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE);
1188 if (structsize < KF_PATH)
1189 error (_("malformed core note - file structure too small"));
1191 if (bfd_get_32 (core_bfd, descdata + KF_TYPE) == KINFO_FILE_TYPE_VNODE
1192 && bfd_get_signed_32 (core_bfd, descdata + KF_FD) == fd)
1194 char *path = (char *) descdata + KF_PATH;
1195 return gdb::unique_xmalloc_ptr<char> (xstrdup (path));
1198 descdata += structsize;
1203 /* Helper function to read a struct timeval. */
1206 fbsd_core_fetch_timeval (struct gdbarch *gdbarch, unsigned char *data,
1207 LONGEST &sec, ULONGEST &usec)
1209 if (gdbarch_addr_bit (gdbarch) == 64)
1211 sec = bfd_get_signed_64 (core_bfd, data);
1212 usec = bfd_get_64 (core_bfd, data + 8);
1214 else if (bfd_get_arch (core_bfd) == bfd_arch_i386)
1216 sec = bfd_get_signed_32 (core_bfd, data);
1217 usec = bfd_get_32 (core_bfd, data + 4);
1221 sec = bfd_get_signed_64 (core_bfd, data);
1222 usec = bfd_get_32 (core_bfd, data + 8);
1226 /* Print out the contents of a signal set. */
1229 fbsd_print_sigset (const char *descr, unsigned char *sigset)
1231 printf_filtered ("%s: ", descr);
1232 for (int i = 0; i < SIG_WORDS; i++)
1233 printf_filtered ("%08x ",
1234 (unsigned int) bfd_get_32 (core_bfd, sigset + i * 4));
1235 printf_filtered ("\n");
1238 /* Implement "info proc status" for a corefile. */
1241 fbsd_core_info_proc_status (struct gdbarch *gdbarch)
1243 const struct kinfo_proc_layout *kp;
1245 unsigned char *descdata;
1246 int addr_bit, long_bit;
1251 section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.proc");
1252 if (section == NULL)
1254 warning (_("unable to find process info in core file"));
1258 addr_bit = gdbarch_addr_bit (gdbarch);
1260 kp = &kinfo_proc_layout_64;
1261 else if (bfd_get_arch (core_bfd) == bfd_arch_i386)
1262 kp = &kinfo_proc_layout_i386;
1264 kp = &kinfo_proc_layout_32;
1265 long_bit = gdbarch_long_bit (gdbarch);
1268 * Ensure that the note is large enough for all of the fields fetched
1269 * by this function. In particular, the note must contain the 32-bit
1270 * structure size, then it must be long enough to access the last
1271 * field used (ki_rusage_ch.ru_majflt) which is the size of a long.
1273 note_size = bfd_get_section_size (section);
1274 if (note_size < (4 + kp->ki_rusage_ch + kp->ru_majflt
1275 + long_bit / TARGET_CHAR_BIT))
1276 error (_("malformed core note - too short"));
1278 gdb::def_vector<unsigned char> contents (note_size);
1279 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
1281 error (_("could not get core note contents"));
1283 descdata = contents.data ();
1285 /* Skip over the structure size. */
1288 /* Verify 'ki_layout' is 0. */
1289 if (bfd_get_32 (core_bfd, descdata + kp->ki_layout) != 0)
1291 warning (_("unsupported process information in core file"));
1295 printf_filtered ("Name: %.19s\n", descdata + kp->ki_comm);
1296 printf_filtered ("Process ID: %s\n",
1297 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pid)));
1298 printf_filtered ("Parent process: %s\n",
1299 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ppid)));
1300 printf_filtered ("Process group: %s\n",
1301 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pgid)));
1302 printf_filtered ("Session id: %s\n",
1303 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_sid)));
1305 /* FreeBSD 12.0 and later store a 64-bit dev_t at 'ki_tdev'. Older
1306 kernels store a 32-bit dev_t at 'ki_tdev_freebsd11'. In older
1307 kernels the 64-bit 'ki_tdev' field is in a reserved section of
1308 the structure that is cleared to zero. Assume that a zero value
1309 in ki_tdev indicates a core dump from an older kernel and use the
1310 value in 'ki_tdev_freebsd11' instead. */
1311 value = bfd_get_64 (core_bfd, descdata + kp->ki_tdev);
1313 value = bfd_get_32 (core_bfd, descdata + kp->ki_tdev_freebsd11);
1314 printf_filtered ("TTY: %s\n", pulongest (value));
1315 printf_filtered ("TTY owner process group: %s\n",
1316 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_tpgid)));
1317 printf_filtered ("User IDs (real, effective, saved): %s %s %s\n",
1318 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ruid)),
1319 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_uid)),
1320 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svuid)));
1321 printf_filtered ("Group IDs (real, effective, saved): %s %s %s\n",
1322 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_rgid)),
1323 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_groups)),
1324 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svgid)));
1325 printf_filtered ("Groups: ");
1326 uint16_t ngroups = bfd_get_16 (core_bfd, descdata + kp->ki_ngroups);
1327 for (int i = 0; i < ngroups; i++)
1328 printf_filtered ("%s ",
1329 pulongest (bfd_get_32 (core_bfd,
1330 descdata + kp->ki_groups + i * 4)));
1331 printf_filtered ("\n");
1332 value = bfd_get (long_bit, core_bfd,
1333 descdata + kp->ki_rusage + kp->ru_minflt);
1334 printf_filtered ("Minor faults (no memory page): %s\n", pulongest (value));
1335 value = bfd_get (long_bit, core_bfd,
1336 descdata + kp->ki_rusage_ch + kp->ru_minflt);
1337 printf_filtered ("Minor faults, children: %s\n", pulongest (value));
1338 value = bfd_get (long_bit, core_bfd,
1339 descdata + kp->ki_rusage + kp->ru_majflt);
1340 printf_filtered ("Major faults (memory page faults): %s\n",
1342 value = bfd_get (long_bit, core_bfd,
1343 descdata + kp->ki_rusage_ch + kp->ru_majflt);
1344 printf_filtered ("Major faults, children: %s\n", pulongest (value));
1345 fbsd_core_fetch_timeval (gdbarch,
1346 descdata + kp->ki_rusage + kp->ru_utime,
1348 printf_filtered ("utime: %s.%06d\n", plongest (sec), (int) value);
1349 fbsd_core_fetch_timeval (gdbarch,
1350 descdata + kp->ki_rusage + kp->ru_stime,
1352 printf_filtered ("stime: %s.%06d\n", plongest (sec), (int) value);
1353 fbsd_core_fetch_timeval (gdbarch,
1354 descdata + kp->ki_rusage_ch + kp->ru_utime,
1356 printf_filtered ("utime, children: %s.%06d\n", plongest (sec), (int) value);
1357 fbsd_core_fetch_timeval (gdbarch,
1358 descdata + kp->ki_rusage_ch + kp->ru_stime,
1360 printf_filtered ("stime, children: %s.%06d\n", plongest (sec), (int) value);
1361 printf_filtered ("'nice' value: %d\n",
1362 bfd_get_signed_8 (core_bfd, descdata + kp->ki_nice));
1363 fbsd_core_fetch_timeval (gdbarch, descdata + kp->ki_start, sec, value);
1364 printf_filtered ("Start time: %s.%06d\n", plongest (sec), (int) value);
1365 printf_filtered ("Virtual memory size: %s kB\n",
1366 pulongest (bfd_get (addr_bit, core_bfd,
1367 descdata + kp->ki_size) / 1024));
1368 printf_filtered ("Data size: %s pages\n",
1369 pulongest (bfd_get (addr_bit, core_bfd,
1370 descdata + kp->ki_dsize)));
1371 printf_filtered ("Stack size: %s pages\n",
1372 pulongest (bfd_get (addr_bit, core_bfd,
1373 descdata + kp->ki_ssize)));
1374 printf_filtered ("Text size: %s pages\n",
1375 pulongest (bfd_get (addr_bit, core_bfd,
1376 descdata + kp->ki_tsize)));
1377 printf_filtered ("Resident set size: %s pages\n",
1378 pulongest (bfd_get (addr_bit, core_bfd,
1379 descdata + kp->ki_rssize)));
1380 printf_filtered ("Maximum RSS: %s pages\n",
1381 pulongest (bfd_get (long_bit, core_bfd,
1382 descdata + kp->ki_rusage
1384 fbsd_print_sigset ("Ignored Signals", descdata + kp->ki_sigignore);
1385 fbsd_print_sigset ("Caught Signals", descdata + kp->ki_sigcatch);
1388 /* Implement the "core_info_proc" gdbarch method. */
1391 fbsd_core_info_proc (struct gdbarch *gdbarch, const char *args,
1392 enum info_proc_what what)
1394 bool do_cmdline = false;
1395 bool do_cwd = false;
1396 bool do_exe = false;
1397 bool do_files = false;
1398 bool do_mappings = false;
1399 bool do_status = false;
1440 pid = bfd_core_file_pid (core_bfd);
1442 printf_filtered (_("process %d\n"), pid);
1446 const char *cmdline;
1448 cmdline = bfd_core_file_failing_command (core_bfd);
1450 printf_filtered ("cmdline = '%s'\n", cmdline);
1452 warning (_("Command line unavailable"));
1456 gdb::unique_xmalloc_ptr<char> cwd =
1457 fbsd_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_CWD);
1459 printf_filtered ("cwd = '%s'\n", cwd.get ());
1461 warning (_("unable to read current working directory"));
1465 gdb::unique_xmalloc_ptr<char> exe =
1466 fbsd_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_TEXT);
1468 printf_filtered ("exe = '%s'\n", exe.get ());
1470 warning (_("unable to read executable path name"));
1473 fbsd_core_info_proc_files (gdbarch);
1475 fbsd_core_info_proc_mappings (gdbarch);
1477 fbsd_core_info_proc_status (gdbarch);
1480 /* Print descriptions of FreeBSD-specific AUXV entries to FILE. */
1483 fbsd_print_auxv_entry (struct gdbarch *gdbarch, struct ui_file *file,
1484 CORE_ADDR type, CORE_ADDR val)
1487 const char *description;
1488 enum auxv_format format;
1492 #define _TAGNAME(tag) #tag
1493 #define TAGNAME(tag) _TAGNAME(AT_##tag)
1494 #define TAG(tag, text, kind) \
1495 case AT_FREEBSD_##tag: name = TAGNAME(tag); description = text; format = kind; break
1496 TAG (EXECPATH, _("Executable path"), AUXV_FORMAT_STR);
1497 TAG (CANARY, _("Canary for SSP"), AUXV_FORMAT_HEX);
1498 TAG (CANARYLEN, ("Length of the SSP canary"), AUXV_FORMAT_DEC);
1499 TAG (OSRELDATE, _("OSRELDATE"), AUXV_FORMAT_DEC);
1500 TAG (NCPUS, _("Number of CPUs"), AUXV_FORMAT_DEC);
1501 TAG (PAGESIZES, _("Pagesizes"), AUXV_FORMAT_HEX);
1502 TAG (PAGESIZESLEN, _("Number of pagesizes"), AUXV_FORMAT_DEC);
1503 TAG (TIMEKEEP, _("Pointer to timehands"), AUXV_FORMAT_HEX);
1504 TAG (STACKPROT, _("Initial stack protection"), AUXV_FORMAT_HEX);
1505 TAG (EHDRFLAGS, _("ELF header e_flags"), AUXV_FORMAT_HEX);
1506 TAG (HWCAP, _("Machine-dependent CPU capability hints"), AUXV_FORMAT_HEX);
1508 default_print_auxv_entry (gdbarch, file, type, val);
1512 fprint_auxv_entry (file, name, description, format, type, val);
1515 /* Implement the "get_siginfo_type" gdbarch method. */
1517 static struct type *
1518 fbsd_get_siginfo_type (struct gdbarch *gdbarch)
1520 struct fbsd_gdbarch_data *fbsd_gdbarch_data;
1521 struct type *int_type, *int32_type, *uint32_type, *long_type, *void_ptr_type;
1522 struct type *uid_type, *pid_type;
1523 struct type *sigval_type, *reason_type;
1524 struct type *siginfo_type;
1527 fbsd_gdbarch_data = get_fbsd_gdbarch_data (gdbarch);
1528 if (fbsd_gdbarch_data->siginfo_type != NULL)
1529 return fbsd_gdbarch_data->siginfo_type;
1531 int_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
1533 int32_type = arch_integer_type (gdbarch, 32, 0, "int32_t");
1534 uint32_type = arch_integer_type (gdbarch, 32, 1, "uint32_t");
1535 long_type = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
1537 void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
1540 sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
1541 TYPE_NAME (sigval_type) = xstrdup ("sigval");
1542 append_composite_type_field (sigval_type, "sival_int", int_type);
1543 append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type);
1546 pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
1547 TYPE_LENGTH (int32_type) * TARGET_CHAR_BIT, "__pid_t");
1548 TYPE_TARGET_TYPE (pid_type) = int32_type;
1549 TYPE_TARGET_STUB (pid_type) = 1;
1552 uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
1553 TYPE_LENGTH (uint32_type) * TARGET_CHAR_BIT,
1555 TYPE_TARGET_TYPE (uid_type) = uint32_type;
1556 TYPE_TARGET_STUB (uid_type) = 1;
1559 reason_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
1562 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1563 append_composite_type_field (type, "si_trapno", int_type);
1564 append_composite_type_field (reason_type, "_fault", type);
1567 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1568 append_composite_type_field (type, "si_timerid", int_type);
1569 append_composite_type_field (type, "si_overrun", int_type);
1570 append_composite_type_field (reason_type, "_timer", type);
1573 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1574 append_composite_type_field (type, "si_mqd", int_type);
1575 append_composite_type_field (reason_type, "_mesgq", type);
1578 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1579 append_composite_type_field (type, "si_band", long_type);
1580 append_composite_type_field (reason_type, "_poll", type);
1583 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1584 append_composite_type_field (type, "__spare1__", long_type);
1585 append_composite_type_field (type, "__spare2__",
1586 init_vector_type (int_type, 7));
1587 append_composite_type_field (reason_type, "__spare__", type);
1589 /* struct siginfo */
1590 siginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1591 TYPE_NAME (siginfo_type) = xstrdup ("siginfo");
1592 append_composite_type_field (siginfo_type, "si_signo", int_type);
1593 append_composite_type_field (siginfo_type, "si_errno", int_type);
1594 append_composite_type_field (siginfo_type, "si_code", int_type);
1595 append_composite_type_field (siginfo_type, "si_pid", pid_type);
1596 append_composite_type_field (siginfo_type, "si_uid", uid_type);
1597 append_composite_type_field (siginfo_type, "si_status", int_type);
1598 append_composite_type_field (siginfo_type, "si_addr", void_ptr_type);
1599 append_composite_type_field (siginfo_type, "si_value", sigval_type);
1600 append_composite_type_field (siginfo_type, "_reason", reason_type);
1602 fbsd_gdbarch_data->siginfo_type = siginfo_type;
1604 return siginfo_type;
1607 /* Implement the "get_syscall_number" gdbarch method. */
1610 fbsd_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread)
1613 /* FreeBSD doesn't use gdbarch_get_syscall_number since FreeBSD
1614 native targets fetch the system call number from the
1615 'pl_syscall_code' member of struct ptrace_lwpinfo in fbsd_wait.
1616 However, system call catching requires this function to be
1619 internal_error (__FILE__, __LINE__, _("fbsd_get_sycall_number called"));
1622 /* To be called from GDB_OSABI_FREEBSD handlers. */
1625 fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1627 set_gdbarch_core_pid_to_str (gdbarch, fbsd_core_pid_to_str);
1628 set_gdbarch_core_thread_name (gdbarch, fbsd_core_thread_name);
1629 set_gdbarch_core_xfer_siginfo (gdbarch, fbsd_core_xfer_siginfo);
1630 set_gdbarch_make_corefile_notes (gdbarch, fbsd_make_corefile_notes);
1631 set_gdbarch_core_info_proc (gdbarch, fbsd_core_info_proc);
1632 set_gdbarch_print_auxv_entry (gdbarch, fbsd_print_auxv_entry);
1633 set_gdbarch_get_siginfo_type (gdbarch, fbsd_get_siginfo_type);
1635 /* `catch syscall' */
1636 set_xml_syscall_file_name (gdbarch, "syscalls/freebsd.xml");
1637 set_gdbarch_get_syscall_number (gdbarch, fbsd_get_syscall_number);
1641 _initialize_fbsd_tdep (void)
1643 fbsd_gdbarch_data_handle =
1644 gdbarch_data_register_post_init (init_fbsd_gdbarch_data);