From: simon.marchi@polymtl.ca
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>, Lancelot SIX <Lancelot.Six@amd.com>,
Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH v3 09/10] gdb: change default objfile iteration order to start with current objfile
Date: Wed, 8 Jul 2026 17:51:41 -0400 [thread overview]
Message-ID: <20260708215145.93134-10-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20260708215145.93134-1-simon.marchi@polymtl.ca>
From: Simon Marchi <simon.marchi@polymtl.ca>
The current default objfile search strategy, defined both in
solib_ops::iterate_over_objfiles_in_search_order (when the solib_ops
hasn't overridden it) and in
program_space::iterate_over_objfiles_in_search_order (when there is no
solib_ops in the program space, for some reason), is to scan the objfile
list linearly.
program_space::iterate_over_objfiles_in_search_order:
for (auto &objfile : this->objfiles ())
if (cb (&objfile))
return;
solib_ops::iterate_over_objfiles_in_search_order:
for (objfile &objfile : m_pspace->objfiles ())
if (cb (&objfile))
return;
The following patch adds support for multiple concurrent solib_ops in a
program space. Everything that deals with an solib_ops needs to be
adapted to deal with multiple solib_ops, including
program_space::iterate_over_objfiles_in_search_order. What I came up
with for that method introduces a change in behavior where the current
objfile will always be searched first. Rather than hide the change in
behavior in that big patch, do it in this preparatory patch, in the hope
that any potential problems it causes can be more easily bisected and
analyzed.
Concretely, the change is to check the current objfile first, in the two
spots:
if (current_objfile != nullptr && cb (current_objfile))
return;
This happens to be what windows_solib_ops did, so remove that
specialization.
svr4_solib_ops already has its own iterate_over_objfiles_in_search_order
that conditionally checks the current objfile first, based on the
DT_SYMBOLIC dynamic tag. So it is not affected by this change.
The solib_ops potentially affected by this change are (we know that
rocm_solib_ops doesn't care):
- frv_solib_ops
- target_solib_ops
- darwin_solib_ops
- dsbt_solib_ops
- aix_solib_ops
I don't really know if searching objfiles in order (so, main objfile
first typically) is essential for any of these solib_ops.
Intuitively, searching the current objfile first makes sense, unless
there is some fancy symbol interposition happening, in which case that
solib_ops should probably implement a custom
iterate_over_objfiles_in_search_order.
Change-Id: I58195af6b53ca202e6061a5f36d5f74e1a0d5c17
Approved-By: Tom Tromey <tom@tromey.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17003
---
gdb/progspace.c | 5 ++++-
gdb/solib.c | 5 ++++-
gdb/windows-tdep.c | 40 ----------------------------------------
3 files changed, 8 insertions(+), 42 deletions(-)
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 1407b058dfdf..7023ccddc546 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -128,8 +128,11 @@ program_space::iterate_over_objfiles_in_search_order
return m_solib_ops->iterate_over_objfiles_in_search_order
(cb, current_objfile);
+ if (current_objfile != nullptr && cb (current_objfile))
+ return;
+
for (auto &objfile : this->objfiles ())
- if (cb (&objfile))
+ if (&objfile != current_objfile && cb (&objfile))
return;
}
diff --git a/gdb/solib.c b/gdb/solib.c
index b9b0f11cb477..6ed56aaf5159 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -451,8 +451,11 @@ solib_ops::iterate_over_objfiles_in_search_order
(iterate_over_objfiles_in_search_order_cb_ftype cb,
objfile *current_objfile) const
{
+ if (current_objfile != nullptr && cb (current_objfile))
+ return;
+
for (objfile &objfile : m_pspace->objfiles ())
- if (cb (&objfile))
+ if (&objfile != current_objfile && cb (&objfile))
return;
}
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index 261c38b35635..d65e6e76faeb 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -829,9 +829,6 @@ struct windows_solib_ops : target_solib_ops
using target_solib_ops::target_solib_ops;
void create_inferior_hook (int from_tty) override;
- void iterate_over_objfiles_in_search_order
- (iterate_over_objfiles_in_search_order_cb_ftype cb,
- objfile *current_objfile) const override;
};
/* Return a new solib_ops for Windows systems. */
@@ -890,43 +887,6 @@ windows_solib_ops::create_inferior_hook (int from_tty)
}
}
-/* Implement the "iterate_over_objfiles_in_search_order" gdbarch
- method. It searches all objfiles, starting with CURRENT_OBJFILE
- first (if not NULL).
-
- On Windows, the system behaves a little differently when two
- objfiles each define a global symbol using the same name, compared
- to other platforms such as GNU/Linux for instance. On GNU/Linux,
- all instances of the symbol effectively get merged into a single
- one, but on Windows, they remain distinct.
-
- As a result, it usually makes sense to start global symbol searches
- with the current objfile before expanding it to all other objfiles.
- This helps for instance when a user debugs some code in a DLL that
- refers to a global variable defined inside that DLL. When trying
- to print the value of that global variable, it would be unhelpful
- to print the value of another global variable defined with the same
- name, but in a different DLL. */
-
-void
-windows_solib_ops::iterate_over_objfiles_in_search_order
- (iterate_over_objfiles_in_search_order_cb_ftype cb,
- objfile *current_objfile) const
-{
- if (current_objfile)
- {
- if (cb (current_objfile))
- return;
- }
-
- for (objfile &objfile : m_pspace->objfiles ())
- if (&objfile != current_objfile)
- {
- if (cb (&objfile))
- return;
- }
-}
-
/* Implement the "auto_wide_charset" gdbarch method. */
static const char *
--
2.55.0
next prev parent reply other threads:[~2026-07-08 21:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 21:51 [PATCH v3 00/10] Multiple solib_ops in a program_space simon.marchi
2026-07-08 21:51 ` [PATCH v3 01/10] gdb/solib-rocm: assert that host ops isn't rocm_solib_ops simon.marchi
2026-07-08 21:51 ` [PATCH v3 02/10] gdb/solib-rocm: pass reference to cache to rocm_code_object_stream_file simon.marchi
2026-07-08 21:51 ` [PATCH v3 03/10] gdb/solib-rocm: add cached_target_fd to manage cached fd lifetime simon.marchi
2026-07-08 21:51 ` [PATCH v3 04/10] gdb: de-constify some methods of solib_ops simon.marchi
2026-07-08 21:51 ` [PATCH v3 05/10] gdb/solib: add remove_solib function simon.marchi
2026-07-08 21:51 ` [PATCH v3 06/10] gdb/solib-rocm: move per-inferior data to rocm_solib_ops simon.marchi
2026-07-08 21:51 ` [PATCH v3 07/10] gdb/solib-rocm: save inferior in rocm_solib_ops simon.marchi
2026-07-08 21:51 ` [PATCH v3 08/10] gdb: add objfile -> solib backlink simon.marchi
2026-07-21 17:31 ` Tom Tromey
2026-07-08 21:51 ` simon.marchi [this message]
2026-07-08 21:51 ` [PATCH v3 10/10] gdb: multiple solib_ops per program space simon.marchi
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=20260708215145.93134-10-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=Lancelot.Six@amd.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/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