]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Share the code to format "info proc mappings" entries for FreeBSD.
authorJohn Baldwin <jhb@FreeBSD.org>
Wed, 17 Oct 2018 18:41:30 +0000 (11:41 -0700)
committerJohn Baldwin <jhb@FreeBSD.org>
Wed, 17 Oct 2018 18:42:00 +0000 (11:42 -0700)
gdb/ChangeLog:

* fbsd-nat.c (fbsd_nat_target::info_proc) Use
fbsd_info_proc_mappings_header and fbsd_info_proc_mappings_entry.
* fbsd-tdep.c (fbsd_vm_map_entry_flags): Mark static.
(fbsd_info_proc_mappings_header, fbsd_info_proc_mappings_entry):
New functions.
(fbsd_core_info_proc_mappings): Use fbsd_info_proc_mappings_header
and fbsd_info_proc_mappings_header.
* fbsd-tdep.h (fbsd_vm_map_entry_flags): Remove.
(fbsd_info_proc_mappings_header, fbsd_info_proc_mappings_entry):
New.

gdb/ChangeLog
gdb/fbsd-nat.c
gdb/fbsd-tdep.c
gdb/fbsd-tdep.h

index fb83f22dc411f348208f19db6333338cf8dacb34..36a4eeb9718de1d47031721774f99107ef6d12aa 100644 (file)
@@ -1,3 +1,16 @@
+2018-10-17  John Baldwin  <jhb@FreeBSD.org>
+
+       * fbsd-nat.c (fbsd_nat_target::info_proc) Use
+       fbsd_info_proc_mappings_header and fbsd_info_proc_mappings_entry.
+       * fbsd-tdep.c (fbsd_vm_map_entry_flags): Mark static.
+       (fbsd_info_proc_mappings_header, fbsd_info_proc_mappings_entry):
+       New functions.
+       (fbsd_core_info_proc_mappings): Use fbsd_info_proc_mappings_header
+       and fbsd_info_proc_mappings_header.
+       * fbsd-tdep.h (fbsd_vm_map_entry_flags): Remove.
+       (fbsd_info_proc_mappings_header, fbsd_info_proc_mappings_entry):
+       New.
+
 2018-10-17  Joel Brobecker  <brobecker@adacore.com>
 
        * MAINTAINERS (Responsible Maintainers): Add Rainer Orth as
index 24e40e2406b80cec06c8435ae2ae0a6c6652e3b0..107a729b3cf50cb7f89147b80fb4c1bec00b6c74 100644 (file)
@@ -413,46 +413,15 @@ fbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
 
       if (vmentl != nullptr)
        {
-         printf_filtered (_("Mapped address spaces:\n\n"));
-#ifdef __LP64__
-         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");
-#endif
+         int addr_bit = TARGET_CHAR_BIT * sizeof (void *);
+         fbsd_info_proc_mappings_header (addr_bit);
 
          struct kinfo_vmentry *kve = vmentl.get ();
          for (int i = 0; i < nvment; i++, kve++)
-           {
-             ULONGEST start, end;
-
-             start = kve->kve_start;
-             end = kve->kve_end;
-#ifdef __LP64__
-             printf_filtered ("  %18s %18s %10s %10s %9s %s\n",
-                              hex_string (start),
-                              hex_string (end),
-                              hex_string (end - start),
-                              hex_string (kve->kve_offset),
-                              fbsd_vm_map_entry_flags (kve->kve_flags,
-                                                       kve->kve_protection),
-                              kve->kve_path);
-#else
-             printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
-                              hex_string (start),
-                              hex_string (end),
-                              hex_string (end - start),
-                              hex_string (kve->kve_offset),
-                              fbsd_vm_map_entry_flags (kve->kve_flags,
-                                                       kve->kve_protection),
-                              kve->kve_path);
-#endif
-           }
+           fbsd_info_proc_mappings_entry (addr_bit, kve->kve_start,
+                                          kve->kve_end, kve->kve_offset,
+                                          kve->kve_flags, kve->kve_protection,
+                                          kve->kve_path);
        }
       else
        warning (_("unable to fetch virtual memory map"));
