diff options
author | Tom Tromey <tromey@adacore.com> | 2022-03-31 10:08:45 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2022-04-04 13:58:37 -0600 |
commit | 44c6a4106ea9c8d903e62b20357ea8d5387b8f4f (patch) | |
tree | 3ea034be470c32f3b611b73add7e1bd7a4701cb5 | |
parent | 04ae91ea5223735820f44d580055362b06a6df73 (diff) | |
download | gdb-44c6a4106ea9c8d903e62b20357ea8d5387b8f4f.zip gdb-44c6a4106ea9c8d903e62b20357ea8d5387b8f4f.tar.gz gdb-44c6a4106ea9c8d903e62b20357ea8d5387b8f4f.tar.bz2 |
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.)
-rw-r--r-- | gdb/windows-nat.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 74f7361..e732487 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; } |