Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Subject: [PATCH 05/11] gdb: add setter / getter for thread_info resumed state
Date: Tue, 22 Jun 2021 12:56:58 -0400	[thread overview]
Message-ID: <20210622165704.2404007-6-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20210622165704.2404007-1-simon.marchi@polymtl.ca>

A following patch will want to do things when a thread's resumed state
changes.  Make the `resumed` field private (renamed to `m_resumed`) and
add a getter and a setter for it.  The following patch in question will
therefore be able to add some code to the setter.

gdb/ChangeLog:

	* gdbthread.h (struct thread_info) <resumed>: Rename to...
	<m_resumed>: This.  Change all uses to use the resumed and
	set_resumed methods.
	<resumed, set_resumed>: New methods.

Change-Id: I360c48cc55a036503174313261ce4e757d795319
---
 gdb/breakpoint.c |  3 +--
 gdb/gdbthread.h  | 23 +++++++++++++++--------
 gdb/infrun.c     | 44 ++++++++++++++++++++++----------------------
 gdb/remote.c     |  2 +-
 gdb/thread.c     |  2 +-
 5 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 7d7e299ad5ff..73d2b536b35d 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -406,8 +406,7 @@ breakpoints_should_be_inserted_now (void)
       /* Don't remove breakpoints yet if, even though all threads are
 	 stopped, we still have events to process.  */
       for (thread_info *tp : all_non_exited_threads ())
-	if (tp->resumed
-	    && tp->suspend.waitstatus_pending_p)
+	if (tp->resumed () && tp->suspend.waitstatus_pending_p)
 	  return 1;
     }
   return 0;
diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index 54c097206d16..2f3d85d34eaa 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -293,14 +293,11 @@ class thread_info : public refcounted_object,
      thread is off and running.  */
   bool executing = false;
 
-  /* True if this thread is resumed from infrun's perspective.
-     Note that a thread can be marked both as not-executing and
-     resumed at the same time.  This happens if we try to resume a
-     thread that has a wait status pending.  We shouldn't let the
-     thread really run until that wait status has been processed, but
-     we should not process that wait status if we didn't try to let
-     the thread run.  */
-  bool resumed = false;
+  bool resumed () const
+  { return m_resumed; }
+
+  void set_resumed (bool resumed)
+  { m_resumed = resumed; }
 
   /* Frontend view of the thread state.  Note that the THREAD_RUNNING/
      THREAD_STOPPED states are different from EXECUTING.  When the
@@ -393,6 +390,16 @@ class thread_info : public refcounted_object,
 
   /* Displaced-step state for this thread.  */
   displaced_step_thread_state displaced_step_state;
+
+private:
+  /* True if this thread is resumed from infrun's perspective.
+     Note that a thread can be marked both as not-executing and
+     resumed at the same time.  This happens if we try to resume a
+     thread that has a wait status pending.  We shouldn't let the
+     thread really run until that wait status has been processed, but
+     we should not process that wait status if we didn't try to let
+     the thread run.  */
+  bool m_resumed = false;
 };
 
 /* A gdb::ref_ptr pointer to a thread_info.  */
diff --git a/gdb/infrun.c b/gdb/infrun.c
index fcd0f4e10ced..450e6177cb89 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1920,7 +1920,7 @@ start_step_over (void)
 	}
 
       if (tp->control.trap_expected
-	  || tp->resumed
+	  || tp->resumed ()
 	  || tp->executing)
 	{
 	  internal_error (__FILE__, __LINE__,
@@ -1928,7 +1928,7 @@ start_step_over (void)
 			  "trap_expected=%d, resumed=%d, executing=%d\n",
 			  target_pid_to_str (tp->ptid).c_str (),
 			  tp->control.trap_expected,
-			  tp->resumed,
+			  tp->resumed (),
 			  tp->executing);
 	}
 
@@ -1953,7 +1953,7 @@ start_step_over (void)
 
       /* If the thread's step over could not be initiated because no buffers
 	 were available, it was re-added to the global step over chain.  */
