Blame SOURCES/gdb-rhbz1842691-corefile-mem-access-7of15.patch

6543d1
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
6543d1
From: Keith Seitz <keiths@redhat.com>
6543d1
Date: Mon, 27 Jul 2020 18:01:32 -0400
6543d1
Subject: gdb-rhbz1842691-corefile-mem-access-7of15.patch
6543d1
6543d1
;; Add new gdbarch method, read_core_file_mappings
6543d1
;; Kevin Buettner, RH BZ 1842961
6543d1
6543d1
   Author: Kevin Buettner <kevinb@redhat.com>
6543d1
   Date:   Fri Jul 3 13:32:08 2020 -0700
6543d1
6543d1
    Add new gdbarch method, read_core_file_mappings
6543d1
6543d1
    The new gdbarch method, read_core_file_mappings, will be used for
6543d1
    reading file-backed mappings from a core file.  It'll be used
6543d1
    for two purposes: 1) to construct a table of file-backed mappings
6543d1
    in corelow.c, and 2) for display of core file mappings.
6543d1
6543d1
    For Linux, I tried a different approach in which knowledge of the note
6543d1
    format was placed directly in corelow.c.  This seemed okay at first;
6543d1
    it was only one note format and the note format was fairly simple.
6543d1
    After looking at FreeBSD's note/mapping reading code, I concluded
6543d1
    that it's best to leave architecture specific details for decoding
6543d1
    the note in (architecture specific) tdep files.
6543d1
6543d1
    With regard to display of core file mappings, I experimented with
6543d1
    placing the mappings display code in corelow.c.  It has access to the
6543d1
    file-backed mappings which were read in when the core file was loaded.
6543d1
    And, better, still common code could be used for all architectures.
6543d1
    But, again, the FreeBSD mapping code convinced me that this was not
6543d1
    the best approach since it has even more mapping info than Linux.
6543d1
    Display code which would work well for Linux will leave out mappings
6543d1
    as well as protection info for mappings.
6543d1
6543d1
    So, for these reasons, I'm introducing a new gdbarch method for
6543d1
    reading core file mappings.
6543d1
6543d1
    gdb/ChangeLog:
6543d1
6543d1
    	* arch-utils.c (default_read_core_file_mappings): New function.
6543d1
    	* arch-utils.c (default_read_core_file_mappings): Declare.
6543d1
    	* gdbarch.sh (read_core_file_mappings): New gdbarch method.
6543d1
    	* gdbarch.h, gdbarch.c: Regenerate.
6543d1
6543d1
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
6543d1
--- a/gdb/arch-utils.c
6543d1
+++ b/gdb/arch-utils.c
6543d1
@@ -997,6 +997,22 @@ default_type_align (struct gdbarch *gdbarch, struct type *type)
6543d1
   return type_length_units (check_typedef (type));
6543d1
 }
6543d1
 
6543d1
+/* See arch-utils.h.  */
6543d1
+void
6543d1
+default_read_core_file_mappings (struct gdbarch *gdbarch,
6543d1
+                                 struct bfd *cbfd,
6543d1
+                                gdb::function_view<void (ULONGEST count)>
6543d1
+                                  pre_loop_cb,
6543d1
+                                gdb::function_view
6543d1
+                                                         ULONGEST start,
6543d1
+                                                         ULONGEST end,
6543d1
+                                                         ULONGEST file_ofs,
6543d1
+                                                         const char *filename,
6543d1
+                                                         const void *other)>
6543d1
+                                  loop_cb)
6543d1
+{
6543d1
+}
6543d1
+
6543d1
 void
6543d1
 _initialize_gdbarch_utils (void)
6543d1
 {
6543d1
diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
6543d1
--- a/gdb/arch-utils.h
6543d1
+++ b/gdb/arch-utils.h
6543d1
@@ -271,4 +271,16 @@ extern bool default_in_indirect_branch_thunk (gdbarch *gdbarch,
6543d1
 extern ULONGEST default_type_align (struct gdbarch *gdbarch,
6543d1
 				    struct type *type);
6543d1
 
6543d1
+/* Default implementation of gdbarch read_core_file_mappings method.  */
6543d1
+extern void default_read_core_file_mappings (struct gdbarch *gdbarch,
6543d1
+                                            struct bfd *cbfd,
6543d1
+                                            gdb::function_view<void (ULONGEST count)>
6543d1
+                                              pre_loop_cb,
6543d1
+                                            gdb::function_view
6543d1
+                                                                     ULONGEST start,
6543d1
+                                                                     ULONGEST end,
6543d1
+                                                                     ULONGEST file_ofs,
6543d1
+                                                                     const char *filename,
6543d1
+                                                                     const void *other)>
6543d1
+					     loop_cb);
6543d1
 #endif
6543d1
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
6543d1
--- a/gdb/gdbarch.c
6543d1
+++ b/gdb/gdbarch.c
6543d1
@@ -354,6 +354,7 @@ struct gdbarch
6543d1
   char ** disassembler_options;
6543d1
   const disasm_options_and_args_t * valid_disassembler_options;
6543d1
   gdbarch_type_align_ftype *type_align;
6543d1
+  gdbarch_read_core_file_mappings_ftype *read_core_file_mappings;
6543d1
 };
6543d1
 
