[Lldb-commits] [lldb] r181863 - Change the mechanism around SBValue::GetSP() so that it always requires the target API lock AND the

Jim Ingham jingham at apple.com
Tue May 14 19:16:21 PDT 2013


Author: jingham
Date: Tue May 14 21:16:21 2013
New Revision: 181863

URL: http://llvm.org/viewvc/llvm-project?rev=181863&view=rev
Log:
Change the mechanism around SBValue::GetSP() so that it always requires the target API lock AND the
process StopLocker (if there is a process) before it will hand out SBValues.  We were doing this in 
an ad hoc fashion previously, and then playing whack-a-mole whenever we found a place where we should
have been doing this but weren't.  Really, it doesn't make sense to be poking at SBValues when the target
is running, the dynamic and synthetic values can't really be computed, and the underlying memory may be
incoherent.

<rdar://problem/13819378> Sometimes when stepping fast, my inferior is killed by debugserver

Modified:
    lldb/trunk/include/lldb/API/SBValue.h
    lldb/trunk/source/API/SBValue.cpp

Modified: lldb/trunk/include/lldb/API/SBValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBValue.h?rev=181863&r1=181862&r2=181863&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBValue.h (original)
+++ lldb/trunk/include/lldb/API/SBValue.h Tue May 14 21:16:21 2013
@@ -15,11 +15,14 @@
 #include "lldb/API/SBType.h"
 
 class ValueImpl;
+class ValueLocker;
 
 namespace lldb {
 
 class SBValue
 {
+friend class ValueLocker;
+
 public:
     SBValue ();
 
@@ -414,6 +417,16 @@ public:
     lldb::SBWatchpoint
     WatchPointee (bool resolve_location, bool read, bool write, SBError &error);
 
+    //------------------------------------------------------------------
+    /// Same as the protected version of GetSP that takes a locker, except that we make the
+    /// locker locally in the function.  Since the Target API mutex is recursive, and the
+    /// StopLocker is a read lock, you can call this function even if you are already
+    /// holding the two above-mentioned locks.
+    ///
+    /// @return
+    ///     A ValueObjectSP of the best kind (static, dynamic or synthetic) we
+    ///     can cons up, in accordance with the SBValue's settings.
+    //------------------------------------------------------------------
     lldb::ValueObjectSP
     GetSP () const;
 
@@ -424,6 +437,28 @@ protected:
     friend class SBThread;
     friend class SBValueList;
 
+    //------------------------------------------------------------------
+    /// Get the appropriate ValueObjectSP from this SBValue, consulting the
+    /// use_dynamic and use_synthetic options passed in to SetSP when the
+    /// SBValue's contents were set.  Since this often requires examining memory,
+    /// and maybe even running code, it needs to acquire the Target API and Process StopLock.
+    /// Those are held in an opaque class ValueLocker which is currently local to SBValue.cpp.
+    /// So you don't have to get these yourself just default construct a ValueLocker, and pass it into this.
+    /// If we need to make a ValueLocker and use it in some other .cpp file, we'll have to move it to
+    /// ValueObject.h/cpp or somewhere else convenient.  We haven't needed to so far.
+    ///
+    /// @param[in] value_locker
+    ///     An object that will hold the Target API, and Process RunLocks, and
+    ///     auto-destroy them when it goes out of scope.  Currently this is only useful in
+    ///     SBValue.cpp.
+    ///
+    /// @return
+    ///     A ValueObjectSP of the best kind (static, dynamic or synthetic) we
+    ///     can cons up, in accordance with the SBValue's settings.
+    //------------------------------------------------------------------
+    lldb::ValueObjectSP
+    GetSP (ValueLocker &value_locker) const;
+    
     // these calls do the right thing WRT adjusting their settings according to the target's preferences
     void
     SetSP (const lldb::ValueObjectSP &sp);
@@ -437,6 +472,9 @@ protected:
     void
     SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic);
     
+    void
+    SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name);
+    
 private:
     typedef std::shared_ptr<ValueImpl> ValueImplSP;
     ValueImplSP m_opaque_sp;

Modified: lldb/trunk/source/API/SBValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=181863&r1=181862&r2=181863&view=diff
==============================================================================
--- lldb/trunk/source/API/SBValue.cpp (original)
+++ lldb/trunk/source/API/SBValue.cpp Tue May 14 21:16:21 2013
@@ -59,19 +59,24 @@ public:
     {
     }
     
-    ValueImpl (lldb::ValueObjectSP opaque_sp,
+    ValueImpl (lldb::ValueObjectSP in_valobj_sp,
                lldb::DynamicValueType use_dynamic,
-               bool use_synthetic) :
-        m_opaque_sp(opaque_sp),
+               bool use_synthetic,
+               const char *name = NULL) :
+        m_valobj_sp(in_valobj_sp),
         m_use_dynamic(use_dynamic),
-        m_use_synthetic(use_synthetic)
+        m_use_synthetic(use_synthetic),
+        m_name (name)
     {
+        if (!m_name.IsEmpty() && m_valobj_sp)
+            m_valobj_sp->SetName(m_name);
     }
     
     ValueImpl (const ValueImpl& rhs) :
