From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 4/5] Mark two program_space fields as private
Date: Tue, 10 Nov 2026 19:06:58 -0700 [thread overview]
Message-ID: <20261110-minor-assert-v1-4-bb33660ca557@tromey.com> (raw)
In-Reply-To: <20261110-minor-assert-v1-0-bb33660ca557@tromey.com>
This changes the 'ebfd' and 'ebfd_mtime' fields in program_space to be
private. A new method is added to access the mtime. This patch also
found one remaining spot that was directly accessing ebfd.
---
gdb/corefile.c | 4 ++--
gdb/exec.c | 2 +-
gdb/progspace.c | 20 ++++++++++----------
gdb/progspace.h | 23 ++++++++++++++---------
gdb/source-cache.c | 2 +-
5 files changed, 28 insertions(+), 23 deletions(-)
diff --git a/gdb/corefile.c b/gdb/corefile.c
index 37f04fa7794..ac488e8143f 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -55,8 +55,8 @@ reopen_exec_file (void)
int res = gdb_bfd_stat (exec_bfd, &st);
if (res == 0
- && current_program_space->ebfd_mtime != 0
- && current_program_space->ebfd_mtime != st.st_mtime)
+ && current_program_space->exec_bfd_mtime () != 0
+ && current_program_space->exec_bfd_mtime () != st.st_mtime)
exec_file_attach (bfd_get_filename (exec_bfd), 0);
}
\f
diff --git a/gdb/exec.c b/gdb/exec.c
index 125ba9d2c44..000b1170145 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -499,7 +499,7 @@ exec_file_attach (const char *filename, int from_tty)
list of sections. This possibly pushes the exec_ops
target. */
current_program_space->add_target_sections
- (current_program_space->ebfd.get (), sections);
+ (current_program_space->exec_bfd (), sections);
}
/* Are are loading the same executable? */
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 430629c57b3..619db5ef2fb 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -281,12 +281,12 @@ void
program_space::set_exec_bfd (gdb_bfd_ref_ptr &&abfd,
gdb::unique_xmalloc_ptr<char> new_filename)
{
- gdb_assert (ebfd == nullptr);
+ gdb_assert (m_ebfd == nullptr);
gdb_assert (abfd != nullptr);
- ebfd = std::move (abfd);
- gdb_assert (m_exec_filename = nullptr);
+ m_ebfd = std::move (abfd);
+ gdb_assert (m_exec_filename == nullptr);
m_exec_filename = std::move (new_filename);
- ebfd_mtime = gdb_bfd_get_mtime (ebfd.get ());
+ m_ebfd_mtime = gdb_bfd_get_mtime (m_ebfd.get ());
}
/* See progspace.h. */
@@ -294,15 +294,15 @@ program_space::set_exec_bfd (gdb_bfd_ref_ptr &&abfd,
void
program_space::exec_close ()
{
- if (ebfd != nullptr)
+ if (m_ebfd != nullptr)
{
/* Removing target sections may close the exec_ops target.
- Clear ebfd before doing so to prevent recursion. We
+ Clear m_ebfd before doing so to prevent recursion. We
move it to another ref_ptr instead of saving it to a raw
pointer to avoid it looking like possible use-after-free. */
- gdb_bfd_ref_ptr saved_ebfd = std::move (ebfd);
- ebfd.reset (nullptr);
- ebfd_mtime = 0;
+ gdb_bfd_ref_ptr saved_ebfd = std::move (m_ebfd);
+ m_ebfd.reset (nullptr);
+ m_ebfd_mtime = 0;
remove_target_sections (saved_ebfd.get ());
@@ -599,7 +599,7 @@ initialize_progspace ()
_initialize_foo routines may need to install their per-pspace
data keys. We can only allocate a progspace when all those
modules have done that. Do this before
- initialize_current_architecture, because that accesses the ebfd
+ initialize_current_architecture, because that accesses the m_ebfd
of current_program_space. */
current_program_space = new program_space (new_address_space ());
}
diff --git a/gdb/progspace.h b/gdb/progspace.h
index f55444ce88c..a5e5f0ea3f5 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -304,13 +304,19 @@ struct program_space
/* Return the exec BFD for this program space. */
bfd *exec_bfd () const
- { return ebfd.get (); }
+ { return m_ebfd.get (); }
/* Set the exec BFD for this program space to ABFD. This also
updates the ebfd_mtime and set the exec filename. */
void set_exec_bfd (gdb_bfd_ref_ptr &&abfd,
gdb::unique_xmalloc_ptr<char> new_filename);
+ /* Return the saved mtime of the exec BFD. */
+ long exec_bfd_mtime () const
+ {
+ return m_ebfd_mtime;
+ }
+
/* Reset saved solib data at the start of an solib event. This lets
us properly collect the data when calling solib_add, so it can then
later be printed. */
@@ -367,14 +373,6 @@ struct program_space
/* Unique ID number. */
int num = 0;
- /* The main executable loaded into this program space. This is
- managed by the exec target. */
-
- /* The BFD handle for the main executable. */
- gdb_bfd_ref_ptr ebfd;
- /* The last-modified time, from when the exec was brought in. */
- long ebfd_mtime = 0;
-
/* The address space attached to this program space. More than one
program space may be bound to the same address space. In the
traditional unix-like debugging scenario, this will usually
@@ -419,6 +417,13 @@ struct program_space
registry<program_space> registry_fields;
private:
+ /* The main executable loaded into this program space. This is
+ managed by the exec target. */
+ /* The BFD handle for the main executable. */
+ gdb_bfd_ref_ptr m_ebfd;
+ /* The last-modified time, from when the exec was brought in. */
+ long m_ebfd_mtime = 0;
+
/* All known objfiles are kept in a linked list. */
owning_intrusive_list<objfile> m_objfiles_list;
diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index 804a6a08a8c..c2e98cae168 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -114,7 +114,7 @@ source_cache::get_plain_source_lines (struct symtab *s,
&& s->compunit ().objfile ()->obfd != NULL)
mtime = s->compunit ().objfile ()->mtime;
else if (current_program_space->exec_bfd ())
- mtime = current_program_space->ebfd_mtime;
+ mtime = current_program_space->exec_bfd_mtime ();
if (mtime && mtime < st.st_mtime)
warning (_("Source file is more recent than executable."));
--
2.49.0
next prev parent reply other threads:[~2026-11-11 2:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 2:06 [PATCH 0/5] Minor updates to program space and setting the exec file Tom Tromey
2026-11-11 2:06 ` [PATCH 1/5] Reject null pointers in program_space::set_exec_bfd Tom Tromey
2026-11-11 2:06 ` [PATCH 2/5] Hoist call to gdb_bfd_check_format_matches in exec.c Tom Tromey
2026-11-11 2:06 ` [PATCH 3/5] Have program_space::set_exec_bfd do more work Tom Tromey
2026-11-11 2:06 ` Tom Tromey [this message]
2026-11-11 2:06 ` [PATCH 5/5] Add some uses of bool to progspace and exec_file_attach Tom Tromey
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=20261110-minor-assert-v1-4-bb33660ca557@tromey.com \
--to=tom@tromey.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