aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2018-10-17 11:41:30 -0700
committerJohn Baldwin <jhb@FreeBSD.org>2018-10-17 11:42:00 -0700
commit6f3b1098e820cef84709ef71c287c4b72e6c671b (patch)
tree6c32813cdedcfb6114f14779cc2f2e49f815fb1a
parentd500b4f23fc329f5c8cce6ee8fa3629c0f130038 (diff)
downloadgdb-6f3b1098e820cef84709ef71c287c4b72e6c671b.zip
gdb-6f3b1098e820cef84709ef71c287c4b72e6c671b.tar.gz
gdb-6f3b1098e820cef84709ef71c287c4b72e6c671b.tar.bz2
Share the code to format "info proc mappings" entries for FreeBSD.
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.
-rw-r--r--gdb/ChangeLog13
-rw-r--r--gdb/fbsd-nat.c43
-rw-r--r--gdb/fbsd-tdep.c107
-rw-r--r--gdb/fbsd-tdep.h23
4 files changed, 98 insertions, 88 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index fb83f22..36a4eeb 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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
diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index 24e40e2..107a729 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -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"));
diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
index 070d448..94ae2d6 100644
--- a/gdb/fbsd-tdep.c
+++ b/gdb/fbsd-tdep.c
@@ -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;
}
diff --git a/gdb/fbsd-tdep.h b/gdb/fbsd-tdep.h
index e0cad7d..700f23e 100644
--- a/gdb/fbsd-tdep.h
+++ b/gdb/fbsd-tdep.h
@@ -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 */