From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 5/5] gdb/linux: handle missing NT_FILE note when opening core files
Date: Sat, 14 Mar 2026 14:32:22 +0000 [thread overview]
Message-ID: <84829f29d55cd681c1829c60109c9eb140353795.1773498341.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1773498341.git.aburgess@redhat.com>
This patch originated from this mailing list discussion:
https://inbox.sourceware.org/gdb-patches/b9b5bf03c59b58e02ca27b522338c6103d5ae49f.camel@gnu.org
The user has some core files which lack an NT_FILE note. They
wondered why GDB was still unable to find the shared libraries based
on their build-id.
The reason right now is that GDB only records the build-id information
for mappings based on the entries in the NT_FILE note. With the
entries in this note we build several lookup tables; a filename to
build-id table, a soname (extracted from the file if it is a shared
library) to build-id table, and an address range to build-id table.
When a shared library is being loaded we perform a lookup using two
pieces of information; the shared library's filename, and an address
that we know is within the shared library. If either of these give a
build-id, then we can use that build-id to ensure GDB loads the
shared library that matches the core file.
If the NT_FILE note is missing then none of the lookup tables are
created, and so the shared library build-id lookup fails, meaning that
all GDB can do is look for the shared library by name on the local
file system. This often results in the wrong library version being
loaded, or the library not being found at all.
However, Linux core files also have the segment table. This table
gives address ranges. The segment table doesn't tell us what file was
mapped in, or the offset within the file that was mapped in. But if
we go back to the three lookup tables, we can use the segment table to
build the address to build-id lookup table, and that would be enough
to allow GDB to find the build-id for a shared library in most cases.
So, here's what this patch does: linux_read_core_file_mappings (in
linux-tdep.c) is updated to first parse the NT_FILE note as it
currently does. But after this we also walk the segment table (BFD
actually converts these into sections with the LOAD flag set), and if
a segment has a build-id, and doesn't correspond to an entry found in
the NT_FILE note, we create an anonymous mapping. An anonymous
mapping is just like a mapping from the NT_FILE note, but without a
filename and file offset. This mapping is passed through the callback
just like the traditional, non-anonymous, mappings.
Then in corelow.c various functions are updated in order to handle
anonymous mappings.
Back in linux-tdep.c, function linux_core_info_proc_mappings gets a
small update to handle anonymous mappings.
The corefile-buildid.exp test is updated to remove the NT_FILE notes
and rerun the tests. This should make no difference as all this test
is checking is that GDB is able to find and load the shared libraries
and executable based on their build-ids; this is something we can do
fine now without the NT_FILE note.
I have also had to update the Python core file API documentation after
this commit. Previously we claimed that CorefileMappedFile.filename
would never be empty, but this is now possible. Luckily, this API has
not yet been in a released version of GDB, so this minor tweak isn't
going to break any existing user code. I did consider having
CorefileMappedFile.filename be a non-empty string or None, but I
couldn't see much value in this, so I just documented that the string
could be empty, and what this means.
The py-corefile.exp test needed a minor update to filter out anonymous
mappings (those without a filename), this matches the behaviour of the
builtin 'info proc mappings' command.
---
gdb/corelow.c | 56 ++--
gdb/doc/python.texi | 10 +-
gdb/gdbcore.h | 28 +-
gdb/linux-tdep.c | 304 +++++++++++++-------
gdb/testsuite/gdb.base/corefile-buildid.exp | 27 ++
gdb/testsuite/gdb.python/py-corefile.py | 4 +
6 files changed, 295 insertions(+), 134 deletions(-)
diff --git a/gdb/corelow.c b/gdb/corelow.c
index d63dd5f8f0d..d1412c4903a 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -405,12 +405,25 @@ core_target::build_file_mappings ()
gdb::unordered_string_map<struct bfd *> bfd_map;
gdb::unordered_set<std::string> unavailable_paths;
- /* All files mapped into the core file. The key is the filename. */
+ /* All files mapped into the core file. */
std::vector<core_mapped_file> mapped_files
= gdb_read_core_file_mappings (m_core_gdbarch, this->core_bfd ());
for (const core_mapped_file &file_data : mapped_files)
{
+ /* A mapping without a filename can still have a build-id. Tracking
+ these mappings is useful as when the shared libraries are loaded,
+ if the shared library is within this anonymous region, we can
+ validate the build-id of the shared library being loaded. */
+ if (file_data.filename.empty ())
+ {
+ gdb_assert (file_data.build_id != nullptr);
+ std::vector<mem_range> ranges = file_data.mem_ranges ();
+ m_mapped_file_info.add (nullptr, nullptr, nullptr,
+ std::move (ranges), file_data.build_id);
+ continue;
+ }
+
/* If this mapped file is marked as the main executable then record
the filename as we can use this later. */
if (file_data.is_main_exec && m_expected_exec_filename.empty ())
@@ -476,10 +489,6 @@ core_target::build_file_mappings ()
}
}
- std::vector<mem_range> ranges;
- for (const core_mapped_file::region ®ion : file_data.regions)
- ranges.emplace_back (region.start, region.end - region.start);
-
if (expanded_fname == nullptr
|| abfd == nullptr
|| !bfd_check_format (abfd.get (), bfd_object))
@@ -592,7 +601,7 @@ core_target::build_file_mappings ()
libraries. */
if (file_data.build_id != nullptr)
{
- normalize_mem_ranges (&ranges);
+ std::vector<mem_range> ranges = file_data.mem_ranges ();
const char *actual_filename = nullptr;
gdb::unique_xmalloc_ptr<char> soname;
@@ -1963,7 +1972,6 @@ mapped_file_info::add (const char *soname,
const bfd_build_id *build_id)
{
gdb_assert (build_id != nullptr);
- gdb_assert (expected_filename != nullptr);
if (soname != nullptr)
{
@@ -1983,13 +1991,17 @@ mapped_file_info::add (const char *soname,
m_soname_to_build_id_map[soname] = build_id;
}
- /* When the core file is initially opened and the mapped files are
- parsed, we group the build-id information based on the file name. As
- a consequence, we should see each EXPECTED_FILENAME value exactly
- once. This means that each insertion should always succeed. */
- const auto inserted
- = m_filename_to_build_id_map.emplace (expected_filename, build_id).second;
- gdb_assert (inserted);
+ /* Ignore empty filenames. */
+ if (expected_filename != nullptr)
+ {
+ /* When the core file is initially opened and the mapped files are
+ parsed, we group the build-id information based on the file name. As
+ a consequence, we should see each EXPECTED_FILENAME value exactly
+ once. This means that each insertion should always succeed. */
+ const auto inserted
+ = m_filename_to_build_id_map.emplace (expected_filename, build_id).second;
+ gdb_assert (inserted);
+ }
/* Setup the reverse build-id to file name map. */
if (actual_filename != nullptr)
@@ -2135,9 +2147,19 @@ gdb_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd)
[&] (ULONGEST start, ULONGEST end, ULONGEST file_ofs,
const char *filename, const bfd_build_id *build_id)
{
- /* Architecture-specific read_core_mapping methods are expected to
- weed out non-file-backed mappings. */
- gdb_assert (filename != nullptr);
+ if (filename == nullptr)
+ {
+ /* A mapping without a filename MUST have a build-id, and the
+ file_ofs MUST be 0, but the file_ofs is actually meaningless
+ in this case. */
+ gdb_assert (build_id != nullptr);
+ gdb_assert (file_ofs == 0);
+
+ results.emplace_back ();
+ results.back ().build_id = build_id;
+ results.back ().regions.emplace_back (start, end, file_ofs);
+ return;
+ }
/* Add this mapped region to the data for FILENAME. */
auto iter = mapped_files.find (filename);
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 2df3b7c0423..6653601f4e2 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -9016,8 +9016,10 @@ Core Files In Python
A @code{gdb.CorefileMappedFile} object has the following attributes:
@defvar CorefileMappedFile.filename
-This read only attribute contains a non-empty string, the file name of
-the mapped file.
+This read only attribute contains a string, the file name of the
+mapped file. This string can be empty if @value{GDBN} was unable to
+find the name of the mapped file. If this string is empty then
+@code{CorefileMappedFile.build_id} will not be @code{None}.
@end defvar
@defvar CorefileMappedFile.build_id
@@ -9057,7 +9059,9 @@ Core Files In Python
@defvar CorefileMappedFileRegion.file_offset
This read only attribute contains the offset within the mapped file
-for this mapping.
+for this mapping. This attribute will be @code{0} if the containing
+@code{CorefileMappedFile.filename} is empty, in which case this
+attribute has no meaning.
@end defvar
@node Python Auto-loading
diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h
index 89586e0c6ec..3fd91770c54 100644
--- a/gdb/gdbcore.h
+++ b/gdb/gdbcore.h
@@ -261,7 +261,9 @@ core_target_find_mapped_file (const char *filename,
/* Type holding information about a single file mapped into the inferior
at the point when the core file was created. Associates a build-id
- with the list of regions the file is mapped into. */
+ with the list of regions the file is mapped into. It is acceptable to
+ have a core_mapped_file with an empty filename, so long as we have a
+ build-id for the mapping. */
struct core_mapped_file
{
/* Type for a region of a file that was mapped into the inferior when
@@ -281,15 +283,22 @@ struct core_mapped_file
/* The inferior address immediately after the mapped region. */
CORE_ADDR end;
- /* The offset within the mapped file for this content. */
+ /* The offset within the mapped file for this content. If the
+ filename of the mapping is empty then this field will be 0, but has
+ no meaning. */
CORE_ADDR file_ofs;
};
- /* The filename as recorded in the core file. */
+ /* The filename as recorded in the core file. This can be empty meaning
+ that GDB was unable to find a filename for this mapping. If the
+ filename is empty then the build_id field MUST be non-NULL. If this
+ is empty then the region::file_ofs fields will all be 0, and have no
+ meaning. */
std::string filename;
/* If not nullptr, then this is the build-id associated with this
- file. */
+ mapping. If the filename field is empty, then this MUST be
+ non-NULL. */
const bfd_build_id *build_id = nullptr;
/* All the mapped regions of this file. */
@@ -297,6 +306,17 @@ struct core_mapped_file
/* True if this is the main executable. */
bool is_main_exec = false;
+
+ /* Convert the REGIONS to a vector of mem_range objects. */
+ std::vector<mem_range>
+ mem_ranges () const
+ {
+ std::vector<mem_range> ranges;
+ for (const core_mapped_file::region ®ion : this->regions)
+ ranges.emplace_back (region.start, region.end - region.start);
+ normalize_mem_ranges (&ranges);
+ return ranges;
+ }
};
extern std::vector<core_mapped_file> gdb_read_core_file_mappings
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 0eaf9597ad8..b9bfa80af4d 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1116,6 +1116,33 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
}
}
+/* Return a map from the start address of any LOAD segment in CBFD to the
+ associated build-id. The map only contains entries for those segments
+ where a build-id is found, so the build-id will never be NULL, but not
+ every segment will have an entry in the map. */
+
+static gdb::unordered_map<CORE_ADDR, const bfd_build_id *>
+linux_read_build_ids_from_core_file_mappings (struct bfd *cbfd)
+{
+ gdb::unordered_map<CORE_ADDR, const bfd_build_id *> vma_to_build_id_map;
+
+ auto restore_cbfd_build_id = make_scoped_restore (&cbfd->build_id);
+
+ /* Search for solib build-ids in the core file. Each time one is found,
+ map the start vma of the corresponding elf header to the build-id. */
+ for (bfd_section *sec = cbfd->sections; sec != nullptr; sec = sec->next)
+ {
+ cbfd->build_id = nullptr;
+
+ if (sec->flags & SEC_LOAD
+ && (get_elf_backend_data (cbfd)->elf_backend_core_find_build_id
+ (cbfd, (bfd_vma) sec->filepos)))
+ vma_to_build_id_map[sec->vma] = cbfd->build_id;
+ }
+
+ return vma_to_build_id_map;
+}
+
/* Implementation of `gdbarch_read_core_file_mappings', as defined in
gdbarch.h.
@@ -1132,103 +1159,39 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
long file_ofs
followed by COUNT filenames in ASCII: "FILE1" NUL "FILE2" NUL...
+ In addition to reading the NT_FILE note, this function also considers
+ all of the LOADable segments (which BFD turns into sections). If a
+ segment is loadable, has a build-id, and isn't covered by an NT_FILE
+ entry, then we consider it an anonymous mapping. Tracking these is
+ useful when we load shared libraries. If a shared library corresponds
+ to an anonymous mapping then we can validate the build-id of the shared
+ library. This is useful when core files are created without an NT_FILE
+ note.
+
CBFD is the BFD of the core file.
LOOP_CB is the callback function that will be executed once
for each mapping. */
static void
-linux_read_core_file_mappings
- (struct gdbarch *gdbarch,
- struct bfd *cbfd,
- read_core_file_mappings_loop_ftype loop_cb)
+linux_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd,
+ read_core_file_mappings_loop_ftype loop_cb)
{
/* Ensure that ULONGEST is big enough for reading 64-bit core files. */
static_assert (sizeof (ULONGEST) >= 8);
- /* It's not required that the NT_FILE note exists, so return silently
- if it's not found. Beyond this point though, we'll complain
- if problems are found. */
- asection *section = bfd_get_section_by_name (cbfd, ".note.linuxcore.file");
- if (section == nullptr)
- return;
+ /* Map from the start address of LOAD segments to the associated
+ build-id, but only for segments that have a build-id. */
+ gdb::unordered_map<CORE_ADDR, const bfd_build_id *> vma_map
+ = linux_read_build_ids_from_core_file_mappings (cbfd);
- unsigned int addr_size_bits = gdbarch_addr_bit (gdbarch);
- unsigned int addr_size = addr_size_bits / 8;
- size_t note_size = bfd_section_size (section);
+ /* Track the start address of each mapping found. This allows us to
+ quickly drop duplicates when processing the NT_FILE note then the LOAD
+ segments. */
+ gdb::unordered_set<CORE_ADDR> mapping_start_addresses;
- if (note_size < 2 * addr_size)
- {
- warning (_("malformed core note - too short for header"));
- return;
- }
-
- gdb::byte_vector contents (note_size);
- if (!bfd_get_section_contents (cbfd, section, contents.data (), 0,
- note_size))
- {
- warning (_("could not get core note contents"));
- return;
- }
-
- gdb_byte *descdata = contents.data ();
- char *descend = (char *) descdata + note_size;
-
- if (descdata[note_size - 1] != '\0')
- {
- warning (_("malformed note - does not end with \\0"));
- return;
- }
-
- ULONGEST count = bfd_get (addr_size_bits, cbfd, descdata);
- descdata += addr_size;
-
- ULONGEST page_size = bfd_get (addr_size_bits, cbfd, descdata);
- descdata += addr_size;
-
- if (note_size < 2 * addr_size + count * 3 * addr_size)
- {
- warning (_("malformed note - too short for supplied file count"));
- return;
- }
-
- char *filenames = (char *) descdata + count * 3 * addr_size;
-
- /* Make sure that the correct number of filenames exist. Complain
- if there aren't enough or are too many. */
- char *f = filenames;
- for (int i = 0; i < count; i++)
- {
- if (f >= descend)
- {
- warning (_("malformed note - filename area is too small"));
- return;
- }
- f += strnlen (f, descend - f) + 1;
- }
- /* Complain, but don't return early if the filename area is too big. */
- if (f != descend)
- warning (_("malformed note - filename area is too big"));
-
- const bfd_build_id *orig_build_id = cbfd->build_id;
- gdb::unordered_map<ULONGEST, const bfd_build_id *> vma_map;
-
- /* Search for solib build-ids in the core file. Each time one is found,
- map the start vma of the corresponding elf header to the build-id. */
- for (bfd_section *sec = cbfd->sections; sec != nullptr; sec = sec->next)
- {
- cbfd->build_id = nullptr;
-
- if (sec->flags & SEC_LOAD
- && (get_elf_backend_data (cbfd)->elf_backend_core_find_build_id
- (cbfd, (bfd_vma) sec->filepos)))
- vma_map[sec->vma] = cbfd->build_id;
- }
-
- cbfd->build_id = orig_build_id;
-
- /* Vector to collect proc mappings. */
- struct proc_mapping
+ /* Vector to collect all mappings. */
+ struct a_mapping
{
ULONGEST start;
ULONGEST end;
@@ -1236,38 +1199,155 @@ linux_read_core_file_mappings
const char *filename;
const bfd_build_id *build_id;
};
- std::vector<struct proc_mapping> proc_mappings;
+ std::vector<struct a_mapping> all_mappings;
- /* Collect proc mappings. */
- for (int i = 0; i < count; i++)
+ /* If we find the NT_FILE section below then we need to load its
+ contents, and those contents need to remain live until the end of this
+ function. This vector will hold the contents. */
+ gdb::byte_vector contents;
+
+ /* It's not required that the NT_FILE note exists, so return silently
+ if it's not found. Beyond this point though, we'll complain
+ if problems are found. */
+ asection *section = bfd_get_section_by_name (cbfd, ".note.linuxcore.file");
+ if (section != nullptr)
{
- struct proc_mapping m;
- m.start = bfd_get (addr_size_bits, cbfd, descdata);
- descdata += addr_size;
- m.end = bfd_get (addr_size_bits, cbfd, descdata);
- descdata += addr_size;
- m.file_ofs = bfd_get (addr_size_bits, cbfd, descdata) * page_size;
- descdata += addr_size;
- m.filename = filenames;
- filenames += strlen ((char *) filenames) + 1;
+ unsigned int addr_size_bits = gdbarch_addr_bit (gdbarch);
+ unsigned int addr_size = addr_size_bits / 8;
+ size_t note_size = bfd_section_size (section);
- m.build_id = nullptr;
- auto vma_map_it = vma_map.find (m.start);
- if (vma_map_it != vma_map.end ())
- m.build_id = vma_map_it->second;
+ if (note_size < 2 * addr_size)
+ {
+ warning (_("malformed core note - too short for header"));
+ return;
+ }
- proc_mappings.push_back (m);
+ contents.resize (note_size);
+ if (!bfd_get_section_contents (cbfd, section, contents.data (), 0,
+ note_size))
+ {
+ warning (_("could not get core note contents"));
+ return;
+ }
+
+ gdb_byte *descdata = contents.data ();
+ char *descend = (char *) descdata + note_size;
+
+ if (descdata[note_size - 1] != '\0')
+ {
+ warning (_("malformed note - does not end with \\0"));
+ return;
+ }
+
+ ULONGEST count = bfd_get (addr_size_bits, cbfd, descdata);
+ descdata += addr_size;
+
+ ULONGEST page_size = bfd_get (addr_size_bits, cbfd, descdata);
+ descdata += addr_size;
+
+ if (note_size < 2 * addr_size + count * 3 * addr_size)
+ {
+ warning (_("malformed note - too short for supplied file count"));
+ return;
+ }
+
+ char *filenames = (char *) descdata + count * 3 * addr_size;
+
+ /* Make sure that the correct number of filenames exist. Complain
+ if there aren't enough or are too many. */
+ char *f = filenames;
+ for (int i = 0; i < count; i++)
+ {
+ if (f >= descend)
+ {
+ warning (_("malformed note - filename area is too small"));
+ return;
+ }
+ f += strnlen (f, descend - f) + 1;
+ }
+ /* Complain, but don't return early if the filename area is too big. */
+ if (f != descend)
+ warning (_("malformed note - filename area is too big"));
+
+ /* Collect proc mappings. */
+ for (int i = 0; i < count; i++)
+ {
+ struct a_mapping m;
+ m.start = bfd_get (addr_size_bits, cbfd, descdata);
+ descdata += addr_size;
+ m.end = bfd_get (addr_size_bits, cbfd, descdata);
+ descdata += addr_size;
+ m.file_ofs = bfd_get (addr_size_bits, cbfd, descdata) * page_size;
+ descdata += addr_size;
+ m.filename = filenames;
+ filenames += strlen ((char *) filenames) + 1;
+
+ m.build_id = nullptr;
+ auto vma_map_it = vma_map.find (m.start);
+ if (vma_map_it != vma_map.end ())
+ m.build_id = vma_map_it->second;
+
+ all_mappings.push_back (m);
+ mapping_start_addresses.insert (m.start);
+ }
}
- /* Sort proc mappings. */
- std::sort (proc_mappings.begin (), proc_mappings.end (),
- [] (const proc_mapping &a, const proc_mapping &b)
- {
- return a.start < b.start;
- });
+ /* Now look through the LOAD segments. These have all been converted to
+ sections with the SEC_LOAD flag by BFD. If we find a section that
+ contains a build-id, and which wasn't covered by an NT_FILE note, then
+ we create a mapping entry with no filename. */
+ for (bfd_section *sec = cbfd->sections; sec != nullptr; sec = sec->next)
+ {
+ /* Skip non LOAD segments. */
+ if ((sec->flags & SEC_LOAD) == 0)
+ continue;
- /* Call loop_cb with sorted proc mappings. */
- for (const auto &m : proc_mappings)
+ CORE_ADDR start = bfd_section_vma (sec);
+
+ /* If there is already a mapping at this address (likely from the
+ NT_FILE processing above) then skip this LOAD segment. Currently
+ this is assuming that the mapping from NT_FILE will be the same
+ size as the LOAD segment, if this ever turns out not to be the
+ case then we might need to be smarter here and figure out
+ non-overlapping regions. But that seems like unnecessary
+ complexity for now. */
+ auto mapping_start_addresses_it = mapping_start_addresses.find (start);
+ if (mapping_start_addresses_it != mapping_start_addresses.end ())
+ continue;
+
+ /* This LOAD segment is not covered by an NT_FILE entry, so we are
+ not going to have a filename associated with the mapping. Still,
+ we might be able to find a build-id, and if we can, then tracking
+ this mapping is still useful as, when we load shared libraries, if
+ a library sits in this mapping we can validate the library's
+ build-id. If we cannot find a build-id for this mapping then
+ there's no point tracking it, as it tells us nothing of value; no
+ filename, no build-id. */
+ const bfd_build_id *build_id = nullptr;
+ auto vma_map_it = vma_map.find (start);
+ if (vma_map_it != vma_map.end ())
+ build_id = vma_map_it->second;
+ if (build_id == nullptr)
+ continue;
+
+ /* Create an anonymous mapping object, one without a filename. */
+ CORE_ADDR end = start + bfd_section_size (sec);
+
+ struct a_mapping m { .start = start, .end = end,
+ .file_ofs = 0, .filename = nullptr, .build_id = build_id };
+ all_mappings.push_back (m);
+ mapping_start_addresses.insert (start);
+ }
+
+ /* Sort the mappings. */
+ std::sort (all_mappings.begin (), all_mappings.end (),
+ [] (const a_mapping &a, const a_mapping &b)
+ {
+ return a.start < b.start;
+ });
+
+ /* Call loop_cb with sorted mappings. */
+ for (const a_mapping &m : all_mappings)
loop_cb (m.start, m.end, m.file_ofs, m.filename, m.build_id);
}
@@ -1283,6 +1363,10 @@ linux_core_info_proc_mappings (struct gdbarch *gdbarch, struct bfd *cbfd,
[&] (ULONGEST start, ULONGEST end, ULONGEST file_ofs,
const char *filename, const bfd_build_id *build_id)
{
+ /* Ignore anonymous mappings. */
+ if (filename == nullptr)
+ return;
+
if (!emitter.has_value ())
{
gdb_printf (_("Mapped address spaces:\n\n"));
diff --git a/gdb/testsuite/gdb.base/corefile-buildid.exp b/gdb/testsuite/gdb.base/corefile-buildid.exp
index 1dec651e03c..f9e0e072d92 100644
--- a/gdb/testsuite/gdb.base/corefile-buildid.exp
+++ b/gdb/testsuite/gdb.base/corefile-buildid.exp
@@ -21,6 +21,10 @@
standard_testfile .c -shlib-shr.c -shlib.c
+# Reuse the Python script from another test. This provides a command
+# to remove a particular note from a core file.
+set pyfile [gdb_remote_download host ${srcdir}/${subdir}/corefile-no-threads.py]
+
# Create a corefile from PROGNAME. Return the name of the generated
# corefile, or the empty string if anything goes wrong.
#
@@ -345,6 +349,21 @@ foreach_with_prefix mode { exec shared } {
return
}
+ if { [allow_python_tests] } {
+ # Create a corefile with no NT_FILE notes.
+ gdb_start
+ set corefile_no_nt_file [standard_output_file ${corefile}-no-nt_file]
+ remote_exec build "cp $corefile $corefile_no_nt_file"
+ gdb_test_no_output "source $::pyfile" "import python scripts"
+ gdb_test "modify-core-file \"$corefile_no_nt_file\" NT_FILE" \
+ [multi_line \
+ "Located PT_NOTE segment: \[^\r\n\]+" \
+ "\\s+Found note with type $hex at file offset $hex\\..*" \
+ "Successfully updated $decimal note\\(s\\) in \[^\r\n\]+"] \
+ "update core file"
+ gdb_exit
+ }
+
# Create a directory for the non-stripped test, copy every build
# artefact into this directory.
set combined_dirname [standard_output_file ${mode}_not-stripped]
@@ -394,6 +413,14 @@ foreach_with_prefix mode { exec shared } {
locate_exec_from_core_build_id $corefile $dirname \
$build_artefacts $sepdebug $symlink \
[expr {$mode eq "shared"}]
+
+ if { [allow_python_tests] } {
+ with_test_prefix "NT_FILE removed" {
+ locate_exec_from_core_build_id $corefile_no_nt_file $dirname \
+ $build_artefacts $sepdebug $symlink \
+ [expr {$mode eq "shared"}]
+ }
+ }
}
}
}
diff --git a/gdb/testsuite/gdb.python/py-corefile.py b/gdb/testsuite/gdb.python/py-corefile.py
index 43b64085117..22049cdf6ae 100644
--- a/gdb/testsuite/gdb.python/py-corefile.py
+++ b/gdb/testsuite/gdb.python/py-corefile.py
@@ -56,6 +56,10 @@ def info_proc_mappings():
result = []
for m in mappings:
+ # Ignore anonymous mappings.
+ if m.filename == "":
+ continue
+
for r in m.regions:
result.append(Mapping(m, r))
--
2.25.4
next prev parent reply other threads:[~2026-03-14 14:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-14 14:32 [PATCH 0/5] Improved support for core files with missing NT_FILE note Andrew Burgess
2026-03-14 14:32 ` [PATCH 1/5] gdb/testsuite: improve corefile-no-threads.py script Andrew Burgess
2026-03-14 14:32 ` [PATCH 2/5] gdb/testsuite: restructure gdb.base/corefile-buildid.exp Andrew Burgess
2026-03-14 14:32 ` [PATCH 3/5] gdb: remove 'num' argument from gdbarch_read_core_file_mappings callback Andrew Burgess
2026-03-14 14:32 ` [PATCH 4/5] gdb: remove pre-loop callback from gdbarch_read_core_file_mappings Andrew Burgess
2026-03-14 14:32 ` Andrew Burgess [this message]
2026-04-23 22:08 ` [PATCH 5/5] gdb/linux: handle missing NT_FILE note when opening core files Keith Seitz
2026-05-01 19:09 ` Andrew Burgess
2026-04-23 22:06 ` [PATCH 0/5] Improved support for core files with missing NT_FILE note Keith Seitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=84829f29d55cd681c1829c60109c9eb140353795.1773498341.git.aburgess@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox