[Lldb-commits] [lldb] r155092 - in /lldb/trunk: include/lldb/Target/Process.h source/Target/Process.cpp

Jim Ingham jingham at apple.com
Wed Apr 18 18:40:33 PDT 2012


Author: jingham
Date: Wed Apr 18 20:40:33 2012
New Revision: 155092

URL: http://llvm.org/viewvc/llvm-project?rev=155092&view=rev
Log:
Switch to setting the write side of the run lock when we call Resume.  Then make a PrivateResume that doesn't switch the run-lock state, and use that where we are resuming without changing the public resume state.

Modified:
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/source/Target/Process.cpp

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=155092&r1=155091&r2=155092&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Wed Apr 18 20:40:33 2012
@@ -1769,6 +1769,12 @@
     /// 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 @@
     /// @see Thread:Suspend()
     //------------------------------------------------------------------
     Error
-    Resume ();
-
+    Resume();
+    
     //------------------------------------------------------------------
     /// Halts a running process.
     ///
@@ -2306,6 +2312,16 @@
     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

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=155092&r1=155091&r2=155092&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Wed Apr 18 20:40:33 2012
@@ -1293,6 +1293,10 @@
         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 @@
                     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 @@
                 if (m_exec_count > 0)
                 {
                     --m_exec_count;
-                    m_process->Resume();
+                    m_process->PrivateResume ();
                     return eEventActionRetry;
                 }
                 else
@@ -2797,7 +2811,7 @@
 
 
 Error
-Process::Resume ()
+Process::PrivateResume ()
 {
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
     if (log)
@@ -3096,7 +3110,7 @@
 
                     if (log)
                         log->Printf ("Process::ShouldBroadcastEvent (%p) Restarting process from state: %s", event_ptr, StateAsCString(state));
-                    Resume ();
+                    PrivateResume ();
                 }
                 else
                 {
@@ -3503,6 +3517,8 @@
             {
                 // 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 @@
         {
             // 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());





More information about the lldb-commits mailing list