6543d1
 /* Create a new ``struct gdbarch'' based on information provided by
6543d1
@@ -466,6 +467,7 @@ gdbarch_alloc (const struct gdbarch_info *info,
6543d1
   gdbarch->gnu_triplet_regexp = default_gnu_triplet_regexp;
6543d1
   gdbarch->addressable_memory_unit_size = default_addressable_memory_unit_size;
6543d1
   gdbarch->type_align = default_type_align;
6543d1
+  gdbarch->read_core_file_mappings = default_read_core_file_mappings;
6543d1
   /* gdbarch_alloc() */
6543d1
 
6543d1
   return gdbarch;
6543d1
@@ -712,6 +714,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
6543d1
   /* Skip verify of disassembler_options, invalid_p == 0 */
6543d1
   /* Skip verify of valid_disassembler_options, invalid_p == 0 */
6543d1
   /* Skip verify of type_align, invalid_p == 0 */
6543d1
+  /* Skip verify of read_core_file_mappings, invalid_p == 0 */
6543d1
   if (!log.empty ())
6543d1
     internal_error (__FILE__, __LINE__,
6543d1
                     _("verify_gdbarch: the following are invalid ...%s"),
6543d1
@@ -1275,6 +1278,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
6543d1
   fprintf_unfiltered (file,
6543d1
                       "gdbarch_dump: ravenscar_ops = %s\n",
6543d1
                       host_address_to_string (gdbarch->ravenscar_ops));
6543d1
+  fprintf_unfiltered (file,
6543d1
+                      "gdbarch_dump: read_core_file_mappings = <%s>\n",
6543d1
+                      host_address_to_string (gdbarch->read_core_file_mappings));
6543d1
   fprintf_unfiltered (file,
6543d1
                       "gdbarch_dump: gdbarch_read_pc_p() = %d\n",
6543d1
                       gdbarch_read_pc_p (gdbarch));
6543d1
@@ -5117,6 +5123,23 @@ set_gdbarch_type_align (struct gdbarch *gdbarch,
6543d1
   gdbarch->type_align = type_align;
6543d1
 }
6543d1
 
6543d1
+void
6543d1
+gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd,gdb::function_view<void (ULONGEST count)> pre_loop_cb,gdb::function_view<void (int num, ULONGEST start, ULONGEST end, ULONGEST file_ofs, const char *filename, const void *other)> loop_cb)
6543d1
+{
6543d1
+  gdb_assert (gdbarch != NULL);
6543d1
+  gdb_assert (gdbarch->read_core_file_mappings != NULL);
6543d1
+  if (gdbarch_debug >= 2)
6543d1
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_read_core_file_mappings called\n");
6543d1
+  gdbarch->read_core_file_mappings (gdbarch, cbfd, pre_loop_cb, loop_cb);
6543d1
+}
6543d1
+
6543d1
+void
6543d1
+set_gdbarch_read_core_file_mappings (struct gdbarch *gdbarch,
6543d1
+                                     gdbarch_read_core_file_mappings_ftype read_core_file_mappings)
6543d1
+{
6543d1
+  gdbarch->read_core_file_mappings = read_core_file_mappings;
6543d1
+}
6543d1
+
6543d1
 
6543d1
 /* Keep a registry of per-architecture data-pointers required by GDB
6543d1
    modules.  */
6543d1
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
6543d1
--- a/gdb/gdbarch.h
6543d1
+++ b/gdb/gdbarch.h
6543d1
@@ -1566,6 +1566,12 @@ typedef ULONGEST (gdbarch_type_align_ftype) (struct gdbarch *gdbarch, struct typ
6543d1
 extern ULONGEST gdbarch_type_align (struct gdbarch *gdbarch, struct type *type);
6543d1
 extern void set_gdbarch_type_align (struct gdbarch *gdbarch, gdbarch_type_align_ftype *type_align);
6543d1
 
6543d1
+/* Read core file mappings */
6543d1
+
6543d1
+typedef void (gdbarch_read_core_file_mappings_ftype) (struct gdbarch *gdbarch, struct bfd *cbfd,gdb::function_view<void (ULONGEST count)> pre_loop_cb,gdb::function_view<void (int num, ULONGEST start, ULONGEST end, ULONGEST file_ofs, const char *filename, const void *other)> loop_cb);
6543d1
+extern void gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd,gdb::function_view<void (ULONGEST count)> pre_loop_cb,gdb::function_view<void (int num, ULONGEST start, ULONGEST end, ULONGEST file_ofs, const char *filename, const void *other)> loop_cb);
6543d1
+extern void set_gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, gdbarch_read_core_file_mappings_ftype *read_core_file_mappings);
6543d1
+
6543d1
 /* Definition for an unknown syscall, used basically in error-cases.  */
6543d1
 #define UNKNOWN_SYSCALL (-1)
6543d1
 
6543d1
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
6543d1
--- a/gdb/gdbarch.sh
6543d1
+++ b/gdb/gdbarch.sh
6543d1
@@ -1164,6 +1164,9 @@ v;const disasm_options_and_args_t *;valid_disassembler_options;;;0;0;;0;host_add
6543d1
 # Type alignment.
6543d1
 m;ULONGEST;type_align;struct type *type;type;;default_type_align;;0
6543d1
 
6543d1
+# Read core file mappings
6543d1
+m;void;read_core_file_mappings;struct bfd *cbfd,gdb::function_view<void (ULONGEST count)> pre_loop_cb,gdb::function_view<void (int num, ULONGEST start, ULONGEST end, ULONGEST file_ofs, const char *filename, const void *other)> loop_cb;cbfd, pre_loop_cb, loop_cb;;default_read_core_file_mappings;;0
6543d1
+
6543d1
 EOF
6543d1
 }
6543d1