Blame SOURCES/gdb-rhbz1518243-gcore-VM_DONTDUMP-5of5.patch

2c2fa1
commit 3e1a70a0189ae8d2dacfef93790e42e42e721762
2c2fa1
Author: Sergio Lopez <slp@redhat.com>
2c2fa1
Date:   Mon Dec 4 09:17:16 2017 +0100
2c2fa1
2c2fa1
    Extend gdb.core/coredump-filter.exp to test dump-excluded-mappings.
2c2fa1
    
2c2fa1
    gdb/testsuite/ChangeLog:
2c2fa1
    2017-11-30  Sergio Lopez  <slp@redhat.com>
2c2fa1
    
2c2fa1
            * gdb.core/coredump-filter.exp: Extend test to verify
2c2fa1
            the functionality of the dump-excluded-mappings command.
2c2fa1
2c2fa1
Index: gdb-7.6.1/gdb/testsuite/gdb.base/coredump-filter.exp
2c2fa1
===================================================================
2c2fa1
--- gdb-7.6.1.orig/gdb/testsuite/gdb.base/coredump-filter.exp	2017-12-06 20:59:21.016161086 +0100
2c2fa1
+++ gdb-7.6.1/gdb/testsuite/gdb.base/coredump-filter.exp	2017-12-06 21:03:20.445710226 +0100
2c2fa1
@@ -95,16 +95,26 @@
2c2fa1
     return -1
2c2fa1
 }
2c2fa1
 
2c2fa1
-proc do_save_core { filter_flag core ipid } {
2c2fa1
+proc do_save_core { filter_flag core ipid dump_excluded } {
2c2fa1
     verbose -log "writing $filter_flag to /proc/$ipid/coredump_filter"
2c2fa1
 
2c2fa1
     remote_exec target "sh -c \"echo $filter_flag > /proc/$ipid/coredump_filter\""
2c2fa1
 
2c2fa1
+    # Enable dumping of excluded mappings (i.e. VM_DONTDUMP).
2c2fa1
+    if { $dump_excluded == 1 } {
2c2fa1
+        gdb_test_no_output "set dump-excluded-mappings on"
2c2fa1
+    }
2c2fa1
+
2c2fa1
     # Generate a corefile.
2c2fa1
     gdb_gcore_cmd "$core" "save corefile"
2c2fa1
+
2c2fa1
+    # Restore original status.
2c2fa1
+    if { $dump_excluded == 1 } {
2c2fa1
+        gdb_test_no_output "set dump-excluded-mappings off"
2c2fa1
+    }
2c2fa1
 }
2c2fa1
 
2c2fa1
-proc do_load_and_test_core { core var working_var working_value } {
2c2fa1
+proc do_load_and_test_core { core var working_var working_value dump_excluded } {
2c2fa1
     global hex decimal addr
2c2fa1
 
2c2fa1
     set core_loaded [gdb_core_cmd "$core" "load core"]
2c2fa1
@@ -114,10 +124,16 @@
2c2fa1
     }
2c2fa1
 
2c2fa1
     # Access the memory the addresses point to.
2c2fa1
-    gdb_test "print/x *(char *) $addr($var)" "\(\\\$$decimal = <error: \)?Cannot access memory at address $hex\(>\)?" \
2c2fa1
-	"printing $var when core is loaded (should not work)"
2c2fa1
-    gdb_test "print/x *(char *) $addr($working_var)" " = $working_value.*" \
2c2fa1
-	"print/x *$working_var ( = $working_value)"
2c2fa1
+    if { $dump_excluded == 0 } {
2c2fa1
+	gdb_test "print/x *(char *) $addr($var)" "\(\\\$$decimal = <error: \)?Cannot access memory at address $hex\(>\)?" \
2c2fa1
+	    "printing $var when core is loaded (should not work)"
2c2fa1
+	gdb_test "print/x *(char *) $addr($working_var)" " = $working_value.*" \
2c2fa1
+	    "print/x *$working_var ( = $working_value)"
2c2fa1
+    } else {
2c2fa1
+        # Check if VM_DONTDUMP mappings are present in the core file.
2c2fa1
+        gdb_test "print/x *(char *) $addr($var)" " = $working_value.*" \
2c2fa1
+	    "print/x *$var ( = $working_value)"
2c2fa1
+    }
2c2fa1
 }
2c2fa1
 
2c2fa1
 # We do not do file-backed mappings in the test program, but it is
2c2fa1
@@ -169,6 +185,7 @@
2c2fa1
 # A corefile without {private,shared} {anonymous,file-backed} pages
2c2fa1
 set non_private_shared_anon_file_core [standard_output_file non-private-shared-anon-file.gcore]
2c2fa1
 set dont_dump_core [standard_output_file dont-dump.gcore]
2c2fa1
+set dump_excluded_core [standard_output_file dump-excluded.gcore]
2c2fa1
 
2c2fa1
 # We will generate a few corefiles.
2c2fa1
 #
2c2fa1
@@ -184,6 +201,8 @@
2c2fa1
 # - name of a variable in the C source code that points to a memory
2c2fa1
 #   mapping that WILL be present in the corefile
2c2fa1
 # - corresponding value expected for the above variable
2c2fa1
+# - whether to include mappings marked as VM_DONTDUMP in the
2c2fa1
+#   corefile (1) or not (0).
2c2fa1
 #
2c2fa1
 # This list refers to the corefiles generated by MAP_ANONYMOUS in the
2c2fa1
 # test program.
2c2fa1
@@ -191,13 +210,16 @@
2c2fa1
 set all_anon_corefiles { { "non-Private-Anonymous" "0x7e" \
2c2fa1
 			       $non_private_anon_core \
2c2fa1
 			       "private_anon" \
2c2fa1
-			       "shared_anon" "0x22" }
2c2fa1
+			       "shared_anon" "0x22" "0" }
2c2fa1
     { "non-Shared-Anonymous" "0x7d" \
2c2fa1
 	  $non_shared_anon_core "shared_anon" \
2c2fa1
-	  "private_anon" "0x11" }
2c2fa1
+	  "private_anon" "0x11" "0" }
2c2fa1
     { "DoNotDump" "0x33" \
2c2fa1
 	  $dont_dump_core "dont_dump" \
2c2fa1
-	  "shared_anon" "0x22" } }
2c2fa1
+	  "shared_anon" "0x22" "0" }
2c2fa1
+    { "DoNotDump-DumpExcluded" "0x33" \
2c2fa1
+	  $dump_excluded_core "dont_dump" \
2c2fa1
+	  "shared_anon" "0x55" "1" } }
2c2fa1
 
