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

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