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

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