Added a new Host class: ReadWriteLock

This abstracts read/write locks on the current host system. It is currently backed by pthread_rwlock_t objects so it should work on all unix systems.

We also need a way to control multi-threaded access to the process through the public API when it is running. For example it isn't a good idea to try and get stack frames while the process is running. To implement this, the lldb_private::Process class now contains a ReadWriteLock member variable named m_run_lock which is used to control the public process state. The public process state represents the state of the process as the client knows it. The private is used to control the actual current process state. So the public state of the process can be stopped, yet the private state can be running when evaluating an expression for example. 

Adding the read/write lock where readers are clients that want the process to stay stopped, and writers are clients that run the process, allows us to accurately control multi-threaded access to the process.

Switched the SBThread and SBFrame over to us shared pointers to the ExecutionContextRef class instead of making their own class to track this. This fixed an issue with assigning on SBFrame to another and will also centralize the code that tracks weak references to execution context objects into one location.



git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@154099 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBFrame.cpp b/source/API/SBFrame.cpp
index 9f4709f..c84ac13 100644
--- a/source/API/SBFrame.cpp
+++ b/source/API/SBFrame.cpp
@@ -42,91 +42,17 @@
 #include "lldb/API/SBSymbolContext.h"
 #include "lldb/API/SBThread.h"
 
-namespace lldb_private {
-
-    class StackFrameImpl
-    {
-    public:
-        StackFrameImpl (const lldb::StackFrameSP &frame_sp) :
-            m_frame_wp (frame_sp),
-            m_thread_wp (),
-            m_stack_id ()
-        {
-            if (frame_sp)
-            {
-                m_thread_wp = frame_sp->GetThread();
-                m_stack_id = frame_sp->GetStackID();
-            }
-        }
-        
-        ~StackFrameImpl()
-        {
-        }
-
-        lldb::StackFrameSP
-        GetFrameSP ()
-        {
-            lldb::StackFrameSP frame_sp;
-            // We have a weak pointer to our thread, which might
-            // be NULL'ed out if the thread went away, so first
-            // make sure our thread is still alive.
-            lldb::ThreadSP thread_sp (m_thread_wp.lock());
-            if (thread_sp)
-            {
-                // Our thread is still here, check if our frame
-                // is still alive as well.
-                frame_sp = m_frame_wp.lock();
-                if (frame_sp)
-                {
-                    // Our frame is still alive, make sure that our thread
-                    // still has this exact frame...
-                    lldb::StackFrameSP tmp_frame_sp (thread_sp->GetStackFrameAtIndex (frame_sp->GetFrameIndex()));
-                    if (tmp_frame_sp == frame_sp)
-                        return frame_sp;
-                }
-                // The original stack frame might have gone away,
-                // we need to check for the frame by stack ID
-                frame_sp = thread_sp->GetFrameWithStackID (m_stack_id);
-                m_frame_wp = frame_sp;
-            }
-            return frame_sp;
-        }
-
-        void
-        SetFrameSP (const lldb::StackFrameSP &frame_sp)
-        {
-            if (frame_sp)
-            {
-                m_frame_wp = frame_sp;
-                m_thread_wp = frame_sp->GetThread();
-                m_stack_id = frame_sp->GetStackID();
-            }
-            else
-            {
-                m_frame_wp.reset();
-                m_thread_wp.reset();
-                m_stack_id.Clear();
-            }
-        }
-
-    protected:
-        lldb::StackFrameWP m_frame_wp;
-        lldb::ThreadWP m_thread_wp;
-        StackID m_stack_id;
-    };
-} // namespace lldb_private
-
 using namespace lldb;
 using namespace lldb_private;
 
 
 SBFrame::SBFrame () :
-    m_opaque_sp ()
+    m_opaque_sp (new ExecutionContextRef())
 {
 }
 
 SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) :
-    m_opaque_sp (new StackFrameImpl (lldb_object_sp))
+    m_opaque_sp (new ExecutionContextRef (lldb_object_sp))
 {
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
@@ -141,7 +67,7 @@
 }
 
 SBFrame::SBFrame(const SBFrame &rhs) :
