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

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