From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTP id E1CC7394B004 for ; Fri, 13 Mar 2020 19:08:58 +0000 (GMT) Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id C30B1561B3; Fri, 13 Mar 2020 15:08:58 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com 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 zGmw1eaCqiD3; Fri, 13 Mar 2020 15:08:58 -0400 (EDT) Received: from murgatroyd.Home (184-96-250-69.hlrn.qwest.net [184.96.250.69]) (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 7FD6F561B0; Fri, 13 Mar 2020 15:08:58 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v3 05/29] Use new and delete for windows_thread_info Date: Fri, 13 Mar 2020 13:08:31 -0600 Message-Id: <20200313190855.28662-6-tromey@adacore.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200313190855.28662-1-tromey@adacore.com> References: <20200313190855.28662-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-25.0 required=5.0 tests=GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Mar 2020 19:08:59 -0000 This adds a constructor, destructor, and member initializers to windows_thread_info, and changes gdb and gdbserver to use new and delete. gdb/ChangeLog 2020-03-13 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. gdbserver/ChangeLog 2020-03-13 Tom Tromey * win32-low.c (child_add_thread): Use new. (delete_thread_info): Use delete. --- gdb/ChangeLog | 8 ++++++++ gdb/nat/windows-nat.h | 26 ++++++++++++++++++++------ gdb/windows-nat.c | 15 ++++++--------- gdbserver/ChangeLog | 5 +++++ gdbserver/win32-low.cc | 7 ++----- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 71df097ed0b..a3da2686422 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -25,6 +25,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; @@ -35,17 +49,17 @@ 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. */ union { - CONTEXT context; + CONTEXT context {}; #ifdef __x86_64__ WOW64_CONTEXT wow64_context; #endif @@ -53,14 +67,14 @@ struct windows_thread_info /* 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 d2c4ecd6daf..095a0da75dc 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -468,16 +468,14 @@ 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; + CORE_ADDR base = (CORE_ADDR) (uintptr_t) tlb; #ifdef __x86_64__ /* For WOW64 processes, this is actually the pointer to the 64bit TIB, and the 32bit TIB is exactly 2 pages after it. */ if (wow64_process) - th->thread_local_base += 0x2000; + base += 0x2000; #endif + th = new windows_thread_info (id, h, base); thread_list.push_back (th); /* Add this new thread to the list of threads. @@ -536,7 +534,7 @@ windows_init_thread_list (void) init_thread_list (); for (windows_thread_info *here : thread_list) - xfree (here); + delete here; thread_list.clear (); } @@ -581,8 +579,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); } } @@ -1718,7 +1715,7 @@ windows_nat_target::get_windows_debug_event (int pid, 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; diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 55e8322cebb..1284ed177cb 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -212,10 +212,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); @@ -233,7 +230,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. */ -- 2.21.1