From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id E163A383E814 for ; Wed, 22 Jul 2020 00:59:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E163A383E814 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-74-d77lzvyoOh6fOQfnn-S9Yw-1; Tue, 21 Jul 2020 20:59:23 -0400 X-MC-Unique: d77lzvyoOh6fOQfnn-S9Yw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0384D1005504 for ; Wed, 22 Jul 2020 00:59:23 +0000 (UTC) Received: from f32-1.lan (ovpn-112-21.phx2.redhat.com [10.3.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA26D5C662; Wed, 22 Jul 2020 00:59:22 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Subject: [PATCH v5 09/14] Add test for accessing read-only mmapped data in a core file Date: Tue, 21 Jul 2020 17:58:27 -0700 Message-Id: <20200722005832.863276-10-kevinb@redhat.com> In-Reply-To: <20200722005832.863276-1-kevinb@redhat.com> References: <20200722005832.863276-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jul 2020 00:59:29 -0000 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 eaabe6c0f8..8abf62b51f 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