From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/3] Use gdb_dir_up in linux_proc_attach_tgid_threads
Date: Tue, 03 Oct 2023 11:56:23 -0600 [thread overview]
Message-ID: <20231003-attach-bug-v1-2-f5de2e583c5d@adacore.com> (raw)
In-Reply-To: <20231003-attach-bug-v1-0-f5de2e583c5d@adacore.com>
This changes linux_proc_attach_tgid_threads to use gdb_dir_up. This
makes it robust against exceptions.
---
gdb/nat/linux-procfs.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c
index 95ecae443e4..c7d8ba2bd67 100644
--- a/gdb/nat/linux-procfs.c
+++ b/gdb/nat/linux-procfs.c
@@ -275,7 +275,6 @@ void
linux_proc_attach_tgid_threads (pid_t pid,
linux_proc_attach_lwp_func attach_lwp)
{
- DIR *dir;
char pathname[128];
int new_threads_found;
int iterations;
@@ -284,7 +283,7 @@ linux_proc_attach_tgid_threads (pid_t pid,
return;
xsnprintf (pathname, sizeof (pathname), "/proc/%ld/task", (long) pid);
- dir = opendir (pathname);
+ gdb_dir_up dir (opendir (pathname));
if (dir == NULL)
{
warning (_("Could not open %s."), pathname);
@@ -300,7 +299,7 @@ linux_proc_attach_tgid_threads (pid_t pid,
struct dirent *dp;
new_threads_found = 0;
- while ((dp = readdir (dir)) != NULL)
+ while ((dp = readdir (dir.get ())) != NULL)
{
unsigned long lwp;
@@ -321,10 +320,8 @@ linux_proc_attach_tgid_threads (pid_t pid,
iterations = -1;
}
- rewinddir (dir);
+ rewinddir (dir.get ());
}
-
- closedir (dir);
}
/* See linux-procfs.h. */
--
2.40.1
next prev parent reply other threads:[~2023-10-03 17:56 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-03 17:56 [PATCH 0/3] Fix "attach" infinite loop Tom Tromey
2023-10-03 17:56 ` [PATCH 1/3] Minor cleanup in linux_proc_attach_tgid_threads Tom Tromey
2023-10-04 1:29 ` Simon Marchi
2023-10-03 17:56 ` Tom Tromey [this message]
2023-10-04 1:30 ` [PATCH 2/3] Use gdb_dir_up " Simon Marchi
2023-10-03 17:56 ` [PATCH 3/3] Bail out of "attach" if a thread cannot be traced Tom Tromey
2023-10-04 1:29 ` Simon Marchi
2023-10-04 14:14 ` Tom Tromey
2023-10-04 17:38 ` Simon Marchi
2023-12-01 17:41 ` [PATCH 0/3] Fix "attach" infinite loop Tom Tromey
2023-12-04 14:25 ` Luis Machado
2023-12-05 19:27 ` Tom Tromey
2023-12-15 19:33 ` Tom Tromey
2023-12-18 9:50 ` Luis Machado
2023-12-18 11:33 ` Luis Machado
2023-12-18 14:30 ` Tom Tromey
2023-12-18 15:10 ` Luis Machado
2024-01-02 19:14 ` Carl Love
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=20231003-attach-bug-v1-2-f5de2e583c5d@adacore.com \
--to=tromey@adacore.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).