public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v4 09/14] Add test for accessing read-only mmapped data in a core file
Date: Sun,  5 Jul 2020 15:58:02 -0700	[thread overview]
Message-ID: <20200705225807.2264705-10-kevinb@redhat.com> (raw)
In-Reply-To: <20200705225807.2264705-1-kevinb@redhat.com>

This test passes when run using a GDB with my corefile patches.  When
run against a GDB without my patches, I see the following failures,
the first of which is due to the test added by this commit:

FAIL: gdb.base/corefile.exp: accessing read-only mmapped data in core file (mapping address not found in core file)
FAIL: gdb.base/corefile.exp: accessing anonymous, unwritten-to mmap data

gdb/testsuite/ChangeLog:

	* gdb.base/corefile.exp: Add test "accessing read-only mmapped
	data in core file".
	* gdb.base/coremaker.c (buf2ro): New global.
	(mmapdata): Add a read-only mmap mapping.
---
 gdb/testsuite/gdb.base/corefile.exp | 18 +++++++++++++++++-
 gdb/testsuite/gdb.base/coremaker.c  | 14 ++++++++++++--
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/gdb.base/corefile.exp b/gdb/testsuite/gdb.base/corefile.exp
index d46b38704c..b0020a5fa9 100644
--- a/gdb/testsuite/gdb.base/corefile.exp
+++ b/gdb/testsuite/gdb.base/corefile.exp
@@ -34,7 +34,10 @@ if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
     return -1
 }
 
-set corefile [core_find $binfile {coremmap.data}]
+# Do not delete coremap.data when calling core_find.  This file is
+# required for GDB to find mmap'd data in the "accessing read-only
+# mmapped data in core file" test.
+set corefile [core_find $binfile {}]
 if {$corefile == ""} {
     return 0
 }
@@ -175,6 +178,19 @@ gdb_test_multiple "x/8bd buf2" "$test" {
     }
 }
 
+set test "accessing read-only mmapped data in core file"
+gdb_test_multiple "x/8bd buf2ro" "$test" {
+    -re ".*:.*0.*1.*2.*3.*4.*5.*6.*7.*$gdb_prompt $" {
+	pass "$test"
+    }
+    -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" {
+	fail "$test (mapping failed at runtime)"
+    }
+    -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" {
+	fail "$test (mapping address not found in core file)"
+    }
+}
+
 # Test ability to read anonymous and, more importantly, unwritten-to
 # mmap'd data.
 
diff --git a/gdb/testsuite/gdb.base/coremaker.c b/gdb/testsuite/gdb.base/coremaker.c
index 0981b21738..3fc13e9287 100644
--- a/gdb/testsuite/gdb.base/coremaker.c
+++ b/gdb/testsuite/gdb.base/coremaker.c
@@ -38,6 +38,7 @@
 
 char *buf1;
 char *buf2;
+char *buf2ro;
 char *buf3;
 
 int coremaker_data = 1;	/* In Data section */
@@ -90,16 +91,25 @@ mmapdata ()
       return;
     }
 
+  /* Map in another copy, read-only.  We won't write to this copy so it
+     will likely not end up in the core file.  */
+  buf2ro = (char *) mmap (0, MAPSIZE, PROT_READ, MAP_PRIVATE, fd, 0);
+  if (buf2ro == (char *) -1)
+    {
+      perror ("mmap failed");
+      return;
+    }
+
   /* Verify that the original data and the mapped data are identical.
      If not, we'd rather fail now than when trying to access the mapped
      data from the core file. */
 
   for (j = 0; j < MAPSIZE; ++j)
     {
-      if (buf1[j] != buf2[j])
+      if (buf1[j] != buf2[j] || buf1[j] != buf2ro[j])
 	{
 	  fprintf (stderr, "mapped data is incorrect");
-	  buf2 = (char *) -1;
+	  buf2 = buf2ro = (char *) -1;
 	  return;
 	}
     }
-- 
2.26.2


  parent reply	other threads:[~2020-07-05 22:59 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-05 22:57 [PATCH v4 00/14] Fix BZ 25631 - core file memory access problem Kevin Buettner
2020-07-05 22:57 ` [PATCH v4 01/14] Remove hack for GDB which sets the section size to 0 Kevin Buettner
2020-07-05 22:57 ` [PATCH v4 02/14] Adjust corefile.exp test to show regression after bfd hack removal Kevin Buettner
2020-07-05 22:57 ` [PATCH v4 03/14] section_table_xfer_memory: Replace section name with callback predicate Kevin Buettner
2020-07-05 22:57 ` [PATCH v4 04/14] Provide access to non SEC_HAS_CONTENTS core file sections Kevin Buettner
2020-07-05 22:57 ` [PATCH v4 05/14] Test ability to access unwritten-to mmap data in core file Kevin Buettner
2020-07-05 22:57 ` [PATCH v4 06/14] Update binary_get_section_contents to seek using section's file position Kevin Buettner
2020-07-05 22:58 ` [PATCH v4 07/14] Add new gdbarch method, read_core_file_mappings Kevin Buettner
2020-07-05 22:58 ` [PATCH v4 08/14] Use NT_FILE note section for reading core target memory Kevin Buettner
2020-07-10 20:08   ` Pedro Alves
2020-07-14  7:53     ` Kevin Buettner
2020-07-21 18:21       ` Tom Tromey
2020-07-21  2:09     ` Kevin Buettner
2020-07-05 22:58 ` Kevin Buettner [this message]
2020-07-05 22:58 ` [PATCH v4 10/14] gcore command: Place all file-backed mappings in NT_FILE note Kevin Buettner
2020-07-05 22:58 ` [PATCH v4 11/14] xfail gdb.base/coredump-filter.exp test which now works without a binary Kevin Buettner
2020-07-10 20:07   ` Pedro Alves
2020-07-13 11:38     ` Strasuns, Mihails
2020-07-13 17:04       ` Kevin Buettner
2020-07-05 22:58 ` [PATCH v4 12/14] Add new command "maint print core-file-backed-mappings" Kevin Buettner
2020-07-10 20:08   ` Pedro Alves
2020-07-10 20:10     ` Pedro Alves
2020-07-13 17:33     ` Kevin Buettner
2020-07-05 22:58 ` [PATCH v4 13/14] Add documentation for " Kevin Buettner
2020-07-06  2:26   ` Eli Zaretskii
2020-07-05 22:58 ` [PATCH v4 14/14] New core file tests with mappings over existing program memory Kevin Buettner
2020-07-10 20:08   ` Pedro Alves
2020-07-10 20:13 ` [PATCH v4 00/14] Fix BZ 25631 - core file memory access problem Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200705225807.2264705-10-kevinb@redhat.com \
    --to=kevinb@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).