public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/3] gdbserver: make thread_info non-POD
@ 2021-10-12 16:17 Simon Marchi
  2021-10-12 16:17 ` [PATCH 2/3] gdbserver: initialize the members of lwp_info in-class Simon Marchi
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Simon Marchi @ 2021-10-12 16:17 UTC (permalink / raw)
  To: gdb-patches

From: Simon Marchi <simon.marchi@polymtl.ca>

Add a constructor and a destructor.  The constructor takes care of the
initialization that happened in add_thread, while the destructor takes
care of the freeing that happened in free_one_thread.  This is needed to
make target_waitstatus non-POD, as thread_info contains a member of that
type.

Change-Id: I1db321b4de9dd233ede0d5c101950f1d6f1d13b7
---
 gdbserver/gdbthread.h  | 21 ++++++++++++++++-----
 gdbserver/inferiors.cc | 11 ++---------
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/gdbserver/gdbthread.h b/gdbserver/gdbthread.h
index 0e45f9a7100..fc9b4d20435 100644
--- a/gdbserver/gdbthread.h
+++ b/gdbserver/gdbthread.h
@@ -29,20 +29,31 @@ struct regcache;
 
 struct thread_info
 {
+  thread_info (ptid_t id, void *target_data)
+    : id (id), target_data (target_data)
+  {
+    this->last_status.kind = TARGET_WAITKIND_IGNORE;
+  }
+
+  ~thread_info ()
+  {
+    free_register_cache (this->regcache_data);
+  }
+
   /* The id of this thread.  */
   ptid_t id;
 
   void *target_data;
-  struct regcache *regcache_data;
+  struct regcache *regcache_data = nullptr;
 
   /* The last resume GDB requested on this thread.  */
-  enum resume_kind last_resume_kind;
+  enum resume_kind last_resume_kind = resume_continue;
 
   /* The last wait status reported for this thread.  */
   struct target_waitstatus last_status;
 
   /* True if LAST_STATUS hasn't been reported to GDB yet.  */
-  int status_pending_p;
+  int status_pending_p = 0;
 
   /* Given `while-stepping', a thread may be collecting data for more
      than one tracepoint simultaneously.  E.g.:
@@ -67,10 +78,10 @@ struct thread_info
    tracepoint actions this thread is now collecting; NULL if empty.
    Each item in the list holds the current step of the while-stepping
    action.  */
-  struct wstep_state *while_stepping;
+  struct wstep_state *while_stepping = nullptr;
 
   /* Branch trace target information for this thread.  */
-  struct btrace_target_info *btrace;
+  struct btrace_target_info *btrace = nullptr;
 };
 
 extern std::list<thread_info *> all_threads;
diff --git a/gdbserver/inferiors.cc b/gdbserver/inferiors.cc
index 32f847812e6..a636266c798 100644
--- a/gdbserver/inferiors.cc
+++ b/gdbserver/inferiors.cc
@@ -36,19 +36,13 @@ static std::string current_inferior_cwd;
 struct thread_info *
 add_thread (ptid_t thread_id, void *target_data)
 {
-  struct thread_info *new_thread = XCNEW (struct thread_info);
-
-  new_thread->id = thread_id;
-  new_thread->last_resume_kind = resume_continue;
-  new_thread->last_status.kind = TARGET_WAITKIND_IGNORE;
+  thread_info *new_thread = new thread_info (thread_id, target_data);
 
   all_threads.push_back (new_thread);
 
   if (current_thread == NULL)
     current_thread = new_thread;
 
-  new_thread->target_data = target_data;
-
   return new_thread;
 }
 
@@ -93,8 +87,7 @@ find_any_thread_of_pid (int pid)
 static void
 free_one_thread (thread_info *thread)
 {
-  free_register_cache (thread_regcache_data (thread));
-  free (thread);
+  delete thread;
 }
 
 void
-- 
2.33.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-10-21 20:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12 16:17 [PATCH 1/3] gdbserver: make thread_info non-POD Simon Marchi
2021-10-12 16:17 ` [PATCH 2/3] gdbserver: initialize the members of lwp_info in-class Simon Marchi
2021-10-12 16:17 ` [PATCH 3/3] gdb, gdbserver: make target_waitstatus safe Simon Marchi
2021-10-12 17:04   ` John Baldwin
2021-10-12 17:28     ` Simon Marchi
2021-10-13  1:57       ` Simon Marchi
2021-10-13  2:08         ` John Baldwin
2021-10-21 20:15 ` [PATCH 1/3] gdbserver: make thread_info non-POD Simon Marchi

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).