-        m_opaque_sp(rhs.m_opaque_sp),
+        m_valobj_sp(rhs.m_valobj_sp),
         m_use_dynamic(rhs.m_use_dynamic),
-        m_use_synthetic(rhs.m_use_synthetic)
+        m_use_synthetic(rhs.m_use_synthetic),
+        m_name (rhs.m_name)
     {
     }
     
@@ -80,9 +85,10 @@ public:
     {
         if (this != &rhs)
         {
-            m_opaque_sp = rhs.m_opaque_sp;
+            m_valobj_sp = rhs.m_valobj_sp;
             m_use_dynamic = rhs.m_use_dynamic;
             m_use_synthetic = rhs.m_use_synthetic;
+            m_name = rhs.m_name;
         }
         return *this;
     }
@@ -90,31 +96,51 @@ public:
     bool
     IsValid ()
     {
-        return m_opaque_sp.get() != NULL;
+        return m_valobj_sp.get() != NULL;
     }
     
     lldb::ValueObjectSP
     GetRootSP ()
     {
-        return m_opaque_sp;
+        return m_valobj_sp;
     }
     
     lldb::ValueObjectSP
-    GetSP ()
+    GetSP (Process::StopLocker &stop_locker, Mutex::Locker &api_locker, Error &error)
     {
-        if (!m_opaque_sp)
-            return m_opaque_sp;
-        lldb::ValueObjectSP value_sp = m_opaque_sp;
+        Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+        if (!m_valobj_sp)
+        {
+            error.SetErrorString("invalid value object");
+            return m_valobj_sp;
+        }
+        
+        lldb::ValueObjectSP value_sp = m_valobj_sp;
         
-        Mutex::Locker api_lock;
         Target *target = value_sp->GetTargetSP().get();
         if (target)
-            api_lock.Lock(target->GetAPIMutex());
-        
+            api_locker.Lock(target->GetAPIMutex());
+
+        ProcessSP process_sp(value_sp->GetProcessSP());
+        if (process_sp && !stop_locker.TryLock (&process_sp->GetRunLock()))
+        {
+            // We don't allow people to play around with ValueObject if the process is running.
+            // If you want to look at values, pause the process, then look.
+            if (log)
+                log->Printf ("SBValue(%p)::GetSP() => error: process is running", value_sp.get());
+            error.SetErrorString ("process must be stopped.");
+            return ValueObjectSP();
+        }
+
         if (value_sp->GetDynamicValue(m_use_dynamic))
             value_sp = value_sp->GetDynamicValue(m_use_dynamic);
         if (value_sp->GetSyntheticValue(m_use_synthetic))
             value_sp = value_sp->GetSyntheticValue(m_use_synthetic);
+        if (!value_sp)
+            error.SetErrorString("invalid value object");
+        if (!m_name.IsEmpty())
+            value_sp->SetName(m_name);
+        
         return value_sp;
     }
     
@@ -141,11 +167,78 @@ public:
     {
         return m_use_synthetic;
     }
+
+    // All the derived values that we would make from the m_valobj_sp will share
+    // the ExecutionContext with m_valobj_sp, so we don't need to do the calculations
+    // in GetSP to return the Target, Process, Thread or Frame.  It is convenient to
+    // provide simple accessors for these, which I do here.
+    TargetSP
+    GetTargetSP ()
+    {
+        if (m_valobj_sp)
+            return m_valobj_sp->GetTargetSP();
+        else
+            return TargetSP();
+    }
+    
+    ProcessSP
+    GetProcessSP ()
+    {
+        if (m_valobj_sp)
+            return m_valobj_sp->GetProcessSP();
+        else
+            return ProcessSP();
+    }
+    
+    ThreadSP
+    GetThreadSP ()
+    {
+        if (m_valobj_sp)
+            return m_valobj_sp->GetThreadSP();
+        else
+            return ThreadSP();
+    }
     
+    StackFrameSP
+    GetFrameSP ()
+    {
+        if (m_valobj_sp)
+            return m_valobj_sp->GetFrameSP();
+        else
+            return StackFrameSP();
+    }
+
 private:
-    lldb::ValueObjectSP m_opaque_sp;
+    lldb::ValueObjectSP m_valobj_sp;
     lldb::DynamicValueType m_use_dynamic;
     bool m_use_synthetic;
+    ConstString m_name;
+};
+
+class ValueLocker
+{
+public:
+    ValueLocker ()
+    {
+    }
+    
+    ValueObjectSP
+    GetLockedSP(ValueImpl &in_value)
+    {
+        return in_value.GetSP(m_stop_locker, m_api_locker, m_lock_error);
+    }
+
+    Error &
+    GetError()
+    {
+        return m_lock_error;
+    }
+    
+private:
+    Process::StopLocker m_stop_locker;
+    Mutex::Locker m_api_locker;
+    Error m_lock_error;
+
 };
 
 SBValue::SBValue () :
@@ -197,11 +290,12 @@ SBValue::GetError()
 {
     SBError sb_error;
     
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
         sb_error.SetError(value_sp->GetError());
     else
-        sb_error.SetErrorString("error: invalid value");
+        sb_error.SetErrorStringWithFormat ("error: %s", locker.GetError().AsCString());
     
     return sb_error;
 }
