public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Use unique_ptr in the Windows thread list
@ 2022-04-04 19:59 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-04-04 19:59 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=44c6a4106ea9c8d903e62b20357ea8d5387b8f4f
commit 44c6a4106ea9c8d903e62b20357ea8d5387b8f4f
Author: Tom Tromey <tromey@adacore.com>
Date: Thu Mar 31 10:08:45 2022 -0600
Use unique_ptr in the Windows thread list
windows-nat.c uses some manual memory management when manipulating the
thread_list global. Changing this to use unique_ptr simplifies the
code, in particular windows_init_thread_list. (Note that, while I
think the the call to init_thread_list in there is wrong, I haven't
removed it in this patch.)
Diff:
---
gdb/windows-nat.c | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 74f73614c47..e7324878031 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -152,7 +152,7 @@ static CORE_ADDR cygwin_get_dr (int i);
static unsigned long cygwin_get_dr6 (void);
static unsigned long cygwin_get_dr7 (void);
-static std::vector<windows_thread_info *> thread_list;
+static std::vector<std::unique_ptr<windows_thread_info>> thread_list;
/* Counts of things. */
static int saw_create;
@@ -319,7 +319,7 @@ check (BOOL ok, const char *file, int line)
windows_thread_info *
windows_nat::thread_rec (ptid_t ptid, thread_disposition_type disposition)
{
- for (windows_thread_info *th : thread_list)
+ for (auto &th : thread_list)
if (th->tid == ptid.lwp ())
{
if (!th->suspended)
@@ -340,7 +340,7 @@ windows_nat::thread_rec (ptid_t ptid, thread_disposition_type disposition)
break;
}
}
- return th;
+ return th.get ();
}
return NULL;
@@ -372,7 +372,7 @@ windows_add_thread (ptid_t ptid, HANDLE h, void *tlb, bool main_thread_p)
base += 0x2000;
#endif
th = new windows_thread_info (ptid.lwp (), h, base);
- thread_list.push_back (th);
+ thread_list.emplace_back (th);
/* Add this new thread to the list of threads.
@@ -398,10 +398,6 @@ windows_init_thread_list (void)
{
DEBUG_EVENTS ("called");
init_thread_list ();
-
- for (windows_thread_info *here : thread_list)
- delete here;
-
thread_list.clear ();
}
@@ -438,16 +434,13 @@ windows_delete_thread (ptid_t ptid, DWORD exit_code, bool main_thread_p)
delete_thread (find_thread_ptid (&the_windows_nat_target, ptid));
auto iter = std::find_if (thread_list.begin (), thread_list.end (),
- [=] (windows_thread_info *th)
+ [=] (auto &th)
{
return th->tid == id;
});
if (iter != thread_list.end ())
- {
- delete *iter;
- thread_list.erase (iter);
- }
+ thread_list.erase (iter);
}
/* Fetches register number R from the given windows_thread_info,
@@ -1146,7 +1139,7 @@ windows_continue (DWORD continue_status, int id, int killed)
if (matching_pending_stop (debug_events))
return TRUE;
- for (windows_thread_info *th : thread_list)
+ for (auto &th : thread_list)
if (id == -1 || id == (int) th->tid)
{
#ifdef __x86_64__
@@ -3133,7 +3126,7 @@ cygwin_set_dr (int i, CORE_ADDR addr)
_("Invalid register %d in cygwin_set_dr.\n"), i);
dr[i] = addr;
- for (windows_thread_info *th : thread_list)
+ for (auto &th : thread_list)
th->debug_registers_changed = true;
}
@@ -3145,7 +3138,7 @@ cygwin_set_dr7 (unsigned long val)
{
dr[7] = (CORE_ADDR) val;
- for (windows_thread_info *th : thread_list)
+ for (auto &th : thread_list)
th->debug_registers_changed = true;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-04-04 19:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-04 19:59 [binutils-gdb] Use unique_ptr in the Windows thread list Tom Tromey
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).