index 070d448b4e91965585abec8581845ec5a7ae7989..94ae2d6ab55aba6540fc42a09805d21e26dae1eb 100644 (file)
@@ -1047,7 +1047,7 @@ fbsd_core_info_proc_files (struct gdbarch *gdbarch)
 /* Helper function to generate mappings flags for a single VM map
    entry in 'info proc mappings'.  */
 
-const char *
+static const char *
 fbsd_vm_map_entry_flags (int kve_flags, int kve_protection)
 {
   static char vm_flags[9];
@@ -1066,6 +1066,58 @@ fbsd_vm_map_entry_flags (int kve_flags, int kve_protection)
   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
@@ -1097,55 +1149,20 @@ fbsd_core_info_proc_mappings (struct gdbarch *gdbarch)
   /* Skip over the structure size.  */
   descdata += 4;
 
-  printf_filtered (_("Mapped address spaces:\n\n"));
-  if (gdbarch_addr_bit (gdbarch) == 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");
-    }
-
+  fbsd_info_proc_mappings_header (gdbarch_addr_bit (gdbarch));
   while (descdata + KVE_PATH < descend)
     {
-      ULONGEST start, end, offset, flags, prot, structsize;
-
-      structsize = bfd_get_32 (core_bfd, descdata + KVE_STRUCTSIZE);
+      ULONGEST structsize = bfd_get_32 (core_bfd, descdata + KVE_STRUCTSIZE);
       if (structsize < KVE_PATH)
        error (_("malformed core note - vmmap entry too small"));
 
-      start = bfd_get_64 (core_bfd, descdata + KVE_START);
-      end = bfd_get_64 (core_bfd, descdata + KVE_END);
-      offset = bfd_get_64 (core_bfd, descdata + KVE_OFFSET);
-      flags = bfd_get_32 (core_bfd, descdata + KVE_FLAGS);
-      prot = bfd_get_32 (core_bfd, descdata + KVE_PROTECTION);
-      if (gdbarch_addr_bit (gdbarch) == 64)
-       {
-         printf_filtered ("  %18s %18s %10s %10s %9s %s\n",
-                          paddress (gdbarch, start),
-                          paddress (gdbarch, end),
-                          hex_string (end - start),
-                          hex_string (offset),
-                          fbsd_vm_map_entry_flags (flags, prot),
-                          descdata + KVE_PATH);
-       }
-      else
-       {
-         printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
-                          paddress (gdbarch, start),
-                          paddress (gdbarch, end),
-                          hex_string (end - start),
-                          hex_string (offset),
-                          fbsd_vm_map_entry_flags (flags, prot),
-                          descdata + KVE_PATH);
-       }
+      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;
     }
index e0cad7deadb7bdbf81c8d86364942478e083e664..700f23eb325a439f36df8152c4e3396d50338721 100644 (file)
@@ -42,11 +42,22 @@ extern void fbsd_info_proc_files_entry (int kf_type, int kf_fd, int kf_flags,
                                        const void *kf_sa_peer,
                                        const void *kf_path);
 
-/* Helper function to generate mappings flags for a single VM map
-   entry in 'info proc mappings'.  The KVE_FLAGS and KVE_PROTECTION
-   parameters should contain the values of the corresponding fields in
-   a 'struct kinfo_vmentry'.  */
-
-extern const char *fbsd_vm_map_entry_flags (int kve_flags, int kve_protection);
+/* Output the header for "info proc mappings".  ADDR_BIT is the size
+   of a virtual address in bits.  */
+
+extern void fbsd_info_proc_mappings_header (int addr_bit);
+
+/* Output description of a single memory range for "info proc
+   mappings".  ADDR_BIT is the size of a virtual address in bits.  The
+   KVE_START, KVE_END, KVE_OFFSET, KVE_FLAGS, and KVE_PROTECTION
+   parameters should contain the value of the corresponding fields in
+   a 'struct kinfo_vmentry'.  The KVE_PATH parameter should contain a
+   pointer to the 'kve_path' field in a 'struct kinfo_vmentry'. */
+
+extern 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);
 
 #endif /* fbsd-tdep.h */