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

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