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

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