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

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