Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: Lancelot SIX <lancelot.six@amd.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 4/11] gdb/solib-rocm: add cached_fd to manage cached fd lifetime
Date: Thu, 7 May 2026 21:52:32 -0400	[thread overview]
Message-ID: <0b5b68fc-2eed-46c8-a6a8-c5826f40ece3@efficios.com> (raw)
In-Reply-To: <xt7elaezoo6rczttwfabrkempi34ts3iy6uscdoygqbsjcbdmx@4ona637celka>

On 5/7/26 4:17 PM, Lancelot SIX wrote:
> On Tue, Dec 09, 2025 at 02:32:08PM -0500, Simon Marchi wrote:
>> Make the management of the cached fds automatic.
>>
>> Change rocm_solib_fd_cache::open to return a cached_fd, an RAII type
>> that calls rocm_solib_fd_cache::close on destruction.  cached_fd holds
>> the actual fd and a reference to the cache it comes from.
>>
>> Change rocm_code_object_stream_file to hold a cached_fd and remove the
>> explicit destructor.
>>
>> This is not essential, I just thought it would be nice.
>>
>> Change-Id: I2529ac1caebbe6b7e6e60d228a403064f6f38d06
>> ---
>>  gdb/solib-rocm.c | 91 ++++++++++++++++++++++++++++++------------------
>>  1 file changed, 58 insertions(+), 33 deletions(-)
>>
>> diff --git a/gdb/solib-rocm.c b/gdb/solib-rocm.c
>> index bde34bafd8b1..5560a6035184 100644
>> --- a/gdb/solib-rocm.c
>> +++ b/gdb/solib-rocm.c
>> @@ -39,22 +39,58 @@ struct rocm_solib_fd_cache
>>    explicit rocm_solib_fd_cache (inferior *inf) : m_inferior (inf) {}
>>    DISABLE_COPY_AND_ASSIGN (rocm_solib_fd_cache);
>>  
>> +  /* The open method returns an object of this type.
>> +
>> +     On destruction, automatically call close to indicate the caller no longer
>> +     uses the fd.  */
>> +  struct cached_fd
>> +  {
>> +    cached_fd (int fd, rocm_solib_fd_cache &cache)
>> +      : fd (fd),
>> +	cache (cache)
>> +    {
>> +    }
>> +
>> +    cached_fd (cached_fd &&other)
>> +      : fd (other.fd),
>> +	cache (other.cache)
>> +    {
>> +      other.fd = -1;
>> +    }
>> +
>> +    ~cached_fd ()
>> +    {
>> +      if (fd == -1)
>> +	return;
>> +
>> +      fileio_error target_errno;
>> +      if (cache.close (fd, &target_errno) != 0)
>> +	warning (_("Failed to close solib: %s"),
>> +		 strerror (fileio_error_to_host (target_errno)));
>> +    }
>> +
>> +    DISABLE_COPY_AND_ASSIGN (cached_fd);
>> +
>> +    int fd;
> 
> Given some changes since this patch was sent, this is now a target_fd.

Ok, I will rename the type to cached_target_fd.

> 
>> +    rocm_solib_fd_cache &cache;
> 
> the cache field is never accessed outside of the class, there is no need
> to have it public.

Ok, while at it I made the fd field private too and added a getter.

> I expect quite a few conflicts when rebasing this patch, nevertheless
> the direction so far works for me.

Not too bad, because the fd didn't change meaning, it juste changed to a
stricter type.

Simon

  reply	other threads:[~2026-05-08  1:53 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-09 19:32 [PATCH 00/11] Multiple solib_ops in a program_space Simon Marchi
2025-12-09 19:32 ` [PATCH 01/11] gdb/solib-rocm: assert that host ops isn't rocm_solib_ops Simon Marchi
2026-05-07 17:56   ` [PATCH 1/11] " Lancelot SIX
2026-05-08  1:37     ` Simon Marchi
2026-05-08 10:36       ` Lancelot SIX
2026-06-08 18:36         ` Simon Marchi
2025-12-09 19:32 ` [PATCH 02/11] gdb/solib: use early return in solib_read_symbols Simon Marchi
2026-04-28 16:16   ` Tom Tromey
2026-05-08  1:44     ` Simon Marchi
2025-12-09 19:32 ` [PATCH 03/11] gdb/solib-rocm: pass reference to cache to rocm_code_object_stream_file Simon Marchi
2026-05-07 18:20   ` [PATCH 3/11] " Lancelot SIX
2026-05-08  1:48     ` Simon Marchi
2025-12-09 19:32 ` [PATCH 04/11] gdb/solib-rocm: add cached_fd to manage cached fd lifetime Simon Marchi
2026-05-07 20:17   ` [PATCH 4/11] " Lancelot SIX
2026-05-08  1:52     ` Simon Marchi [this message]
2025-12-09 19:32 ` [PATCH 05/11] gdb: de-constify some methods of solib_ops Simon Marchi
2025-12-09 19:32 ` [PATCH 06/11] gdb/solib-rocm: move per-inferior data to rocm_solib_ops Simon Marchi
2026-04-28 16:19   ` Tom Tromey
2026-05-08  2:02     ` Simon Marchi
2025-12-09 19:32 ` [PATCH 07/11] gdb/solib-rocm: save inferior in rocm_solib_ops Simon Marchi
     [not found]   ` <87a4unm59w.fsf@tromey.com>
2026-05-08  2:10     ` Simon Marchi
2025-12-09 19:32 ` [PATCH 08/11] gdb/solib: add remove_solib function Simon Marchi
2026-04-28 16:23   ` Tom Tromey
2025-12-09 19:32 ` [PATCH 09/11] gdb: add objfile -> solib backlink Simon Marchi
2026-04-28 16:28   ` Tom Tromey
2026-05-08  2:25     ` Simon Marchi
2025-12-09 19:32 ` [PATCH 10/11] gdb: change default objfile iteration order to start with current objfile Simon Marchi
2026-04-28 16:42   ` Tom Tromey
2026-05-08  2:40     ` Simon Marchi
2025-12-09 19:32 ` [PATCH 11/11] gdb: multiple solib_ops per program space Simon Marchi
2026-04-28 17:27   ` Tom Tromey
2026-05-08  2:52     ` Simon Marchi
2026-04-28 16:00 ` [PATCH 00/11] Multiple solib_ops in a program_space Simon Marchi
2026-04-28 17:28   ` Tom Tromey
2026-05-08  2:40     ` 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=0b5b68fc-2eed-46c8-a6a8-c5826f40ece3@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    --cc=lancelot.six@amd.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