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

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