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

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