-    m_opaque_sp (rhs.m_opaque_sp)
+    m_opaque_sp (new ExecutionContextRef (*rhs.m_opaque_sp))
 {
 }
 
@@ -149,7 +75,7 @@
 SBFrame::operator = (const SBFrame &rhs)
 {
     if (this != &rhs)
-        m_opaque_sp = rhs.m_opaque_sp;
+        *m_opaque_sp = *rhs.m_opaque_sp;
     return *this;
 }
 
@@ -160,42 +86,19 @@
 StackFrameSP
 SBFrame::GetFrameSP() const
 {
-    StackFrameImplSP impl_sp (m_opaque_sp);
-    StackFrameSP frame_sp;
-    if (impl_sp)
-        frame_sp = impl_sp->GetFrameSP();
-    return frame_sp;
+    return m_opaque_sp->GetFrameSP();
 }
 
 void
 SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp)
 {
-    if (lldb_object_sp)
-    {
-        if (m_opaque_sp)
-        {
-            StackFrameImplSP impl_sp (m_opaque_sp);
-            if (impl_sp)
-                impl_sp->SetFrameSP (lldb_object_sp);
-        }
-        else
-        {
-            m_opaque_sp = StackFrameImplSP (new StackFrameImpl(lldb_object_sp));
-        }
-    }
-    else
-    {
-        m_opaque_sp.reset();
-    }
+    return m_opaque_sp->SetFrameSP(lldb_object_sp);
 }
 
 bool
 SBFrame::IsValid() const
 {
-    StackFrameImplSP impl_sp (m_opaque_sp);
-    if (impl_sp)
-        return (impl_sp->GetFrameSP().get() != NULL);
-    return false;
+    return GetFrameSP().get() != NULL;
 }
 
 SBSymbolContext
@@ -203,13 +106,17 @@
 {
 
     SBSymbolContext sb_sym_ctx;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope));
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope));
+        }
     }
 
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
@@ -225,14 +132,18 @@
 {
     SBModule sb_module;
     ModuleSP module_sp;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp;
-        sb_module.SetSP (module_sp);
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp;
+            sb_module.SetSP (module_sp);
+        }
     }
 
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
@@ -247,13 +158,17 @@
 SBFrame::GetCompileUnit () const
 {
     SBCompileUnit sb_comp_unit;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
+        }
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
@@ -267,13 +182,17 @@
 SBFrame::GetFunction () const
 {
     SBFunction sb_function;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function);
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function);
+        }
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
@@ -287,13 +206,17 @@
 SBFrame::GetSymbol () const
 {
     SBSymbol sb_symbol;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol);
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol);
+        }
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
@@ -306,13 +229,17 @@
 SBFrame::GetBlock () const
 {
     SBBlock sb_block;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block);
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block);
+        }
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
@@ -325,13 +252,17 @@
 SBFrame::GetFrameBlock () const
 {
     SBBlock sb_block;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        sb_block.SetPtr(frame->GetFrameBlock ());
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            sb_block.SetPtr(frame->GetFrameBlock ());
+        }
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
@@ -344,13 +275,17 @@
 SBFrame::GetLineEntry () const
 {
     SBLineEntry sb_line_entry;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry);
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry);
+        }
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
@@ -364,11 +299,9 @@
 {
     uint32_t frame_idx = UINT32_MAX;
     
-    
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
-    Target *target = exe_ctx.GetTargetPtr();
-    if (frame && target)
+    if (frame)
         frame_idx = frame->GetFrameIndex ();
     
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
@@ -382,13 +315,17 @@
 SBFrame::GetPC () const
 {
     addr_t addr = LLDB_INVALID_ADDRESS;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target);
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target);
+        }
     }
 
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
@@ -402,13 +339,17 @@
 SBFrame::SetPC (addr_t new_pc)
 {
     bool ret_val = false;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        ret_val = frame->GetRegisterContext()->SetPC (new_pc);
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            ret_val = frame->GetRegisterContext()->SetPC (new_pc);
+        }
     }
 
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
@@ -423,13 +364,17 @@
 SBFrame::GetSP () const
 {
     addr_t addr = LLDB_INVALID_ADDRESS;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        addr = frame->GetRegisterContext()->GetSP();
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            addr = frame->GetRegisterContext()->GetSP();
+        }
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
@@ -443,13 +388,17 @@
 SBFrame::GetFP () const
 {
     addr_t addr = LLDB_INVALID_ADDRESS;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        addr = frame->GetRegisterContext()->GetFP();
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            addr = frame->GetRegisterContext()->GetFP();
+        }
     }
 
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
@@ -463,13 +412,17 @@
 SBFrame::GetPCAddress () const
 {
     SBAddress sb_addr;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        sb_addr.SetAddress (&frame->GetFrameCodeAddress());
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            sb_addr.SetAddress (&frame->GetFrameCodeAddress());
+        }
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
@@ -487,13 +440,17 @@
 SBFrame::GetValueForVariablePath (const char *var_path)
 {
     SBValue sb_value;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        lldb::DynamicValueType  use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
-        sb_value = GetValueForVariablePath (var_path, use_dynamic);
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            lldb::DynamicValueType  use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue();
+            sb_value = GetValueForVariablePath (var_path, use_dynamic);
+        }
     }
     return sb_value;
 }
