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 /* See fbsd-tdep.h. */
1072 fbsd_info_proc_mappings_header (int addr_bit)
1074 printf_filtered (_("Mapped address spaces:\n\n"));
1077 printf_filtered (" %18s %18s %10s %10s %9s %s\n",
1080 " Size", " Offset", "Flags ", "File");
1084 printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
1087 " Size", " Offset", "Flags ", "File");
1091 /* See fbsd-tdep.h. */
1094 fbsd_info_proc_mappings_entry (int addr_bit, ULONGEST kve_start,
1095 ULONGEST kve_end, ULONGEST kve_offset,
1096 int kve_flags, int kve_protection,
1097 const void *kve_path)
1101 printf_filtered (" %18s %18s %10s %10s %9s %s\n",
1102 hex_string (kve_start),
1103 hex_string (kve_end),
1104 hex_string (kve_end - kve_start),
1105 hex_string (kve_offset),
1106 fbsd_vm_map_entry_flags (kve_flags, kve_protection),
1107 reinterpret_cast<const char *> (kve_path));
1111 printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
1112 hex_string (kve_start),
1113 hex_string (kve_end),
1114 hex_string (kve_end - kve_start),
1115 hex_string (kve_offset),
1116 fbsd_vm_map_entry_flags (kve_flags, kve_protection),
1117 reinterpret_cast<const char *> (kve_path));
1121 /* Implement "info proc mappings" for a corefile. */
1124 fbsd_core_info_proc_mappings (struct gdbarch *gdbarch)
1127 unsigned char *descdata, *descend;
1130 section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.vmmap");
1131 if (section == NULL)
1133 warning (_("unable to find mappings in core file"));
1137 note_size = bfd_get_section_size (section);
1139 error (_("malformed core note - too short for header"));
1141 gdb::def_vector<unsigned char> contents (note_size);
1142 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
1144 error (_("could not get core note contents"));
1146 descdata = contents.data ();
1147 descend = descdata + note_size;
1149 /* Skip over the structure size. */
1152 fbsd_info_proc_mappings_header (gdbarch_addr_bit (gdbarch));
1153 while (descdata + KVE_PATH < descend)
1155 ULONGEST structsize = bfd_get_32 (core_bfd, descdata + KVE_STRUCTSIZE);
1156 if (structsize < KVE_PATH)
1157 error (_("malformed core note - vmmap entry too small"));
1159 ULONGEST start = bfd_get_64 (core_bfd, descdata + KVE_START);
1160 ULONGEST end = bfd_get_64 (core_bfd, descdata + KVE_END);
1161 ULONGEST offset = bfd_get_64 (core_bfd, descdata + KVE_OFFSET);
1162 LONGEST flags = bfd_get_signed_32 (core_bfd, descdata + KVE_FLAGS);
1163 LONGEST prot = bfd_get_signed_32 (core_bfd, descdata + KVE_PROTECTION);
1164 fbsd_info_proc_mappings_entry (gdbarch_addr_bit (gdbarch), start, end,
1165 offset, flags, prot, descdata + KVE_PATH);
1167 descdata += structsize;
1171 /* Fetch the pathname of a vnode for a single file descriptor from the
1172 file table core note. */
1174 static gdb::unique_xmalloc_ptr<char>
1175 fbsd_core_vnode_path (struct gdbarch *gdbarch, int fd)
1178 unsigned char *descdata, *descend;
1181 section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files");
1182 if (section == NULL)
1185 note_size = bfd_get_section_size (section);
1187 error (_("malformed core note - too short for header"));
1189 gdb::def_vector<unsigned char> contents (note_size);
1190 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
1192 error (_("could not get core note contents"));
1194 descdata = contents.data ();
1195 descend = descdata + note_size;
1197 /* Skip over the structure size. */
1200 while (descdata + KF_PATH < descend)
1202 ULONGEST structsize;
1204 structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE);
1205 if (structsize < KF_PATH)
1206 error (_("malformed core note - file structure too small"));
1208 if (bfd_get_32 (core_bfd, descdata + KF_TYPE) == KINFO_FILE_TYPE_VNODE
1209 && bfd_get_signed_32 (core_bfd, descdata + KF_FD) == fd)
1211 char *path = (char *) descdata + KF_PATH;
1212 return gdb::unique_xmalloc_ptr<char> (xstrdup (path));
1215 descdata += structsize;
1220 /* Helper function to read a struct timeval. */
1223 fbsd_core_fetch_timeval (struct gdbarch *gdbarch, unsigned char *data,
1224 LONGEST &sec, ULONGEST &usec)
1226 if (gdbarch_addr_bit (gdbarch) == 64)
1228 sec = bfd_get_signed_64 (core_bfd, data);
1229 usec = bfd_get_64 (core_bfd, data + 8);
1231 else if (bfd_get_arch (core_bfd) == bfd_arch_i386)
1233 sec = bfd_get_signed_32 (core_bfd, data);
1234 usec = bfd_get_32 (core_bfd, data + 4);
1238 sec = bfd_get_signed_64 (core_bfd, data);
1239 usec = bfd_get_32 (core_bfd, data + 8);
1243 /* Print out the contents of a signal set. */
1246 fbsd_print_sigset (const char *descr, unsigned char *sigset)
1248 printf_filtered ("%s: ", descr);
1249 for (int i = 0; i < SIG_WORDS; i++)
1250 printf_filtered ("%08x ",
1251 (unsigned int) bfd_get_32 (core_bfd, sigset + i * 4));
1252 printf_filtered ("\n");
1255 /* Implement "info proc status" for a corefile. */
1258 fbsd_core_info_proc_status (struct gdbarch *gdbarch)
1260 const struct kinfo_proc_layout *kp;
1262 unsigned char *descdata;
1263 int addr_bit, long_bit;
1268 section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.proc");
1269 if (section == NULL)
1271 warning (_("unable to find process info in core file"));
1275 addr_bit = gdbarch_addr_bit (gdbarch);
1277 kp = &kinfo_proc_layout_64;
1278 else if (bfd_get_arch (core_bfd) == bfd_arch_i386)
1279 kp = &kinfo_proc_layout_i386;
1281 kp = &kinfo_proc_layout_32;
1282 long_bit = gdbarch_long_bit (gdbarch);
1285 * Ensure that the note is large enough for all of the fields fetched
1286 * by this function. In particular, the note must contain the 32-bit
1287 * structure size, then it must be long enough to access the last
1288 * field used (ki_rusage_ch.ru_majflt) which is the size of a long.
1290 note_size = bfd_get_section_size (section);
1291 if (note_size < (4 + kp->ki_rusage_ch + kp->ru_majflt
1292 + long_bit / TARGET_CHAR_BIT))
1293 error (_("malformed core note - too short"));
1295 gdb::def_vector<unsigned char> contents (note_size);
1296 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
1298 error (_("could not get core note contents"));
1300 descdata = contents.data ();
1302 /* Skip over the structure size. */
1305 /* Verify 'ki_layout' is 0. */
1306 if (bfd_get_32 (core_bfd, descdata + kp->ki_layout) != 0)
1308 warning (_("unsupported process information in core file"));
1312 printf_filtered ("Name: %.19s\n", descdata + kp->ki_comm);
1313 printf_filtered ("Process ID: %s\n",
1314 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pid)));
1315 printf_filtered ("Parent process: %s\n",
1316 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ppid)));
1317 printf_filtered ("Process group: %s\n",
1318 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pgid)));
1319 printf_filtered ("Session id: %s\n",
1320 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_sid)));
1322 /* FreeBSD 12.0 and later store a 64-bit dev_t at 'ki_tdev'. Older
1323 kernels store a 32-bit dev_t at 'ki_tdev_freebsd11'. In older
1324 kernels the 64-bit 'ki_tdev' field is in a reserved section of
1325 the structure that is cleared to zero. Assume that a zero value
1326 in ki_tdev indicates a core dump from an older kernel and use the
1327 value in 'ki_tdev_freebsd11' instead. */
1328 value = bfd_get_64 (core_bfd, descdata + kp->ki_tdev);
1330 value = bfd_get_32 (core_bfd, descdata + kp->ki_tdev_freebsd11);
1331 printf_filtered ("TTY: %s\n", pulongest (value));
1332 printf_filtered ("TTY owner process group: %s\n",
1333 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_tpgid)));
1334 printf_filtered ("User IDs (real, effective, saved): %s %s %s\n",
1335 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ruid)),
1336 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_uid)),
1337 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svuid)));
1338 printf_filtered ("Group IDs (real, effective, saved): %s %s %s\n",
1339 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_rgid)),
1340 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_groups)),
1341 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svgid)));
1342 printf_filtered ("Groups: ");
1343 uint16_t ngroups = bfd_get_16 (core_bfd, descdata + kp->ki_ngroups);
1344 for (int i = 0; i < ngroups; i++)
1345 printf_filtered ("%s ",
1346 pulongest (bfd_get_32 (core_bfd,
1347 descdata + kp->ki_groups + i * 4)));
1348 printf_filtered ("\n");
1349 value = bfd_get (long_bit, core_bfd,
1350 descdata + kp->ki_rusage + kp->ru_minflt);
1351 printf_filtered ("Minor faults (no memory page): %s\n", pulongest (value));
1352 value = bfd_get (long_bit, core_bfd,
1353 descdata + kp->ki_rusage_ch + kp->ru_minflt);
1354 printf_filtered ("Minor faults, children: %s\n", pulongest (value));
1355 value = bfd_get (long_bit, core_bfd,
1356 descdata + kp->ki_rusage + kp->ru_majflt);
1357 printf_filtered ("Major faults (memory page faults): %s\n",
1359 value = bfd_get (long_bit, core_bfd,
1360 descdata + kp->ki_rusage_ch + kp->ru_majflt);
1361 printf_filtered ("Major faults, children: %s\n", pulongest (value));
1362 fbsd_core_fetch_timeval (gdbarch,
1363 descdata + kp->ki_rusage + kp->ru_utime,
1365 printf_filtered ("utime: %s.%06d\n", plongest (sec), (int) value);
1366 fbsd_core_fetch_timeval (gdbarch,
1367 descdata + kp->ki_rusage + kp->ru_stime,
1369 printf_filtered ("stime: %s.%06d\n", plongest (sec), (int) value);
1370 fbsd_core_fetch_timeval (gdbarch,
1371 descdata + kp->ki_rusage_ch + kp->ru_utime,
1373 printf_filtered ("utime, children: %s.%06d\n", plongest (sec), (int) value);
1374 fbsd_core_fetch_timeval (gdbarch,
1375 descdata + kp->ki_rusage_ch + kp->ru_stime,
1377 printf_filtered ("stime, children: %s.%06d\n", plongest (sec), (int) value);
1378 printf_filtered ("'nice' value: %d\n",
1379 bfd_get_signed_8 (core_bfd, descdata + kp->ki_nice));
1380 fbsd_core_fetch_timeval (gdbarch, descdata + kp->ki_start, sec, value);
1381 printf_filtered ("Start time: %s.%06d\n", plongest (sec), (int) value);
1382 printf_filtered ("Virtual memory size: %s kB\n",
1383 pulongest (bfd_get (addr_bit, core_bfd,
1384 descdata + kp->ki_size) / 1024));
1385 printf_filtered ("Data size: %s pages\n",
1386 pulongest (bfd_get (addr_bit, core_bfd,
1387 descdata + kp->ki_dsize)));
1388 printf_filtered ("Stack size: %s pages\n",
1389 pulongest (bfd_get (addr_bit, core_bfd,
1390 descdata + kp->ki_ssize)));
1391 printf_filtered ("Text size: %s pages\n",
1392 pulongest (bfd_get (addr_bit, core_bfd,
1393 descdata + kp->ki_tsize)));
1394 printf_filtered ("Resident set size: %s pages\n",
1395 pulongest (bfd_get (addr_bit, core_bfd,
1396 descdata + kp->ki_rssize)));
1397 printf_filtered ("Maximum RSS: %s pages\n",
1398 pulongest (bfd_get (long_bit, core_bfd,
1399 descdata + kp->ki_rusage
1401 fbsd_print_sigset ("Ignored Signals", descdata + kp->ki_sigignore);
1402 fbsd_print_sigset ("Caught Signals", descdata + kp->ki_sigcatch);
1405 /* Implement the "core_info_proc" gdbarch method. */
1408 fbsd_core_info_proc (struct gdbarch *gdbarch, const char *args,
1409 enum info_proc_what what)
1411 bool do_cmdline = false;
1412 bool do_cwd = false;
1413 bool do_exe = false;
1414 bool do_files = false;
1415 bool do_mappings = false;
1416 bool do_status = false;
1457 pid = bfd_core_file_pid (core_bfd);
1459 printf_filtered (_("process %d\n"), pid);
1463 const char *cmdline;
1465 cmdline = bfd_core_file_failing_command (core_bfd);
1467 printf_filtered ("cmdline = '%s'\n", cmdline);
1469 warning (_("Command line unavailable"));
1473 gdb::unique_xmalloc_ptr<char> cwd =
1474 fbsd_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_CWD);
1476 printf_filtered ("cwd = '%s'\n", cwd.get ());
1478 warning (_("unable to read current working directory"));
1482 gdb::unique_xmalloc_ptr<char> exe =
1483 fbsd_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_TEXT);
1485 printf_filtered ("exe = '%s'\n", exe.get ());
1487 warning (_("unable to read executable path name"));
1490 fbsd_core_info_proc_files (gdbarch);
1492 fbsd_core_info_proc_mappings (gdbarch);
1494 fbsd_core_info_proc_status (gdbarch);
1497 /* Print descriptions of FreeBSD-specific AUXV entries to FILE. */
1500 fbsd_print_auxv_entry (struct gdbarch *gdbarch, struct ui_file *file,
1501 CORE_ADDR type, CORE_ADDR val)
1504 const char *description;
1505 enum auxv_format format;
1509 #define _TAGNAME(tag) #tag
1510 #define TAGNAME(tag) _TAGNAME(AT_##tag)
1511 #define TAG(tag, text, kind) \
1512 case AT_FREEBSD_##tag: name = TAGNAME(tag); description = text; format = kind; break
1513 TAG (EXECPATH, _("Executable path"), AUXV_FORMAT_STR);
1514 TAG (CANARY, _("Canary for SSP"), AUXV_FORMAT_HEX);
1515 TAG (CANARYLEN, ("Length of the SSP canary"), AUXV_FORMAT_DEC);
1516 TAG (OSRELDATE, _("OSRELDATE"), AUXV_FORMAT_DEC);
1517 TAG (NCPUS, _("Number of CPUs"), AUXV_FORMAT_DEC);
1518 TAG (PAGESIZES, _("Pagesizes"), AUXV_FORMAT_HEX);
1519 TAG (PAGESIZESLEN, _("Number of pagesizes"), AUXV_FORMAT_DEC);
1520 TAG (TIMEKEEP, _("Pointer to timehands"), AUXV_FORMAT_HEX);
1521 TAG (STACKPROT, _("Initial stack protection"), AUXV_FORMAT_HEX);
1522 TAG (EHDRFLAGS, _("ELF header e_flags"), AUXV_FORMAT_HEX);
1523 TAG (HWCAP, _("Machine-dependent CPU capability hints"), AUXV_FORMAT_HEX);
1525 default_print_auxv_entry (gdbarch, file, type, val);
1529 fprint_auxv_entry (file, name, description, format, type, val);
1532 /* Implement the "get_siginfo_type" gdbarch method. */
1534 static struct type *
1535 fbsd_get_siginfo_type (struct gdbarch *gdbarch)
1537 struct fbsd_gdbarch_data *fbsd_gdbarch_data;
1538 struct type *int_type, *int32_type, *uint32_type, *long_type, *void_ptr_type;
1539 struct type *uid_type, *pid_type;
1540 struct type *sigval_type, *reason_type;
1541 struct type *siginfo_type;
1544 fbsd_gdbarch_data = get_fbsd_gdbarch_data (gdbarch);
1545 if (fbsd_gdbarch_data->siginfo_type != NULL)
1546 return fbsd_gdbarch_data->siginfo_type;
1548 int_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
1550 int32_type = arch_integer_type (gdbarch, 32, 0, "int32_t");
1551 uint32_type = arch_integer_type (gdbarch, 32, 1, "uint32_t");
1552 long_type = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
1554 void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
1557 sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
1558 TYPE_NAME (sigval_type) = xstrdup ("sigval");
1559 append_composite_type_field (sigval_type, "sival_int", int_type);
1560 append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type);
1563 pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
1564 TYPE_LENGTH (int32_type) * TARGET_CHAR_BIT, "__pid_t");
1565 TYPE_TARGET_TYPE (pid_type) = int32_type;
1566 TYPE_TARGET_STUB (pid_type) = 1;
1569 uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
1570 TYPE_LENGTH (uint32_type) * TARGET_CHAR_BIT,
1572 TYPE_TARGET_TYPE (uid_type) = uint32_type;
1573 TYPE_TARGET_STUB (uid_type) = 1;
1576 reason_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
1579 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1580 append_composite_type_field (type, "si_trapno", int_type);
1581 append_composite_type_field (reason_type, "_fault", type);
1584 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1585 append_composite_type_field (type, "si_timerid", int_type);
1586 append_composite_type_field (type, "si_overrun", int_type);
1587 append_composite_type_field (reason_type, "_timer", type);
1590 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1591 append_composite_type_field (type, "si_mqd", int_type);
1592 append_composite_type_field (reason_type, "_mesgq", type);
1595 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1596 append_composite_type_field (type, "si_band", long_type);
1597 append_composite_type_field (reason_type, "_poll", type);
1600 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1601 append_composite_type_field (type, "__spare1__", long_type);
1602 append_composite_type_field (type, "__spare2__",
1603 init_vector_type (int_type, 7));
1604 append_composite_type_field (reason_type, "__spare__", type);
1606 /* struct siginfo */
1607 siginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1608 TYPE_NAME (siginfo_type) = xstrdup ("siginfo");
1609 append_composite_type_field (siginfo_type, "si_signo", int_type);
1610 append_composite_type_field (siginfo_type, "si_errno", int_type);
1611 append_composite_type_field (siginfo_type, "si_code", int_type);
1612 append_composite_type_field (siginfo_type, "si_pid", pid_type);
1613 append_composite_type_field (siginfo_type, "si_uid", uid_type);
1614 append_composite_type_field (siginfo_type, "si_status", int_type);
1615 append_composite_type_field (siginfo_type, "si_addr", void_ptr_type);
1616 append_composite_type_field (siginfo_type, "si_value", sigval_type);
1617 append_composite_type_field (siginfo_type, "_reason", reason_type);
1619 fbsd_gdbarch_data->siginfo_type = siginfo_type;
1621 return siginfo_type;
1624 /* Implement the "get_syscall_number" gdbarch method. */
1627 fbsd_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread)
1630 /* FreeBSD doesn't use gdbarch_get_syscall_number since FreeBSD
1631 native targets fetch the system call number from the
1632 'pl_syscall_code' member of struct ptrace_lwpinfo in fbsd_wait.
1633 However, system call catching requires this function to be
1636 internal_error (__FILE__, __LINE__, _("fbsd_get_sycall_number called"));
1639 /* To be called from GDB_OSABI_FREEBSD handlers. */
1642 fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1644 set_gdbarch_core_pid_to_str (gdbarch, fbsd_core_pid_to_str);
1645 set_gdbarch_core_thread_name (gdbarch, fbsd_core_thread_name);
1646 set_gdbarch_core_xfer_siginfo (gdbarch, fbsd_core_xfer_siginfo);
1647 set_gdbarch_make_corefile_notes (gdbarch, fbsd_make_corefile_notes);
1648 set_gdbarch_core_info_proc (gdbarch, fbsd_core_info_proc);
1649 set_gdbarch_print_auxv_entry (gdbarch, fbsd_print_auxv_entry);
1650 set_gdbarch_get_siginfo_type (gdbarch, fbsd_get_siginfo_type);
1652 /* `catch syscall' */
1653 set_xml_syscall_file_name (gdbarch, "syscalls/freebsd.xml");
1654 set_gdbarch_get_syscall_number (gdbarch, fbsd_get_syscall_number);
1658 _initialize_fbsd_tdep (void)
1660 fbsd_gdbarch_data_handle =
1661 gdbarch_data_register_post_init (init_fbsd_gdbarch_data);