@@ -209,7 +303,8 @@ SBValue::GetError()
 user_id_t
 SBValue::GetID()
 {
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
         return value_sp->GetID();
     return LLDB_INVALID_UID;
@@ -218,9 +313,9 @@ SBValue::GetID()
 const char *
 SBValue::GetName()
 {
-
     const char *name = NULL;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
         name = value_sp->GetName().GetCString();
 
@@ -241,28 +336,11 @@ SBValue::GetTypeName ()
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     const char *name = NULL;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        // For a dynamic type we might have to run code to determine the type we are going to report,
-        // and we might not have updated the type before we get asked this.  So make sure to get the API lock.
-        
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            if (log)
-                log->Printf ("SBValue(%p)::GetTypeName() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                name = value_sp->GetQualifiedTypeName().GetCString();
-            }
-        }
+        name = value_sp->GetQualifiedTypeName().GetCString();
     }
     
     if (log)
@@ -282,28 +360,11 @@ SBValue::GetByteSize ()
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     size_t result = 0;
 
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        // For a dynamic type we might have to run code to determine the type we are going to report,
-        // and we might not have updated the type before we get asked this.  So make sure to get the API lock.
-        
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            if (log)
-                log->Printf ("SBValue(%p)::GetTypeName() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                result = value_sp->GetByteSize();
-            }
-        }
+        result = value_sp->GetByteSize();
     }
 
     if (log)
@@ -317,15 +378,11 @@ SBValue::IsInScope ()
 {
     bool result = false;
 
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        TargetSP target_sp(value_sp->GetTargetSP());
-        if (target_sp)
-        {
-            Mutex::Locker api_locker (target_sp->GetAPIMutex());
-            result = value_sp->IsInScope ();
-        }
+        result = value_sp->IsInScope ();
     }
 
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
@@ -341,25 +398,11 @@ SBValue::GetValue ()
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
     const char *cstr = NULL;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            if (log)
-                log->Printf ("SBValue(%p)::GetValue() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                cstr = value_sp->GetValueAsCString ();
-            }
-        }
+        cstr = value_sp->GetValueAsCString ();
     }
     if (log)
     {
@@ -376,9 +419,11 @@ ValueType
 SBValue::GetValueType ()
 {
     ValueType result = eValueTypeInvalid;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
         result = value_sp->GetValueType();
+    
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
     {
@@ -402,25 +447,11 @@ SBValue::GetObjectDescription ()
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     const char *cstr = NULL;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            if (log)
-                log->Printf ("SBValue(%p)::GetObjectDescription() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                cstr = value_sp->GetObjectDescription ();
-            }
-        }
+        cstr = value_sp->GetObjectDescription ();
     }
     if (log)
     {
@@ -437,27 +468,13 @@ SBValue::GetType()
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     SBType sb_type;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     TypeImplSP type_sp;
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            if (log)
-                log->Printf ("SBValue(%p)::GetType() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType())));
-                sb_type.SetSP(type_sp);
-            }
-        }
+        type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType())));
+        sb_type.SetSP(type_sp);
     }
     if (log)
     {
@@ -474,25 +491,11 @@ SBValue::GetValueDidChange ()
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     bool result = false;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            if (log)
-                log->Printf ("SBValue(%p)::GetValueDidChange() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                result = value_sp->GetValueDidChange ();
-            }
-        }
+        result = value_sp->GetValueDidChange ();
     }
     if (log)
         log->Printf ("SBValue(%p)::GetValueDidChange() => %i", value_sp.get(), result);
@@ -506,25 +509,11 @@ SBValue::GetSummary ()
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     const char *cstr = NULL;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            if (log)
-                log->Printf ("SBValue(%p)::GetSummary() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                cstr = value_sp->GetSummaryAsCString();
-            }
-        }
+        cstr = value_sp->GetSummaryAsCString();
     }
     if (log)
     {
@@ -542,25 +531,11 @@ SBValue::GetLocation ()
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     const char *cstr = NULL;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            if (log)
-                log->Printf ("SBValue(%p)::GetLocation() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                cstr = value_sp->GetLocationAsCString();
-            }
-        }
+        cstr = value_sp->GetLocationAsCString();
     }
     if (log)
     {
@@ -584,27 +559,16 @@ bool
 SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
 {
     bool success = false;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            if (log)
-                log->Printf ("SBValue(%p)::SetValueFromCString() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                success = value_sp->SetValueFromCString (value_str,error.ref());
-            }
-        }
+        success = value_sp->SetValueFromCString (value_str,error.ref());
     }
+    else
+        error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString());
+    
     if (log)
         log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i", value_sp.get(), value_str, success);
 
@@ -615,30 +579,15 @@ lldb::SBTypeFormat
 SBValue::GetTypeFormat ()
 {
     lldb::SBTypeFormat format;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
+        if (value_sp->UpdateValueIfNeeded(true))
         {
-            Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-            if (log)
-                log->Printf ("SBValue(%p)::GetTypeFormat() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                if (value_sp->UpdateValueIfNeeded(true))
-                {
-                    lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
-                    if (format_sp)
-                        format.SetSP(format_sp);
-                }
-            }
+            lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
+            if (format_sp)
+                format.SetSP(format_sp);
         }
     }
     return format;
