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

59b2e3
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
59b2e3
From: Keith Seitz <keiths@redhat.com>
59b2e3
Date: Mon, 27 Jul 2020 18:01:32 -0400
59b2e3
Subject: gdb-rhbz1842691-corefile-mem-access-7of15.patch
59b2e3
59b2e3
;; Add new gdbarch method, read_core_file_mappings
59b2e3
;; Kevin Buettner, RH BZ 1842961
59b2e3
59b2e3
   Author: Kevin Buettner <kevinb@redhat.com>
59b2e3
   Date:   Fri Jul 3 13:32:08 2020 -0700
59b2e3
59b2e3
    Add new gdbarch method, read_core_file_mappings
59b2e3
59b2e3
    The new gdbarch method, read_core_file_mappings, will be used for
59b2e3
    reading file-backed mappings from a core file.  It'll be used
59b2e3
    for two purposes: 1) to construct a table of file-backed mappings
59b2e3
    in corelow.c, and 2) for display of core file mappings.
59b2e3
59b2e3
    For Linux, I tried a different approach in which knowledge of the note
59b2e3
    format was placed directly in corelow.c.  This seemed okay at first;
59b2e3
    it was only one note format and the note format was fairly simple.
59b2e3
    After looking at FreeBSD's note/mapping reading code, I concluded
59b2e3
    that it's best to leave architecture specific details for decoding
59b2e3
    the note in (architecture specific) tdep files.
59b2e3
59b2e3
    With regard to display of core file mappings, I experimented with
59b2e3
    placing the mappings display code in corelow.c.  It has access to the
59b2e3
    file-backed mappings which were read in when the core file was loaded.
59b2e3
    And, better, still common code could be used for all architectures.
59b2e3
    But, again, the FreeBSD mapping code convinced me that this was not
59b2e3
    the best approach since it has even more mapping info than Linux.
59b2e3
    Display code which would work well for Linux will leave out mappings
59b2e3
    as well as protection info for mappings.
59b2e3
59b2e3
    So, for these reasons, I'm introducing a new gdbarch method for
59b2e3
    reading core file mappings.
59b2e3
59b2e3
    gdb/ChangeLog:
59b2e3
59b2e3
    	* arch-utils.c (default_read_core_file_mappings): New function.
59b2e3
    	* arch-utils.c (default_read_core_file_mappings): Declare.
59b2e3
    	* gdbarch.sh (read_core_file_mappings): New gdbarch method.
59b2e3
    	* gdbarch.h, gdbarch.c: Regenerate.
59b2e3
59b2e3
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
59b2e3
--- a/gdb/arch-utils.c
59b2e3
+++ b/gdb/arch-utils.c
59b2e3
@@ -1004,6 +1004,22 @@ default_get_pc_address_flags (frame_info *frame, CORE_ADDR pc)
59b2e3
   return "";
59b2e3
 }
59b2e3
 
59b2e3
+/* See arch-utils.h.  */
59b2e3
+void
59b2e3
+default_read_core_file_mappings (struct gdbarch *gdbarch,
59b2e3
+                                 struct bfd *cbfd,
59b2e3
+				 gdb::function_view<void (ULONGEST count)>
59b2e3
+				   pre_loop_cb,
59b2e3
+				 gdb::function_view
59b2e3
+				                          ULONGEST start,
59b2e3
+							  ULONGEST end,
59b2e3
+							  ULONGEST file_ofs,
59b2e3
+							  const char *filename,
59b2e3
+							  const void *other)>
59b2e3
+				   loop_cb)
59b2e3
+{
59b2e3
+}
59b2e3
+
59b2e3
 void
59b2e3
 _initialize_gdbarch_utils (void)
59b2e3
 {
59b2e3
diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
59b2e3
--- a/gdb/arch-utils.h
59b2e3
+++ b/gdb/arch-utils.h
59b2e3
@@ -276,4 +276,16 @@ extern ULONGEST default_type_align (struct gdbarch *gdbarch,
59b2e3
 extern std::string default_get_pc_address_flags (frame_info *frame,
59b2e3
 						 CORE_ADDR pc);
59b2e3
 
59b2e3
+/* Default implementation of gdbarch read_core_file_mappings method.  */
59b2e3
+extern void default_read_core_file_mappings (struct gdbarch *gdbarch,
59b2e3
+					     struct bfd *cbfd,
59b2e3
+					     gdb::function_view<void (ULONGEST count)>
59b2e3
+					       pre_loop_cb,
59b2e3
+					     gdb::function_view
59b2e3
+								      ULONGEST start,
59b2e3
+								      ULONGEST end,
59b2e3
+								      ULONGEST file_ofs,
59b2e3
+								      const char *filename,
59b2e3
+								      const void *other)>
59b2e3
+					       loop_cb);
59b2e3
 #endif /* ARCH_UTILS_H */
59b2e3
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
59b2e3
--- a/gdb/gdbarch.c
59b2e3
+++ b/gdb/gdbarch.c
59b2e3
@@ -358,6 +358,7 @@ struct gdbarch
59b2e3
   const disasm_options_and_args_t * valid_disassembler_options;
59b2e3
   gdbarch_type_align_ftype *type_align;
59b2e3
   gdbarch_get_pc_address_flags_ftype *get_pc_address_flags;
59b2e3
+  gdbarch_read_core_file_mappings_ftype *read_core_file_mappings;
59b2e3
 };
