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

be07d7
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
be07d7
From: Keith Seitz <keiths@redhat.com>
be07d7
Date: Tue, 28 Jul 2020 09:26:44 -0400
be07d7
Subject: gdb-rhbz1842691-corefile-mem-access-11of15.patch
be07d7
be07d7
;; Adjust coredump-filter.exp to account for NT_FILE note handling
be07d7
;; Kevin Buettner, RH BZ 1842961
be07d7
be07d7
   Author: Kevin Buettner <kevinb@redhat.com>
be07d7
   Date:   Fri Jul 3 20:10:22 2020 -0700
be07d7
be07d7
    Adjust coredump-filter.exp to account for NT_FILE note handling
be07d7
be07d7
    This commit makes adjustments to coredump-filter.exp to account
be07d7
    for the fact that NT_FILE file-backed mappings are now available
be07d7
    when a core file is loaded.  Thus, a test which was expected
be07d7
    to PASS when a memory region was determined to be unavailable
be07d7
    (due to no file-backed mappings being available) will now FAIL
be07d7
    due to those mappings being available from having loaded the
be07d7
    NT_FILE note.
be07d7
be07d7
    I had originally marked the test as XFAIL, but Mihails Strasuns
be07d7
    suggested a much better approach:
be07d7
be07d7
        1) First test that it still works if file is accessible in the
be07d7
           filesystem.
be07d7
        2) Temporarily move / rename the file and test that disassembly
be07d7
           doesn't work anymore.
be07d7
be07d7
    That's what this commit implements.
be07d7
be07d7
    gdb/testsuite/ChangeLog:
be07d7
be07d7
    	* gdb.base/coredump-filter.exp: Add second
be07d7
    	non-Private-Shared-Anon-File test.
be07d7
    	(test_disasm): Rename binfile for test which is expected
be07d7
    	to fail.
be07d7
be07d7
diff --git a/gdb/testsuite/gdb.base/coredump-filter.exp b/gdb/testsuite/gdb.base/coredump-filter.exp
be07d7
--- a/gdb/testsuite/gdb.base/coredump-filter.exp
be07d7
+++ b/gdb/testsuite/gdb.base/coredump-filter.exp
be07d7
@@ -80,15 +80,26 @@ proc do_load_and_test_core { core var working_var working_value dump_excluded }
be07d7
 # disassemble of a function (i.e., the binary's .text section).  GDB
be07d7
 # should fail in this case.  However, it must succeed if the binary is
be07d7
 # provided along with the corefile.  This is what we test here.
be07d7
+#
be07d7
+# A further complication is that Linux NT_FILE notes are now read from
be07d7
+# the corefile.  This note allows GDB to find the binary for file
be07d7
+# backed mappings even though the binary wasn't loaded by GDB in the
be07d7
+# conventional manner.  In order to see the expected failure for this
be07d7
+# case, we rename the binary in order to perform this test.
be07d7
 
be07d7
 proc test_disasm { core address should_fail } {
be07d7
-    global testfile hex
be07d7
+    global testfile hex binfile
be07d7
 
be07d7
     # Restart GDB without loading the binary.
be07d7
     with_test_prefix "no binary" {
be07d7
 	gdb_exit
be07d7
 	gdb_start
be07d7
 
be07d7
+	set hide_binfile [standard_output_file "${testfile}.hide"]
be07d7
+	if { $should_fail == 1 } {
be07d7
+	    remote_exec host "mv -f $binfile $hide_binfile"
be07d7
+	}
be07d7
+
be07d7
 	set core_loaded [gdb_core_cmd "$core" "load core"]
be07d7
 	if { $core_loaded == -1 } {
be07d7
 	    fail "loading $core"
be07d7
@@ -96,6 +107,7 @@ proc test_disasm { core address should_fail } {
be07d7
 	}
be07d7
 
be07d7
 	if { $should_fail == 1 } {
be07d7
+	    remote_exec host "mv -f $hide_binfile $binfile"
be07d7
 	    gdb_test "x/i \$pc" "=> $hex:\tCannot access memory at address $hex" \
be07d7
 		"disassemble function with corefile and without a binary"
be07d7
 	} else {
be07d7
@@ -225,5 +237,9 @@ foreach item $all_anon_corefiles {
be07d7
 }
be07d7
 
be07d7
 with_test_prefix "loading and testing corefile for non-Private-Shared-Anon-File" {
be07d7
+    test_disasm $non_private_shared_anon_file_core $main_addr 0
be07d7
+}
be07d7
+
be07d7
+with_test_prefix "loading and testing corefile for non-Private-Shared-Anon-File with renamed binary" {
be07d7
     test_disasm $non_private_shared_anon_file_core $main_addr 1
be07d7
 }