gdb: silence some 'Can't open file' warnings from core file loading

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
This commit is contained in:
Andrew Burgess
2025-03-12 11:16:42 +00:00
parent 7fa205d2fe
commit 33d5188ab1
3 changed files with 223 additions and 4 deletions

View File

@@ -540,11 +540,41 @@ core_target::build_file_mappings ()
/* If ABFD was opened, but the wrong format, close it now. */
abfd = nullptr;
/* When true, this indicates that the mapped contents of this
file are available within the core file. When false, some of
the mapped contents are not available. If the contents are
entirely available within the core file, then we don't need to
warn the user if GDB cannot find the file. */
bool content_is_in_core_file_p = true;
/* Record all regions for this file as unavailable. */
for (const mapped_file::region &region : file_data.regions)
m_core_unavailable_mappings.emplace_back (region.start,
region.end
- region.start);
{
/* Check to see if the region is available within the core
file. */
bool found_region_in_core_file = false;
for (const target_section &ts : m_core_section_table)
{
if (ts.addr <= region.start && ts.endaddr >= region.end
&& (ts.the_bfd_section->flags & SEC_HAS_CONTENTS) != 0)
{
found_region_in_core_file = true;
break;
}
}
/* This region is not available within the core file.
Without the file available to read from it is not possible
for GDB to read this mapping within the inferior. Warn
the user about this case. */
if (!found_region_in_core_file)
content_is_in_core_file_p = false;
/* Record the unavailable region. */
m_core_unavailable_mappings.emplace_back (region.start,
region.end
- region.start);
}
/* And give the user an appropriate warning. */
if (build_id_mismatch)
@@ -564,7 +594,7 @@ core_target::build_file_mappings ()
styled_string (file_name_style.style (),
expanded_fname.get ()));
}
else
else if (!content_is_in_core_file_p)
{
if (expanded_fname == nullptr
|| filename == expanded_fname.get ())