@@ -502,20 +459,24 @@
 SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic)
 {
     SBValue sb_value;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target && var_path && var_path[0])
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        VariableSP var_sp;
-        Error error;
-        ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path, 
-                                                                          use_dynamic,
-                                                                          StackFrame::eExpressionPathOptionCheckPtrVsMember,
-                                                                          var_sp,
-                                                                          error));
-        sb_value.SetSP(value_sp);
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            VariableSP var_sp;
+            Error error;
+            ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path, 
+                                                                              use_dynamic,
+                                                                              StackFrame::eExpressionPathOptionCheckPtrVsMember,
+                                                                              var_sp,
+                                                                              error));
+            sb_value.SetSP(value_sp);
+        }
     }
     return sb_value;
 }
@@ -524,7 +485,7 @@
 SBFrame::FindVariable (const char *name)
 {
     SBValue value;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
@@ -542,36 +503,39 @@
     VariableSP var_sp;
     SBValue sb_value;
     ValueObjectSP value_sp;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target && name && name[0])
     {
-        VariableList variable_list;
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
-
-        if (sc.block)
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
         {
-            const bool can_create = true;
-            const bool get_parent_variables = true;
-            const bool stop_if_block_is_inlined_function = true;
-            
-            if (sc.block->AppendVariables (can_create, 
-                                           get_parent_variables,
-                                           stop_if_block_is_inlined_function,
-                                           &variable_list))
+            VariableList variable_list;
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
+
+            if (sc.block)
             {
-                var_sp = variable_list.FindVariable (ConstString(name));
+                const bool can_create = true;
+                const bool get_parent_variables = true;
+                const bool stop_if_block_is_inlined_function = true;
+                
+                if (sc.block->AppendVariables (can_create, 
+                                               get_parent_variables,
+                                               stop_if_block_is_inlined_function,
+                                               &variable_list))
+                {
+                    var_sp = variable_list.FindVariable (ConstString(name));
+                }
+            }
+
+            if (var_sp)
+            {
+                value_sp = frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
+                sb_value.SetSP(value_sp);
             }
         }
-
-        if (var_sp)
-        {
-            value_sp = frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
-            sb_value.SetSP(value_sp);
-        }
-        
     }
     
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
@@ -586,7 +550,7 @@
 SBFrame::FindValue (const char *name, ValueType value_type)
 {
     SBValue value;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
@@ -602,109 +566,113 @@
 {
     SBValue sb_value;
     ValueObjectSP value_sp;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target && name && name[0])
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-    
-        switch (value_type)
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
         {
-        case eValueTypeVariableGlobal:      // global variable
-        case eValueTypeVariableStatic:      // static variable
-        case eValueTypeVariableArgument:    // function argument variables
-        case eValueTypeVariableLocal:       // function local variables
+            Mutex::Locker api_locker (target->GetAPIMutex());
+        
+            switch (value_type)
             {
-                VariableList *variable_list = frame->GetVariableList(true);
+            case eValueTypeVariableGlobal:      // global variable
+            case eValueTypeVariableStatic:      // static variable
+            case eValueTypeVariableArgument:    // function argument variables
+            case eValueTypeVariableLocal:       // function local variables
+                {
+                    VariableList *variable_list = frame->GetVariableList(true);
 
-                SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
+                    SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock));
 
-                const bool can_create = true;
-                const bool get_parent_variables = true;
-                const bool stop_if_block_is_inlined_function = true;
+                    const bool can_create = true;
+                    const bool get_parent_variables = true;
+                    const bool stop_if_block_is_inlined_function = true;
 
-                if (sc.block && sc.block->AppendVariables (can_create, 
-                                                           get_parent_variables,
-                                                           stop_if_block_is_inlined_function,
-                                                           variable_list))
+                    if (sc.block && sc.block->AppendVariables (can_create, 
+                                                               get_parent_variables,
+                                                               stop_if_block_is_inlined_function,
+                                                               variable_list))
+                    {
+                        ConstString const_name(name);
+                        const uint32_t num_variables = variable_list->GetSize();
+                        for (uint32_t i = 0; i < num_variables; ++i)
+                        {
+                            VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
+                            if (variable_sp && 
+                                variable_sp->GetScope() == value_type &&
+                                variable_sp->GetName() == const_name)
+                            {
+                                value_sp = frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic);
+                                sb_value.SetSP (value_sp);
+                                break;
+                            }
+                        }
+                    }
+                }
+                break;
+
+            case eValueTypeRegister:            // stack frame register value
+                {
+                    RegisterContextSP reg_ctx (frame->GetRegisterContext());
+                    if (reg_ctx)
+                    {
+                        const uint32_t num_regs = reg_ctx->GetRegisterCount();
+                        for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
+                        {
+                            const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
+                            if (reg_info && 
+                                ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
+                                 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
+                            {
+                                value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
+                                sb_value.SetSP (value_sp);
+                                break;
+                            }
+                        }
+                    }
+                }
+                break;
+
+            case eValueTypeRegisterSet:         // A collection of stack frame register values
+                {
+                    RegisterContextSP reg_ctx (frame->GetRegisterContext());
+                    if (reg_ctx)
+                    {
+                        const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
+                        for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
+                        {
+                            const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
+                            if (reg_set && 
+                                ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
+                                 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
+                            {
+                                value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
+                                sb_value.SetSP (value_sp);
+                                break;
+                            }
+                        }
+                    }
+                }
+                break;
+
+            case eValueTypeConstResult:         // constant result variables
                 {
                     ConstString const_name(name);
-                    const uint32_t num_variables = variable_list->GetSize();
-                    for (uint32_t i = 0; i < num_variables; ++i)
+                    ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name));
+                    if (expr_var_sp)
                     {
-                        VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
-                        if (variable_sp && 
-                            variable_sp->GetScope() == value_type &&
-                            variable_sp->GetName() == const_name)
-                        {
-                            value_sp = frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic);
-                            sb_value.SetSP (value_sp);
-                            break;
-                        }
+                        value_sp = expr_var_sp->GetValueObject();
+                        sb_value.SetSP (value_sp);
                     }
                 }
