aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2025-03-17 14:50:38 -0600
committerTom Tromey <tom@tromey.com>2025-03-18 05:30:50 -0600
commit246a63ad0a7e68b283f830ac3e4920f435a9968e (patch)
treef79865c2ac86cc98cb6a2569ee7d0e61fdd71966 /gdb
parent57d2ceb311aaaf02fe6fae194e1280001a087b6f (diff)
downloadbinutils-246a63ad0a7e68b283f830ac3e4920f435a9968e.zip
binutils-246a63ad0a7e68b283f830ac3e4920f435a9968e.tar.gz
binutils-246a63ad0a7e68b283f830ac3e4920f435a9968e.tar.bz2
Use scoped_fd in linux-nat.c:proc_mem_file
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. Approved-by: Kevin Buettner <kevinb@redhat.com>
Diffstat (limited to 'gdb')
-rw-r--r--gdb/linux-nat.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index b16f9f9..1727a06 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -4029,24 +4029,21 @@ 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 ()
+ int fd () const noexcept
{
- return m_fd;
+ return m_fd.get ();
}
private:
@@ -4055,7 +4052,7 @@ private:
ptid_t m_ptid;
/* The file descriptor. */
- int m_fd = -1;
+ scoped_fd m_fd;
};
/* The map between an inferior process id, and the open /proc/PID/mem
@@ -4093,9 +4090,9 @@ open_proc_mem_file (ptid_t ptid)
xsnprintf (filename, sizeof filename,
"/proc/%d/task/%ld/mem", ptid.pid (), ptid.lwp ());
- int fd = gdb_open_cloexec (filename, O_RDWR | O_LARGEFILE, 0).release ();
+ scoped_fd fd = gdb_open_cloexec (filename, O_RDWR | O_LARGEFILE, 0);
- if (fd == -1)
+ if (fd.get () == -1)
{
warning (_("opening /proc/PID/mem file for lwp %d.%ld failed: %s (%d)"),
ptid.pid (), ptid.lwp (),
@@ -4103,12 +4100,11 @@ open_proc_mem_file (ptid_t ptid)
return;
}
+ linux_nat_debug_printf ("opened fd %d for lwp %d.%ld",
+ fd.get (), ptid.pid (), ptid.lwp ());
proc_mem_file_map.emplace (std::piecewise_construct,
std::forward_as_tuple (ptid.pid ()),
- std::forward_as_tuple (ptid, fd));
-
- linux_nat_debug_printf ("opened fd %d for lwp %d.%ld",
- fd, ptid.pid (), ptid.lwp ());
+ std::forward_as_tuple (ptid, std::move (fd)));
}
/* Helper for linux_proc_xfer_memory_partial and