@@ -649,30 +598,15 @@ lldb::SBTypeSummary
 SBValue::GetTypeSummary ()
 {
     lldb::SBTypeSummary summary;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
+        if (value_sp->UpdateValueIfNeeded(true))
         {
-            Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-            if (log)
-                log->Printf ("SBValue(%p)::GetTypeSummary() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                if (value_sp->UpdateValueIfNeeded(true))
-                {
-                    lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
-                    if (summary_sp)
-                        summary.SetSP(summary_sp);
-                }
-            }
+            lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
+            if (summary_sp)
+                summary.SetSP(summary_sp);
         }
     }
     return summary;
@@ -683,33 +617,18 @@ lldb::SBTypeFilter
 SBValue::GetTypeFilter ()
 {
     lldb::SBTypeFilter filter;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
+        if (value_sp->UpdateValueIfNeeded(true))
         {
-            Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-            if (log)
-                log->Printf ("SBValue(%p)::GetTypeFilter() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
+            lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
+            
+            if (synthetic_sp && !synthetic_sp->IsScripted())
             {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                if (value_sp->UpdateValueIfNeeded(true))
-                {
-                    lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
-                    
-                    if (synthetic_sp && !synthetic_sp->IsScripted())
-                    {
-                        TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
-                        filter.SetSP(filter_sp);
-                    }
-                }
+                TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
+                filter.SetSP(filter_sp);
             }
         }
     }
@@ -721,33 +640,18 @@ lldb::SBTypeSynthetic
 SBValue::GetTypeSynthetic ()
 {
     lldb::SBTypeSynthetic synthetic;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
+        if (value_sp->UpdateValueIfNeeded(true))
         {
-            Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-            if (log)
-                log->Printf ("SBValue(%p)::GetTypeSynthetic() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
+            lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
+            
+            if (children_sp && children_sp->IsScripted())
             {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                if (value_sp->UpdateValueIfNeeded(true))
-                {
-                    lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
-                    
-                    if (children_sp && children_sp->IsScripted())
-                    {
-                        ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
-                        synthetic.SetSP(synth_sp);
-                    }
-                }
+                ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
+                synthetic.SetSP(synth_sp);
             }
         }
     }
@@ -759,33 +663,15 @@ lldb::SBValue
 SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
 {
     lldb::SBValue sb_value;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     lldb::ValueObjectSP new_value_sp;
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-            if (log)
-                log->Printf ("SBValue(%p)::CreateChildAtOffset() => error: process is running", value_sp.get());
-        }
-        else
+        TypeImplSP type_sp (type.GetSP());
+        if (type.IsValid())
         {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                TypeImplSP type_sp (type.GetSP());
-                if (type.IsValid())
-                {
-                    sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true),GetPreferDynamicValue(),GetPreferSyntheticValue());
-                    new_value_sp = sb_value.GetSP();
-                    if (new_value_sp)
-                        new_value_sp->SetName(ConstString(name));
-                }
-            }
+            sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name);
         }
     }
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
@@ -806,7 +692,8 @@ lldb::SBValue
 SBValue::Cast (SBType type)
 {
     lldb::SBValue sb_value;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     TypeImplSP type_sp (type.GetSP());
     if (value_sp && type_sp)
         sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()),GetPreferDynamicValue(),GetPreferSyntheticValue());
