From 9c5ec5c2dab18154b44a7bbb430cc7d393424116 Mon Sep 17 00:00:00 2001 From: Kevin Buettner Date: Fri, 3 Jul 2020 20:10:22 -0700 Subject: [PATCH] Adjust coredump-filter.exp to account for NT_FILE note handling This commit makes adjustments to coredump-filter.exp to account for the fact that NT_FILE file-backed mappings are now available when a core file is loaded. Thus, a test which was expected to PASS when a memory region was determined to be unavailable (due to no file-backed mappings being available) will now FAIL due to those mappings being available from having loaded the NT_FILE note. I had originally marked the test as XFAIL, but Mihails Strasuns suggested a much better approach: 1) First test that it still works if file is accessible in the filesystem. 2) Temporarily move / rename the file and test that disassembly doesn't work anymore. That's what this commit implements. gdb/testsuite/ChangeLog: * gdb.base/coredump-filter.exp: Add second non-Private-Shared-Anon-File test. (test_disasm): Rename binfile for test which is expected to fail. --- gdb/ChangeLog | 11 +++++++++++ gdb/testsuite/ChangeLog | 7 +++++++ gdb/testsuite/gdb.base/coredump-filter.exp | 18 +++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e773891c764..7dc6c4146ab 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,14 @@ +2020-07-22 Kevin Buettner + + * linux-tdep.c (dump_note_entry_p): New function. + (linux_dump_mapping_p_ftype): New typedef. + (linux_find_memory_regions_full): Add new parameter, + should_dump_mapping_p. + (linux_find_memory_regions): Adjust call to + linux_find_memory_regions_full. + (linux_make_mappings_core_file_notes): Use dump_note_entry_p in + call to linux_find_memory_regions_full. + 2020-07-22 Kevin Buettner * corelow.c (solist.h, unordered_map): Include. diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 5ed9969d187..b074741d889 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2020-07-22 Kevin Buettner + + * gdb.base/coredump-filter.exp: Add second + non-Private-Shared-Anon-File test. + (test_disasm): Rename binfile for test which is expected + to fail. + 2020-07-22 Kevin Buettner * gdb.base/corefile.exp: Add test "accessing read-only mmapped diff --git a/gdb/testsuite/gdb.base/coredump-filter.exp b/gdb/testsuite/gdb.base/coredump-filter.exp index ff398f2b851..5407d116325 100644 --- a/gdb/testsuite/gdb.base/coredump-filter.exp +++ b/gdb/testsuite/gdb.base/coredump-filter.exp @@ -80,15 +80,26 @@ proc do_load_and_test_core { core var working_var working_value dump_excluded } # disassemble of a function (i.e., the binary's .text section). GDB # should fail in this case. However, it must succeed if the binary is # provided along with the corefile. This is what we test here. +# +# A further complication is that Linux NT_FILE notes are now read from +# the corefile. This note allows GDB to find the binary for file +# backed mappings even though the binary wasn't loaded by GDB in the +# conventional manner. In order to see the expected failure for this +# case, we rename the binary in order to perform this test. proc test_disasm { core address should_fail } { - global testfile hex + global testfile hex binfile # Restart GDB without loading the binary. with_test_prefix "no binary" { gdb_exit gdb_start + set hide_binfile [standard_output_file "${testfile}.hide"] + if { $should_fail == 1 } { + remote_exec host "mv -f $binfile $hide_binfile" + } + set core_loaded [gdb_core_cmd "$core" "load core"] if { $core_loaded == -1 } { fail "loading $core" @@ -96,6 +107,7 @@ proc test_disasm { core address should_fail } { } if { $should_fail == 1 } { + remote_exec host "mv -f $hide_binfile $binfile" gdb_test "x/i \$pc" "=> $hex:\tCannot access memory at address $hex" \ "disassemble function with corefile and without a binary" } else { @@ -225,5 +237,9 @@ foreach item $all_anon_corefiles { } with_test_prefix "loading and testing corefile for non-Private-Shared-Anon-File" { + test_disasm $non_private_shared_anon_file_core $main_addr 0 +} + +with_test_prefix "loading and testing corefile for non-Private-Shared-Anon-File with renamed binary" { test_disasm $non_private_shared_anon_file_core $main_addr 1 } -- 2.30.2