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

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