From: Tom Tromey <tom@tromey.com>
To: Andrew Burgess <aburgess@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/2] gdb: move all bfd_cache_close_all calls in gdb_bfd.c
Date: Fri, 27 Oct 2023 13:30:37 -0600 [thread overview]
Message-ID: <87o7gjlv6q.fsf@tromey.com> (raw)
In-Reply-To: <b8b8e8ea0ce3909f6a824587cf98f4b6902dec71.1698246342.git.aburgess@redhat.com> (Andrew Burgess's message of "Wed, 25 Oct 2023 16:08:17 +0100")
>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
Andrew> Better I think would be to track down where the bfd is being opened
Andrew> and add a corresponding bfd_cache_close_all() call elsewhere in GDB
Andrew> once we've finished doing whatever it is that caused us to open the
Andrew> bfd in the first place.
I had contemplated this solution as well, though using bfd_cache_close
on the specific BFD, instead.
Like you point out, though, it seems finicky to get right. We could
move up the call chain and add the close calls at some higher level, but
even that seems hard to be assured of.
Andrew> (a) Just before we display a GDB prompt. We display a prompt after
Andrew> completing a command, and GDB is about to enter an idle state
Andrew> waiting for further input from the user (or in async mode, for an
Andrew> inferior event). If while we are in this idle state the user
Andrew> changes the on-disk file(s) then we would like GDB to notice this
Andrew> the next time it leaves its idle state, e.g. the next time the user
Andrew> executes a command, or when an inferior event arrives,
Andrew> (b) When we resume the inferior. In synchronous mode, resuming the
Andrew> inferior is another time when GDB is blocked and sitting idle, but
Andrew> in this case we don't display a prompt. As with (a) above, when an
Andrew> inferior event arrives we want GDB to notice any changes to on-disk
Andrew> files.
I've been working on moving DWARF reading to the background. For the
most part, your plan won't be an issue -- gdb pre-reads the relevant
section data on the main thread and doesn't require the BFD to be open
when scanning.
However, there is one case where this will change: opening dwo files.
Now, the way the background reading is implemented, the worst case here
is some inefficiency: the main thread might close all the BFDs, and then
the background reader might immediately reopen one.
Maybe this isn't something to worry about? I could make the background
reader also call bfd_cache_close for the DWO BFDs, to ensure they are
closed. (This only really matters for the "rebuild" case, not any sort
of exec case, because DWOs aren't really part of the inferior.)
Andrew> Right now, the only other users of the observers that I'm connecting
Andrew> too are the extension languages, specifically, Python. I suspect it
Andrew> must be possible for Python to carry out actions that can cause the
Andrew> bfd cache to be populated, so maybe there is a risk here.
Andrew> To counter this risk, we could move the bfd_cache_close_all() calls
Andrew> out of observers, and move them into GDB core close too, but after the
Andrew> two observers in questions are actually called, so into
Andrew> top_level_prompt for the before_prompt observer and into
Andrew> notify_target_resumed for the target_resumed observer.
Andrew> Another choice would be to add a bfd_cache_close_all() into
Andrew> gdbpy_enter::~gdbpy_enter, so whenever we call into a Python
Andrew> extension, we always clear the bfd cache once we're done.
Andrew> For now I haven't made either of these changes, maybe I'm worrying
Andrew> about nothing? I'd appreciate peoples thoughts.
Do we know of specific Python APIs that could cause problems?
I guess anything that reads memory if trust-readonly-sections is
enabled? That's the only one I could think of offhand.
Maybe we need a combo approach where some calls call bfd_cache_close at
the end.
Tom
next prev parent reply other threads:[~2023-10-27 19:31 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-25 15:08 [PATCH 0/2] BFD cache management And Exec file with target: prefix Andrew Burgess
2023-10-25 15:08 ` [PATCH 1/2] gdb: move all bfd_cache_close_all calls in gdb_bfd.c Andrew Burgess
2023-10-26 9:06 ` Lancelot SIX
2023-10-27 8:49 ` Andrew Burgess
2023-10-27 19:30 ` Tom Tromey [this message]
2023-10-30 10:20 ` Andrew Burgess
2023-10-31 18:28 ` Tom Tromey
2023-11-01 10:46 ` Andrew Burgess
2023-11-12 23:38 ` Tom Tromey
2023-10-25 15:08 ` [PATCH 2/2] gdb: fix reopen_exec_file for files with target: prefix Andrew Burgess
2023-10-27 18:39 ` Tom Tromey
2023-10-30 13:41 ` [PATCH 0/2] BFD cache management And Exec file " Andrew Burgess
2023-10-30 13:41 ` [PATCH 1/2] gdb: move all bfd_cache_close_all calls in gdb_bfd.c Andrew Burgess
2023-10-30 13:41 ` [PATCH 2/2] gdb: fix reopen_exec_file for files with target: prefix Andrew Burgess
2023-11-12 23:40 ` [PATCH 0/2] BFD cache management And Exec file " 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=87o7gjlv6q.fsf@tromey.com \
--to=tom@tromey.com \
--cc=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