-            }
-            break;
+                break;
 
-        case eValueTypeRegister:            // stack frame register value
-            {
-                RegisterContextSP reg_ctx (frame->GetRegisterContext());
-                if (reg_ctx)
-                {
-                    const uint32_t num_regs = reg_ctx->GetRegisterCount();
-                    for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
-                    {
-                        const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
-                        if (reg_info && 
-                            ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
-                             (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
-                        {
-                            value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx);
-                            sb_value.SetSP (value_sp);
-                            break;
-                        }
-                    }
-                }
+            default:
+                break;
             }
-            break;
-
-        case eValueTypeRegisterSet:         // A collection of stack frame register values
-            {
-                RegisterContextSP reg_ctx (frame->GetRegisterContext());
-                if (reg_ctx)
-                {
-                    const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
-                    for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
-                    {
-                        const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
-                        if (reg_set && 
-                            ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
-                             (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
-                        {
-                            value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx);
-                            sb_value.SetSP (value_sp);
-                            break;
-                        }
-                    }
-                }
-            }
-            break;
-
-        case eValueTypeConstResult:         // constant result variables
-            {
-                ConstString const_name(name);
-                ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name));
-                if (expr_var_sp)
-                {
-                    value_sp = expr_var_sp->GetValueObject();
-                    sb_value.SetSP (value_sp);
-                }
-            }
-            break;
-
-        default:
-            break;
         }
     }
     
