[Lldb-commits] [lldb] r181651 - <rdar://problem/13700260>

Greg Clayton gclayton at apple.com
Fri May 10 16:48:11 PDT 2013


Author: gclayton
Date: Fri May 10 18:48:10 2013
New Revision: 181651

URL: http://llvm.org/viewvc/llvm-project?rev=181651&view=rev
Log:
<rdar://problem/13700260>

Avoid a deadlock when using the OperatingSystemPython code and typing "process interrupt". There was a possible lock inversion between the target API lock and the process' thread list lock due to code trying to discard the thread list. This was fixed by adding a boolean to Process::Halt() that indicates if the thread plans should be discarded and doing it in the private state thread when we process the stopped state.


Modified:
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/source/Commands/CommandObjectProcess.cpp
    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=181651&r1=181650&r2=181651&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Fri May 10 18:48:10 2013
@@ -1936,12 +1936,15 @@ public:
     /// process event with GetInterrupted will be broadcast.  If false, we will
     /// halt the process with no events generated by the halt.
     ///
+    /// @param[in] clear_thread_plans
+    ///     If true, when the process stops, clear all thread plans.
+    ///
     /// @return
     ///     Returns an error object.  If the error is empty, the process is halted.
     ///     otherwise the halt has failed.
     //------------------------------------------------------------------
     Error
-    Halt ();
+    Halt (bool clear_thread_plans = false);
 
     //------------------------------------------------------------------
     /// Detaches from a running or stopped process.
@@ -3668,6 +3671,7 @@ protected:
     bool                        m_currently_handling_do_on_removals;
     bool                        m_resume_requested;         // If m_currently_handling_event or m_currently_handling_do_on_removals are true, Resume will only request a resume, using this flag to check.
     bool                        m_finalize_called;
+    bool                        m_clear_thread_plans_on_stop;
     lldb::StateType             m_last_broadcast_state;   /// This helps with the Public event coalescing in ShouldBroadcastEvent.
     bool m_destroy_in_process;
     

Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=181651&r1=181650&r2=181651&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Fri May 10 18:48:10 2013
@@ -1470,7 +1470,7 @@ public:
 protected:
     bool
     DoExecute (Args& command,
-             CommandReturnObject &result)
+               CommandReturnObject &result)
     {
         Process *process = m_exe_ctx.GetProcessPtr();
         if (process == NULL)
@@ -1482,14 +1482,11 @@ protected:
 
         if (command.GetArgumentCount() == 0)
         {
-            Error error(process->Halt ());
+            bool clear_thread_plans = true;
+            Error error(process->Halt (clear_thread_plans));
             if (error.Success())
             {
                 result.SetStatus (eReturnStatusSuccessFinishResult);
-                
-                // Maybe we should add a "SuspendThreadPlans so we
-                // can halt, and keep in place all the current thread plans.
-                process->GetThreadList().DiscardThreadPlans();
             }
             else
             {

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=181651&r1=181650&r2=181651&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Fri May 10 18:48:10 2013
@@ -1035,6 +1035,7 @@ Process::Process(Target &target, Listene
     m_private_run_lock (),
     m_currently_handling_event(false),
     m_finalize_called(false),
+    m_clear_thread_plans_on_stop (false),
     m_last_broadcast_state (eStateInvalid),
     m_destroy_in_process (false),
     m_can_jit(eCanJITDontKnow)
@@ -3332,8 +3333,13 @@ Process::PrivateResume ()
 }
 
 Error
-Process::Halt ()
+Process::Halt (bool clear_thread_plans)
 {
+    // Don't clear the m_clear_thread_plans_on_stop, only set it to true if
+    // in case it was already set and some thread plan logic calls halt on its
+    // own.
+    m_clear_thread_plans_on_stop |= clear_thread_plans;
+    
     // First make sure we aren't in the middle of handling an event, or we might restart.  This is pretty weak, since
     // we could just straightaway get another event.  It just narrows the window...
     m_currently_handling_event.WaitForValueEqualTo(false);
@@ -4035,6 +4041,12 @@ Process::RunPrivateStateThread ()
 
         if (internal_state != eStateInvalid)
         {
+            if (m_clear_thread_plans_on_stop &&
+                StateIsStoppedState(internal_state, true))
+            {
+                m_clear_thread_plans_on_stop = false;
+                m_thread_list.DiscardThreadPlans();
+            }
             HandlePrivateEvent (event_sp);
         }
 





More information about the lldb-commits mailing list