summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Target/Process.h20
-rw-r--r--lldb/source/Target/Process.cpp36
2 files changed, 44 insertions, 12 deletions
diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h
index cca72d1043e..e673c4434b5 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -1769,6 +1769,12 @@ public:
/// re-enabling breakpoints, and enabling the basic flow control
/// that the plug-in instances need not worry about.
///
+ /// N.B. This function also sets the Write side of the Run Lock,
+ /// which is unset when the corresponding stop event is pulled off
+ /// the Public Event Queue. If you need to resume the process without
+ /// setting the Run Lock, use PrivateResume (though you should only do
+ /// that from inside the Process class.
+ ///
/// @return
/// Returns an error object.
///
@@ -1777,8 +1783,8 @@ public:
/// @see Thread:Suspend()
//------------------------------------------------------------------
Error
- Resume ();
-
+ Resume();
+
//------------------------------------------------------------------
/// Halts a running process.
///
@@ -2306,6 +2312,16 @@ protected:
GetPrivateState ();
//------------------------------------------------------------------
+ /// The "private" side of resuming a process. This doesn't alter the
+ /// state of m_run_lock, but just causes the process to resume.
+ ///
+ /// @return
+ /// An Error object describing the success or failure of the resume.
+ //------------------------------------------------------------------
+ Error
+ PrivateResume ();
+
+ //------------------------------------------------------------------
// Called internally
//------------------------------------------------------------------
void
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index dd283c5f736..2a02bd52d17 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -1293,6 +1293,10 @@ Process::SetPublicState (StateType new_state)
log->Printf("Process::SetPublicState (%s)", StateAsCString(new_state));
const StateType old_state = m_public_state.GetValue();
m_public_state.SetValue (new_state);
+
+ // On the transition from Run to Stopped, we unlock the writer end of the
+ // run lock. The lock gets locked in Resume, which is the public API
+ // to tell the program to run.
if (!IsHijackedForEvent(eBroadcastBitStateChanged))
{
const bool old_state_is_stopped = StateIsStoppedState(old_state, false);
@@ -1305,16 +1309,26 @@ Process::SetPublicState (StateType new_state)
log->Printf("Process::SetPublicState (%s) -- unlocking run lock", StateAsCString(new_state));
m_run_lock.WriteUnlock();
}
- else
- {
- if (log)
- log->Printf("Process::SetPublicState (%s) -- locking run lock", StateAsCString(new_state));
- m_run_lock.WriteLock();
- }
}
}
}
+Error
+Process::Resume ()
+{
+ LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS));
+ if (log)
+ log->Printf("Process::Resume -- locking run lock");
+ if (!m_run_lock.WriteTryLock())
+ {
+ Error error("Resume request failed - process still running.");
+ if (log)
+ log->Printf ("Process::Resume: -- WriteTryLock failed, not resuming.");
+ return error;
+ }
+ return PrivateResume();
+}
+
StateType
Process::GetPrivateState ()
{
@@ -2495,7 +2509,7 @@ Process::AttachCompletionHandler::PerformAction (lldb::EventSP &event_sp)
if (m_exec_count > 0)
{
--m_exec_count;
- m_process->Resume();
+ m_process->PrivateResume ();
return eEventActionRetry;
}
else
@@ -2797,7 +2811,7 @@ Process::ConnectRemote (const char *remote_url)
Error
-Process::Resume ()
+Process::PrivateResume ()
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
if (log)
@@ -3096,7 +3110,7 @@ Process::ShouldBroadcastEvent (Event *event_ptr)
if (log)
log->Printf ("Process::ShouldBroadcastEvent (%p) Restarting process from state: %s", event_ptr, StateAsCString(state));
- Resume ();
+ PrivateResume ();
}
else
{
@@ -3503,6 +3517,8 @@ Process::ProcessEventData::DoOnRemoval (Event *event_ptr)
{
// We've been asked to continue, so do that here.
SetRestarted(true);
+ // Use the public resume method here, since this is just
+ // extending a public resume.
m_process_sp->Resume();
}
else
@@ -4042,7 +4058,7 @@ Process::RunThreadPlan (ExecutionContext &exe_ctx,
{
// Do the initial resume and wait for the running event before going further.
- Error resume_error = Resume ();
+ Error resume_error = PrivateResume ();
if (!resume_error.Success())
{
errors.Printf("Error resuming inferior: \"%s\".\n", resume_error.AsCString());
OpenPOWER on IntegriCloud