From patchwork Mon Oct 14 16:15:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 34950 Received: (qmail 15634 invoked by alias); 14 Oct 2019 16:22:42 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 15620 invoked by uid 89); 14 Oct 2019 16:22:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 14 Oct 2019 16:22:40 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 7F2C85604B; Mon, 14 Oct 2019 12:15:24 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id wCY7BFjltdwT; Mon, 14 Oct 2019 12:15:24 -0400 (EDT) Received: from murgatroyd.Home (174-29-53-230.hlrn.qwest.net [174.29.53.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 2B18156043; Mon, 14 Oct 2019 12:15:24 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 5/9] Use new and delete for windows_thread_info Date: Mon, 14 Oct 2019 10:15:16 -0600 Message-Id: <20191014161520.13150-6-tromey@adacore.com> In-Reply-To: <20191014161520.13150-1-tromey@adacore.com> References: <20191014161520.13150-1-tromey@adacore.com> MIME-Version: 1.0 This adds a constructor, destructor, and member initializers to windows_thread_info, and changes gdb and gdbserver to use new and delete. 2019-10-14 Tom Tromey * windows-nat.c (windows_add_thread): Use new. (windows_init_thread_list, windows_delete_thread): Use delete. (get_windows_debug_event): Update. * nat/windows-nat.h (struct windows_thread_info): Add constructor, destructor, and initializers. gdb/gdbserver/ChangeLog 2019-10-14 Tom Tromey * win32-low.c (child_add_thread): Use new. (delete_thread_info): Use delete. --- gdb/ChangeLog | 8 ++++++++ gdb/gdbserver/ChangeLog | 5 +++++ gdb/gdbserver/win32-low.c | 7 ++----- gdb/nat/windows-nat.h | 26 ++++++++++++++++++++------ gdb/windows-nat.c | 12 ++++-------- 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c index 7120b1d4dd1..b478d970b5f 100644 --- a/gdb/gdbserver/win32-low.c +++ b/gdb/gdbserver/win32-low.c @@ -213,10 +213,7 @@ child_add_thread (DWORD pid, DWORD tid, HANDLE h, void *tlb) if ((th = thread_rec (ptid, FALSE))) return th; - th = XCNEW (windows_thread_info); - th->tid = tid; - th->h = h; - th->thread_local_base = (CORE_ADDR) (uintptr_t) tlb; + th = new windows_thread_info (tid, h, (CORE_ADDR) (uintptr_t) tlb); add_thread (ptid, th); @@ -234,7 +231,7 @@ delete_thread_info (thread_info *thread) remove_thread (thread); CloseHandle (th->h); - free (th); + delete th; } /* Delete a thread from the list of threads. */ diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 30fce27de2f..2fe2a2f0e88 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -23,6 +23,20 @@ each thread. */ struct windows_thread_info { + windows_thread_info (DWORD tid_, HANDLE h_, CORE_ADDR tlb) + : tid (tid_), + h (h_), + thread_local_base (tlb) + { + } + + ~windows_thread_info () + { + xfree (name); + } + + DISABLE_COPY_AND_ASSIGN (windows_thread_info); + /* The Win32 thread identifier. */ DWORD tid; @@ -33,26 +47,26 @@ struct windows_thread_info CORE_ADDR thread_local_base; /* Non zero if SuspendThread was called on this thread. */ - int suspended; + int suspended = 0; #ifdef _WIN32_WCE /* The context as retrieved right after suspending the thread. */ - CONTEXT base_context; + CONTEXT base_context {}; #endif /* The context of the thread, including any manipulations. */ - CONTEXT context; + CONTEXT context {}; /* Whether debug registers changed since we last set CONTEXT back to the thread. */ - int debug_registers_changed; + int debug_registers_changed = 0; /* Nonzero if CONTEXT is invalidated and must be re-read from the inferior thread. */ - int reload_context; + int reload_context = 0; /* The name of the thread, allocated by xmalloc. */ - char *name; + char *name = nullptr; }; #endif diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 010d6565330..210bcfb6f7f 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -429,10 +429,7 @@ windows_add_thread (ptid_t ptid, HANDLE h, void *tlb, bool main_thread_p) if ((th = thread_rec (id, FALSE))) return th; - th = XCNEW (windows_thread_info); - th->tid = id; - th->h = h; - th->thread_local_base = (CORE_ADDR) (uintptr_t) tlb; + th = new windows_thread_info (id, h, (CORE_ADDR) (uintptr_t) tlb); thread_list.push_back (th); /* Add this new thread to the list of threads. @@ -472,7 +469,7 @@ windows_init_thread_list (void) init_thread_list (); for (windows_thread_info *here : thread_list) - xfree (here); + delete here; thread_list.clear (); } @@ -517,8 +514,7 @@ windows_delete_thread (ptid_t ptid, DWORD exit_code, bool main_thread_p) if (iter != thread_list.end ()) { - xfree ((*iter)->name); - xfree (*iter); + delete *iter; thread_list.erase (iter); } } @@ -1501,7 +1497,7 @@ get_windows_debug_event (struct target_ops *ops, BOOL debug_event; DWORD continue_status, event_code; windows_thread_info *th; - static windows_thread_info dummy_thread_info; + static windows_thread_info dummy_thread_info (0, 0, 0); DWORD thread_id = 0; last_sig = GDB_SIGNAL_0;