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

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