@@ -742,7 +710,7 @@
 {
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     ThreadSP thread_sp (exe_ctx.GetThreadSP());
     SBThread sb_thread (thread_sp);
 
@@ -763,13 +731,17 @@
 SBFrame::Disassemble () const
 {
     const char *disassembly = NULL;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        disassembly = frame->Disassemble();
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            disassembly = frame->Disassemble();
+        }
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
@@ -787,7 +759,7 @@
                        bool in_scope_only)
 {
     SBValueList value_list;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
@@ -808,7 +780,7 @@
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
     SBValueList value_list;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
 
@@ -822,54 +794,58 @@
     
     if (frame && target)
     {
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
 
-        size_t i;
-        VariableList *variable_list = NULL;
-        // Scope for locker
-        {
-            Mutex::Locker api_locker (target->GetAPIMutex());
-            variable_list = frame->GetVariableList(true);
-        }
-        if (variable_list)
-        {
-            const size_t num_variables = variable_list->GetSize();
-            if (num_variables)
+            size_t i;
+            VariableList *variable_list = NULL;
+            // Scope for locker
             {
-                for (i = 0; i < num_variables; ++i)
+                Mutex::Locker api_locker (target->GetAPIMutex());
+                variable_list = frame->GetVariableList(true);
+            }
+            if (variable_list)
+            {
+                const size_t num_variables = variable_list->GetSize();
+                if (num_variables)
                 {
-                    VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
-                    if (variable_sp)
+                    for (i = 0; i < num_variables; ++i)
                     {
-                        bool add_variable = false;
-                        switch (variable_sp->GetScope())
+                        VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
+                        if (variable_sp)
                         {
-                        case eValueTypeVariableGlobal:
-                        case eValueTypeVariableStatic:
-                            add_variable = statics;
-                            break;
+                            bool add_variable = false;
+                            switch (variable_sp->GetScope())
+                            {
+                            case eValueTypeVariableGlobal:
+                            case eValueTypeVariableStatic:
+                                add_variable = statics;
+                                break;
 
-                        case eValueTypeVariableArgument:
-                            add_variable = arguments;
-                            break;
+                            case eValueTypeVariableArgument:
+                                add_variable = arguments;
+                                break;
 
-                        case eValueTypeVariableLocal:
-                            add_variable = locals;
-                            break;
+                            case eValueTypeVariableLocal:
+                                add_variable = locals;
+                                break;
 
-                        default:
-                            break;
-                        }
-                        if (add_variable)
-                        {
-                            if (in_scope_only && !variable_sp->IsInScope(frame))
-                                continue;
+                            default:
+                                break;
+                            }
+                            if (add_variable)
+                            {
+                                if (in_scope_only && !variable_sp->IsInScope(frame))
+                                    continue;
 
-                            value_list.Append(frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic));
+                                value_list.Append(frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic));
+                            }
                         }
                     }
                 }
             }
-        }        
+        }
     }
 
     if (log)
@@ -887,19 +863,23 @@
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
     SBValueList value_list;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        RegisterContextSP reg_ctx (frame->GetRegisterContext());
-        if (reg_ctx)
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
         {
-            const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
-            for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            RegisterContextSP reg_ctx (frame->GetRegisterContext());
+            if (reg_ctx)
             {
-                value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
+                const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
+                for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
+                {
+                    value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx));
+                }
             }
         }
     }