@@ -826,33 +713,24 @@ SBValue::CreateValueFromExpression (cons
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     lldb::SBValue sb_value;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     lldb::ValueObjectSP new_value_sp;
     if (value_sp)
     {
         ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
-        ProcessSP process_sp(exe_ctx.GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            if (log)
-                log->Printf ("SBValue(%p)::CreateValueFromExpression() => error: process is running", value_sp.get());
-        }
-        else
+        Target* target = exe_ctx.GetTargetPtr();
+        if (target)
         {
-            Target* target = exe_ctx.GetTargetPtr();
-            if (target)
+            options.ref().SetKeepInMemory(true);
+            target->EvaluateExpression (expression,
+                                        exe_ctx.GetFramePtr(),
+                                        new_value_sp,
+                                        options.ref());
+            if (new_value_sp)
             {
-                options.ref().SetKeepInMemory(true);
-                target->EvaluateExpression (expression,
-                                            exe_ctx.GetFramePtr(),
-                                            new_value_sp,
-                                            options.ref());
-                if (new_value_sp)
-                {
-                    new_value_sp->SetName(ConstString(name));
-                    sb_value.SetSP(new_value_sp);
-                }
+                new_value_sp->SetName(ConstString(name));
+                sb_value.SetSP(new_value_sp);
             }
         }
     }
@@ -877,7 +755,8 @@ lldb::SBValue
 SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
 {
     lldb::SBValue sb_value;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     lldb::ValueObjectSP new_value_sp;
     lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
     if (value_sp && type_impl_sp)
@@ -925,7 +804,8 @@ SBValue::CreateValueFromData (const char
 {
     lldb::SBValue sb_value;
     lldb::ValueObjectSP new_value_sp;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
         ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
@@ -955,13 +835,13 @@ SBValue::GetChildAtIndex (uint32_t idx)
 {
     const bool can_create_synthetic = false;
     lldb::DynamicValueType use_dynamic = eNoDynamicValues;
-    lldb::ValueObjectSP value_sp(GetSP());
-    if (value_sp)
-    {
-        TargetSP target_sp(value_sp->GetTargetSP());
-        if (target_sp)
-            use_dynamic = target_sp->GetPreferDynamicValue();
-    }
+    TargetSP target_sp;
+    if (m_opaque_sp)
+        target_sp = m_opaque_sp->GetTargetSP();
+    
+    if (target_sp)
+        use_dynamic = target_sp->GetPreferDynamicValue();
+
     return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
 }
 
@@ -971,36 +851,21 @@ SBValue::GetChildAtIndex (uint32_t idx,
     lldb::ValueObjectSP child_sp;
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            if (log)
-                log->Printf ("SBValue(%p)::GetChildAtIndex() => error: process is running", value_sp.get());
-        }
-        else
+        const bool can_create = true;
+        child_sp = value_sp->GetChildAtIndex (idx, can_create);
+        if (can_create_synthetic && !child_sp)
         {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
+            if (value_sp->IsPointerType())
             {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                const bool can_create = true;
-                child_sp = value_sp->GetChildAtIndex (idx, can_create);
-                if (can_create_synthetic && !child_sp)
-                {
-                    if (value_sp->IsPointerType())
-                    {
-                        child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
-                    }
-                    else if (value_sp->IsArrayType())
-                    {
-                        child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
-                    }
-                }
-                    
+                child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
+            }
+            else if (value_sp->IsArrayType())
+            {
+                child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
             }
         }
     }
@@ -1017,16 +882,11 @@ uint32_t
 SBValue::GetIndexOfChildWithName (const char *name)
 {
     uint32_t idx = UINT32_MAX;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        TargetSP target_sp(value_sp->GetTargetSP());
-        if (target_sp)
-        {
-            Mutex::Locker api_locker (target_sp->GetAPIMutex());
-        
-            idx = value_sp->GetIndexOfChildWithName (ConstString(name));
-        }
+        idx = value_sp->GetIndexOfChildWithName (ConstString(name));
     }
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
@@ -1042,19 +902,14 @@ SBValue::GetIndexOfChildWithName (const
 SBValue
 SBValue::GetChildMemberWithName (const char *name)
 {
-    lldb::ValueObjectSP value_sp(GetSP());
-    if (value_sp)
-    {
-        lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
-        TargetSP target_sp(value_sp->GetTargetSP());
-        if (target_sp)
-        {
-            Mutex::Locker api_locker (target_sp->GetAPIMutex());
-            use_dynamic_value = target_sp->GetPreferDynamicValue();
-        }
-        return GetChildMemberWithName (name, use_dynamic_value);
-    }
-    return SBValue();
+    lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
+    TargetSP target_sp;
+    if (m_opaque_sp)
+        target_sp = m_opaque_sp->GetTargetSP();
+    
+    if (target_sp)
+        use_dynamic_value = target_sp->GetPreferDynamicValue();
+    return GetChildMemberWithName (name, use_dynamic_value);
 }
 
 SBValue
@@ -1065,25 +920,11 @@ SBValue::GetChildMemberWithName (const c
 
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            if (log)
-                log->Printf ("SBValue(%p)::GetChildMemberWithName() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                child_sp = value_sp->GetChildMemberWithName (str_name, true);
-            }
-        }
+        child_sp = value_sp->GetChildMemberWithName (str_name, true);
     }
     
     SBValue sb_value;
@@ -1164,32 +1005,20 @@ SBValue::SetPreferSyntheticValue (bool u
 bool
 SBValue::IsDynamic()
 {
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
-    {
-        TargetSP target_sp(value_sp->GetTargetSP());
-        if (target_sp)
-        {
-            Mutex::Locker api_locker (target_sp->GetAPIMutex());
-            return value_sp->IsDynamic();
-        }
-    }
+        return value_sp->IsDynamic();
     return false;
 }
 
 bool
 SBValue::IsSynthetic ()
 {
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
-    {
-        TargetSP target_sp(value_sp->GetTargetSP());
-        if (target_sp)
-        {
-            Mutex::Locker api_locker (target_sp->GetAPIMutex());
-            return value_sp->IsSynthetic();
-        }
-    }
+        return value_sp->IsSynthetic();
     return false;
 }
 
@@ -1198,26 +1027,12 @@ SBValue::GetValueForExpressionPath(const
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     lldb::ValueObjectSP child_sp;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            if (log)
-                log->Printf ("SBValue(%p)::GetValueForExpressionPath() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                // using default values for all the fancy options, just do it if you can
-                child_sp = value_sp->GetValueForExpressionPath(expr_path);
-            }
-        }
+        // using default values for all the fancy options, just do it if you can
+        child_sp = value_sp->GetValueForExpressionPath(expr_path);
     }
     
     SBValue sb_value;
@@ -1233,35 +1048,19 @@ int64_t
 SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
 {
     error.Clear();
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-            if (log)
-                log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
-            error.SetErrorString("process is running");
-        }
+        Scalar scalar;
+        if (value_sp->ResolveValue (scalar))
+            return scalar.SLongLong (fail_value);
         else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                Scalar scalar;
-                if (value_sp->ResolveValue (scalar))
-                    return scalar.SLongLong(fail_value);
-                else
-                    error.SetErrorString("could not get value");
-            }
-            else
-                error.SetErrorString("could not get target");
-        }
+            error.SetErrorString ("could not resolve value");
     }
