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

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