-      if (tp->resumed)
+      if (tp->resumed  ())
 	{
 	  infrun_debug_printf ("[%s] was resumed.",
 			       target_pid_to_str (tp->ptid).c_str ());
@@ -2220,7 +2220,7 @@ resume_1 (enum gdb_signal sig)
 	 currently_stepping (tp));
 
       tp->inf->process_target ()->threads_executing = true;
-      tp->resumed = true;
+      tp->set_resumed (true);
 
       /* FIXME: What should we do if we are supposed to resume this
 	 thread with a signal?  Maybe we should maintain a queue of
@@ -2342,7 +2342,7 @@ resume_1 (enum gdb_signal sig)
 
 	      resume_ptid = internal_resume_ptid (user_step);
 	      do_target_resume (resume_ptid, false, GDB_SIGNAL_0);
-	      tp->resumed = true;
+	      tp->set_resumed (true);
 	      return;
 	    }
 	}
@@ -2551,7 +2551,7 @@ resume_1 (enum gdb_signal sig)
     }
 
   do_target_resume (resume_ptid, step, sig);
-  tp->resumed = true;
+  tp->set_resumed (true);
 }
 
 /* Resume the inferior.  SIG is the signal to give the inferior
@@ -2803,7 +2803,7 @@ maybe_set_commit_resumed_all_targets ()
 	 resuming more threads.  */
       bool has_thread_with_pending_status = false;
       for (thread_info *thread : all_non_exited_threads (proc_target))
-	if (thread->resumed && thread->suspend.waitstatus_pending_p)
+	if (thread->resumed () && thread->suspend.waitstatus_pending_p)
 	  {
 	    has_thread_with_pending_status = true;
 	    break;
@@ -3238,7 +3238,7 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal)
 		continue;
 	      }
 
-	    if (tp->resumed)
+	    if (tp->resumed ())
 	      {
 		infrun_debug_printf ("[%s] resumed",
 				     target_pid_to_str (tp->ptid).c_str ());
@@ -3263,7 +3263,7 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal)
 	      error (_("Command aborted."));
 	  }
       }
-    else if (!cur_thr->resumed && !thread_is_in_step_over_chain (cur_thr))
+    else if (!cur_thr->resumed () && !thread_is_in_step_over_chain (cur_thr))
       {
 	/* The thread wasn't started, and isn't queued, run it now.  */
 	reset_ecs (ecs, cur_thr);
@@ -3408,7 +3408,7 @@ infrun_thread_stop_requested (ptid_t ptid)
       /* Otherwise we can process the (new) pending event now.  Set
 	 it so this pending event is considered by
 	 do_target_wait.  */
-      tp->resumed = true;
+      tp->set_resumed (true);
     }
 }
 
@@ -3505,7 +3505,7 @@ random_pending_event_thread (inferior *inf, ptid_t waiton_ptid)
   auto has_event = [&] (thread_info *tp)
     {
       return (tp->ptid.matches (waiton_ptid)
-	      && tp->resumed
+	      && tp->resumed ()
 	      && tp->suspend.waitstatus_pending_p);
     };
 
@@ -3852,7 +3852,7 @@ prepare_for_detach (void)
 		    }
 		}
 	      else
-		thr->resumed = false;
+		thr->set_resumed (false);
 	    }
 	}
 
@@ -4893,7 +4893,7 @@ handle_one (const wait_one_event &event)
 
       t->stop_requested = 0;
       t->executing = 0;
-      t->resumed = false;
+      t->set_resumed (false);
       t->control.may_range_step = 0;
 
       /* This may be the first time we see the inferior report
@@ -5063,7 +5063,7 @@ stop_all_threads (void)
 
 		  /* The thread may be not executing, but still be
 		     resumed with a pending status to process.  */
-		  t->resumed = false;
+		  t->set_resumed (false);
 		}
 	    }
 
@@ -5808,7 +5808,7 @@ restart_threads (struct thread_info *event_thread)
 	  continue;
 	}
 