-    error.SetErrorString("invalid SBValue");
+    else
+        error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
+    
     return fail_value;
 }
 
@@ -1269,63 +1068,32 @@ uint64_t
 SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
 {
     error.Clear();
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-            if (log)
-                log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
-            error.SetErrorString("process is running");
-        }
+        Scalar scalar;
+        if (value_sp->ResolveValue (scalar))
+            return scalar.ULongLong(fail_value);
         else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                Scalar scalar;
-                if (value_sp->ResolveValue (scalar))
-                    return scalar.ULongLong(fail_value);
-                else
-                    error.SetErrorString("could not get value");
-            }
-            else
-                error.SetErrorString("could not get target");
-        }
+            error.SetErrorString("could not resolve value");
     }
-    error.SetErrorString("invalid SBValue");
+    else
+        error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
+    
     return fail_value;
 }
 
 int64_t
 SBValue::GetValueAsSigned(int64_t fail_value)
 {
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-            if (log)
-                log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                Scalar scalar;
-                if (value_sp->ResolveValue (scalar))
-                    return scalar.SLongLong(fail_value);
-            }
-        }
+        Scalar scalar;
+        if (value_sp->ResolveValue (scalar))
+            return scalar.SLongLong(fail_value);
     }
     return fail_value;
 }
@@ -1333,28 +1101,13 @@ SBValue::GetValueAsSigned(int64_t fail_v
 uint64_t
 SBValue::GetValueAsUnsigned(uint64_t fail_value)
 {
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-            if (log)
-                log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                Scalar scalar;
-                if (value_sp->ResolveValue (scalar))
-                    return scalar.ULongLong(fail_value);
-            }
-        }
+        Scalar scalar;
+        if (value_sp->ResolveValue (scalar))
+            return scalar.ULongLong(fail_value);
     }
     return fail_value;
 }
@@ -1364,7 +1117,8 @@ SBValue::MightHaveChildren ()
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     bool has_children = false;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
         has_children = value_sp->MightHaveChildren();
 
@@ -1379,27 +1133,10 @@ SBValue::GetNumChildren ()
     uint32_t num_children = 0;
 
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
-    {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            if (log)
-                log->Printf ("SBValue(%p)::GetNumChildren() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp(value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-
-                num_children = value_sp->GetNumChildren();
-            }
-        }
-    }
+        num_children = value_sp->GetNumChildren();
 
     if (log)
         log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
@@ -1412,17 +1149,12 @@ SBValue
 SBValue::Dereference ()
 {
     SBValue sb_value;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        TargetSP target_sp(value_sp->GetTargetSP());
-        if (target_sp)
-        {
-            Mutex::Locker api_locker (target_sp->GetAPIMutex());
-
             Error error;
             sb_value = value_sp->Dereference (error);
-        }
     }
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
@@ -1436,17 +1168,10 @@ SBValue::TypeIsPointerType ()
 {
     bool is_ptr_type = false;
 
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
-    {
-        TargetSP target_sp(value_sp->GetTargetSP());
-        if (target_sp)
-        {
-            Mutex::Locker api_locker (target_sp->GetAPIMutex());
-
-            is_ptr_type = value_sp->IsPointerType();
-        }
-    }
+        is_ptr_type = value_sp->IsPointerType();
 
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
@@ -1459,17 +1184,10 @@ SBValue::TypeIsPointerType ()
 void *
 SBValue::GetOpaqueType()
 {
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
-    {
-        TargetSP target_sp(value_sp->GetTargetSP());
-        if (target_sp)
-        {
-            Mutex::Locker api_locker (target_sp->GetAPIMutex());
-
-            return value_sp->GetClangType();
-        }
-    }
+        return value_sp->GetClangType();
     return NULL;
 }
 
@@ -1478,19 +1196,18 @@ SBValue::GetTarget()
 {
     SBTarget sb_target;
     TargetSP target_sp;
-    lldb::ValueObjectSP value_sp(GetSP());
-    if (value_sp)
+    if (m_opaque_sp)
     {
-        target_sp = value_sp->GetTargetSP();
+        target_sp = m_opaque_sp->GetTargetSP();
         sb_target.SetSP (target_sp);
     }
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
     {
         if (target_sp.get() == NULL)
-            log->Printf ("SBValue(%p)::GetTarget () => NULL", value_sp.get());
+            log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get());
         else
-            log->Printf ("SBValue(%p)::GetTarget () => %p", value_sp.get(), target_sp.get());
+            log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), target_sp.get());
     }
     return sb_target;
 }
