Implement "info proc mappings" for NetBSD
[deliverable/binutils-gdb.git] / gdb / nbsd-tdep.c
index 158a43bebaa1e2ccc48bc7e4313ee81551500e2a..52e0640e35cad506e1eb31d075d97206b8bbc3eb 100644 (file)
 #include "gdbarch.h"
 #include "objfiles.h"
 
+/* Flags in the 'kve_protection' field in struct kinfo_vmentry.  These
+   match the KVME_PROT_* constants in <sys/sysctl.h>.  */
+
+#define        KINFO_VME_PROT_READ     0x00000001
+#define        KINFO_VME_PROT_WRITE    0x00000002
+#define        KINFO_VME_PROT_EXEC     0x00000004
+
+/* Flags in the 'kve_flags' field in struct kinfo_vmentry.  These
+   match the KVME_FLAG_* constants in <sys/sysctl.h>.  */
+
+#define        KINFO_VME_FLAG_COW              0x00000001
+#define        KINFO_VME_FLAG_NEEDS_COPY       0x00000002
+#define        KINFO_VME_FLAG_NOCOREDUMP       0x00000004
+#define        KINFO_VME_FLAG_PAGEABLE         0x00000008
+#define        KINFO_VME_FLAG_GROWS_UP         0x00000010
+#define        KINFO_VME_FLAG_GROWS_DOWN       0x00000020
+
 /* FIXME: kettenis/20060115: We should really eliminate the next two
    functions completely.  */
 
@@ -357,6 +374,78 @@ nbsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
 
 /* See nbsd-tdep.h.  */
 
+void
+nbsd_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");
+    }
+}
+
+/* Helper function to generate mappings flags for a single VM map
+   entry in 'info proc mappings'.  */
+
+static const char *
+nbsd_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_PAGEABLE) ? 'P' : '-';
+  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;
+}
+
+void
+nbsd_info_proc_mappings_entry (int addr_bit, ULONGEST kve_start,
+                              ULONGEST kve_end, ULONGEST kve_offset,
+                              int kve_flags, int kve_protection,
+                              const char *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),
+                      nbsd_vm_map_entry_flags (kve_flags, kve_protection),
+                      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),
+                      nbsd_vm_map_entry_flags (kve_flags, kve_protection),
+                      kve_path);
+    }
+}
+
+/* See nbsd-tdep.h.  */
+
 void
 nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
This page took 0.024136 seconds and 4 git commands to generate.