-      if (tp->resumed)
+      if (tp->resumed ())
 	{
 	  infrun_debug_printf ("restart threads: [%s] resumed",
 			      target_pid_to_str (tp->ptid).c_str ());
@@ -5820,7 +5820,7 @@ restart_threads (struct thread_info *event_thread)
 	{
 	  infrun_debug_printf ("restart threads: [%s] needs step-over",
 			       target_pid_to_str (tp->ptid).c_str ());
-	  gdb_assert (!tp->resumed);
+	  gdb_assert (!tp->resumed ());
 	  continue;
 	}
 
@@ -5829,7 +5829,7 @@ restart_threads (struct thread_info *event_thread)
 	{
 	  infrun_debug_printf ("restart threads: [%s] has pending status",
 			       target_pid_to_str (tp->ptid).c_str ());
-	  tp->resumed = true;
+	  tp->set_resumed (true);
 	  continue;
 	}
 
@@ -5873,7 +5873,7 @@ static int
 resumed_thread_with_pending_status (struct thread_info *tp,
 				    void *arg)
 {
-  return (tp->resumed
+  return (tp->resumed ()
 	  && tp->suspend.waitstatus_pending_p);
 }
 
@@ -5959,7 +5959,7 @@ finish_step_over (struct execution_control_state *ecs)
 	  /* This was cleared early, by handle_inferior_event.  Set it
 	     so this pending event is considered by
 	     do_target_wait.  */
-	  tp->resumed = true;
+	  tp->set_resumed (true);
 
 	  gdb_assert (!tp->executing);
 
@@ -7519,7 +7519,7 @@ restart_after_all_stop_detach (process_stratum_target *proc_target)
 
       /* If we have a pending event to process, skip resuming the
 	 target and go straight to processing it.  */
-      if (thr->resumed && thr->suspend.waitstatus_pending_p)
+      if (thr->resumed () && thr->suspend.waitstatus_pending_p)
 	return;
     }
 
@@ -7624,7 +7624,7 @@ keep_going_stepped_thread (struct thread_info *tp)
 				     get_frame_address_space (frame),
 				     tp->suspend.stop_pc);
 
-      tp->resumed = true;
+      tp->set_resumed (true);
       resume_ptid = internal_resume_ptid (tp->control.stepping_command);
       do_target_resume (resume_ptid, false, GDB_SIGNAL_0);
     }
