1 /* Target-dependent code for FreeBSD, architecture-independent.
3 Copyright (C) 2002-2019 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"
34 /* This enum is derived from FreeBSD's <sys/signal.h>. */
63 FREEBSD_SIGVTALRM = 26,
65 FREEBSD_SIGWINCH = 28,
70 FREEBSD_SIGLIBRT = 33,
71 FREEBSD_SIGRTMIN = 65,
72 FREEBSD_SIGRTMAX = 126,
75 /* FreeBSD kernels 12.0 and later include a copy of the
76 'ptrace_lwpinfo' structure returned by the PT_LWPINFO ptrace
77 operation in an ELF core note (NT_FREEBSD_PTLWPINFO) for each LWP.
78 The constants below define the offset of field members and flags in
79 this structure used by methods in this file. Note that the
80 'ptrace_lwpinfo' struct in the note is preceded by a 4 byte integer
81 containing the size of the structure. */
83 #define LWPINFO_OFFSET 0x4
85 /* Offsets in ptrace_lwpinfo. */
86 #define LWPINFO_PL_FLAGS 0x8
87 #define LWPINFO64_PL_SIGINFO 0x30
88 #define LWPINFO32_PL_SIGINFO 0x2c
90 /* Flags in pl_flags. */
91 #define PL_FLAG_SI 0x20 /* siginfo is valid */
93 /* Sizes of siginfo_t. */
94 #define SIZE64_SIGINFO_T 80
95 #define SIZE32_SIGINFO_T 64
97 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_VMMAP core
98 dump notes. See <sys/user.h> for the definition of struct
99 kinfo_vmentry. This data structure should have the same layout on
102 Note that FreeBSD 7.0 used an older version of this structure
103 (struct kinfo_ovmentry), but the NT_FREEBSD_PROCSTAT_VMMAP core
104 dump note wasn't introduced until FreeBSD 9.2. As a result, the
105 core dump note has always used the 7.1 and later structure
108 #define KVE_STRUCTSIZE 0x0
109 #define KVE_START 0x8
111 #define KVE_OFFSET 0x18
112 #define KVE_FLAGS 0x2c
113 #define KVE_PROTECTION 0x38
114 #define KVE_PATH 0x88
116 /* Flags in the 'kve_protection' field in struct kinfo_vmentry. These
117 match the KVME_PROT_* constants in <sys/user.h>. */
119 #define KINFO_VME_PROT_READ 0x00000001
120 #define KINFO_VME_PROT_WRITE 0x00000002
121 #define KINFO_VME_PROT_EXEC 0x00000004
123 /* Flags in the 'kve_flags' field in struct kinfo_vmentry. These
124 match the KVME_FLAG_* constants in <sys/user.h>. */
126 #define KINFO_VME_FLAG_COW 0x00000001
127 #define KINFO_VME_FLAG_NEEDS_COPY 0x00000002
128 #define KINFO_VME_FLAG_NOCOREDUMP 0x00000004
129 #define KINFO_VME_FLAG_SUPER 0x00000008
130 #define KINFO_VME_FLAG_GROWS_UP 0x00000010
131 #define KINFO_VME_FLAG_GROWS_DOWN 0x00000020
133 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_FILES core
134 dump notes. See <sys/user.h> for the definition of struct
135 kinfo_file. This data structure should have the same layout on all
138 Note that FreeBSD 7.0 used an older version of this structure
139 (struct kinfo_ofile), but the NT_FREEBSD_PROCSTAT_FILES core dump
140 note wasn't introduced until FreeBSD 9.2. As a result, the core
141 dump note has always used the 7.1 and later structure format. */
143 #define KF_STRUCTSIZE 0x0
146 #define KF_FLAGS 0x10
147 #define KF_OFFSET 0x18
148 #define KF_VNODE_TYPE 0x20
149 #define KF_SOCK_DOMAIN 0x24
150 #define KF_SOCK_TYPE 0x28
151 #define KF_SOCK_PROTOCOL 0x2c
152 #define KF_SA_LOCAL 0x30
153 #define KF_SA_PEER 0xb0
154 #define KF_PATH 0x170
156 /* Constants for the 'kf_type' field in struct kinfo_file. These
157 match the KF_TYPE_* constants in <sys/user.h>. */
159 #define KINFO_FILE_TYPE_VNODE 1
160 #define KINFO_FILE_TYPE_SOCKET 2
161 #define KINFO_FILE_TYPE_PIPE 3
162 #define KINFO_FILE_TYPE_FIFO 4
163 #define KINFO_FILE_TYPE_KQUEUE 5
164 #define KINFO_FILE_TYPE_CRYPTO 6
165 #define KINFO_FILE_TYPE_MQUEUE 7
166 #define KINFO_FILE_TYPE_SHM 8
167 #define KINFO_FILE_TYPE_SEM 9
168 #define KINFO_FILE_TYPE_PTS 10
169 #define KINFO_FILE_TYPE_PROCDESC 11
171 /* Special values for the 'kf_fd' field in struct kinfo_file. These
172 match the KF_FD_TYPE_* constants in <sys/user.h>. */
174 #define KINFO_FILE_FD_TYPE_CWD -1
175 #define KINFO_FILE_FD_TYPE_ROOT -2
176 #define KINFO_FILE_FD_TYPE_JAIL -3
177 #define KINFO_FILE_FD_TYPE_TRACE -4
178 #define KINFO_FILE_FD_TYPE_TEXT -5
179 #define KINFO_FILE_FD_TYPE_CTTY -6
181 /* Flags in the 'kf_flags' field in struct kinfo_file. These match
182 the KF_FLAG_* constants in <sys/user.h>. */
184 #define KINFO_FILE_FLAG_READ 0x00000001
185 #define KINFO_FILE_FLAG_WRITE 0x00000002
186 #define KINFO_FILE_FLAG_APPEND 0x00000004
187 #define KINFO_FILE_FLAG_ASYNC 0x00000008
188 #define KINFO_FILE_FLAG_FSYNC 0x00000010
189 #define KINFO_FILE_FLAG_NONBLOCK 0x00000020
190 #define KINFO_FILE_FLAG_DIRECT 0x00000040
191 #define KINFO_FILE_FLAG_HASLOCK 0x00000080
192 #define KINFO_FILE_FLAG_EXEC 0x00004000
194 /* Constants for the 'kf_vnode_type' field in struct kinfo_file.
195 These match the KF_VTYPE_* constants in <sys/user.h>. */
197 #define KINFO_FILE_VTYPE_VREG 1
198 #define KINFO_FILE_VTYPE_VDIR 2
199 #define KINFO_FILE_VTYPE_VCHR 4
200 #define KINFO_FILE_VTYPE_VLNK 5
201 #define KINFO_FILE_VTYPE_VSOCK 6
202 #define KINFO_FILE_VTYPE_VFIFO 7
204 /* Constants for socket address families. These match AF_* constants
205 in <sys/socket.h>. */
207 #define FBSD_AF_UNIX 1
208 #define FBSD_AF_INET 2
209 #define FBSD_AF_INET6 28
211 /* Constants for socket types. These match SOCK_* constants in
214 #define FBSD_SOCK_STREAM 1
215 #define FBSD_SOCK_DGRAM 2
216 #define FBSD_SOCK_SEQPACKET 5
218 /* Constants for IP protocols. These match IPPROTO_* constants in
221 #define FBSD_IPPROTO_ICMP 1
222 #define FBSD_IPPROTO_TCP 6
223 #define FBSD_IPPROTO_UDP 17
224 #define FBSD_IPPROTO_SCTP 132
226 /* Socket address structures. These have the same layout on all
227 FreeBSD architectures. In addition, multibyte fields such as IP
228 addresses are always stored in network byte order. */
230 struct fbsd_sockaddr_in
239 struct fbsd_sockaddr_in6
243 uint8_t sin6_port[2];
244 uint32_t sin6_flowinfo;
245 uint8_t sin6_addr[16];
246 uint32_t sin6_scope_id;
249 struct fbsd_sockaddr_un
256 /* Number of 32-bit words in a signal set. This matches _SIG_WORDS in
257 <sys/_sigset.h> and is the same value on all architectures. */
261 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_PROC core
262 dump notes. See <sys/user.h> for the definition of struct
263 kinfo_proc. This data structure has different layouts on different
264 architectures mostly due to ILP32 vs LP64. However, FreeBSD/i386
265 uses a 32-bit time_t while all other architectures use a 64-bit
268 The core dump note actually contains one kinfo_proc structure for
269 each thread, but all of the process-wide data can be obtained from
270 the first structure. One result of this note's format is that some
271 of the process-wide status available in the native target method
272 from the kern.proc.pid.<pid> sysctl such as ki_stat and ki_siglist
273 is not available from a core dump. Instead, the per-thread data
274 structures contain the value of these fields for individual
277 struct kinfo_proc_layout
279 /* Offsets of struct kinfo_proc members. */
286 int ki_tdev_freebsd11;
308 /* Offsets of struct rusage members. */
316 const struct kinfo_proc_layout kinfo_proc_layout_32 =
324 .ki_tdev_freebsd11 = 0x44,
325 .ki_sigignore = 0x68,
344 .ki_rusage_ch = 0x278,
353 const struct kinfo_proc_layout kinfo_proc_layout_i386 =
361 .ki_tdev_freebsd11 = 0x44,
362 .ki_sigignore = 0x68,
381 .ki_rusage_ch = 0x258,
390 const struct kinfo_proc_layout kinfo_proc_layout_64 =
398 .ki_tdev_freebsd11 = 0x64,
399 .ki_sigignore = 0x88,
418 .ki_rusage_ch = 0x2f0,
427 static struct gdbarch_data *fbsd_gdbarch_data_handle;
429 struct fbsd_gdbarch_data
431 struct type *siginfo_type;
435 init_fbsd_gdbarch_data (struct gdbarch *gdbarch)
437 return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct fbsd_gdbarch_data);
440 static struct fbsd_gdbarch_data *
441 get_fbsd_gdbarch_data (struct gdbarch *gdbarch)
443 return ((struct fbsd_gdbarch_data *)
444 gdbarch_data (gdbarch, fbsd_gdbarch_data_handle));
447 /* This is how we want PTIDs from core files to be printed. */
450 fbsd_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
454 if (ptid.lwp () != 0)
456 xsnprintf (buf, sizeof buf, "LWP %ld", ptid.lwp ());
460 return normal_pid_to_str (ptid);
463 /* Extract the name assigned to a thread from a core. Returns the
464 string in a static buffer. */
467 fbsd_core_thread_name (struct gdbarch *gdbarch, struct thread_info *thr)
470 struct bfd_section *section;
473 if (thr->ptid.lwp () != 0)
475 /* FreeBSD includes a NT_FREEBSD_THRMISC note for each thread
476 whose contents are defined by a "struct thrmisc" declared in
477 <sys/procfs.h> on FreeBSD. The per-thread name is stored as
478 a null-terminated string as the first member of the
479 structure. Rather than define the full structure here, just
480 extract the null-terminated name from the start of the
482 thread_section_name section_name (".thrmisc", thr->ptid);
484 section = bfd_get_section_by_name (core_bfd, section_name.c_str ());
485 if (section != NULL && bfd_section_size (core_bfd, section) > 0)
487 /* Truncate the name if it is longer than "buf". */
488 size = bfd_section_size (core_bfd, section);
489 if (size > sizeof buf - 1)
490 size = sizeof buf - 1;
491 if (bfd_get_section_contents (core_bfd, section, buf, (file_ptr) 0,
497 /* Note that each thread will report the process command
498 as its thread name instead of an empty name if a name
499 has not been set explicitly. Return a NULL name in
501 if (strcmp (buf, elf_tdata (core_bfd)->core->program) != 0)
510 /* Implement the "core_xfer_siginfo" gdbarch method. */
513 fbsd_core_xfer_siginfo (struct gdbarch *gdbarch, gdb_byte *readbuf,
514 ULONGEST offset, ULONGEST len)
518 if (gdbarch_long_bit (gdbarch) == 32)
519 siginfo_size = SIZE32_SIGINFO_T;
521 siginfo_size = SIZE64_SIGINFO_T;
522 if (offset > siginfo_size)
525 thread_section_name section_name (".note.freebsdcore.lwpinfo", inferior_ptid);
526 asection *section = bfd_get_section_by_name (core_bfd, section_name.c_str ());
531 if (!bfd_get_section_contents (core_bfd, section, buf,
532 LWPINFO_OFFSET + LWPINFO_PL_FLAGS, 4))
535 int pl_flags = extract_signed_integer (buf, 4, gdbarch_byte_order (gdbarch));
536 if (!(pl_flags & PL_FLAG_SI))
539 if (offset + len > siginfo_size)
540 len = siginfo_size - offset;
542 ULONGEST siginfo_offset;
543 if (gdbarch_long_bit (gdbarch) == 32)
544 siginfo_offset = LWPINFO_OFFSET + LWPINFO32_PL_SIGINFO;
546 siginfo_offset = LWPINFO_OFFSET + LWPINFO64_PL_SIGINFO;
548 if (!bfd_get_section_contents (core_bfd, section, readbuf,
549 siginfo_offset + offset, len))
556 find_signalled_thread (struct thread_info *info, void *data)
558 if (info->suspend.stop_signal != GDB_SIGNAL_0
559 && info->ptid.pid () == inferior_ptid.pid ())
565 /* Structure for passing information from
566 fbsd_collect_thread_registers via an iterator to
567 fbsd_collect_regset_section_cb. */
569 struct fbsd_collect_regset_section_cb_data
571 const struct regcache *regcache;
576 enum gdb_signal stop_signal;
581 fbsd_collect_regset_section_cb (const char *sect_name, int supply_size,
582 int collect_size, const struct regset *regset,
583 const char *human_name, void *cb_data)
586 struct fbsd_collect_regset_section_cb_data *data
587 = (struct fbsd_collect_regset_section_cb_data *) cb_data;
589 if (data->abort_iteration)
592 gdb_assert (regset->collect_regset);
594 buf = (char *) xmalloc (collect_size);
595 regset->collect_regset (regset, data->regcache, -1, buf, collect_size);
597 /* PRSTATUS still needs to be treated specially. */
598 if (strcmp (sect_name, ".reg") == 0)
599 data->note_data = (char *) elfcore_write_prstatus
600 (data->obfd, data->note_data, data->note_size, data->lwp,
601 gdb_signal_to_host (data->stop_signal), buf);
603 data->note_data = (char *) elfcore_write_register_note
604 (data->obfd, data->note_data, data->note_size,
605 sect_name, buf, collect_size);
608 if (data->note_data == NULL)
609 data->abort_iteration = 1;
612 /* Records the thread's register state for the corefile note
616 fbsd_collect_thread_registers (const struct regcache *regcache,
617 ptid_t ptid, bfd *obfd,
618 char *note_data, int *note_size,
619 enum gdb_signal stop_signal)
621 struct gdbarch *gdbarch = regcache->arch ();
622 struct fbsd_collect_regset_section_cb_data data;
624 data.regcache = regcache;
626 data.note_data = note_data;
627 data.note_size = note_size;
628 data.stop_signal = stop_signal;
629 data.abort_iteration = 0;
630 data.lwp = ptid.lwp ();
632 gdbarch_iterate_over_regset_sections (gdbarch,
633 fbsd_collect_regset_section_cb,
635 return data.note_data;
638 struct fbsd_corefile_thread_data
640 struct gdbarch *gdbarch;
644 enum gdb_signal stop_signal;
647 /* Records the thread's register state for the corefile note
651 fbsd_corefile_thread (struct thread_info *info,
652 struct fbsd_corefile_thread_data *args)
654 struct regcache *regcache;
656 regcache = get_thread_arch_regcache (info->ptid, args->gdbarch);
658 target_fetch_registers (regcache, -1);
660 args->note_data = fbsd_collect_thread_registers
661 (regcache, info->ptid, args->obfd, args->note_data,
662 args->note_size, args->stop_signal);
665 /* Return a byte_vector containing the contents of a core dump note
666 for the target object of type OBJECT. If STRUCTSIZE is non-zero,
667 the data is prefixed with a 32-bit integer size to match the format
668 used in FreeBSD NT_PROCSTAT_* notes. */
670 static gdb::optional<gdb::byte_vector>
671 fbsd_make_note_desc (enum target_object object, uint32_t structsize)
673 gdb::optional<gdb::byte_vector> buf =
674 target_read_alloc (current_top_target (), object, NULL);
675 if (!buf || buf->empty ())
681 gdb::byte_vector desc (sizeof (structsize) + buf->size ());
682 memcpy (desc.data (), &structsize, sizeof (structsize));
683 memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ());
687 /* Create appropriate note sections for a corefile, returning them in
691 fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
693 struct fbsd_corefile_thread_data thread_args;
694 char *note_data = NULL;
695 Elf_Internal_Ehdr *i_ehdrp;
696 struct thread_info *curr_thr, *signalled_thr;
698 /* Put a "FreeBSD" label in the ELF header. */
699 i_ehdrp = elf_elfheader (obfd);
700 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
702 gdb_assert (gdbarch_iterate_over_regset_sections_p (gdbarch));
704 if (get_exec_file (0))
706 const char *fname = lbasename (get_exec_file (0));
707 char *psargs = xstrdup (fname);
709 if (get_inferior_args ())
710 psargs = reconcat (psargs, psargs, " ", get_inferior_args (),
713 note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
717 /* Thread register information. */
720 update_thread_list ();
722 CATCH (e, RETURN_MASK_ERROR)
724 exception_print (gdb_stderr, e);
728 /* Like the kernel, prefer dumping the signalled thread first.
729 "First thread" is what tools use to infer the signalled thread.
730 In case there's more than one signalled thread, prefer the
731 current thread, if it is signalled. */
732 curr_thr = inferior_thread ();
733 if (curr_thr->suspend.stop_signal != GDB_SIGNAL_0)
734 signalled_thr = curr_thr;
737 signalled_thr = iterate_over_threads (find_signalled_thread, NULL);
738 if (signalled_thr == NULL)
739 signalled_thr = curr_thr;
742 thread_args.gdbarch = gdbarch;
743 thread_args.obfd = obfd;
744 thread_args.note_data = note_data;
745 thread_args.note_size = note_size;
746 thread_args.stop_signal = signalled_thr->suspend.stop_signal;
748 fbsd_corefile_thread (signalled_thr, &thread_args);
749 for (thread_info *thr : current_inferior ()->non_exited_threads ())
751 if (thr == signalled_thr)
754 fbsd_corefile_thread (thr, &thread_args);
757 note_data = thread_args.note_data;
759 /* Auxiliary vector. */
760 uint32_t structsize = gdbarch_ptr_bit (gdbarch) / 4; /* Elf_Auxinfo */
761 gdb::optional<gdb::byte_vector> note_desc =
762 fbsd_make_note_desc (TARGET_OBJECT_AUXV, structsize);
763 if (note_desc && !note_desc->empty ())
765 note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
766 NT_FREEBSD_PROCSTAT_AUXV,
767 note_desc->data (), note_desc->size ());
772 /* Virtual memory mappings. */
773 note_desc = fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_VMMAP, 0);
774 if (note_desc && !note_desc->empty ())
776 note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
777 NT_FREEBSD_PROCSTAT_VMMAP,
778 note_desc->data (), note_desc->size ());
783 note_desc = fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_PS_STRINGS, 0);
784 if (note_desc && !note_desc->empty ())
786 note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
787 NT_FREEBSD_PROCSTAT_PSSTRINGS,
788 note_desc->data (), note_desc->size ());
796 /* Helper function to generate the file descriptor description for a
797 single open file in 'info proc files'. */
800 fbsd_file_fd (int kf_fd)
804 case KINFO_FILE_FD_TYPE_CWD:
806 case KINFO_FILE_FD_TYPE_ROOT:
808 case KINFO_FILE_FD_TYPE_JAIL:
810 case KINFO_FILE_FD_TYPE_TRACE:
812 case KINFO_FILE_FD_TYPE_TEXT:
814 case KINFO_FILE_FD_TYPE_CTTY:
817 return int_string (kf_fd, 10, 1, 0, 0);
821 /* Helper function to generate the file type for a single open file in
822 'info proc files'. */
825 fbsd_file_type (int kf_type, int kf_vnode_type)
829 case KINFO_FILE_TYPE_VNODE:
830 switch (kf_vnode_type)
832 case KINFO_FILE_VTYPE_VREG:
834 case KINFO_FILE_VTYPE_VDIR:
836 case KINFO_FILE_VTYPE_VCHR:
838 case KINFO_FILE_VTYPE_VLNK:
840 case KINFO_FILE_VTYPE_VSOCK:
842 case KINFO_FILE_VTYPE_VFIFO:
846 char *str = get_print_cell ();
848 xsnprintf (str, PRINT_CELL_SIZE, "vn:%d", kf_vnode_type);
852 case KINFO_FILE_TYPE_SOCKET:
854 case KINFO_FILE_TYPE_PIPE:
856 case KINFO_FILE_TYPE_FIFO:
858 case KINFO_FILE_TYPE_KQUEUE:
860 case KINFO_FILE_TYPE_CRYPTO:
862 case KINFO_FILE_TYPE_MQUEUE:
864 case KINFO_FILE_TYPE_SHM:
866 case KINFO_FILE_TYPE_SEM:
868 case KINFO_FILE_TYPE_PTS:
870 case KINFO_FILE_TYPE_PROCDESC:
873 return int_string (kf_type, 10, 1, 0, 0);
877 /* Helper function to generate the file flags for a single open file in
878 'info proc files'. */
881 fbsd_file_flags (int kf_flags)
883 static char file_flags[10];
885 file_flags[0] = (kf_flags & KINFO_FILE_FLAG_READ) ? 'r' : '-';
886 file_flags[1] = (kf_flags & KINFO_FILE_FLAG_WRITE) ? 'w' : '-';
887 file_flags[2] = (kf_flags & KINFO_FILE_FLAG_EXEC) ? 'x' : '-';
888 file_flags[3] = (kf_flags & KINFO_FILE_FLAG_APPEND) ? 'a' : '-';
889 file_flags[4] = (kf_flags & KINFO_FILE_FLAG_ASYNC) ? 's' : '-';
890 file_flags[5] = (kf_flags & KINFO_FILE_FLAG_FSYNC) ? 'f' : '-';
891 file_flags[6] = (kf_flags & KINFO_FILE_FLAG_NONBLOCK) ? 'n' : '-';
892 file_flags[7] = (kf_flags & KINFO_FILE_FLAG_DIRECT) ? 'd' : '-';
893 file_flags[8] = (kf_flags & KINFO_FILE_FLAG_HASLOCK) ? 'l' : '-';
894 file_flags[9] = '\0';
899 /* Helper function to generate the name of an IP protocol. */
902 fbsd_ipproto (int protocol)
906 case FBSD_IPPROTO_ICMP:
908 case FBSD_IPPROTO_TCP:
910 case FBSD_IPPROTO_UDP:
912 case FBSD_IPPROTO_SCTP:
916 char *str = get_print_cell ();
918 xsnprintf (str, PRINT_CELL_SIZE, "ip<%d>", protocol);
924 /* Helper function to print out an IPv4 socket address. */
927 fbsd_print_sockaddr_in (const void *sockaddr)
929 const struct fbsd_sockaddr_in *sin =
930 reinterpret_cast<const struct fbsd_sockaddr_in *> (sockaddr);
931 char buf[INET_ADDRSTRLEN];
933 if (inet_ntop (AF_INET, sin->sin_addr, buf, sizeof buf) == nullptr)
934 error (_("Failed to format IPv4 address"));
935 printf_filtered ("%s:%u", buf,
936 (sin->sin_port[0] << 8) | sin->sin_port[1]);
939 /* Helper function to print out an IPv6 socket address. */
942 fbsd_print_sockaddr_in6 (const void *sockaddr)
944 const struct fbsd_sockaddr_in6 *sin6 =
945 reinterpret_cast<const struct fbsd_sockaddr_in6 *> (sockaddr);
946 char buf[INET6_ADDRSTRLEN];
948 if (inet_ntop (AF_INET6, sin6->sin6_addr, buf, sizeof buf) == nullptr)
949 error (_("Failed to format IPv6 address"));
950 printf_filtered ("%s.%u", buf,
951 (sin6->sin6_port[0] << 8) | sin6->sin6_port[1]);
954 /* See fbsd-tdep.h. */
957 fbsd_info_proc_files_header ()
959 printf_filtered (_("Open files:\n\n"));
960 printf_filtered (" %6s %6s %10s %9s %s\n",
961 "FD", "Type", "Offset", "Flags ", "Name");
964 /* See fbsd-tdep.h. */
967 fbsd_info_proc_files_entry (int kf_type, int kf_fd, int kf_flags,
968 LONGEST kf_offset, int kf_vnode_type,
969 int kf_sock_domain, int kf_sock_type,
970 int kf_sock_protocol, const void *kf_sa_local,
971 const void *kf_sa_peer, const void *kf_path)
973 printf_filtered (" %6s %6s %10s %8s ",
974 fbsd_file_fd (kf_fd),
975 fbsd_file_type (kf_type, kf_vnode_type),
976 kf_offset > -1 ? hex_string (kf_offset) : "-",
977 fbsd_file_flags (kf_flags));
978 if (kf_type == KINFO_FILE_TYPE_SOCKET)
980 switch (kf_sock_domain)
984 switch (kf_sock_type)
986 case FBSD_SOCK_STREAM:
987 printf_filtered ("unix stream:");
989 case FBSD_SOCK_DGRAM:
990 printf_filtered ("unix dgram:");
992 case FBSD_SOCK_SEQPACKET:
993 printf_filtered ("unix seqpacket:");
996 printf_filtered ("unix <%d>:", kf_sock_type);
1000 /* For local sockets, print out the first non-nul path
1001 rather than both paths. */
1002 const struct fbsd_sockaddr_un *sun
1003 = reinterpret_cast<const struct fbsd_sockaddr_un *> (kf_sa_local);
1004 if (sun->sun_path[0] == 0)
1005 sun = reinterpret_cast<const struct fbsd_sockaddr_un *>
1007 printf_filtered ("%s", sun->sun_path);
1011 printf_filtered ("%s4 ", fbsd_ipproto (kf_sock_protocol));
1012 fbsd_print_sockaddr_in (kf_sa_local);
1013 printf_filtered (" -> ");
1014 fbsd_print_sockaddr_in (kf_sa_peer);
1017 printf_filtered ("%s6 ", fbsd_ipproto (kf_sock_protocol));
1018 fbsd_print_sockaddr_in6 (kf_sa_local);
1019 printf_filtered (" -> ");
1020 fbsd_print_sockaddr_in6 (kf_sa_peer);
1025 printf_filtered ("%s", reinterpret_cast<const char *> (kf_path));
1026 printf_filtered ("\n");
1029 /* Implement "info proc files" for a corefile. */
1032 fbsd_core_info_proc_files (struct gdbarch *gdbarch)
1035 = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files");
1036 if (section == NULL)
1038 warning (_("unable to find open files in core file"));
1042 size_t note_size = bfd_get_section_size (section);
1044 error (_("malformed core note - too short for header"));
1046 gdb::def_vector<unsigned char> contents (note_size);
1047 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
1049 error (_("could not get core note contents"));
1051 unsigned char *descdata = contents.data ();
1052 unsigned char *descend = descdata + note_size;
1054 /* Skip over the structure size. */
1057 fbsd_info_proc_files_header ();
1059 while (descdata + KF_PATH < descend)
1061 ULONGEST structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE);
1062 if (structsize < KF_PATH)
1063 error (_("malformed core note - file structure too small"));
1065 LONGEST type = bfd_get_signed_32 (core_bfd, descdata + KF_TYPE);
1066 LONGEST fd = bfd_get_signed_32 (core_bfd, descdata + KF_FD);
1067 LONGEST flags = bfd_get_signed_32 (core_bfd, descdata + KF_FLAGS);
1068 LONGEST offset = bfd_get_signed_64 (core_bfd, descdata + KF_OFFSET);
1069 LONGEST vnode_type = bfd_get_signed_32 (core_bfd,
1070 descdata + KF_VNODE_TYPE);
1071 LONGEST sock_domain = bfd_get_signed_32 (core_bfd,
1072 descdata + KF_SOCK_DOMAIN);
1073 LONGEST sock_type = bfd_get_signed_32 (core_bfd, descdata + KF_SOCK_TYPE);
1074 LONGEST sock_protocol = bfd_get_signed_32 (core_bfd,
1075 descdata + KF_SOCK_PROTOCOL);
1076 fbsd_info_proc_files_entry (type, fd, flags, offset, vnode_type,
1077 sock_domain, sock_type, sock_protocol,
1078 descdata + KF_SA_LOCAL, descdata + KF_SA_PEER,
1079 descdata + KF_PATH);
1081 descdata += structsize;
1085 /* Helper function to generate mappings flags for a single VM map
1086 entry in 'info proc mappings'. */
1089 fbsd_vm_map_entry_flags (int kve_flags, int kve_protection)
1091 static char vm_flags[9];
1093 vm_flags[0] = (kve_protection & KINFO_VME_PROT_READ) ? 'r' : '-';
1094 vm_flags[1] = (kve_protection & KINFO_VME_PROT_WRITE) ? 'w' : '-';
1095 vm_flags[2] = (kve_protection & KINFO_VME_PROT_EXEC) ? 'x' : '-';
1097 vm_flags[4] = (kve_flags & KINFO_VME_FLAG_COW) ? 'C' : '-';
1098 vm_flags[5] = (kve_flags & KINFO_VME_FLAG_NEEDS_COPY) ? 'N' : '-';
1099 vm_flags[6] = (kve_flags & KINFO_VME_FLAG_SUPER) ? 'S' : '-';
1100 vm_flags[7] = (kve_flags & KINFO_VME_FLAG_GROWS_UP) ? 'U'
1101 : (kve_flags & KINFO_VME_FLAG_GROWS_DOWN) ? 'D' : '-';
1107 /* See fbsd-tdep.h. */
1110 fbsd_info_proc_mappings_header (int addr_bit)
1112 printf_filtered (_("Mapped address spaces:\n\n"));
1115 printf_filtered (" %18s %18s %10s %10s %9s %s\n",
1118 " Size", " Offset", "Flags ", "File");
1122 printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
1125 " Size", " Offset", "Flags ", "File");
1129 /* See fbsd-tdep.h. */
1132 fbsd_info_proc_mappings_entry (int addr_bit, ULONGEST kve_start,
1133 ULONGEST kve_end, ULONGEST kve_offset,
1134 int kve_flags, int kve_protection,
1135 const void *kve_path)
1139 printf_filtered (" %18s %18s %10s %10s %9s %s\n",
1140 hex_string (kve_start),
1141 hex_string (kve_end),
1142 hex_string (kve_end - kve_start),
1143 hex_string (kve_offset),
1144 fbsd_vm_map_entry_flags (kve_flags, kve_protection),
1145 reinterpret_cast<const char *> (kve_path));
1149 printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
1150 hex_string (kve_start),
1151 hex_string (kve_end),
1152 hex_string (kve_end - kve_start),
1153 hex_string (kve_offset),
1154 fbsd_vm_map_entry_flags (kve_flags, kve_protection),
1155 reinterpret_cast<const char *> (kve_path));
1159 /* Implement "info proc mappings" for a corefile. */
1162 fbsd_core_info_proc_mappings (struct gdbarch *gdbarch)
1165 unsigned char *descdata, *descend;
1168 section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.vmmap");
1169 if (section == NULL)
1171 warning (_("unable to find mappings in core file"));
1175 note_size = bfd_get_section_size (section);
1177 error (_("malformed core note - too short for header"));
1179 gdb::def_vector<unsigned char> contents (note_size);
1180 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
1182 error (_("could not get core note contents"));
1184 descdata = contents.data ();
1185 descend = descdata + note_size;
1187 /* Skip over the structure size. */
1190 fbsd_info_proc_mappings_header (gdbarch_addr_bit (gdbarch));
1191 while (descdata + KVE_PATH < descend)
1193 ULONGEST structsize = bfd_get_32 (core_bfd, descdata + KVE_STRUCTSIZE);
1194 if (structsize < KVE_PATH)
1195 error (_("malformed core note - vmmap entry too small"));
1197 ULONGEST start = bfd_get_64 (core_bfd, descdata + KVE_START);
1198 ULONGEST end = bfd_get_64 (core_bfd, descdata + KVE_END);
1199 ULONGEST offset = bfd_get_64 (core_bfd, descdata + KVE_OFFSET);
1200 LONGEST flags = bfd_get_signed_32 (core_bfd, descdata + KVE_FLAGS);
1201 LONGEST prot = bfd_get_signed_32 (core_bfd, descdata + KVE_PROTECTION);
1202 fbsd_info_proc_mappings_entry (gdbarch_addr_bit (gdbarch), start, end,
1203 offset, flags, prot, descdata + KVE_PATH);
1205 descdata += structsize;
1209 /* Fetch the pathname of a vnode for a single file descriptor from the
1210 file table core note. */
1212 static gdb::unique_xmalloc_ptr<char>
1213 fbsd_core_vnode_path (struct gdbarch *gdbarch, int fd)
1216 unsigned char *descdata, *descend;
1219 section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files");
1220 if (section == NULL)
1223 note_size = bfd_get_section_size (section);
1225 error (_("malformed core note - too short for header"));
1227 gdb::def_vector<unsigned char> contents (note_size);
1228 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
1230 error (_("could not get core note contents"));
1232 descdata = contents.data ();
1233 descend = descdata + note_size;
1235 /* Skip over the structure size. */
1238 while (descdata + KF_PATH < descend)
1240 ULONGEST structsize;
1242 structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE);
1243 if (structsize < KF_PATH)
1244 error (_("malformed core note - file structure too small"));
1246 if (bfd_get_32 (core_bfd, descdata + KF_TYPE) == KINFO_FILE_TYPE_VNODE
1247 && bfd_get_signed_32 (core_bfd, descdata + KF_FD) == fd)
1249 char *path = (char *) descdata + KF_PATH;
1250 return gdb::unique_xmalloc_ptr<char> (xstrdup (path));
1253 descdata += structsize;
1258 /* Helper function to read a struct timeval. */
1261 fbsd_core_fetch_timeval (struct gdbarch *gdbarch, unsigned char *data,
1262 LONGEST &sec, ULONGEST &usec)
1264 if (gdbarch_addr_bit (gdbarch) == 64)
1266 sec = bfd_get_signed_64 (core_bfd, data);
1267 usec = bfd_get_64 (core_bfd, data + 8);
1269 else if (bfd_get_arch (core_bfd) == bfd_arch_i386)
1271 sec = bfd_get_signed_32 (core_bfd, data);
1272 usec = bfd_get_32 (core_bfd, data + 4);
1276 sec = bfd_get_signed_64 (core_bfd, data);
1277 usec = bfd_get_32 (core_bfd, data + 8);
1281 /* Print out the contents of a signal set. */
1284 fbsd_print_sigset (const char *descr, unsigned char *sigset)
1286 printf_filtered ("%s: ", descr);
1287 for (int i = 0; i < SIG_WORDS; i++)
1288 printf_filtered ("%08x ",
1289 (unsigned int) bfd_get_32 (core_bfd, sigset + i * 4));
1290 printf_filtered ("\n");
1293 /* Implement "info proc status" for a corefile. */
1296 fbsd_core_info_proc_status (struct gdbarch *gdbarch)
1298 const struct kinfo_proc_layout *kp;
1300 unsigned char *descdata;
1301 int addr_bit, long_bit;
1306 section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.proc");
1307 if (section == NULL)
1309 warning (_("unable to find process info in core file"));
1313 addr_bit = gdbarch_addr_bit (gdbarch);
1315 kp = &kinfo_proc_layout_64;
1316 else if (bfd_get_arch (core_bfd) == bfd_arch_i386)
1317 kp = &kinfo_proc_layout_i386;
1319 kp = &kinfo_proc_layout_32;
1320 long_bit = gdbarch_long_bit (gdbarch);
1323 * Ensure that the note is large enough for all of the fields fetched
1324 * by this function. In particular, the note must contain the 32-bit
1325 * structure size, then it must be long enough to access the last
1326 * field used (ki_rusage_ch.ru_majflt) which is the size of a long.
1328 note_size = bfd_get_section_size (section);
1329 if (note_size < (4 + kp->ki_rusage_ch + kp->ru_majflt
1330 + long_bit / TARGET_CHAR_BIT))
1331 error (_("malformed core note - too short"));
1333 gdb::def_vector<unsigned char> contents (note_size);
1334 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
1336 error (_("could not get core note contents"));
1338 descdata = contents.data ();
1340 /* Skip over the structure size. */
1343 /* Verify 'ki_layout' is 0. */
1344 if (bfd_get_32 (core_bfd, descdata + kp->ki_layout) != 0)
1346 warning (_("unsupported process information in core file"));
1350 printf_filtered ("Name: %.19s\n", descdata + kp->ki_comm);
1351 printf_filtered ("Process ID: %s\n",
1352 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pid)));
1353 printf_filtered ("Parent process: %s\n",
1354 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ppid)));
1355 printf_filtered ("Process group: %s\n",
1356 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pgid)));
1357 printf_filtered ("Session id: %s\n",
1358 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_sid)));
1360 /* FreeBSD 12.0 and later store a 64-bit dev_t at 'ki_tdev'. Older
1361 kernels store a 32-bit dev_t at 'ki_tdev_freebsd11'. In older
1362 kernels the 64-bit 'ki_tdev' field is in a reserved section of
1363 the structure that is cleared to zero. Assume that a zero value
1364 in ki_tdev indicates a core dump from an older kernel and use the
1365 value in 'ki_tdev_freebsd11' instead. */
1366 value = bfd_get_64 (core_bfd, descdata + kp->ki_tdev);
1368 value = bfd_get_32 (core_bfd, descdata + kp->ki_tdev_freebsd11);
1369 printf_filtered ("TTY: %s\n", pulongest (value));
1370 printf_filtered ("TTY owner process group: %s\n",
1371 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_tpgid)));
1372 printf_filtered ("User IDs (real, effective, saved): %s %s %s\n",
1373 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ruid)),
1374 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_uid)),
1375 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svuid)));
1376 printf_filtered ("Group IDs (real, effective, saved): %s %s %s\n",
1377 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_rgid)),
1378 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_groups)),
1379 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svgid)));
1380 printf_filtered ("Groups: ");
1381 uint16_t ngroups = bfd_get_16 (core_bfd, descdata + kp->ki_ngroups);
1382 for (int i = 0; i < ngroups; i++)
1383 printf_filtered ("%s ",
1384 pulongest (bfd_get_32 (core_bfd,
1385 descdata + kp->ki_groups + i * 4)));
1386 printf_filtered ("\n");
1387 value = bfd_get (long_bit, core_bfd,
1388 descdata + kp->ki_rusage + kp->ru_minflt);
1389 printf_filtered ("Minor faults (no memory page): %s\n", pulongest (value));
1390 value = bfd_get (long_bit, core_bfd,
1391 descdata + kp->ki_rusage_ch + kp->ru_minflt);
1392 printf_filtered ("Minor faults, children: %s\n", pulongest (value));
1393 value = bfd_get (long_bit, core_bfd,
1394 descdata + kp->ki_rusage + kp->ru_majflt);
1395 printf_filtered ("Major faults (memory page faults): %s\n",
1397 value = bfd_get (long_bit, core_bfd,
1398 descdata + kp->ki_rusage_ch + kp->ru_majflt);
1399 printf_filtered ("Major faults, children: %s\n", pulongest (value));
1400 fbsd_core_fetch_timeval (gdbarch,
1401 descdata + kp->ki_rusage + kp->ru_utime,
1403 printf_filtered ("utime: %s.%06d\n", plongest (sec), (int) value);
1404 fbsd_core_fetch_timeval (gdbarch,
1405 descdata + kp->ki_rusage + kp->ru_stime,
1407 printf_filtered ("stime: %s.%06d\n", plongest (sec), (int) value);
1408 fbsd_core_fetch_timeval (gdbarch,
1409 descdata + kp->ki_rusage_ch + kp->ru_utime,
1411 printf_filtered ("utime, children: %s.%06d\n", plongest (sec), (int) value);
1412 fbsd_core_fetch_timeval (gdbarch,
1413 descdata + kp->ki_rusage_ch + kp->ru_stime,
1415 printf_filtered ("stime, children: %s.%06d\n", plongest (sec), (int) value);
1416 printf_filtered ("'nice' value: %d\n",
1417 bfd_get_signed_8 (core_bfd, descdata + kp->ki_nice));
1418 fbsd_core_fetch_timeval (gdbarch, descdata + kp->ki_start, sec, value);
1419 printf_filtered ("Start time: %s.%06d\n", plongest (sec), (int) value);
1420 printf_filtered ("Virtual memory size: %s kB\n",
1421 pulongest (bfd_get (addr_bit, core_bfd,
1422 descdata + kp->ki_size) / 1024));
1423 printf_filtered ("Data size: %s pages\n",
1424 pulongest (bfd_get (addr_bit, core_bfd,
1425 descdata + kp->ki_dsize)));
1426 printf_filtered ("Stack size: %s pages\n",
1427 pulongest (bfd_get (addr_bit, core_bfd,
1428 descdata + kp->ki_ssize)));
1429 printf_filtered ("Text size: %s pages\n",
1430 pulongest (bfd_get (addr_bit, core_bfd,
1431 descdata + kp->ki_tsize)));
1432 printf_filtered ("Resident set size: %s pages\n",
1433 pulongest (bfd_get (addr_bit, core_bfd,
1434 descdata + kp->ki_rssize)));
1435 printf_filtered ("Maximum RSS: %s pages\n",
1436 pulongest (bfd_get (long_bit, core_bfd,
1437 descdata + kp->ki_rusage
1439 fbsd_print_sigset ("Ignored Signals", descdata + kp->ki_sigignore);
1440 fbsd_print_sigset ("Caught Signals", descdata + kp->ki_sigcatch);
1443 /* Implement the "core_info_proc" gdbarch method. */
1446 fbsd_core_info_proc (struct gdbarch *gdbarch, const char *args,
1447 enum info_proc_what what)
1449 bool do_cmdline = false;
1450 bool do_cwd = false;
1451 bool do_exe = false;
1452 bool do_files = false;
1453 bool do_mappings = false;
1454 bool do_status = false;
1495 pid = bfd_core_file_pid (core_bfd);
1497 printf_filtered (_("process %d\n"), pid);
1501 const char *cmdline;
1503 cmdline = bfd_core_file_failing_command (core_bfd);
1505 printf_filtered ("cmdline = '%s'\n", cmdline);
1507 warning (_("Command line unavailable"));
1511 gdb::unique_xmalloc_ptr<char> cwd =
1512 fbsd_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_CWD);
1514 printf_filtered ("cwd = '%s'\n", cwd.get ());
1516 warning (_("unable to read current working directory"));
1520 gdb::unique_xmalloc_ptr<char> exe =
1521 fbsd_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_TEXT);
1523 printf_filtered ("exe = '%s'\n", exe.get ());
1525 warning (_("unable to read executable path name"));
1528 fbsd_core_info_proc_files (gdbarch);
1530 fbsd_core_info_proc_mappings (gdbarch);
1532 fbsd_core_info_proc_status (gdbarch);
1535 /* Print descriptions of FreeBSD-specific AUXV entries to FILE. */
1538 fbsd_print_auxv_entry (struct gdbarch *gdbarch, struct ui_file *file,
1539 CORE_ADDR type, CORE_ADDR val)
1541 const char *name = "???";
1542 const char *description = "";
1543 enum auxv_format format = AUXV_FORMAT_HEX;
1562 default_print_auxv_entry (gdbarch, file, type, val);
1564 #define _TAGNAME(tag) #tag
1565 #define TAGNAME(tag) _TAGNAME(AT_##tag)
1566 #define TAG(tag, text, kind) \
1567 case AT_FREEBSD_##tag: name = TAGNAME(tag); description = text; format = kind; break
1568 TAG (EXECPATH, _("Executable path"), AUXV_FORMAT_STR);
1569 TAG (CANARY, _("Canary for SSP"), AUXV_FORMAT_HEX);
1570 TAG (CANARYLEN, ("Length of the SSP canary"), AUXV_FORMAT_DEC);
1571 TAG (OSRELDATE, _("OSRELDATE"), AUXV_FORMAT_DEC);
1572 TAG (NCPUS, _("Number of CPUs"), AUXV_FORMAT_DEC);
1573 TAG (PAGESIZES, _("Pagesizes"), AUXV_FORMAT_HEX);
1574 TAG (PAGESIZESLEN, _("Number of pagesizes"), AUXV_FORMAT_DEC);
1575 TAG (TIMEKEEP, _("Pointer to timehands"), AUXV_FORMAT_HEX);
1576 TAG (STACKPROT, _("Initial stack protection"), AUXV_FORMAT_HEX);
1577 TAG (EHDRFLAGS, _("ELF header e_flags"), AUXV_FORMAT_HEX);
1578 TAG (HWCAP, _("Machine-dependent CPU capability hints"), AUXV_FORMAT_HEX);
1579 TAG (HWCAP2, _("Extension of AT_HWCAP"), AUXV_FORMAT_HEX);
1582 fprint_auxv_entry (file, name, description, format, type, val);
1585 /* Implement the "get_siginfo_type" gdbarch method. */
1587 static struct type *
1588 fbsd_get_siginfo_type (struct gdbarch *gdbarch)
1590 struct fbsd_gdbarch_data *fbsd_gdbarch_data;
1591 struct type *int_type, *int32_type, *uint32_type, *long_type, *void_ptr_type;
1592 struct type *uid_type, *pid_type;
1593 struct type *sigval_type, *reason_type;
1594 struct type *siginfo_type;
1597 fbsd_gdbarch_data = get_fbsd_gdbarch_data (gdbarch);
1598 if (fbsd_gdbarch_data->siginfo_type != NULL)
1599 return fbsd_gdbarch_data->siginfo_type;
1601 int_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
1603 int32_type = arch_integer_type (gdbarch, 32, 0, "int32_t");
1604 uint32_type = arch_integer_type (gdbarch, 32, 1, "uint32_t");
1605 long_type = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
1607 void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
1610 sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
1611 TYPE_NAME (sigval_type) = xstrdup ("sigval");
1612 append_composite_type_field (sigval_type, "sival_int", int_type);
1613 append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type);
1616 pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
1617 TYPE_LENGTH (int32_type) * TARGET_CHAR_BIT, "__pid_t");
1618 TYPE_TARGET_TYPE (pid_type) = int32_type;
1619 TYPE_TARGET_STUB (pid_type) = 1;
1622 uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
1623 TYPE_LENGTH (uint32_type) * TARGET_CHAR_BIT,
1625 TYPE_TARGET_TYPE (uid_type) = uint32_type;
1626 TYPE_TARGET_STUB (uid_type) = 1;
1629 reason_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
1632 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1633 append_composite_type_field (type, "si_trapno", int_type);
1634 append_composite_type_field (reason_type, "_fault", type);
1637 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1638 append_composite_type_field (type, "si_timerid", int_type);
1639 append_composite_type_field (type, "si_overrun", int_type);
1640 append_composite_type_field (reason_type, "_timer", type);
1643 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1644 append_composite_type_field (type, "si_mqd", int_type);
1645 append_composite_type_field (reason_type, "_mesgq", type);
1648 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1649 append_composite_type_field (type, "si_band", long_type);
1650 append_composite_type_field (reason_type, "_poll", type);
1653 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1654 append_composite_type_field (type, "__spare1__", long_type);
1655 append_composite_type_field (type, "__spare2__",
1656 init_vector_type (int_type, 7));
1657 append_composite_type_field (reason_type, "__spare__", type);
1659 /* struct siginfo */
1660 siginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1661 TYPE_NAME (siginfo_type) = xstrdup ("siginfo");
1662 append_composite_type_field (siginfo_type, "si_signo", int_type);
1663 append_composite_type_field (siginfo_type, "si_errno", int_type);
1664 append_composite_type_field (siginfo_type, "si_code", int_type);
1665 append_composite_type_field (siginfo_type, "si_pid", pid_type);
1666 append_composite_type_field (siginfo_type, "si_uid", uid_type);
1667 append_composite_type_field (siginfo_type, "si_status", int_type);
1668 append_composite_type_field (siginfo_type, "si_addr", void_ptr_type);
1669 append_composite_type_field (siginfo_type, "si_value", sigval_type);
1670 append_composite_type_field (siginfo_type, "_reason", reason_type);
1672 fbsd_gdbarch_data->siginfo_type = siginfo_type;
1674 return siginfo_type;
1677 /* Implement the "gdb_signal_from_target" gdbarch method. */
1679 static enum gdb_signal
1680 fbsd_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
1685 return GDB_SIGNAL_0;
1687 case FREEBSD_SIGHUP:
1688 return GDB_SIGNAL_HUP;
1690 case FREEBSD_SIGINT:
1691 return GDB_SIGNAL_INT;
1693 case FREEBSD_SIGQUIT:
1694 return GDB_SIGNAL_QUIT;
1696 case FREEBSD_SIGILL:
1697 return GDB_SIGNAL_ILL;
1699 case FREEBSD_SIGTRAP:
1700 return GDB_SIGNAL_TRAP;
1702 case FREEBSD_SIGABRT:
1703 return GDB_SIGNAL_ABRT;
1705 case FREEBSD_SIGEMT:
1706 return GDB_SIGNAL_EMT;
1708 case FREEBSD_SIGFPE:
1709 return GDB_SIGNAL_FPE;
1711 case FREEBSD_SIGKILL:
1712 return GDB_SIGNAL_KILL;
1714 case FREEBSD_SIGBUS:
1715 return GDB_SIGNAL_BUS;
1717 case FREEBSD_SIGSEGV:
1718 return GDB_SIGNAL_SEGV;
1720 case FREEBSD_SIGSYS:
1721 return GDB_SIGNAL_SYS;
1723 case FREEBSD_SIGPIPE:
1724 return GDB_SIGNAL_PIPE;
1726 case FREEBSD_SIGALRM:
1727 return GDB_SIGNAL_ALRM;
1729 case FREEBSD_SIGTERM:
1730 return GDB_SIGNAL_TERM;
1732 case FREEBSD_SIGURG:
1733 return GDB_SIGNAL_URG;
1735 case FREEBSD_SIGSTOP:
1736 return GDB_SIGNAL_STOP;
1738 case FREEBSD_SIGTSTP:
1739 return GDB_SIGNAL_TSTP;
1741 case FREEBSD_SIGCONT:
1742 return GDB_SIGNAL_CONT;
1744 case FREEBSD_SIGCHLD:
1745 return GDB_SIGNAL_CHLD;
1747 case FREEBSD_SIGTTIN:
1748 return GDB_SIGNAL_TTIN;
1750 case FREEBSD_SIGTTOU:
1751 return GDB_SIGNAL_TTOU;
1754 return GDB_SIGNAL_IO;
1756 case FREEBSD_SIGXCPU:
1757 return GDB_SIGNAL_XCPU;
1759 case FREEBSD_SIGXFSZ:
1760 return GDB_SIGNAL_XFSZ;
1762 case FREEBSD_SIGVTALRM:
1763 return GDB_SIGNAL_VTALRM;
1765 case FREEBSD_SIGPROF:
1766 return GDB_SIGNAL_PROF;
1768 case FREEBSD_SIGWINCH:
1769 return GDB_SIGNAL_WINCH;
1771 case FREEBSD_SIGINFO:
1772 return GDB_SIGNAL_INFO;
1774 case FREEBSD_SIGUSR1:
1775 return GDB_SIGNAL_USR1;
1777 case FREEBSD_SIGUSR2:
1778 return GDB_SIGNAL_USR2;
1780 /* SIGTHR is the same as SIGLWP on FreeBSD. */
1781 case FREEBSD_SIGTHR:
1782 return GDB_SIGNAL_LWP;
1784 case FREEBSD_SIGLIBRT:
1785 return GDB_SIGNAL_LIBRT;
1788 if (signal >= FREEBSD_SIGRTMIN && signal <= FREEBSD_SIGRTMAX)
1790 int offset = signal - FREEBSD_SIGRTMIN;
1792 return (enum gdb_signal) ((int) GDB_SIGNAL_REALTIME_65 + offset);
1795 return GDB_SIGNAL_UNKNOWN;
1798 /* Implement the "gdb_signal_to_target" gdbarch method. */
1801 fbsd_gdb_signal_to_target (struct gdbarch *gdbarch,
1802 enum gdb_signal signal)
1809 case GDB_SIGNAL_HUP:
1810 return FREEBSD_SIGHUP;
1812 case GDB_SIGNAL_INT:
1813 return FREEBSD_SIGINT;
1815 case GDB_SIGNAL_QUIT:
1816 return FREEBSD_SIGQUIT;
1818 case GDB_SIGNAL_ILL:
1819 return FREEBSD_SIGILL;
1821 case GDB_SIGNAL_TRAP:
1822 return FREEBSD_SIGTRAP;
1824 case GDB_SIGNAL_ABRT:
1825 return FREEBSD_SIGABRT;
1827 case GDB_SIGNAL_EMT:
1828 return FREEBSD_SIGEMT;
1830 case GDB_SIGNAL_FPE:
1831 return FREEBSD_SIGFPE;
1833 case GDB_SIGNAL_KILL:
1834 return FREEBSD_SIGKILL;
1836 case GDB_SIGNAL_BUS:
1837 return FREEBSD_SIGBUS;
1839 case GDB_SIGNAL_SEGV:
1840 return FREEBSD_SIGSEGV;
1842 case GDB_SIGNAL_SYS:
1843 return FREEBSD_SIGSYS;
1845 case GDB_SIGNAL_PIPE:
1846 return FREEBSD_SIGPIPE;
1848 case GDB_SIGNAL_ALRM:
1849 return FREEBSD_SIGALRM;
1851 case GDB_SIGNAL_TERM:
1852 return FREEBSD_SIGTERM;
1854 case GDB_SIGNAL_URG:
1855 return FREEBSD_SIGURG;
1857 case GDB_SIGNAL_STOP:
1858 return FREEBSD_SIGSTOP;
1860 case GDB_SIGNAL_TSTP:
1861 return FREEBSD_SIGTSTP;
1863 case GDB_SIGNAL_CONT:
1864 return FREEBSD_SIGCONT;
1866 case GDB_SIGNAL_CHLD:
1867 return FREEBSD_SIGCHLD;
1869 case GDB_SIGNAL_TTIN:
1870 return FREEBSD_SIGTTIN;
1872 case GDB_SIGNAL_TTOU:
1873 return FREEBSD_SIGTTOU;
1876 return FREEBSD_SIGIO;
1878 case GDB_SIGNAL_XCPU:
1879 return FREEBSD_SIGXCPU;
1881 case GDB_SIGNAL_XFSZ:
1882 return FREEBSD_SIGXFSZ;
1884 case GDB_SIGNAL_VTALRM:
1885 return FREEBSD_SIGVTALRM;
1887 case GDB_SIGNAL_PROF:
1888 return FREEBSD_SIGPROF;
1890 case GDB_SIGNAL_WINCH:
1891 return FREEBSD_SIGWINCH;
1893 case GDB_SIGNAL_INFO:
1894 return FREEBSD_SIGINFO;
1896 case GDB_SIGNAL_USR1:
1897 return FREEBSD_SIGUSR1;
1899 case GDB_SIGNAL_USR2:
1900 return FREEBSD_SIGUSR2;
1902 case GDB_SIGNAL_LWP:
1903 return FREEBSD_SIGTHR;
1905 case GDB_SIGNAL_LIBRT:
1906 return FREEBSD_SIGLIBRT;
1909 if (signal >= GDB_SIGNAL_REALTIME_65
1910 && signal <= GDB_SIGNAL_REALTIME_126)
1912 int offset = signal - GDB_SIGNAL_REALTIME_65;
1914 return FREEBSD_SIGRTMIN + offset;
1920 /* Implement the "get_syscall_number" gdbarch method. */
1923 fbsd_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread)
1926 /* FreeBSD doesn't use gdbarch_get_syscall_number since FreeBSD
1927 native targets fetch the system call number from the
1928 'pl_syscall_code' member of struct ptrace_lwpinfo in fbsd_wait.
1929 However, system call catching requires this function to be
1932 internal_error (__FILE__, __LINE__, _("fbsd_get_sycall_number called"));
1935 /* To be called from GDB_OSABI_FREEBSD handlers. */
1938 fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1940 set_gdbarch_core_pid_to_str (gdbarch, fbsd_core_pid_to_str);
1941 set_gdbarch_core_thread_name (gdbarch, fbsd_core_thread_name);
1942 set_gdbarch_core_xfer_siginfo (gdbarch, fbsd_core_xfer_siginfo);
1943 set_gdbarch_make_corefile_notes (gdbarch, fbsd_make_corefile_notes);
1944 set_gdbarch_core_info_proc (gdbarch, fbsd_core_info_proc);
1945 set_gdbarch_print_auxv_entry (gdbarch, fbsd_print_auxv_entry);
1946 set_gdbarch_get_siginfo_type (gdbarch, fbsd_get_siginfo_type);
1947 set_gdbarch_gdb_signal_from_target (gdbarch, fbsd_gdb_signal_from_target);
1948 set_gdbarch_gdb_signal_to_target (gdbarch, fbsd_gdb_signal_to_target);
1950 /* `catch syscall' */
1951 set_xml_syscall_file_name (gdbarch, "syscalls/freebsd.xml");
1952 set_gdbarch_get_syscall_number (gdbarch, fbsd_get_syscall_number);
1956 _initialize_fbsd_tdep (void)
1958 fbsd_gdbarch_data_handle =
1959 gdbarch_data_register_post_init (init_fbsd_gdbarch_data);