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

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