@@ -1500,20 +1217,18 @@ SBValue::GetProcess()
 {
     SBProcess sb_process;
     ProcessSP process_sp;
-    lldb::ValueObjectSP value_sp(GetSP());
-    if (value_sp)
+    if (m_opaque_sp)
     {
-        process_sp = value_sp->GetProcessSP();
-        if (process_sp)
-            sb_process.SetSP (process_sp);
+        process_sp = m_opaque_sp->GetProcessSP();
+        sb_process.SetSP (process_sp);
     }
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
     {
         if (process_sp.get() == NULL)
-            log->Printf ("SBValue(%p)::GetProcess () => NULL", value_sp.get());
+            log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get());
         else
-            log->Printf ("SBValue(%p)::GetProcess () => %p", value_sp.get(), process_sp.get());
+            log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), process_sp.get());
     }
     return sb_process;
 }
@@ -1523,19 +1238,18 @@ SBValue::GetThread()
 {
     SBThread sb_thread;
     ThreadSP thread_sp;
-    lldb::ValueObjectSP value_sp(GetSP());
-    if (value_sp)
+    if (m_opaque_sp)
     {
-        thread_sp = value_sp->GetThreadSP();
+        thread_sp = m_opaque_sp->GetThreadSP();
         sb_thread.SetThread(thread_sp);
     }
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
     {
         if (thread_sp.get() == NULL)
-            log->Printf ("SBValue(%p)::GetThread () => NULL", value_sp.get());
+            log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get());
         else
-            log->Printf ("SBValue(%p)::GetThread () => %p", value_sp.get(), thread_sp.get());
+            log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), thread_sp.get());
     }
     return sb_thread;
 }
@@ -1545,30 +1259,36 @@ SBValue::GetFrame()
 {
     SBFrame sb_frame;
     StackFrameSP frame_sp;
-    lldb::ValueObjectSP value_sp(GetSP());
-    if (value_sp)
+    if (m_opaque_sp)
     {
-        frame_sp = value_sp->GetFrameSP();
+        frame_sp = m_opaque_sp->GetFrameSP();
         sb_frame.SetFrameSP (frame_sp);
     }
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
     {
         if (frame_sp.get() == NULL)
-            log->Printf ("SBValue(%p)::GetFrame () => NULL", value_sp.get());
+            log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get());
         else
-            log->Printf ("SBValue(%p)::GetFrame () => %p", value_sp.get(), frame_sp.get());
+            log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), frame_sp.get());
     }
     return sb_frame;
 }
 
 
 lldb::ValueObjectSP
-SBValue::GetSP () const
+SBValue::GetSP (ValueLocker &locker) const
 {
     if (!m_opaque_sp || !m_opaque_sp->IsValid())
         return ValueObjectSP();
-    return m_opaque_sp->GetSP();
+    return locker.GetLockedSP(*m_opaque_sp.get());
+}
+
+lldb::ValueObjectSP
+SBValue::GetSP () const
+{
+    ValueLocker locker;
+    return GetSP(locker);
 }
 
 void
@@ -1638,10 +1358,17 @@ SBValue::SetSP (const lldb::ValueObjectS
     m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
 }
 
