Blame SOURCES/gdb-rhbz1842691-corefile-mem-access-10of15.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 19:38:20 -0400
be07d7
Subject: gdb-rhbz1842691-corefile-mem-access-10of15.patch
be07d7
be07d7
;; gcore command: Place all file-backed mappings in NT_FILE note
be07d7
;; Kevin Buettner, RH BZ 1842961
be07d7
be07d7
   Author: Kevin Buettner <kevinb@redhat.com>
be07d7
   Date:   Wed Jul 1 06:34:50 2020 -0700
be07d7
be07d7
    gcore command: Place all file-backed mappings in NT_FILE note
be07d7
be07d7
    When making a core file with the GDB's gcore command on Linux,
be07d7
    the same criteria used for determining which mappings should be
be07d7
    dumped were also being used for determining which entries should
be07d7
    be placed in the NT_FILE note.  This is wrong; we want to place
be07d7
    all file-backed mappings in this note.
be07d7
be07d7
    The predicate function, dump_mapping_p, was used to determine whether
be07d7
    or not to dump a mapping from within linux_find_memory_regions_full.
be07d7
    This commit leaves this predicate in place, but adds a new parameter,
be07d7
    should_dump_mapping_p, to linux_find_memory_regions_full.  It then
be07d7
    calls should_dump_mapping_p instead of dump_mapping_p.  dump_mapping_p
be07d7
    is passed to linux_find_memory_regions_full at one call site; at the
be07d7
    other call site, dump_note_entry_p is passed instead.
be07d7
be07d7
    gdb/ChangeLog:
be07d7
be07d7
    	* linux-tdep.c (dump_note_entry_p): New function.
be07d7
    	(linux_dump_mapping_p_ftype): New typedef.
be07d7
    	(linux_find_memory_regions_full): Add new parameter,
be07d7
    	should_dump_mapping_p.
be07d7
    	(linux_find_memory_regions): Adjust call to
be07d7
    	linux_find_memory_regions_full.
be07d7
    	(linux_make_mappings_core_file_notes): Use dump_note_entry_p in
be07d7
    	call to linux_find_memory_regions_full.
be07d7
be07d7
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
be07d7
--- a/gdb/linux-tdep.c
be07d7
+++ b/gdb/linux-tdep.c
be07d7
@@ -710,6 +710,25 @@ dump_mapping_p (filter_flags filterflags, const struct smaps_vmflags *v,
be07d7
     }
be07d7
 }
be07d7
 
be07d7
+/* As above, but return true only when we should dump the NT_FILE
be07d7
+   entry.  */
be07d7
+
be07d7
+static int
be07d7
+dump_note_entry_p (filter_flags filterflags, const struct smaps_vmflags *v,
be07d7
+		int maybe_private_p, int mapping_anon_p, int mapping_file_p,
be07d7
+		const char *filename)
be07d7
+{
be07d7
+  /* vDSO and vsyscall mappings will end up in the core file.  Don't
be07d7
+     put them in the NT_FILE note.  */
be07d7
+  if (strcmp ("[vdso]", filename) == 0
be07d7
+      || strcmp ("[vsyscall]", filename) == 0)
be07d7
+    return 0;
be07d7
+
be07d7
+  /* Otherwise, any other file-based mapping should be placed in the
be07d7
+     note.  */
be07d7
+  return filename != nullptr;
be07d7
+}
be07d7
+
be07d7
 /* Implement the "info proc" command.  */
be07d7
 
be07d7
 static void
be07d7
@@ -1224,10 +1243,18 @@ typedef int linux_find_memory_region_ftype (ULONGEST vaddr, ULONGEST size,
be07d7
 					    const char *filename,
be07d7
 					    void *data);
be07d7
 
be07d7
+typedef int linux_dump_mapping_p_ftype (filter_flags filterflags,
be07d7
+					const struct smaps_vmflags *v,
be07d7
+					int maybe_private_p,
be07d7
+					int mapping_anon_p,
be07d7
+					int mapping_file_p,
be07d7
+					const char *filename);
be07d7
+
be07d7
 /* List memory regions in the inferior for a corefile.  */
be07d7
 
be07d7
 static int
be07d7
 linux_find_memory_regions_full (struct gdbarch *gdbarch,
be07d7
+				linux_dump_mapping_p_ftype *should_dump_mapping_p,
be07d7
 				linux_find_memory_region_ftype *func,
be07d7
 				void *obfd)
be07d7
 {
be07d7
@@ -1378,7 +1405,7 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch,
be07d7
 	    }
be07d7
 
be07d7
 	  if (has_anonymous)
be07d7
-	    should_dump_p = dump_mapping_p (filterflags, &v, priv,
be07d7
+	    should_dump_p = should_dump_mapping_p (filterflags, &v, priv,
be07d7
 					    mapping_anon_p, mapping_file_p,
be07d7
 					    filename);
be07d7
 	  else
be07d7
@@ -1444,6 +1471,7 @@ linux_find_memory_regions (struct gdbarch *gdbarch,
be07d7
   data.obfd = obfd;
be07d7
 
be07d7
   return linux_find_memory_regions_full (gdbarch,
be07d7
+					 dump_mapping_p,
be07d7
 					 linux_find_memory_regions_thunk,
be07d7
 					 &data);
be07d7
 }
be07d7
@@ -1606,7 +1634,9 @@ linux_make_mappings_corefile_notes (struct gdbarch *gdbarch, bfd *obfd,
be07d7
   pack_long (buf, long_type, 1);
be07d7
   obstack_grow (&data_obstack, buf, TYPE_LENGTH (long_type));
be07d7
 
be07d7
-  linux_find_memory_regions_full (gdbarch, linux_make_mappings_callback,
be07d7
+  linux_find_memory_regions_full (gdbarch, 
be07d7
+				  dump_note_entry_p,
be07d7
+				  linux_make_mappings_callback,
be07d7
 				  &mapping_data);
be07d7
 
be07d7
   if (mapping_data.file_count != 0)