59b2e3
 
59b2e3
 /* Create a new ``struct gdbarch'' based on information provided by
59b2e3
@@ -473,6 +474,7 @@ gdbarch_alloc (const struct gdbarch_info *info,
59b2e3
   gdbarch->addressable_memory_unit_size = default_addressable_memory_unit_size;
59b2e3
   gdbarch->type_align = default_type_align;
59b2e3
   gdbarch->get_pc_address_flags = default_get_pc_address_flags;
59b2e3
+  gdbarch->read_core_file_mappings = default_read_core_file_mappings;
59b2e3
   /* gdbarch_alloc() */
59b2e3
 
59b2e3
   return gdbarch;
59b2e3
@@ -721,6 +723,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
59b2e3
   /* Skip verify of valid_disassembler_options, invalid_p == 0 */
59b2e3
   /* Skip verify of type_align, invalid_p == 0 */
59b2e3
   /* Skip verify of get_pc_address_flags, invalid_p == 0 */
59b2e3
+  /* Skip verify of read_core_file_mappings, invalid_p == 0 */
59b2e3
   if (!log.empty ())
59b2e3
     internal_error (__FILE__, __LINE__,
59b2e3
                     _("verify_gdbarch: the following are invalid ...%s"),
59b2e3
@@ -1287,6 +1290,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
59b2e3
   fprintf_unfiltered (file,
59b2e3
                       "gdbarch_dump: ravenscar_ops = %s\n",
59b2e3
                       host_address_to_string (gdbarch->ravenscar_ops));
59b2e3
+  fprintf_unfiltered (file,
59b2e3
+                      "gdbarch_dump: read_core_file_mappings = <%s>\n",
59b2e3
+                      host_address_to_string (gdbarch->read_core_file_mappings));
59b2e3
   fprintf_unfiltered (file,
59b2e3
                       "gdbarch_dump: gdbarch_read_pc_p() = %d\n",
59b2e3
                       gdbarch_read_pc_p (gdbarch));
59b2e3
@@ -5156,6 +5162,23 @@ set_gdbarch_get_pc_address_flags (struct gdbarch *gdbarch,
59b2e3
   gdbarch->get_pc_address_flags = get_pc_address_flags;
59b2e3
 }
59b2e3
 
59b2e3
+void
59b2e3
+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)
59b2e3
+{
59b2e3
+  gdb_assert (gdbarch != NULL);
59b2e3
+  gdb_assert (gdbarch->read_core_file_mappings != NULL);
59b2e3
+  if (gdbarch_debug >= 2)
59b2e3
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_read_core_file_mappings called\n");
59b2e3
+  gdbarch->read_core_file_mappings (gdbarch, cbfd, pre_loop_cb, loop_cb);
59b2e3
+}
59b2e3
+
59b2e3
+void
59b2e3
+set_gdbarch_read_core_file_mappings (struct gdbarch *gdbarch,
59b2e3
+                                     gdbarch_read_core_file_mappings_ftype read_core_file_mappings)
59b2e3
+{
59b2e3
+  gdbarch->read_core_file_mappings = read_core_file_mappings;
59b2e3
+}
59b2e3
+
59b2e3
 
59b2e3
 /* Keep a registry of per-architecture data-pointers required by GDB
59b2e3
    modules.  */
59b2e3
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
59b2e3
--- a/gdb/gdbarch.h
59b2e3
+++ b/gdb/gdbarch.h
59b2e3
@@ -1640,6 +1640,12 @@ typedef std::string (gdbarch_get_pc_address_flags_ftype) (frame_info *frame, COR
59b2e3
 extern std::string gdbarch_get_pc_address_flags (struct gdbarch *gdbarch, frame_info *frame, CORE_ADDR pc);
59b2e3
 extern void set_gdbarch_get_pc_address_flags (struct gdbarch *gdbarch, gdbarch_get_pc_address_flags_ftype *get_pc_address_flags);
59b2e3
 
59b2e3
+/* Read core file mappings */
59b2e3
+
59b2e3
+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);
59b2e3
+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);
59b2e3
+extern void set_gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, gdbarch_read_core_file_mappings_ftype *read_core_file_mappings);
59b2e3
+
59b2e3
 extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
59b2e3
 
59b2e3
 
59b2e3
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
59b2e3
--- a/gdb/gdbarch.sh
59b2e3
+++ b/gdb/gdbarch.sh
59b2e3
@@ -1209,6 +1209,9 @@ m;ULONGEST;type_align;struct type *type;type;;default_type_align;;0
59b2e3
 # Return a string containing any flags for the given PC in the given FRAME.
59b2e3
 f;std::string;get_pc_address_flags;frame_info *frame, CORE_ADDR pc;frame, pc;;default_get_pc_address_flags;;0
59b2e3
 
59b2e3
+# Read core file mappings
59b2e3
+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
59b2e3
+
59b2e3
 EOF
59b2e3
 }
59b2e3