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

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