forked from Imagelibrary/binutils-gdb
But PR gdb/20126 highlights a case where GDB emits a large number of
warnings like:
warning: Can't open file /anon_hugepage (deleted) during file-backed mapping note processing
warning: Can't open file /dev/shm/PostgreSQL.1150234652 during file-backed mapping note processing
warning: Can't open file /dev/shm/PostgreSQL.535700290 during file-backed mapping note processing
warning: Can't open file /SYSV604b7d00 (deleted) during file-backed mapping note processing
... etc ...
when opening a core file. This commit aims to avoid at least some of
these warnings.
What we know is that, for at least some of these cases, (e.g. the
'(deleted)' mappings), the content of the mapping will have been
written into the core file itself. As such, the fact that the file
isn't available ('/SYSV604b7d00' at least is a shared memory mapping),
isn't really relevant, GDB can still provide access to the mapping, by
reading the content from the core file itself.
What I propose is that, when processing the file backed mappings, if
all of the mappings for a file are covered by segments within the core
file itself, then there is no need to warn the user that the file
can't be opened again. The debug experience should be unchanged, as
GDB would have read from the in-core mapping anyway.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30126
72 lines
2.4 KiB
Plaintext
72 lines
2.4 KiB
Plaintext
# Copyright 2025 Free Software Foundation, Inc.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# Create a core file with some mapped file regions, but ensure that
|
|
# the the kernel should write the regions into the core file (e.g. r/w
|
|
# file backed mapping).
|
|
#
|
|
# We then delete the file that backed the mapping and load the core
|
|
# file into GDB.
|
|
#
|
|
# GDB shouldn't warn about the file being missing. It doesn't matter;
|
|
# the file contents can all be found in the core file itself.
|
|
|
|
require isnative
|
|
require {!is_remote host}
|
|
|
|
standard_testfile
|
|
|
|
if {[build_executable $testfile.exp $testfile $srcfile] == -1} {
|
|
return
|
|
}
|
|
|
|
set corefile [core_find $binfile {}]
|
|
if {$corefile == ""} {
|
|
return
|
|
}
|
|
|
|
# Move the coremap.data file out of the way, so it cannot be found
|
|
# when we later load the core file into GDB. This file was generated
|
|
# by the inferior as it was running.
|
|
set data_filename \
|
|
[standard_output_file coredir.[getpid]/coremmap.data]
|
|
set backup_filename \
|
|
[standard_output_file coredir.[getpid]/coremmap.data.backup]
|
|
remote_exec host "mv ${data_filename} ${backup_filename}"
|
|
|
|
clean_restart $binfile
|
|
|
|
# Load the core file. The 'coremap.data' file cannot be found by GDB,
|
|
# but all the mappings for that file are r/w and should be present in
|
|
# the core file, so we shouldn't get any warnings from GDB about it.
|
|
set warnings_seen 0
|
|
gdb_test_multiple "core-file $corefile" "core-file command" {
|
|
-re "^warning: Can't open file \[^\r\n\]+ during file-backed mapping note processing\r\n" {
|
|
incr warnings_seen
|
|
exp_continue
|
|
}
|
|
-re "^$gdb_prompt $" {
|
|
gdb_assert { $warnings_seen == 0 } $gdb_test_name
|
|
}
|
|
-re "^\[^\r\n\]*\r\n" {
|
|
exp_continue
|
|
}
|
|
}
|
|
|
|
# Check the mappings are all readable.
|
|
foreach label { rw_mapping malloc_buffer anon_mapping shm_mapping } {
|
|
gdb_test "x/1wd $label" "^$hex:\\s+$decimal"
|
|
}
|