2c2fa1
 # If corefile loading is not supported, we do not even try to run the
2c2fa1
 # tests.
2c2fa1
@@ -239,12 +261,12 @@
2c2fa1
 # Generate corefiles for the "anon" case.
2c2fa1
 foreach item $all_anon_corefiles {
2c2fa1
     with_test_prefix "saving corefile for [lindex $item 0]" {
2c2fa1
-	do_save_core [lindex $item 1] [subst [lindex $item 2]] $infpid
2c2fa1
+	do_save_core [lindex $item 1] [subst [lindex $item 2]] $infpid [lindex $item 6]
2c2fa1
     }
2c2fa1
 }
2c2fa1
 
2c2fa1
 with_test_prefix "saving corefile for non-Private-Shared-Anon-File" {
2c2fa1
-    do_save_core "0x60" $non_private_shared_anon_file_core $infpid
2c2fa1
+    do_save_core "0x60" $non_private_shared_anon_file_core $infpid "0"
2c2fa1
 }
2c2fa1
 
2c2fa1
 clean_restart $testfile
2c2fa1
@@ -252,7 +274,7 @@
2c2fa1
 foreach item $all_anon_corefiles {
2c2fa1
     with_test_prefix "loading and testing corefile for [lindex $item 0]" {
2c2fa1
 	do_load_and_test_core [subst [lindex $item 2]] [lindex $item 3] \
2c2fa1
-	    [lindex $item 4] [lindex $item 5]
2c2fa1
+	    [lindex $item 4] [lindex $item 5] [lindex $item 6]
2c2fa1
     }
2c2fa1
 
2c2fa1
     with_test_prefix "disassembling function main for [lindex $item 0]" {