@@ -915,13 +895,17 @@
 {
     Stream &strm = description.ref();
 
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        frame->DumpUsingSettingsFormat (&strm);
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            frame->DumpUsingSettingsFormat (&strm);
+        }
     }
     else
         strm.PutCString ("No value");
@@ -933,7 +917,7 @@
 SBFrame::EvaluateExpression (const char *expr)
 {
     SBValue result;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
@@ -955,7 +939,7 @@
     SBValue expr_result;
     ValueObjectSP expr_value_sp;
 
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (log)
@@ -963,29 +947,34 @@
 
     if (frame && target)
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        
-        
-        StreamString frame_description;
-        frame->DumpUsingSettingsFormat (&frame_description);
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
 
-        Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
-                                             expr, fetch_dynamic_value, frame_description.GetString().c_str());
+            Mutex::Locker api_locker (target->GetAPIMutex());
+            
+            
+            StreamString frame_description;
+            frame->DumpUsingSettingsFormat (&frame_description);
 
-        const bool coerce_to_id = false;
-        const bool unwind_on_error = true;
-        const bool keep_in_memory = false;
+            Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
+                                                 expr, fetch_dynamic_value, frame_description.GetString().c_str());
 
-        exe_results = target->EvaluateExpression (expr, 
-                                                  frame,
-                                                  eExecutionPolicyOnlyWhenNeeded,
-                                                  coerce_to_id,
-                                                  unwind_on_error, 
-                                                  keep_in_memory, 
-                                                  fetch_dynamic_value, 
-                                                  expr_value_sp);
-        expr_result.SetSP(expr_value_sp);
-        Host::SetCrashDescription (NULL);
+            const bool coerce_to_id = false;
+            const bool unwind_on_error = true;
+            const bool keep_in_memory = false;
+
+            exe_results = target->EvaluateExpression (expr, 
+                                                      frame,
+                                                      eExecutionPolicyOnlyWhenNeeded,
+                                                      coerce_to_id,
+                                                      unwind_on_error, 
+                                                      keep_in_memory, 
+                                                      fetch_dynamic_value, 
+                                                      expr_value_sp);
+            expr_result.SetSP(expr_value_sp);
+            Host::SetCrashDescription (NULL);
+        }
     }
 
 #ifndef LLDB_DISABLE_PYTHON
@@ -1008,14 +997,19 @@
 bool
 SBFrame::IsInlined()
 {
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
-        if (block)
-            return block->GetContainingInlinedBlock () != NULL;
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
+        {
+
+            Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
+            if (block)
+                return block->GetContainingInlinedBlock () != NULL;
+        }
     }
     return false;
 }
@@ -1024,32 +1018,36 @@
 SBFrame::GetFunctionName()
 {
     const char *name = NULL;
-    ExecutionContext exe_ctx(GetFrameSP());
+    ExecutionContext exe_ctx(m_opaque_sp.get());
     StackFrame *frame = exe_ctx.GetFramePtr();
     Target *target = exe_ctx.GetTargetPtr();
     if (frame && target)
     {
-        SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
-        if (sc.block)
+        Process::StopLocker stop_locker;
+        if (stop_locker.TryLock(&exe_ctx.GetProcessPtr()->GetRunLock()))
         {
-            Block *inlined_block = sc.block->GetContainingInlinedBlock ();
-            if (inlined_block)
+            SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
+            if (sc.block)
             {
-                const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
-                name = inlined_info->GetName().AsCString();
+                Block *inlined_block = sc.block->GetContainingInlinedBlock ();
+                if (inlined_block)
+                {
+                    const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo();
+                    name = inlined_info->GetName().AsCString();
+                }
             }
-        }
-        
-        if (name == NULL)
-        {
-            if (sc.function)
-                name = sc.function->GetName().GetCString();
-        }
+            
+            if (name == NULL)
+            {
+                if (sc.function)
+                    name = sc.function->GetName().GetCString();
+            }
 
-        if (name == NULL)
-        {
-            if (sc.symbol)
-                name = sc.symbol->GetName().GetCString();
+            if (name == NULL)
+            {
+                if (sc.symbol)
+                    name = sc.symbol->GetName().GetCString();
+            }
         }
     }
     return name;