@@ -8039,7 +8039,7 @@ static void
 keep_going_pass_signal (struct execution_control_state *ecs)
 {
   gdb_assert (ecs->event_thread->ptid == inferior_ptid);
-  gdb_assert (!ecs->event_thread->resumed);
+  gdb_assert (!ecs->event_thread->resumed ());
 
   /* Save the pc before execution, to compare with pc after stop.  */
   ecs->event_thread->prev_pc
diff --git a/gdb/remote.c b/gdb/remote.c
index 22933eeaeec6..f08616be9b67 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -8132,7 +8132,7 @@ static ptid_t
 first_remote_resumed_thread (remote_target *target)
 {
   for (thread_info *tp : all_non_exited_threads (target, minus_one_ptid))
-    if (tp->resumed)
+    if (tp->resumed ())
       return tp->ptid;
   return null_ptid;
 }
diff --git a/gdb/thread.c b/gdb/thread.c
index 925ed96c3d83..c6c63b742db4 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -708,7 +708,7 @@ void
 set_resumed (process_stratum_target *targ, ptid_t ptid, bool resumed)
 {
   for (thread_info *tp : all_non_exited_threads (targ, ptid))
-    tp->resumed = resumed;
+    tp->set_resumed (resumed);
 }
 
 /* Helper for set_running, that marks one thread either running or
-- 
2.32.0


  parent reply	other threads:[~2021-06-22 16:57 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22 16:56 [PATCH 00/11] Various thread lists optimizations Simon Marchi via Gdb-patches
2021-06-22 16:56 ` [PATCH 01/11] gdb: introduce iterator_range, remove next_adapter Simon Marchi via Gdb-patches
2021-07-05 15:41   ` Pedro Alves
2021-07-06 19:16     ` Simon Marchi via Gdb-patches
2021-06-22 16:56 ` [PATCH 02/11] gdb: introduce intrusive_list, make thread_info use it Simon Marchi via Gdb-patches
2021-06-22 23:13   ` Lancelot SIX via Gdb-patches
2021-06-23  0:48     ` Simon Marchi via Gdb-patches
2021-07-05 15:44   ` Pedro Alves
2021-07-06 19:38     ` Simon Marchi via Gdb-patches
2021-07-06 20:45       ` Simon Marchi via Gdb-patches
2021-07-06 21:04         ` Pedro Alves
2021-07-06 21:38           ` Simon Marchi via Gdb-patches
2021-07-06 21:02       ` Pedro Alves
2021-07-06 21:45         ` Simon Marchi via Gdb-patches
2021-07-07 11:46           ` Pedro Alves
2021-07-07 13:52             ` Simon Marchi via Gdb-patches
2021-06-22 16:56 ` [PATCH 03/11] gdb: make inferior_list use intrusive_list Simon Marchi via Gdb-patches
2021-07-05 15:44   ` Pedro Alves
2021-07-14  6:34     ` Tom de Vries
2021-07-14 16:11       ` Simon Marchi via Gdb-patches
2021-07-14 20:15         ` [PATCH] gdb: make all_inferiors_safe actually work Simon Marchi via Gdb-patches
2021-07-15 10:15           ` Tom de Vries
2021-07-17 12:54             ` Simon Marchi via Gdb-patches
2021-06-22 16:56 ` [PATCH 04/11] gdb: use intrusive list for step-over chain Simon Marchi via Gdb-patches
2021-07-05 15:45   ` Pedro Alves
2021-07-06 20:59     ` Simon Marchi via Gdb-patches
2021-06-22 16:56 ` Simon Marchi via Gdb-patches [this message]
2021-07-05 15:45   ` [PATCH 05/11] gdb: add setter / getter for thread_info resumed state Pedro Alves
2021-06-22 16:56 ` [PATCH 06/11] gdb: make thread_info::suspend private, add getters / setters Simon Marchi via Gdb-patches
2021-07-05 15:45   ` Pedro Alves
2021-06-22 16:57 ` [PATCH 07/11] gdb: maintain per-process-target list of resumed threads with pending wait status Simon Marchi via Gdb-patches
2021-07-05 15:51   ` Pedro Alves
2021-07-06 21:25     ` Simon Marchi via Gdb-patches
2021-07-07 12:01       ` Pedro Alves
2021-07-12 22:28         ` Simon Marchi via Gdb-patches
2021-07-12 22:34           ` Simon Marchi via Gdb-patches
2021-07-13 12:21           ` Pedro Alves
2021-06-22 16:57 ` [PATCH 08/11] gdb: optimize check for resumed threads with pending wait status in maybe_set_commit_resumed_all_targets Simon Marchi via Gdb-patches
2021-07-05 15:51   ` Pedro Alves
2021-06-22 16:57 ` [PATCH 09/11] gdb: optimize selection of resumed thread with pending event Simon Marchi via Gdb-patches
2021-07-05 15:51   ` Pedro Alves
2021-06-22 16:57 ` [PATCH 10/11] gdb: maintain ptid -> thread map, optimize find_thread_ptid Simon Marchi via Gdb-patches
2021-07-05 15:52   ` Pedro Alves
2021-07-06 21:31     ` Simon Marchi via Gdb-patches
2021-07-07 12:13       ` Pedro Alves
2021-06-22 16:57 ` [PATCH 11/11] gdb: optimize all_matching_threads_iterator Simon Marchi via Gdb-patches
2021-07-05 15:52   ` Pedro Alves
2021-07-14  9:40     ` Tom de Vries
2021-07-13  0:47 ` [PATCH 00/11] Various thread lists optimizations Simon Marchi via Gdb-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210622165704.2404007-6-simon.marchi@polymtl.ca \
    --to=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox