Blame SOURCES/gdb-rhbz1842691-corefile-mem-access-5of15.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 17:27:39 -0400
0efd7d
Subject: gdb-rhbz1842691-corefile-mem-access-5of15.patch
0efd7d
0efd7d
;; Test ability to access unwritten-to mmap data in core file
0efd7d
;; Kevin Buettner, RH BZ 1842961
0efd7d
0efd7d
   Author: Kevin Buettner <kevinb@redhat.com>
0efd7d
   Date:   Wed Mar 4 17:42:43 2020 -0700
0efd7d
0efd7d
    Test ability to access unwritten-to mmap data in core file
0efd7d
0efd7d
    gdb/testsuite/ChangeLog:
0efd7d
0efd7d
    	PR corefiles/25631
0efd7d
    	* gdb.base/corefile.exp (accessing anonymous, unwritten-to mmap data):
0efd7d
    	New test.
0efd7d
    	* gdb.base/coremaker.c (buf3): New global.
0efd7d
    	(mmapdata): Add mmap call which uses MAP_ANONYMOUS and MAP_PRIVATE
0efd7d
    	flags.
0efd7d
0efd7d
diff --git a/gdb/testsuite/gdb.base/corefile.exp b/gdb/testsuite/gdb.base/corefile.exp
0efd7d
--- a/gdb/testsuite/gdb.base/corefile.exp
0efd7d
+++ b/gdb/testsuite/gdb.base/corefile.exp
0efd7d
@@ -175,6 +175,15 @@ gdb_test_multiple "x/8bd buf2" "$test" {
0efd7d
     }
0efd7d
 }
0efd7d
 
0efd7d
+# Test ability to read anonymous and, more importantly, unwritten-to
0efd7d
+# mmap'd data.
0efd7d
+
0efd7d
+if { ![istarget *-linux*] } {
0efd7d
+    setup_xfail "*-*-*"
0efd7d
+}
0efd7d
+gdb_test "x/wx buf3" "$hex:\[ \t\]+0x00000000" \
0efd7d
+	 "accessing anonymous, unwritten-to mmap data"
0efd7d
+
0efd7d
 # test reinit_frame_cache
0efd7d
 
0efd7d
 gdb_load ${binfile}
0efd7d
diff --git a/gdb/testsuite/gdb.base/coremaker.c b/gdb/testsuite/gdb.base/coremaker.c
0efd7d
--- a/gdb/testsuite/gdb.base/coremaker.c
0efd7d
+++ b/gdb/testsuite/gdb.base/coremaker.c
0efd7d
@@ -38,6 +38,7 @@
0efd7d
 
0efd7d
 char *buf1;
0efd7d
 char *buf2;
0efd7d
+char *buf3;
0efd7d
 
0efd7d
 int coremaker_data = 1;	/* In Data section */
0efd7d
 int coremaker_bss;	/* In BSS section */
0efd7d
@@ -104,6 +105,15 @@ mmapdata ()
0efd7d
     }
0efd7d
   /* Touch buf2 so kernel writes it out into 'core'. */
0efd7d
   buf2[0] = buf1[0];
0efd7d
+
0efd7d
+  /* Create yet another region which is allocated, but not written to.  */
0efd7d
+  buf3 = mmap (NULL, MAPSIZE, PROT_READ | PROT_WRITE,
0efd7d
+               MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
0efd7d
+  if (buf3 == (char *) -1)
0efd7d
+    {
0efd7d
+      perror ("mmap failed");
0efd7d
+      return;
0efd7d
+    }
0efd7d
 }
0efd7d
 
0efd7d
 void