[4/4] Test ability to access unwritten-to mmap data in core file

Message ID 20200305004243.334607-5-kevinb@redhat.com
State New
Headers show
Series
  • Fix BZ 25631 - core file memory access problem
Related show

Commit Message

Kevin Buettner March 5, 2020, 12:42 a.m.
gdb/testsuite/ChangeLog:

	* gdb.base/corefile.exp (accessing anonymous, unwritten-to mmap data):
	New test.
	* gdb.base/coremaker.c (buf3): New global.
	(mmapdata): Add mmap call which uses MAP_ANONYMOUSE and MAP_PRIVATE
	flags.

Change-Id: Ifb8d77b06050e1220f33f83f1bec27533e4d9ead
---
 gdb/testsuite/gdb.base/corefile.exp |  6 ++++++
 gdb/testsuite/gdb.base/coremaker.c  | 10 ++++++++++
 2 files changed, 16 insertions(+)

-- 
2.24.1

Comments

Jose E. Marchesi via Gdb-patches March 25, 2020, 5:25 p.m. | #1
Hi, Kevin,

Thank you for the test! I know my first thoughts of writing a test for
this culminated in some head-scratching.

On 3/4/20 4:42 PM, Kevin Buettner wrote:

> gdb/testsuite/ChangeLog:

>

> 	* gdb.base/corefile.exp (accessing anonymous, unwritten-to mmap data):

> 	New test.

> 	* gdb.base/coremaker.c (buf3): New global.

> 	(mmapdata): Add mmap call which uses MAP_ANONYMOUSE and MAP_PRIVATE

> 	flags.


The only comment I have (other than LGTM) is to mention the PR in
the ChangeLog entry (again).

Keith

Patch

diff --git a/gdb/testsuite/gdb.base/corefile.exp b/gdb/testsuite/gdb.base/corefile.exp
index 34b903b350..d46b38704c 100644
--- a/gdb/testsuite/gdb.base/corefile.exp
+++ b/gdb/testsuite/gdb.base/corefile.exp
@@ -175,6 +175,12 @@  gdb_test_multiple "x/8bd buf2" "$test" {
     }
 }
 
+# Test ability to read anonymous and, more importantly, unwritten-to
+# mmap'd data.
+
+gdb_test "x/wx buf3" "$hex:\[ \t\]+0x00000000" \
+	 "accessing anonymous, unwritten-to mmap data"
+
 # test reinit_frame_cache
 
 gdb_load ${binfile}
diff --git a/gdb/testsuite/gdb.base/coremaker.c b/gdb/testsuite/gdb.base/coremaker.c
index 55330fd3e8..3a01c16405 100644
--- a/gdb/testsuite/gdb.base/coremaker.c
+++ b/gdb/testsuite/gdb.base/coremaker.c
@@ -38,6 +38,7 @@ 
 
 char *buf1;
 char *buf2;
+char *buf3;
 
 int coremaker_data = 1;	/* In Data section */
 int coremaker_bss;	/* In BSS section */
@@ -98,6 +99,15 @@  mmapdata ()
     }
   /* Touch buf2 so kernel writes it out into 'core'. */
   buf2[0] = buf1[0];
+
+  /* Create yet another region which is allocated, but not written to.  */
+  buf3 = mmap (NULL, MAPSIZE, PROT_READ | PROT_WRITE,
+               MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+  if (buf3 == (char *) -1)
+    {
+      perror ("mmap failed");
+      return;
+    }
 }
 
 void