From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Use scoped_fd in linux-nat.c:proc_mem_file
Date: Mon, 17 Mar 2025 22:16:17 -0400 [thread overview]
Message-ID: <b714c543-afbf-4eed-9d46-e383aada17cd@simark.ca> (raw)
In-Reply-To: <20250317205529.3885971-1-tom@tromey.com>
On 2025-03-17 16:55, Tom Tromey wrote:
> This changes linux-nat.c:proc_mem_file to use a scoped_fd and fixes up
> the users. Regression tested on x86-64 Fedora 40.
> ---
> gdb/linux-nat.c | 29 +++++++++++++++--------------
> 1 file changed, 15 insertions(+), 14 deletions(-)
>
> diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
> index b16f9f96726..8861829f917 100644
> --- a/gdb/linux-nat.c
> +++ b/gdb/linux-nat.c
> @@ -4029,24 +4029,26 @@ linux_nat_target::pid_to_exec_file (int pid)
> class proc_mem_file
> {
> public:
> - proc_mem_file (ptid_t ptid, int fd)
> - : m_ptid (ptid), m_fd (fd)
> + proc_mem_file (ptid_t ptid, scoped_fd fd)
> + : m_ptid (ptid), m_fd (std::move (fd))
> {
> - gdb_assert (m_fd != -1);
> + gdb_assert (m_fd.get () != -1);
> }
>
> ~proc_mem_file ()
> {
> linux_nat_debug_printf ("closing fd %d for /proc/%d/task/%ld/mem",
> - m_fd, m_ptid.pid (), m_ptid.lwp ());
> - close (m_fd);
> + m_fd.get (), m_ptid.pid (), m_ptid.lwp ());
> }
>
> DISABLE_COPY_AND_ASSIGN (proc_mem_file);
>
> - int fd ()
> + proc_mem_file (proc_mem_file &&) = default;
> + proc_mem_file &operator= (proc_mem_file &&) = default;
Is it really needed to add the move constructor / move assignment
operator? In fact, I would think that you could remove the
DISABLE_COPY_AND_ASSIGN, since just having the scoped_fd as a field will
do the right thing.
Otherwise, LGTM (Kevin already gave his AB).
Simon
next prev parent reply other threads:[~2025-03-18 2:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-17 20:55 Tom Tromey
2025-03-18 1:30 ` Kevin Buettner
2025-03-18 2:16 ` Simon Marchi [this message]
2025-03-18 11:29 ` 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=b714c543-afbf-4eed-9d46-e383aada17cd@simark.ca \
--to=simark@simark.ca \
--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