+/* Helper function to generate the file descriptor description for a
+ single open file in 'info proc files'. */
+
+static const char *
+fbsd_file_fd (int kf_fd)
+{
+ switch (kf_fd)
+ {
+ case KINFO_FILE_FD_TYPE_CWD:
+ return "cwd";
+ case KINFO_FILE_FD_TYPE_ROOT:
+ return "root";
+ case KINFO_FILE_FD_TYPE_JAIL:
+ return "jail";
+ case KINFO_FILE_FD_TYPE_TRACE:
+ return "trace";
+ case KINFO_FILE_FD_TYPE_TEXT:
+ return "text";
+ case KINFO_FILE_FD_TYPE_CTTY:
+ return "ctty";
+ default:
+ return int_string (kf_fd, 10, 1, 0, 0);
+ }
+}
+
+/* Helper function to generate the file type for a single open file in
+ 'info proc files'. */
+
+static const char *
+fbsd_file_type (int kf_type, int kf_vnode_type)
+{
+ switch (kf_type)
+ {
+ case KINFO_FILE_TYPE_VNODE:
+ switch (kf_vnode_type)
+ {
+ case KINFO_FILE_VTYPE_VREG:
+ return "file";
+ case KINFO_FILE_VTYPE_VDIR:
+ return "dir";
+ case KINFO_FILE_VTYPE_VCHR:
+ return "chr";
+ case KINFO_FILE_VTYPE_VLNK:
+ return "link";
+ case KINFO_FILE_VTYPE_VSOCK:
+ return "socket";
+ case KINFO_FILE_VTYPE_VFIFO:
+ return "fifo";
+ default:
+ {
+ char *str = get_print_cell ();
+
+ xsnprintf (str, PRINT_CELL_SIZE, "vn:%d", kf_vnode_type);
+ return str;
+ }
+ }
+ case KINFO_FILE_TYPE_SOCKET:
+ return "socket";
+ case KINFO_FILE_TYPE_PIPE:
+ return "pipe";
+ case KINFO_FILE_TYPE_FIFO:
+ return "fifo";
+ case KINFO_FILE_TYPE_KQUEUE:
+ return "kqueue";
+ case KINFO_FILE_TYPE_CRYPTO:
+ return "crypto";
+ case KINFO_FILE_TYPE_MQUEUE:
+ return "mqueue";
+ case KINFO_FILE_TYPE_SHM:
+ return "shm";
+ case KINFO_FILE_TYPE_SEM:
+ return "sem";
+ case KINFO_FILE_TYPE_PTS:
+ return "pts";
+ case KINFO_FILE_TYPE_PROCDESC:
+ return "proc";
+ default:
+ return int_string (kf_type, 10, 1, 0, 0);
+ }
+}
+
+/* Helper function to generate the file flags for a single open file in
+ 'info proc files'. */
+
+static const char *
+fbsd_file_flags (int kf_flags)
+{
+ static char file_flags[10];
+
+ file_flags[0] = (kf_flags & KINFO_FILE_FLAG_READ) ? 'r' : '-';
+ file_flags[1] = (kf_flags & KINFO_FILE_FLAG_WRITE) ? 'w' : '-';
+ file_flags[2] = (kf_flags & KINFO_FILE_FLAG_EXEC) ? 'x' : '-';
+ file_flags[3] = (kf_flags & KINFO_FILE_FLAG_APPEND) ? 'a' : '-';
+ file_flags[4] = (kf_flags & KINFO_FILE_FLAG_ASYNC) ? 's' : '-';
+ file_flags[5] = (kf_flags & KINFO_FILE_FLAG_FSYNC) ? 'f' : '-';
+ file_flags[6] = (kf_flags & KINFO_FILE_FLAG_NONBLOCK) ? 'n' : '-';
+ file_flags[7] = (kf_flags & KINFO_FILE_FLAG_DIRECT) ? 'd' : '-';
+ file_flags[8] = (kf_flags & KINFO_FILE_FLAG_HASLOCK) ? 'l' : '-';
+ file_flags[9] = '\0';
+
+ return file_flags;
+}
+
+/* Helper function to generate the name of an IP protocol. */
+
+static const char *
+fbsd_ipproto (int protocol)
+{
+ switch (protocol)
+ {
+ case FBSD_IPPROTO_ICMP:
+ return "icmp";
+ case FBSD_IPPROTO_TCP:
+ return "tcp";
+ case FBSD_IPPROTO_UDP:
+ return "udp";
+ case FBSD_IPPROTO_SCTP:
+ return "sctp";
+ default:
+ {
+ char *str = get_print_cell ();
+
+ xsnprintf (str, PRINT_CELL_SIZE, "ip<%d>", protocol);
+ return str;
+ }
+ }
+}
+
+/* Helper function to print out an IPv4 socket address. */
+
+static void
+fbsd_print_sockaddr_in (const void *sockaddr)
+{
+ const struct fbsd_sockaddr_in *sin =
+ reinterpret_cast<const struct fbsd_sockaddr_in *> (sockaddr);
+ char buf[INET_ADDRSTRLEN];
+
+ if (inet_ntop (AF_INET, sin->sin_addr, buf, sizeof buf) == nullptr)
+ error (_("Failed to format IPv4 address"));
+ printf_filtered ("%s:%u", buf,
+ (sin->sin_port[0] << 8) | sin->sin_port[1]);
+}
+
+/* Helper function to print out an IPv6 socket address. */
+
+static void
+fbsd_print_sockaddr_in6 (const void *sockaddr)
+{
+ const struct fbsd_sockaddr_in6 *sin6 =
+ reinterpret_cast<const struct fbsd_sockaddr_in6 *> (sockaddr);
+ char buf[INET6_ADDRSTRLEN];
+
+ if (inet_ntop (AF_INET6, sin6->sin6_addr, buf, sizeof buf) == nullptr)
+ error (_("Failed to format IPv6 address"));
+ printf_filtered ("%s.%u", buf,
+ (sin6->sin6_port[0] << 8) | sin6->sin6_port[1]);
+}
+
+/* See fbsd-tdep.h. */
+
+void
+fbsd_info_proc_files_header ()
+{
+ printf_filtered (_("Open files:\n\n"));
+ printf_filtered (" %6s %6s %10s %9s %s\n",
+ "FD", "Type", "Offset", "Flags ", "Name");
+}
+
+/* See fbsd-tdep.h. */
+
+void
+fbsd_info_proc_files_entry (int kf_type, int kf_fd, int kf_flags,
+ LONGEST kf_offset, int kf_vnode_type,
+ int kf_sock_domain, int kf_sock_type,
+ int kf_sock_protocol, const void *kf_sa_local,
+ const void *kf_sa_peer, const void *kf_path)
+{
+ printf_filtered (" %6s %6s %10s %8s ",
+ fbsd_file_fd (kf_fd),
+ fbsd_file_type (kf_type, kf_vnode_type),
+ kf_offset > -1 ? hex_string (kf_offset) : "-",
+ fbsd_file_flags (kf_flags));
+ if (kf_type == KINFO_FILE_TYPE_SOCKET)
+ {
+ switch (kf_sock_domain)
+ {
+ case FBSD_AF_UNIX:
+ {
+ switch (kf_sock_type)
+ {
+ case FBSD_SOCK_STREAM:
+ printf_filtered ("unix stream:");
+ break;
+ case FBSD_SOCK_DGRAM:
+ printf_filtered ("unix dgram:");
+ break;
+ case FBSD_SOCK_SEQPACKET:
+ printf_filtered ("unix seqpacket:");
+ break;
+ default:
+ printf_filtered ("unix <%d>:", kf_sock_type);
+ break;
+ }
+
+ /* For local sockets, print out the first non-nul path
+ rather than both paths. */
+ const struct fbsd_sockaddr_un *saddr_un
+ = reinterpret_cast<const struct fbsd_sockaddr_un *> (kf_sa_local);
+ if (saddr_un->sun_path[0] == 0)
+ saddr_un = reinterpret_cast<const struct fbsd_sockaddr_un *>
+ (kf_sa_peer);
+ printf_filtered ("%s", saddr_un->sun_path);
+ break;
+ }
+ case FBSD_AF_INET:
+ printf_filtered ("%s4 ", fbsd_ipproto (kf_sock_protocol));
+ fbsd_print_sockaddr_in (kf_sa_local);
+ printf_filtered (" -> ");
+ fbsd_print_sockaddr_in (kf_sa_peer);
+ break;
+ case FBSD_AF_INET6:
+ printf_filtered ("%s6 ", fbsd_ipproto (kf_sock_protocol));
+ fbsd_print_sockaddr_in6 (kf_sa_local);
+ printf_filtered (" -> ");
+ fbsd_print_sockaddr_in6 (kf_sa_peer);
+ break;
+ }
+ }
+ else
+ printf_filtered ("%s", reinterpret_cast<const char *> (kf_path));
+ printf_filtered ("\n");
+}
+
+/* Implement "info proc files" for a corefile. */
+
+static void
+fbsd_core_info_proc_files (struct gdbarch *gdbarch)
+{
+ asection *section
+ = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files");
+ if (section == NULL)
+ {
+ warning (_("unable to find open files in core file"));
+ return;
+ }
+
+ size_t note_size = bfd_section_size (section);
+ if (note_size < 4)
+ error (_("malformed core note - too short for header"));
+
+ gdb::def_vector<unsigned char> contents (note_size);
+ if (!bfd_get_section_contents (core_bfd, section, contents.data (),
+ 0, note_size))
+ error (_("could not get core note contents"));
+
+ unsigned char *descdata = contents.data ();
+ unsigned char *descend = descdata + note_size;
+
+ /* Skip over the structure size. */
+ descdata += 4;
+
+ fbsd_info_proc_files_header ();
+
+ while (descdata + KF_PATH < descend)
+ {
+ ULONGEST structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE);
+ if (structsize < KF_PATH)
+ error (_("malformed core note - file structure too small"));
+
+ LONGEST type = bfd_get_signed_32 (core_bfd, descdata + KF_TYPE);
+ LONGEST fd = bfd_get_signed_32 (core_bfd, descdata + KF_FD);
+ LONGEST flags = bfd_get_signed_32 (core_bfd, descdata + KF_FLAGS);
+ LONGEST offset = bfd_get_signed_64 (core_bfd, descdata + KF_OFFSET);
+ LONGEST vnode_type = bfd_get_signed_32 (core_bfd,
+ descdata + KF_VNODE_TYPE);
+ LONGEST sock_domain = bfd_get_signed_32 (core_bfd,
+ descdata + KF_SOCK_DOMAIN);
+ LONGEST sock_type = bfd_get_signed_32 (core_bfd, descdata + KF_SOCK_TYPE);
+ LONGEST sock_protocol = bfd_get_signed_32 (core_bfd,
+ descdata + KF_SOCK_PROTOCOL);
+ fbsd_info_proc_files_entry (type, fd, flags, offset, vnode_type,
+ sock_domain, sock_type, sock_protocol,
+ descdata + KF_SA_LOCAL, descdata + KF_SA_PEER,
+ descdata + KF_PATH);
+
+ descdata += structsize;
+ }
+}
+
+/* Helper function to generate mappings flags for a single VM map
+ entry in 'info proc mappings'. */
+
+static const char *
+fbsd_vm_map_entry_flags (int kve_flags, int kve_protection)
+{
+ static char vm_flags[9];
+
+ vm_flags[0] = (kve_protection & KINFO_VME_PROT_READ) ? 'r' : '-';
+ vm_flags[1] = (kve_protection & KINFO_VME_PROT_WRITE) ? 'w' : '-';
+ vm_flags[2] = (kve_protection & KINFO_VME_PROT_EXEC) ? 'x' : '-';
+ vm_flags[3] = ' ';
+ vm_flags[4] = (kve_flags & KINFO_VME_FLAG_COW) ? 'C' : '-';
+ vm_flags[5] = (kve_flags & KINFO_VME_FLAG_NEEDS_COPY) ? 'N' : '-';
+ vm_flags[6] = (kve_flags & KINFO_VME_FLAG_SUPER) ? 'S' : '-';
+ vm_flags[7] = (kve_flags & KINFO_VME_FLAG_GROWS_UP) ? 'U'
+ : (kve_flags & KINFO_VME_FLAG_GROWS_DOWN) ? 'D' : '-';
+ vm_flags[8] = '\0';
+
+ return vm_flags;
+}
+
+/* See fbsd-tdep.h. */
+
+void
+fbsd_info_proc_mappings_header (int addr_bit)
+{
+ printf_filtered (_("Mapped address spaces:\n\n"));
+ if (addr_bit == 64)
+ {
+ printf_filtered (" %18s %18s %10s %10s %9s %s\n",
+ "Start Addr",
+ " End Addr",
+ " Size", " Offset", "Flags ", "File");
+ }
+ else
+ {
+ printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
+ "Start Addr",
+ " End Addr",
+ " Size", " Offset", "Flags ", "File");
+ }
+}
+
+/* See fbsd-tdep.h. */
+
+void
+fbsd_info_proc_mappings_entry (int addr_bit, ULONGEST kve_start,
+ ULONGEST kve_end, ULONGEST kve_offset,
+ int kve_flags, int kve_protection,
+ const void *kve_path)
+{
+ if (addr_bit == 64)
+ {
+ printf_filtered (" %18s %18s %10s %10s %9s %s\n",
+ hex_string (kve_start),
+ hex_string (kve_end),
+ hex_string (kve_end - kve_start),
+ hex_string (kve_offset),
+ fbsd_vm_map_entry_flags (kve_flags, kve_protection),
+ reinterpret_cast<const char *> (kve_path));
+ }
+ else
+ {
+ printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
+ hex_string (kve_start),
+ hex_string (kve_end),
+ hex_string (kve_end - kve_start),
+ hex_string (kve_offset),
+ fbsd_vm_map_entry_flags (kve_flags, kve_protection),
+ reinterpret_cast<const char *> (kve_path));
+ }
+}
+
+/* Implement "info proc mappings" for a corefile. */
+
+static void
+fbsd_core_info_proc_mappings (struct gdbarch *gdbarch)
+{
+ asection *section;
+ unsigned char *descdata, *descend;
+ size_t note_size;
+
+ section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.vmmap");
+ if (section == NULL)
+ {
+ warning (_("unable to find mappings in core file"));
+ return;
+ }
+
+ note_size = bfd_section_size (section);
+ if (note_size < 4)
+ error (_("malformed core note - too short for header"));
+
+ gdb::def_vector<unsigned char> contents (note_size);
+ if (!bfd_get_section_contents (core_bfd, section, contents.data (),
+ 0, note_size))
+ error (_("could not get core note contents"));
+
+ descdata = contents.data ();
+ descend = descdata + note_size;
+
+ /* Skip over the structure size. */
+ descdata += 4;
+
+ fbsd_info_proc_mappings_header (gdbarch_addr_bit (gdbarch));
+ while (descdata + KVE_PATH < descend)
+ {
+ ULONGEST structsize = bfd_get_32 (core_bfd, descdata + KVE_STRUCTSIZE);
+ if (structsize < KVE_PATH)
+ error (_("malformed core note - vmmap entry too small"));
+
+ ULONGEST start = bfd_get_64 (core_bfd, descdata + KVE_START);
+ ULONGEST end = bfd_get_64 (core_bfd, descdata + KVE_END);
+ ULONGEST offset = bfd_get_64 (core_bfd, descdata + KVE_OFFSET);
+ LONGEST flags = bfd_get_signed_32 (core_bfd, descdata + KVE_FLAGS);
+ LONGEST prot = bfd_get_signed_32 (core_bfd, descdata + KVE_PROTECTION);
+ fbsd_info_proc_mappings_entry (gdbarch_addr_bit (gdbarch), start, end,
+ offset, flags, prot, descdata + KVE_PATH);
+
+ descdata += structsize;
+ }
+}
+
+/* Fetch the pathname of a vnode for a single file descriptor from the
+ file table core note. */
+
+static gdb::unique_xmalloc_ptr<char>
+fbsd_core_vnode_path (struct gdbarch *gdbarch, int fd)
+{
+ asection *section;
+ unsigned char *descdata, *descend;
+ size_t note_size;
+
+ section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files");
+ if (section == NULL)
+ return nullptr;
+
+ note_size = bfd_section_size (section);
+ if (note_size < 4)
+ error (_("malformed core note - too short for header"));
+
+ gdb::def_vector<unsigned char> contents (note_size);
+ if (!bfd_get_section_contents (core_bfd, section, contents.data (),
+ 0, note_size))
+ error (_("could not get core note contents"));
+
+ descdata = contents.data ();
+ descend = descdata + note_size;
+
+ /* Skip over the structure size. */
+ descdata += 4;
+
+ while (descdata + KF_PATH < descend)
+ {
+ ULONGEST structsize;
+
+ structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE);
+ if (structsize < KF_PATH)
+ error (_("malformed core note - file structure too small"));
+
+ if (bfd_get_32 (core_bfd, descdata + KF_TYPE) == KINFO_FILE_TYPE_VNODE
+ && bfd_get_signed_32 (core_bfd, descdata + KF_FD) == fd)
+ {
+ char *path = (char *) descdata + KF_PATH;
+ return make_unique_xstrdup (path);
+ }
+
+ descdata += structsize;
+ }
+ return nullptr;
+}
+
+/* Helper function to read a struct timeval. */
+
+static void
+fbsd_core_fetch_timeval (struct gdbarch *gdbarch, unsigned char *data,
+ LONGEST &sec, ULONGEST &usec)
+{
+ if (gdbarch_addr_bit (gdbarch) == 64)
+ {
+ sec = bfd_get_signed_64 (core_bfd, data);
+ usec = bfd_get_64 (core_bfd, data + 8);
+ }
+ else if (bfd_get_arch (core_bfd) == bfd_arch_i386)
+ {
+ sec = bfd_get_signed_32 (core_bfd, data);
+ usec = bfd_get_32 (core_bfd, data + 4);
+ }
+ else
+ {
+ sec = bfd_get_signed_64 (core_bfd, data);
+ usec = bfd_get_32 (core_bfd, data + 8);
+ }
+}
+
+/* Print out the contents of a signal set. */
+
+static void
+fbsd_print_sigset (const char *descr, unsigned char *sigset)
+{
+ printf_filtered ("%s: ", descr);
+ for (int i = 0; i < SIG_WORDS; i++)
+ printf_filtered ("%08x ",
+ (unsigned int) bfd_get_32 (core_bfd, sigset + i * 4));
+ printf_filtered ("\n");
+}
+
+/* Implement "info proc status" for a corefile. */
+
+static void
+fbsd_core_info_proc_status (struct gdbarch *gdbarch)
+{
+ const struct kinfo_proc_layout *kp;
+ asection *section;
+ unsigned char *descdata;
+ int addr_bit, long_bit;
+ size_t note_size;
+ ULONGEST value;
+ LONGEST sec;
+
+ section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.proc");
+ if (section == NULL)
+ {
+ warning (_("unable to find process info in core file"));
+ return;
+ }
+
+ addr_bit = gdbarch_addr_bit (gdbarch);
+ if (addr_bit == 64)
+ kp = &kinfo_proc_layout_64;
+ else if (bfd_get_arch (core_bfd) == bfd_arch_i386)
+ kp = &kinfo_proc_layout_i386;
+ else
+ kp = &kinfo_proc_layout_32;
+ long_bit = gdbarch_long_bit (gdbarch);
+
+ /*
+ * Ensure that the note is large enough for all of the fields fetched
+ * by this function. In particular, the note must contain the 32-bit
+ * structure size, then it must be long enough to access the last
+ * field used (ki_rusage_ch.ru_majflt) which is the size of a long.
+ */
+ note_size = bfd_section_size (section);
+ if (note_size < (4 + kp->ki_rusage_ch + kp->ru_majflt
+ + long_bit / TARGET_CHAR_BIT))
+ error (_("malformed core note - too short"));
+
+ gdb::def_vector<unsigned char> contents (note_size);
+ if (!bfd_get_section_contents (core_bfd, section, contents.data (),
+ 0, note_size))
+ error (_("could not get core note contents"));
+
+ descdata = contents.data ();
+
+ /* Skip over the structure size. */
+ descdata += 4;
+
+ /* Verify 'ki_layout' is 0. */
+ if (bfd_get_32 (core_bfd, descdata + kp->ki_layout) != 0)
+ {
+ warning (_("unsupported process information in core file"));
+ return;
+ }
+
+ printf_filtered ("Name: %.19s\n", descdata + kp->ki_comm);
+ printf_filtered ("Process ID: %s\n",
+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pid)));
+ printf_filtered ("Parent process: %s\n",
+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ppid)));
+ printf_filtered ("Process group: %s\n",
+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pgid)));
+ printf_filtered ("Session id: %s\n",
+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_sid)));
+
+ /* FreeBSD 12.0 and later store a 64-bit dev_t at 'ki_tdev'. Older
+ kernels store a 32-bit dev_t at 'ki_tdev_freebsd11'. In older
+ kernels the 64-bit 'ki_tdev' field is in a reserved section of
+ the structure that is cleared to zero. Assume that a zero value
+ in ki_tdev indicates a core dump from an older kernel and use the
+ value in 'ki_tdev_freebsd11' instead. */
+ value = bfd_get_64 (core_bfd, descdata + kp->ki_tdev);
+ if (value == 0)
+ value = bfd_get_32 (core_bfd, descdata + kp->ki_tdev_freebsd11);
+ printf_filtered ("TTY: %s\n", pulongest (value));
+ printf_filtered ("TTY owner process group: %s\n",
+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_tpgid)));
+ printf_filtered ("User IDs (real, effective, saved): %s %s %s\n",
+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ruid)),
+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_uid)),
+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svuid)));
+ printf_filtered ("Group IDs (real, effective, saved): %s %s %s\n",
+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_rgid)),
+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_groups)),
+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svgid)));
+ printf_filtered ("Groups: ");
+ uint16_t ngroups = bfd_get_16 (core_bfd, descdata + kp->ki_ngroups);
+ for (int i = 0; i < ngroups; i++)
+ printf_filtered ("%s ",
+ pulongest (bfd_get_32 (core_bfd,
+ descdata + kp->ki_groups + i * 4)));
+ printf_filtered ("\n");
+ value = bfd_get (long_bit, core_bfd,
+ descdata + kp->ki_rusage + kp->ru_minflt);
+ printf_filtered ("Minor faults (no memory page): %s\n", pulongest (value));
+ value = bfd_get (long_bit, core_bfd,
+ descdata + kp->ki_rusage_ch + kp->ru_minflt);
+ printf_filtered ("Minor faults, children: %s\n", pulongest (value));
+ value = bfd_get (long_bit, core_bfd,
+ descdata + kp->ki_rusage + kp->ru_majflt);
+ printf_filtered ("Major faults (memory page faults): %s\n",
+ pulongest (value));
+ value = bfd_get (long_bit, core_bfd,
+ descdata + kp->ki_rusage_ch + kp->ru_majflt);
+ printf_filtered ("Major faults, children: %s\n", pulongest (value));
+ fbsd_core_fetch_timeval (gdbarch,
+ descdata + kp->ki_rusage + kp->ru_utime,
+ sec, value);
+ printf_filtered ("utime: %s.%06d\n", plongest (sec), (int) value);
+ fbsd_core_fetch_timeval (gdbarch,
+ descdata + kp->ki_rusage + kp->ru_stime,
+ sec, value);
+ printf_filtered ("stime: %s.%06d\n", plongest (sec), (int) value);
+ fbsd_core_fetch_timeval (gdbarch,
+ descdata + kp->ki_rusage_ch + kp->ru_utime,
+ sec, value);
+ printf_filtered ("utime, children: %s.%06d\n", plongest (sec), (int) value);
+ fbsd_core_fetch_timeval (gdbarch,
+ descdata + kp->ki_rusage_ch + kp->ru_stime,
+ sec, value);
+ printf_filtered ("stime, children: %s.%06d\n", plongest (sec), (int) value);
+ printf_filtered ("'nice' value: %d\n",
+ (int) bfd_get_signed_8 (core_bfd, descdata + kp->ki_nice));
+ fbsd_core_fetch_timeval (gdbarch, descdata + kp->ki_start, sec, value);
+ printf_filtered ("Start time: %s.%06d\n", plongest (sec), (int) value);
+ printf_filtered ("Virtual memory size: %s kB\n",
+ pulongest (bfd_get (addr_bit, core_bfd,
+ descdata + kp->ki_size) / 1024));
+ printf_filtered ("Data size: %s pages\n",
+ pulongest (bfd_get (addr_bit, core_bfd,
+ descdata + kp->ki_dsize)));
+ printf_filtered ("Stack size: %s pages\n",
+ pulongest (bfd_get (addr_bit, core_bfd,
+ descdata + kp->ki_ssize)));
+ printf_filtered ("Text size: %s pages\n",
+ pulongest (bfd_get (addr_bit, core_bfd,
+ descdata + kp->ki_tsize)));
+ printf_filtered ("Resident set size: %s pages\n",
+ pulongest (bfd_get (addr_bit, core_bfd,
+ descdata + kp->ki_rssize)));
+ printf_filtered ("Maximum RSS: %s pages\n",
+ pulongest (bfd_get (long_bit, core_bfd,
+ descdata + kp->ki_rusage
+ + kp->ru_maxrss)));
+ fbsd_print_sigset ("Ignored Signals", descdata + kp->ki_sigignore);
+ fbsd_print_sigset ("Caught Signals", descdata + kp->ki_sigcatch);
+}
+
+/* Implement the "core_info_proc" gdbarch method. */
+
+static void
+fbsd_core_info_proc (struct gdbarch *gdbarch, const char *args,
+ enum info_proc_what what)
+{
+ bool do_cmdline = false;
+ bool do_cwd = false;
+ bool do_exe = false;
+ bool do_files = false;
+ bool do_mappings = false;
+ bool do_status = false;
+ int pid;
+
+ switch (what)
+ {
+ case IP_MINIMAL:
+ do_cmdline = true;
+ do_cwd = true;
+ do_exe = true;
+ break;
+ case IP_MAPPINGS:
+ do_mappings = true;
+ break;
+ case IP_STATUS:
+ case IP_STAT:
+ do_status = true;
+ break;
+ case IP_CMDLINE:
+ do_cmdline = true;
+ break;
+ case IP_EXE:
+ do_exe = true;
+ break;
+ case IP_CWD:
+ do_cwd = true;
+ break;
+ case IP_FILES:
+ do_files = true;
+ break;
+ case IP_ALL:
+ do_cmdline = true;
+ do_cwd = true;
+ do_exe = true;
+ do_files = true;
+ do_mappings = true;
+ do_status = true;
+ break;
+ default:
+ return;
+ }
+
+ pid = bfd_core_file_pid (core_bfd);
+ if (pid != 0)
+ printf_filtered (_("process %d\n"), pid);
+
+ if (do_cmdline)
+ {
+ const char *cmdline;
+
+ cmdline = bfd_core_file_failing_command (core_bfd);
+ if (cmdline)
+ printf_filtered ("cmdline = '%s'\n", cmdline);
+ else
+ warning (_("Command line unavailable"));
+ }
+ if (do_cwd)
+ {
+ gdb::unique_xmalloc_ptr<char> cwd =
+ fbsd_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_CWD);
+ if (cwd)
+ printf_filtered ("cwd = '%s'\n", cwd.get ());
+ else
+ warning (_("unable to read current working directory"));
+ }
+ if (do_exe)
+ {
+ gdb::unique_xmalloc_ptr<char> exe =
+ fbsd_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_TEXT);
+ if (exe)
+ printf_filtered ("exe = '%s'\n", exe.get ());
+ else
+ warning (_("unable to read executable path name"));
+ }
+ if (do_files)
+ fbsd_core_info_proc_files (gdbarch);
+ if (do_mappings)
+ fbsd_core_info_proc_mappings (gdbarch);
+ if (do_status)
+ fbsd_core_info_proc_status (gdbarch);
+}
+