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

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