+void
+SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
+{
+    m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
+}
+
 bool
 SBValue::GetExpressionPath (SBStream &description)
 {
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
         value_sp->GetExpressionPath (description.ref(), false);
@@ -1653,7 +1380,8 @@ SBValue::GetExpressionPath (SBStream &de
 bool
 SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
 {
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
         value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
@@ -1667,21 +1395,11 @@ SBValue::GetDescription (SBStream &descr
 {
     Stream &strm = description.ref();
 
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-            if (log)
-                log->Printf ("SBValue(%p)::GetDescription() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            ValueObject::DumpValueObject (strm, value_sp.get());
-        }
+        ValueObject::DumpValueObject (strm, value_sp.get());
     }
     else
         strm.PutCString ("No value");
@@ -1692,7 +1410,8 @@ SBValue::GetDescription (SBStream &descr
 lldb::Format
 SBValue::GetFormat ()
 {
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
         return value_sp->GetFormat();
     return eFormatDefault;
@@ -1701,7 +1420,8 @@ SBValue::GetFormat ()
 void
 SBValue::SetFormat (lldb::Format format)
 {
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
         value_sp->SetFormat(format);
 }
@@ -1710,16 +1430,12 @@ lldb::SBValue
 SBValue::AddressOf()
 {
     SBValue sb_value;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        TargetSP target_sp (value_sp->GetTargetSP());
-        if (target_sp)
-        {
-            Mutex::Locker api_locker (target_sp->GetAPIMutex());
-            Error error;
-            sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
-        }
+        Error error;
+        sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
     }
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
@@ -1732,13 +1448,13 @@ lldb::addr_t
 SBValue::GetLoadAddress()
 {
     lldb::addr_t value = LLDB_INVALID_ADDRESS;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
         TargetSP target_sp (value_sp->GetTargetSP());
         if (target_sp)
         {
-            Mutex::Locker api_locker (target_sp->GetAPIMutex());
             const bool scalar_is_load_address = true;
             AddressType addr_type;
             value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
@@ -1769,14 +1485,14 @@ lldb::SBAddress
 SBValue::GetAddress()
 {
     Address addr;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
         TargetSP target_sp (value_sp->GetTargetSP());
         if (target_sp)
         {
             lldb::addr_t value = LLDB_INVALID_ADDRESS;
-            Mutex::Locker api_locker (target_sp->GetAPIMutex());
             const bool scalar_is_load_address = true;
             AddressType addr_type;
             value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
@@ -1809,27 +1525,17 @@ SBValue::GetPointeeData (uint32_t item_i
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     lldb::SBData sb_data;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
+        TargetSP target_sp (value_sp->GetTargetSP());
+        if (target_sp)
         {
-            if (log)
-                log->Printf ("SBValue(%p)::GetPointeeData() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp (value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                DataExtractorSP data_sp(new DataExtractor());
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                value_sp->GetPointeeData(*data_sp, item_idx, item_count);
-                if (data_sp->GetByteSize() > 0)
-                    *sb_data = data_sp;
-            }
+            DataExtractorSP data_sp(new DataExtractor());
+            value_sp->GetPointeeData(*data_sp, item_idx, item_count);
+            if (data_sp->GetByteSize() > 0)
+                *sb_data = data_sp;
         }
     }
     if (log)
@@ -1847,28 +1553,14 @@ SBValue::GetData ()
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     lldb::SBData sb_data;
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            if (log)
-                log->Printf ("SBValue(%p)::GetData() => error: process is running", value_sp.get());
-        }
-        else
-        {
-            TargetSP target_sp (value_sp->GetTargetSP());
-            if (target_sp)
-            {
-                Mutex::Locker api_locker (target_sp->GetAPIMutex());
-                DataExtractorSP data_sp(new DataExtractor());
-                value_sp->GetData(*data_sp);
-                if (data_sp->GetByteSize() > 0)
-                    *sb_data = data_sp;
-            }
-        }
+        DataExtractorSP data_sp(new DataExtractor());
+        value_sp->GetData(*data_sp);
+        if (data_sp->GetByteSize() > 0)
+            *sb_data = data_sp;
     }
     if (log)
         log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
@@ -1882,50 +1574,38 @@ bool
 SBValue::SetData (lldb::SBData &data, SBError &error)
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     bool ret = true;
     
     if (value_sp)
     {
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
+        DataExtractor *data_extractor = data.get();
+        
+        if (!data_extractor)
         {
             if (log)
-                log->Printf ("SBValue(%p)::SetData() => error: process is running", value_sp.get());
+                log->Printf ("SBValue(%p)::SetData() => error: no data to set", value_sp.get());
             
-            error.SetErrorString("Process is running");
+            error.SetErrorString("No data to set");
             ret = false;
         }
         else
         {
-            DataExtractor *data_extractor = data.get();
+            Error set_error;
+            
+            value_sp->SetData(*data_extractor, set_error);
             
-            if (!data_extractor)
+            if (!set_error.Success())
             {
-                if (log)
-                    log->Printf ("SBValue(%p)::SetData() => error: no data to set", value_sp.get());
-                
-                error.SetErrorString("No data to set");
+                error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
                 ret = false;
             }
-            else
-            {
-                Error set_error;
-                
-                value_sp->SetData(*data_extractor, set_error);
-                
-                if (!set_error.Success())
-                {
-                    error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
-                    ret = false;
-                }
-            }
         }
     }
     else
     {
-        error.SetErrorString("Couldn't set data: invalid SBValue");
+        error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
         ret = false;
     }
     
@@ -1940,7 +1620,8 @@ SBValue::SetData (lldb::SBData &data, SB
 lldb::SBDeclaration
 SBValue::GetDeclaration ()
 {
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     SBDeclaration decl_sb;
     if (value_sp)
     {
@@ -1957,21 +1638,11 @@ SBValue::Watch (bool resolve_location, b
     SBWatchpoint sb_watchpoint;
     
     // If the SBValue is not valid, there's no point in even trying to watch it.
-    lldb::ValueObjectSP value_sp(GetSP());
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
     TargetSP target_sp (GetTarget().GetSP());
     if (value_sp && target_sp)
     {
-        // Can't watch this if the process is running
-        ProcessSP process_sp(value_sp->GetProcessSP());
-        Process::StopLocker stop_locker;
-        if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
-        {
-            Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-            if (log)
-                log->Printf ("SBValue(%p)::Watch() => error: process is running", value_sp.get());
-            return sb_watchpoint;
-        }
-
         // Read and Write cannot both be false.
         if (!read && !write)
             return sb_watchpoint;
@@ -2014,6 +1685,22 @@ SBValue::Watch (bool resolve_location, b
             }
         }
     }
+    else if (target_sp)
+    {
+        Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+        if (log)
+            log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s", value_sp.get(), locker.GetError().AsCString());
+        
+        error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
+    }
+    else
+    {
+        Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+        if (log)
+            log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target", value_sp.get());
+        error.SetErrorString("could not set watchpoint, a target is required");
+    }
+    
     return sb_watchpoint;
 }
 





More information about the lldb-commits mailing list