Converted the lldb_private::Process over to use the intrusive
shared pointers.

Changed the ExecutionContext over to use shared pointers for
the target, process, thread and frame since these objects can
easily go away at any time and any object that was holding onto
an ExecutionContext was running the risk of using a bad object.

Now that the shared pointers for target, process, thread and
frame are just a single pointer (they all use the instrusive
shared pointers) the execution context is much safer and still
the same size. 

Made the shared pointers in the the ExecutionContext class protected
and made accessors for all of the various ways to get at the pointers,
references, and shared pointers.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@140298 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/ClangExpressionDeclMap.cpp b/source/Expression/ClangExpressionDeclMap.cpp
index 763546b..42c6f7a 100644
--- a/source/Expression/ClangExpressionDeclMap.cpp
+++ b/source/Expression/ClangExpressionDeclMap.cpp
@@ -69,27 +69,30 @@
 {    
     EnableParserVars();
     m_parser_vars->m_exe_ctx = &exe_ctx;
-        
-    if (exe_ctx.frame)
-        m_parser_vars->m_sym_ctx = exe_ctx.frame->GetSymbolContext(lldb::eSymbolContextEverything);
-    else if (exe_ctx.thread)
-        m_parser_vars->m_sym_ctx = exe_ctx.thread->GetStackFrameAtIndex(0)->GetSymbolContext(lldb::eSymbolContextEverything);
-    else if (exe_ctx.process)
+    
+    Target *target = exe_ctx.GetTargetPtr();
+    if (exe_ctx.GetFramePtr())
+        m_parser_vars->m_sym_ctx = exe_ctx.GetFramePtr()->GetSymbolContext(lldb::eSymbolContextEverything);
+    else if (exe_ctx.GetThreadPtr())
+        m_parser_vars->m_sym_ctx = exe_ctx.GetThreadPtr()->GetStackFrameAtIndex(0)->GetSymbolContext(lldb::eSymbolContextEverything);
+    else if (exe_ctx.GetProcessPtr())
     {
         m_parser_vars->m_sym_ctx.Clear();
-        m_parser_vars->m_sym_ctx.target_sp = exe_ctx.target;
+        m_parser_vars->m_sym_ctx.target_sp = exe_ctx.GetTargetSP();
     }
-    else if (exe_ctx.target)
+    else if (target)
     {
         m_parser_vars->m_sym_ctx.Clear();
-        m_parser_vars->m_sym_ctx.target_sp = exe_ctx.target;
+        m_parser_vars->m_sym_ctx.target_sp = exe_ctx.GetTargetSP();
     }
     
-    if (exe_ctx.target)
-        m_parser_vars->m_persistent_vars = &exe_ctx.target->GetPersistentVariables();
+    if (target)
+    {
+        m_parser_vars->m_persistent_vars = &target->GetPersistentVariables();
     
-    if (exe_ctx.target && !exe_ctx.target->GetScratchClangASTContext())
-        return false;
+        if (!target->GetScratchClangASTContext())
+            return false;
+    }
     
     m_parser_vars->m_target_info = GetTargetInfo();
     
@@ -137,16 +140,23 @@
     TargetInfo ret;
     
     ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
-    
-    if (exe_ctx->process)
+    if (exe_ctx)
     {
-        ret.byte_order = exe_ctx->process->GetByteOrder();
-        ret.address_byte_size = exe_ctx->process->GetAddressByteSize();
-    }
-    else if (exe_ctx->target)
-    {
-        ret.byte_order = exe_ctx->target->GetArchitecture().GetByteOrder();
-        ret.address_byte_size = exe_ctx->target->GetArchitecture().GetAddressByteSize();
+        Process *process = exe_ctx->GetProcessPtr();
+        if (process)
+        {
+            ret.byte_order = process->GetByteOrder();
+            ret.address_byte_size = process->GetAddressByteSize();
+        }
+        else 
+        {
+            Target *target = exe_ctx->GetTargetPtr();
+            if (target)
+            {
+                ret.byte_order = target->GetArchitecture().GetByteOrder();
+                ret.address_byte_size = target->GetArchitecture().GetAddressByteSize();
+            }
+        }
     }
     
     return ret;
@@ -174,7 +184,11 @@
     assert (m_parser_vars.get());
     
     ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
-    ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
+    if (exe_ctx == NULL)
+        return lldb::ClangExpressionVariableSP();
+    Target *target = exe_ctx->GetTargetPtr();
+
+    ASTContext *context(target->GetScratchClangASTContext()->getASTContext());
     
     TypeFromUser user_type(ClangASTContext::CopyType(context, 
                                                      type.GetASTContext(),
@@ -249,7 +263,13 @@
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
     
     ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
-    ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
+    if (exe_ctx == NULL)
+        return lldb::ClangExpressionVariableSP();
+    Target *target = exe_ctx->GetTargetPtr();
+    if (target == NULL)
+        return lldb::ClangExpressionVariableSP();
+
+    ASTContext *context(target->GetScratchClangASTContext()->getASTContext());
     
     ClangExpressionVariableSP var_sp (m_found_entities.GetVariable(decl));
     
@@ -266,12 +286,16 @@
     
     TypeFromUser var_type = var_sp->GetTypeFromUser();
     
-    VariableSP var = FindVariableInScope (*exe_ctx->frame, var_sp->GetName(), &var_type);
+    StackFrame *frame = exe_ctx->GetFramePtr();
+    if (frame == NULL)
+        return lldb::ClangExpressionVariableSP();
+    
+    VariableSP var = FindVariableInScope (*frame, var_sp->GetName(), &var_type);
     
     if (!var)
         return lldb::ClangExpressionVariableSP(); // but we should handle this; it may be a persistent variable
     
-    ValueObjectSP var_valobj = exe_ctx->frame->GetValueObjectForFrameVariable(var, lldb::eNoDynamicValues);
+    ValueObjectSP var_valobj = frame->GetValueObjectForFrameVariable(var, lldb::eNoDynamicValues);
 
     if (!var_valobj)
         return lldb::ClangExpressionVariableSP();
@@ -377,8 +401,13 @@
     
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
     ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
-    
-    ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
+    if (exe_ctx == NULL)
+        return false;
+    Target *target = exe_ctx->GetTargetPtr();
+    if (target == NULL)
+        return false;
+
+    ASTContext *context(target->GetScratchClangASTContext()->getASTContext());
     
     TypeFromUser user_type(ClangASTContext::CopyType(context, 
                                                      parser_type.GetASTContext(),
@@ -612,9 +641,12 @@
     assert (m_parser_vars.get());
     
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-    
+    ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
+    if (exe_ctx == NULL)
+        return false;
+    Target *target = exe_ctx->GetTargetPtr();
     // Back out in all cases where we're not fully initialized
-    if (m_parser_vars->m_exe_ctx->target == NULL)
+    if (target == NULL)
         return false;
     if (!m_parser_vars->m_sym_ctx.target_sp)
         return false;
@@ -665,7 +697,7 @@
     if (!func_so_addr || !func_so_addr->IsValid())
         return false;
     
-    func_addr = func_so_addr->GetCallableLoadAddress (m_parser_vars->m_exe_ctx->target);
+    func_addr = func_so_addr->GetCallableLoadAddress (target);
 
     return true;
 }
@@ -737,10 +769,10 @@
     assert (m_parser_vars.get());
     
     if (!m_parser_vars->m_exe_ctx ||
-        !m_parser_vars->m_exe_ctx->target)
+        !m_parser_vars->m_exe_ctx->GetTargetPtr())
         return false;
     
-    return GetSymbolAddress(*m_parser_vars->m_exe_ctx->target, name);
+    return GetSymbolAddress(m_parser_vars->m_exe_ctx->GetTargetRef(), name);
 }
 
 // Interface for IRInterpreter
@@ -754,9 +786,10 @@
     
     ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
     
+    Process *process = exe_ctx->GetProcessPtr();
     if (value.GetContextType() == Value::eContextTypeRegisterInfo)
     {
-        if (!exe_ctx->process)
+        if (!process)
             return false;
         
         RegisterContext *reg_ctx = exe_ctx->GetRegisterContext();
@@ -768,7 +801,7 @@
         lldb_private::RegisterValue reg_value;
         Error err;
         
-        if (!reg_value.SetFromMemoryData (reg_info, data, length, exe_ctx->process->GetByteOrder(), err))
+        if (!reg_value.SetFromMemoryData (reg_info, data, length, process->GetByteOrder(), err))
             return false;
         
         return reg_ctx->WriteRegister(reg_info, reg_value);
@@ -781,28 +814,29 @@
             return false;
         case Value::eValueTypeFileAddress:
             {
-                if (!exe_ctx->process)
+                if (!process)
                     return false;
                 
+                Target *target = exe_ctx->GetTargetPtr();
                 Address file_addr;
                 
-                if (!exe_ctx->target->GetImages().ResolveFileAddress((lldb::addr_t)value.GetScalar().ULongLong(), file_addr))
+                if (!target->GetImages().ResolveFileAddress((lldb::addr_t)value.GetScalar().ULongLong(), file_addr))
                     return false;
                 
-                lldb::addr_t load_addr = file_addr.GetLoadAddress(exe_ctx->target);
+                lldb::addr_t load_addr = file_addr.GetLoadAddress(target);
                 
                 Error err;
-                exe_ctx->process->WriteMemory(load_addr, data, length, err);
+                process->WriteMemory(load_addr, data, length, err);
                 
                 return err.Success();
             }
         case Value::eValueTypeLoadAddress:
             {
-                if (!exe_ctx->process)
+                if (!process)
                     return false;
                 
                 Error err;
-                exe_ctx->process->WriteMemory((lldb::addr_t)value.GetScalar().ULongLong(), data, length, err);
+                process->WriteMemory((lldb::addr_t)value.GetScalar().ULongLong(), data, length, err);
     
                 return err.Success();
             }
@@ -823,10 +857,12 @@
     assert (m_parser_vars.get());
     
     ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
-    
+
+    Process *process = exe_ctx->GetProcessPtr();
+
     if (value.GetContextType() == Value::eContextTypeRegisterInfo)
     {
-        if (!exe_ctx->process)
+        if (!process)
             return false;
         
         RegisterContext *reg_ctx = exe_ctx->GetRegisterContext();
@@ -841,7 +877,7 @@
         if (!reg_ctx->ReadRegister(reg_info, reg_value))
             return false;
         
-        return reg_value.GetAsMemoryData(reg_info, data, length, exe_ctx->process->GetByteOrder(), err);        
+        return reg_value.GetAsMemoryData(reg_info, data, length, process->GetByteOrder(), err);        
     }
     else
     {
@@ -851,26 +887,27 @@
                 return false;
             case Value::eValueTypeFileAddress:
             {
-                if (!exe_ctx->target)
+                Target *target = exe_ctx->GetTargetPtr();
+                if (target == NULL)
                     return false;
                 
                 Address file_addr;
                 
-                if (!exe_ctx->target->GetImages().ResolveFileAddress((lldb::addr_t)value.GetScalar().ULongLong(), file_addr))
+                if (!target->GetImages().ResolveFileAddress((lldb::addr_t)value.GetScalar().ULongLong(), file_addr))
                     return false;
                 
                 Error err;
-                exe_ctx->target->ReadMemory(file_addr, true, data, length, err);
+                target->ReadMemory(file_addr, true, data, length, err);
                 
                 return err.Success();
             }
             case Value::eValueTypeLoadAddress:
             {
-                if (!exe_ctx->process)
+                if (!process)
                     return false;
                 
                 Error err;
-                exe_ctx->process->ReadMemory((lldb::addr_t)value.GetScalar().ULongLong(), data, length, err);
+                process->ReadMemory((lldb::addr_t)value.GetScalar().ULongLong(), data, length, err);
                 
                 return err.Success();
             }
@@ -898,22 +935,25 @@
         const ConstString &name(expr_var_sp->GetName());
         TypeFromUser type(expr_var_sp->GetTypeFromUser());
         
-        if (m_parser_vars->m_exe_ctx->frame)
+        StackFrame *frame = m_parser_vars->m_exe_ctx->GetFramePtr();
+        if (frame)
         {
-            VariableSP var(FindVariableInScope (*exe_ctx.frame, name, &type));
+            VariableSP var(FindVariableInScope (*frame, name, &type));
             
             if (var)
                 return *GetVariableValue(exe_ctx, var, NULL);
         }
 
-        if (m_parser_vars->m_exe_ctx->target)
+        Target *target = m_parser_vars->m_exe_ctx->GetTargetPtr();
+
+        if (target)
         {
-            VariableSP global(FindGlobalVariable (*exe_ctx.target, name.GetCString(), &type));
+            VariableSP global(FindGlobalVariable (*target, name.GetCString(), &type));
             
             if (global)
                 return *GetVariableValue(exe_ctx, global, NULL);
             
-            lldb::addr_t location_load_addr = GetSymbolAddress(*exe_ctx.target, name);
+            lldb::addr_t location_load_addr = GetSymbolAddress(*target, name);
             
             if (location_load_addr != LLDB_INVALID_ADDRESS)
             {
@@ -962,7 +1002,7 @@
 {
     EnableMaterialVars();
     
-    m_material_vars->m_process = exe_ctx.process;
+    m_material_vars->m_process = exe_ctx.GetProcessPtr();
     
     bool result = DoMaterialize(false /* dematerialize */, 
                                 exe_ctx, 
@@ -989,7 +1029,11 @@
 {
     assert (m_struct_vars.get());
     
-    if (!exe_ctx.frame || !exe_ctx.target || !exe_ctx.process)
+    Target *target = exe_ctx.GetTargetPtr();
+    Process *process = exe_ctx.GetProcessPtr();
+    StackFrame *frame = exe_ctx.GetFramePtr();
+
+    if (frame == NULL || process == NULL || target == NULL)
     {
         err.SetErrorString("Couldn't load 'this' because the context is incomplete");
         return false;
@@ -1001,7 +1045,7 @@
         return false;
     }
     
-    VariableSP object_ptr_var = FindVariableInScope (*exe_ctx.frame,
+    VariableSP object_ptr_var = FindVariableInScope (*frame,
                                                      object_name, 
                                                      (suppress_type_check ? NULL : &m_struct_vars->m_object_pointer_type));
     
@@ -1029,7 +1073,7 @@
     case Value::eValueTypeLoadAddress:
         {
             lldb::addr_t value_addr = location_value->GetScalar().ULongLong();
-            uint32_t address_byte_size = exe_ctx.target->GetArchitecture().GetAddressByteSize();
+            uint32_t address_byte_size = target->GetArchitecture().GetAddressByteSize();
             
             if (ClangASTType::GetClangTypeBitWidth(m_struct_vars->m_object_pointer_type.GetASTContext(), 
                                                    m_struct_vars->m_object_pointer_type.GetOpaqueQualType()) != address_byte_size * 8)
@@ -1039,7 +1083,7 @@
             }
             
             Error read_error;
-            object_ptr = exe_ctx.process->ReadPointerFromMemory (value_addr, read_error);
+            object_ptr = process->ReadPointerFromMemory (value_addr, read_error);
             if (read_error.Fail() || object_ptr == LLDB_INVALID_ADDRESS)
             {
                 err.SetErrorStringWithFormat("Coldn't read '%s' from the target: %s", object_name.GetCString(), read_error.AsCString());
@@ -1133,14 +1177,16 @@
         err.SetErrorString("Structure hasn't been laid out yet");
         return false;
     }
-    
-    if (!exe_ctx.process)
+    Process *process = exe_ctx.GetProcessPtr();
+
+    if (!process)
     {
         err.SetErrorString("Couldn't find the process");
         return false;
     }
     
-    if (!exe_ctx.target)
+    Target *target = exe_ctx.GetTargetPtr();
+    if (!target)
     {
         err.SetErrorString("Couldn't find the target");
         return false;
@@ -1155,7 +1201,7 @@
     lldb::DataBufferSP data_sp(new DataBufferHeap(m_struct_vars->m_struct_size, 0));    
     
     Error error;
-    if (exe_ctx.process->ReadMemory (m_material_vars->m_materialized_location, 
+    if (process->ReadMemory (m_material_vars->m_materialized_location, 
                                      data_sp->GetBytes(), 
                                      data_sp->GetByteSize(), error) != data_sp->GetByteSize())
     {
@@ -1163,7 +1209,7 @@
         return false;
     }
     
-    DataExtractor extractor(data_sp, exe_ctx.process->GetByteOrder(), exe_ctx.target->GetArchitecture().GetAddressByteSize());
+    DataExtractor extractor(data_sp, process->GetByteOrder(), target->GetArchitecture().GetAddressByteSize());
     
     for (size_t member_idx = 0, num_members = m_struct_members.GetSize();
          member_idx < num_members;
@@ -1219,13 +1265,15 @@
         return false;
     }
     
-    if (!exe_ctx.frame)
+    StackFrame *frame = exe_ctx.GetFramePtr();
+    if (!frame)
     {
         err.SetErrorString("Received null execution frame");
         return false;
     }
+    Target *target = exe_ctx.GetTargetPtr();
     
-    ClangPersistentVariables &persistent_vars = exe_ctx.target->GetPersistentVariables();
+    ClangPersistentVariables &persistent_vars = target->GetPersistentVariables();
         
     if (!m_struct_vars->m_struct_size)
     {
@@ -1237,20 +1285,21 @@
         return true;
     }
     
-    const SymbolContext &sym_ctx(exe_ctx.frame->GetSymbolContext(lldb::eSymbolContextEverything));
+    const SymbolContext &sym_ctx(frame->GetSymbolContext(lldb::eSymbolContextEverything));
     
     if (!dematerialize)
     {
+        Process *process = exe_ctx.GetProcessPtr();
         if (m_material_vars->m_materialized_location)
         {
-            exe_ctx.process->DeallocateMemory(m_material_vars->m_materialized_location);
+            process->DeallocateMemory(m_material_vars->m_materialized_location);
             m_material_vars->m_materialized_location = 0;
         }
         
         if (log)
             log->PutCString("Allocating memory for materialized argument struct");
         
-        lldb::addr_t mem = exe_ctx.process->AllocateMemory(m_struct_vars->m_struct_alignment + m_struct_vars->m_struct_size, 
+        lldb::addr_t mem = process->AllocateMemory(m_struct_vars->m_struct_alignment + m_struct_vars->m_struct_size, 
                                                            lldb::ePermissionsReadable | lldb::ePermissionsWritable,
                                                            err);
         
@@ -1369,7 +1418,8 @@
         return false;
     
     Error error;
-    
+    Process *process = exe_ctx.GetProcessPtr();
+
     lldb::addr_t mem; // The address of a spare memory area used to hold the persistent variable.
     
     if (dematerialize)
@@ -1383,7 +1433,7 @@
             // Get the location of the target out of the struct.
             
             Error read_error;
-            mem = exe_ctx.process->ReadPointerFromMemory (addr, read_error);
+            mem = process->ReadPointerFromMemory (addr, read_error);
             
             if (mem == LLDB_INVALID_ADDRESS)
             {
@@ -1429,7 +1479,7 @@
                 // Read the contents of the spare memory area
                                 
                 var_sp->ValueUpdated ();
-                if (exe_ctx.process->ReadMemory (mem, pvar_data, pvar_byte_size, error) != pvar_byte_size)
+                if (process->ReadMemory (mem, pvar_data, pvar_byte_size, error) != pvar_byte_size)
                 {
                     err.SetErrorStringWithFormat ("Couldn't read a composite type from the target: %s", error.AsCString());
                     return false;
@@ -1461,7 +1511,7 @@
                 }
                 else
                 {
-                    Error deallocate_error = exe_ctx.process->DeallocateMemory(mem);
+                    Error deallocate_error = process->DeallocateMemory(mem);
                     
                     if (!err.Success())
                     {
@@ -1488,7 +1538,7 @@
             
             Error allocate_error;
             
-            mem = exe_ctx.process->AllocateMemory(pvar_byte_size, 
+            mem = process->AllocateMemory(pvar_byte_size, 
                                                   lldb::ePermissionsReadable | lldb::ePermissionsWritable, 
                                                   allocate_error);
             
@@ -1518,7 +1568,7 @@
             
             // Write the contents of the variable to the area.
             
-            if (exe_ctx.process->WriteMemory (mem, pvar_data, pvar_byte_size, error) != pvar_byte_size)
+            if (process->WriteMemory (mem, pvar_data, pvar_byte_size, error) != pvar_byte_size)
             {
                 err.SetErrorStringWithFormat ("Couldn't write a composite type to the target: %s", error.AsCString());
                 return false;
@@ -1530,9 +1580,9 @@
         {
             // Now write the location of the area into the struct.
             Error write_error;
-            if (!exe_ctx.process->WriteScalarToMemory (addr, 
+            if (!process->WriteScalarToMemory (addr, 
                                                        var_sp->m_live_sp->GetValue().GetScalar(), 
-                                                       exe_ctx.process->GetAddressByteSize(), 
+                                                       process->GetAddressByteSize(), 
                                                        write_error))
             {
                 err.SetErrorStringWithFormat ("Couldn't write %s to the target: %s", var_sp->GetName().GetCString(), write_error.AsCString());
@@ -1564,8 +1614,11 @@
 )
 {
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-    
-    if (!exe_ctx.frame || !exe_ctx.process)
+    Target *target = exe_ctx.GetTargetPtr();
+    Process *process = exe_ctx.GetProcessPtr();
+    StackFrame *frame = exe_ctx.GetFramePtr();
+
+    if (!frame || !process || !target)
         return false;
     
     // Vital information about the value
@@ -1573,8 +1626,8 @@
     const ConstString &name(expr_var->GetName());
     TypeFromUser type(expr_var->GetTypeFromUser());
     
-    VariableSP var = FindVariableInScope (*exe_ctx.frame, name, &type);
-    Symbol *sym = FindGlobalDataSymbol(*exe_ctx.target, name);
+    VariableSP var = FindVariableInScope (*frame, name, &type);
+    Symbol *sym = FindGlobalDataSymbol(*target, name);
     
     std::auto_ptr<lldb_private::Value> location_value;
     
@@ -1588,7 +1641,7 @@
     {        
         location_value.reset(new Value);
         
-        addr_t location_load_addr = GetSymbolAddress(*exe_ctx.target, name);
+        addr_t location_load_addr = GetSymbolAddress(*target, name);
         
         if (location_load_addr == LLDB_INVALID_ADDRESS)
         {
@@ -1654,9 +1707,9 @@
             {
                 Error write_error;
 
-                if (!exe_ctx.process->WriteScalarToMemory (addr, 
+                if (!process->WriteScalarToMemory (addr, 
                                                            location_value->GetScalar(), 
-                                                           exe_ctx.process->GetAddressByteSize(), 
+                                                           process->GetAddressByteSize(), 
                                                            write_error))
                 {
                     err.SetErrorStringWithFormat ("Couldn't write %s to the target: %s", 
@@ -1738,7 +1791,7 @@
                 
                 // Deallocate the spare area and clear the variable's live data.
                 
-                Error deallocate_error = exe_ctx.process->DeallocateMemory(reg_addr.ULongLong());
+                Error deallocate_error = process->DeallocateMemory(reg_addr.ULongLong());
                 
                 if (!deallocate_error.Success())
                 {
@@ -1757,7 +1810,7 @@
                 
                 Error allocate_error;
                 
-                Scalar reg_addr (exe_ctx.process->AllocateMemory (value_byte_size, 
+                Scalar reg_addr (process->AllocateMemory (value_byte_size, 
                                                                   lldb::ePermissionsReadable | lldb::ePermissionsWritable, 
                                                                   allocate_error));
                 
@@ -1783,9 +1836,9 @@
                 
                 Error write_error;
                 
-                if (!exe_ctx.process->WriteScalarToMemory (addr, 
+                if (!process->WriteScalarToMemory (addr, 
                                                            reg_addr, 
-                                                           exe_ctx.process->GetAddressByteSize(), 
+                                                           process->GetAddressByteSize(), 
                                                            write_error))
                 {
                     err.SetErrorStringWithFormat ("Couldn't write %s to the target: %s", 
@@ -2088,6 +2141,8 @@
 
     // Only look for functions by name out in our symbols if the function 
     // doesn't start with our phony prefix of '$'
+    Target *target = m_parser_vars->m_exe_ctx->GetTargetPtr();
+    StackFrame *frame = m_parser_vars->m_exe_ctx->GetFramePtr();
     if (name_unique_cstr[0] != '$')
     {
         ValueObjectSP valobj;
@@ -2095,9 +2150,9 @@
         Error err;
         bool found = false;
         
-        if (m_parser_vars->m_exe_ctx->frame)
+        if (frame)
         {
-            valobj = m_parser_vars->m_exe_ctx->frame->GetValueForVariableExpressionPath(name_unique_cstr, 
+            valobj = frame->GetValueForVariableExpressionPath(name_unique_cstr, 
                                                                                         eNoDynamicValues, 
                                                                                         StackFrame::eExpressionPathOptionCheckPtrVsMember,
                                                                                         var,
@@ -2110,11 +2165,11 @@
                 found = true;
             }
         }
-        else if (m_parser_vars->m_exe_ctx->target)
+        else if (target)
         {
-            var = FindGlobalVariable(*m_parser_vars->m_exe_ctx->target, 
-                                     name_unique_cstr,
-                                     NULL);
+            var = FindGlobalVariable (*target, 
+                                      name_unique_cstr,
+                                      NULL);
             
             if (var)
             {
@@ -2183,7 +2238,7 @@
                 // We couldn't find a variable or function for this.  Now we'll hunt for a generic 
                 // data symbol, and -- if it is found -- treat it as a variable.
                 
-                Symbol *data_symbol = FindGlobalDataSymbol(*m_parser_vars->m_exe_ctx->target, name);
+                Symbol *data_symbol = FindGlobalDataSymbol(*target, name);
                 
                 if (data_symbol)
                 {
@@ -2221,10 +2276,10 @@
         {
             // Clang is looking for the type of "this"
             
-            if (!m_parser_vars->m_exe_ctx->frame)
+            if (!frame)
                 return;
             
-            VariableList *vars = m_parser_vars->m_exe_ctx->frame->GetVariableList(false);
+            VariableList *vars = frame->GetVariableList(false);
             
             if (!vars)
                 return;
@@ -2232,8 +2287,8 @@
             lldb::VariableSP this_var = vars->FindVariable(ConstString("this"));
             
             if (!this_var ||
-                !this_var->IsInScope(m_parser_vars->m_exe_ctx->frame) || 
-                !this_var->LocationIsValidForFrame (m_parser_vars->m_exe_ctx->frame))
+                !this_var->IsInScope(frame) || 
+                !this_var->LocationIsValidForFrame (frame))
                 return;
             
             Type *this_type = this_var->GetType();
@@ -2286,10 +2341,10 @@
         {
             // Clang is looking for the type of "*self"
             
-            if (!m_parser_vars->m_exe_ctx->frame)
+            if (!frame)
                 return;
             
-            VariableList *vars = m_parser_vars->m_exe_ctx->frame->GetVariableList(false);
+            VariableList *vars = frame->GetVariableList(false);
 
             if (!vars)
                 return;
@@ -2297,8 +2352,8 @@
             lldb::VariableSP self_var = vars->FindVariable(ConstString("self"));
         
             if (!self_var || 
-                !self_var->IsInScope(m_parser_vars->m_exe_ctx->frame) || 
-                !self_var->LocationIsValidForFrame (m_parser_vars->m_exe_ctx->frame))
+                !self_var->IsInScope(frame) || 
+                !self_var->LocationIsValidForFrame (frame))
                 return;
         
             Type *self_type = self_var->GetType();
@@ -2336,10 +2391,10 @@
 
         do
         {
-            if (!m_parser_vars->m_exe_ctx->target)
+            if (!target)
                 break;
             
-            ClangASTContext *scratch_clang_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext();
+            ClangASTContext *scratch_clang_ast_context = target->GetScratchClangASTContext();
             
             if (!scratch_clang_ast_context)
                 break;
@@ -2547,11 +2602,13 @@
     
     lldb::addr_t loclist_base_load_addr = LLDB_INVALID_ADDRESS;
     
+    Target *target = exe_ctx.GetTargetPtr();
+
     if (var_location_expr.IsLocationList())
     {
         SymbolContext var_sc;
         var->CalculateSymbolContext (&var_sc);
-        loclist_base_load_addr = var_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.target);
+        loclist_base_load_addr = var_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (target);
     }
     Error err;
     
@@ -2600,7 +2657,7 @@
         
         Address so_addr(var_location->GetScalar().ULongLong(), object_file->GetSectionList());
         
-        lldb::addr_t load_addr = so_addr.GetLoadAddress(exe_ctx.target);
+        lldb::addr_t load_addr = so_addr.GetLoadAddress(target);
         
         if (load_addr != LLDB_INVALID_ADDRESS)
         {
@@ -2708,7 +2765,12 @@
     
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
     
-    ASTContext *scratch_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext()->getASTContext();
+    Target *target = m_parser_vars->m_exe_ctx->GetTargetPtr();
+
+    if (target == NULL)
+        return;
+
+    ASTContext *scratch_ast_context = target->GetScratchClangASTContext()->getASTContext();
     
     TypeFromUser user_type (ClangASTContext::CreateLValueReferenceType(scratch_ast_context, ClangASTContext::GetVoidPtrType(scratch_ast_context, true)),
                             scratch_ast_context);
@@ -2731,7 +2793,7 @@
     
     AddressRange &symbol_range = symbol.GetAddressRangeRef();
     Address &symbol_address = symbol_range.GetBaseAddress();
-    lldb::addr_t symbol_load_addr = symbol_address.GetLoadAddress(m_parser_vars->m_exe_ctx->target);
+    lldb::addr_t symbol_load_addr = symbol_address.GetLoadAddress(target);
     
     symbol_location->SetContext(Value::eContextTypeClangType, user_type.GetOpaqueQualType());
     symbol_location->GetScalar() = symbol_load_addr;
@@ -2767,8 +2829,9 @@
 ClangExpressionDeclMap::ResolveUnknownTypes()
 {
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-    
-    ASTContext *scratch_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext()->getASTContext();
+    Target *target = m_parser_vars->m_exe_ctx->GetTargetPtr();
+
+    ASTContext *scratch_ast_context = target->GetScratchClangASTContext()->getASTContext();
 
     for (size_t index = 0, num_entities = m_found_entities.GetSize();
          index < num_entities;
@@ -2934,7 +2997,9 @@
         return;
     }
     
-    lldb::addr_t load_addr = fun_address->GetCallableLoadAddress(m_parser_vars->m_exe_ctx->target);
+    Target *target = m_parser_vars->m_exe_ctx->GetTargetPtr();
+
+    lldb::addr_t load_addr = fun_address->GetCallableLoadAddress(target);
     fun_location->SetValueType(Value::eValueTypeLoadAddress);
     fun_location->GetScalar() = load_addr;
     
diff --git a/source/Expression/ClangExpressionParser.cpp b/source/Expression/ClangExpressionParser.cpp
index 3549196..e674565 100644
--- a/source/Expression/ClangExpressionParser.cpp
+++ b/source/Expression/ClangExpressionParser.cpp
@@ -463,9 +463,9 @@
     if (decl_map)
     {
         Stream *error_stream = NULL;
-        
-        if (exe_ctx.target)
-            error_stream = &exe_ctx.target->GetDebugger().GetErrorStream();
+        Target *target = exe_ctx.GetTargetPtr();
+        if (target)
+            error_stream = &target->GetDebugger().GetErrorStream();
     
         IRForTarget ir_for_target(decl_map,
                                   m_expr.NeedsVariableResolution(),
@@ -489,7 +489,9 @@
             return err;
         }
         
-        if (!exe_ctx.process || execution_policy == eExecutionPolicyNever)
+        Process *process = exe_ctx.GetProcessPtr();
+
+        if (!process || execution_policy == eExecutionPolicyNever)
         {
             err.SetErrorToGenericError();
             err.SetErrorString("Execution needed to run in the target, but the target can't be run");
@@ -498,9 +500,9 @@
         
         if (execution_policy != eExecutionPolicyNever &&
             m_expr.NeedsValidation() && 
-            exe_ctx.process)
+            process)
         {
-            if (!exe_ctx.process->GetDynamicCheckers())
+            if (!process->GetDynamicCheckers())
             {                
                 DynamicCheckerFunctions *dynamic_checkers = new DynamicCheckerFunctions();
                 
@@ -516,13 +518,13 @@
                     return err;
                 }
                 
-                exe_ctx.process->SetDynamicCheckers(dynamic_checkers);
+                process->SetDynamicCheckers(dynamic_checkers);
                 
                 if (log)
                     log->Printf("== [ClangUserExpression::Evaluate] Finished installing dynamic checkers ==");
             }
             
-            IRDynamicChecks ir_dynamic_checks(*exe_ctx.process->GetDynamicCheckers(), function_name.c_str());
+            IRDynamicChecks ir_dynamic_checks(*process->GetDynamicCheckers(), function_name.c_str());
         
             if (!ir_dynamic_checks.runOnModule(*module))
             {
@@ -586,9 +588,9 @@
     
     m_jitted_functions.push_back (ClangExpressionParser::JittedFunction(function_name.c_str(), (lldb::addr_t)fun_ptr));
     
-    ExecutionContext &exc_context(exe_ctx);
-    
-    if (exc_context.process == NULL)
+
+    Process *process = exe_ctx.GetProcessPtr();
+    if (process == NULL)
     {
         err.SetErrorToGenericError();
         err.SetErrorString("Couldn't write the JIT compiled code into the target because there is no target");
@@ -615,7 +617,7 @@
     }
     
     Error alloc_error;
-    func_allocation_addr = exc_context.process->AllocateMemory (alloc_size, 
+    func_allocation_addr = process->AllocateMemory (alloc_size, 
                                                                 lldb::ePermissionsReadable|lldb::ePermissionsExecutable, 
                                                                 alloc_error);
     
@@ -636,7 +638,7 @@
         
         Error write_error;
         
-        if (exc_context.process->WriteMemory(cursor, (void *) lstart, size, write_error) != size)
+        if (process->WriteMemory(cursor, (void *) lstart, size, write_error) != size)
         {
             err.SetErrorToGenericError();
             err.SetErrorStringWithFormat("Couldn't copy JIT code for function into the target: %s", write_error.AsCString("unknown error"));
@@ -731,7 +733,8 @@
     if (log)
         log->Printf("Function's code range is [0x%llx-0x%llx]", func_range.first, func_range.second);
     
-    if (!exe_ctx.target)
+    Target *target = exe_ctx.GetTargetPtr();
+    if (!target)
     {
         ret.SetErrorToGenericError();
         ret.SetErrorString("Couldn't find the target");
@@ -739,8 +742,9 @@
     
     lldb::DataBufferSP buffer_sp(new DataBufferHeap(func_range.second - func_remote_addr, 0));
     
+    Process *process = exe_ctx.GetProcessPtr();
     Error err;
-    exe_ctx.process->ReadMemory(func_remote_addr, buffer_sp->GetBytes(), buffer_sp->GetByteSize(), err);
+    process->ReadMemory(func_remote_addr, buffer_sp->GetBytes(), buffer_sp->GetByteSize(), err);
     
     if (!err.Success())
     {
@@ -749,7 +753,7 @@
         return ret;
     }
     
-    ArchSpec arch(exe_ctx.target->GetArchitecture());
+    ArchSpec arch(target->GetArchitecture());
     
     Disassembler *disassembler = Disassembler::FindPlugin(arch, NULL);
     
@@ -760,7 +764,7 @@
         return ret;
     }
     
-    if (!exe_ctx.process)
+    if (!process)
     {
         ret.SetErrorToGenericError();
         ret.SetErrorString("Couldn't find the process");
@@ -768,8 +772,8 @@
     }
     
     DataExtractor extractor(buffer_sp, 
-                            exe_ctx.process->GetByteOrder(),
-                            exe_ctx.target->GetArchitecture().GetAddressByteSize());
+                            process->GetByteOrder(),
+                            target->GetArchitecture().GetAddressByteSize());
     
     if (log)
     {
diff --git a/source/Expression/ClangFunction.cpp b/source/Expression/ClangFunction.cpp
index 21acb5b..642463d 100644
--- a/source/Expression/ClangFunction.cpp
+++ b/source/Expression/ClangFunction.cpp
@@ -237,7 +237,7 @@
 bool
 ClangFunction::WriteFunctionWrapper (ExecutionContext &exe_ctx, Stream &errors)
 {
-    Process *process = exe_ctx.process;
+    Process *process = exe_ctx.GetProcessPtr();
 
     if (!process)
         return false;
@@ -266,8 +266,8 @@
     
     if (!jit_error.Success())
         return false;
-    if (exe_ctx.process && m_jit_alloc != LLDB_INVALID_ADDRESS)
-        m_jit_process_sp = exe_ctx.process->GetSP();
+    if (process && m_jit_alloc != LLDB_INVALID_ADDRESS)
+        m_jit_process_sp = process->GetSP();
 
     return true;
 }
@@ -299,7 +299,7 @@
     using namespace clang;
     ExecutionResults return_value = eExecutionSetupError;
 
-    Process *process = exe_ctx.process;
+    Process *process = exe_ctx.GetProcessPtr();
 
     if (process == NULL)
         return return_value;
@@ -324,7 +324,7 @@
     }
 
     // TODO: verify fun_addr needs to be a callable address
-    Scalar fun_addr (function_address.GetCallableLoadAddress(exe_ctx.target));
+    Scalar fun_addr (function_address.GetCallableLoadAddress(exe_ctx.GetTargetPtr()));
     int first_offset = m_member_offsets[0];
     process->WriteScalarToMemory(args_addr_ref + first_offset, fun_addr, process->GetAddressByteSize(), error);
 
@@ -394,8 +394,8 @@
                                             lldb::addr_t *cmd_arg)
 {
     // FIXME: Use the errors Stream for better error reporting.
-
-    if (exe_ctx.thread == NULL)
+    Thread *thread = exe_ctx.GetThreadPtr();
+    if (thread == NULL)
     {
         errors.Printf("Can't call a function without a valid thread.");
         return NULL;
@@ -404,7 +404,7 @@
     // Okay, now run the function:
 
     Address wrapper_address (NULL, func_addr);
-    ThreadPlan *new_plan = new ThreadPlanCallFunction (*exe_ctx.thread, 
+    ThreadPlan *new_plan = new ThreadPlanCallFunction (*thread, 
                                                        wrapper_address,
                                                        args_addr,
                                                        stop_others, 
@@ -420,7 +420,7 @@
     // Read the return value - it is the last field in the struct:
     // FIXME: How does clang tell us there's no return value?  We need to handle that case.
     
-    Process *process = exe_ctx.process;
+    Process *process = exe_ctx.GetProcessPtr();
     
     if (process == NULL)
         return false;
@@ -446,7 +446,7 @@
     if (pos != m_wrapper_args_addrs.end())
         m_wrapper_args_addrs.erase(pos);
     
-    exe_ctx.process->DeallocateMemory(args_addr);
+    exe_ctx.GetProcessRef().DeallocateMemory(args_addr);
 }
 
 ExecutionResults
@@ -490,16 +490,24 @@
         Stream &errors,
         lldb::addr_t *this_arg)
 {
-    lldb::ThreadPlanSP call_plan_sp(ClangFunction::GetThreadPlanToCallFunction(exe_ctx, function_address, void_arg, 
-                                                                               errors, stop_others, discard_on_error, 
-                                                                               this_arg));
+    lldb::ThreadPlanSP call_plan_sp (ClangFunction::GetThreadPlanToCallFunction (exe_ctx, 
+                                                                                 function_address, 
+                                                                                 void_arg, 
+                                                                                 errors, 
+                                                                                 stop_others, 
+                                                                                 discard_on_error, 
+                                                                                 this_arg));
     if (call_plan_sp == NULL)
         return eExecutionSetupError;
     
     call_plan_sp->SetPrivate(true);
     
-    return exe_ctx.process->RunThreadPlan (exe_ctx, call_plan_sp, stop_others, try_all_threads, discard_on_error,
-                                            single_thread_timeout_usec, errors);
+    return exe_ctx.GetProcessRef().RunThreadPlan (exe_ctx, call_plan_sp, 
+                                                  stop_others, 
+                                                  try_all_threads, 
+                                                  discard_on_error,
+                                                  single_thread_timeout_usec, 
+                                                  errors);
 }  
 
 ExecutionResults
diff --git a/source/Expression/ClangUserExpression.cpp b/source/Expression/ClangUserExpression.cpp
index 194ad95..73ed043 100644
--- a/source/Expression/ClangUserExpression.cpp
+++ b/source/Expression/ClangUserExpression.cpp
@@ -80,12 +80,13 @@
 void
 ClangUserExpression::ScanContext(ExecutionContext &exe_ctx)
 {
-    m_target = exe_ctx.target;
+    m_target = exe_ctx.GetTargetPtr();
     
-    if (!exe_ctx.frame)
+    StackFrame *frame = exe_ctx.GetFramePtr();
+    if (frame == NULL)
         return;
     
-    SymbolContext sym_ctx = exe_ctx.frame->GetSymbolContext(lldb::eSymbolContextFunction);
+    SymbolContext sym_ctx = frame->GetSymbolContext(lldb::eSymbolContextFunction);
     
     if (!sym_ctx.function)
         return;
@@ -246,7 +247,7 @@
     // Set up the target and compiler
     //
     
-    Target *target = exe_ctx.target;
+    Target *target = exe_ctx.GetTargetPtr();
     
     if (!target)
     {
@@ -268,7 +269,8 @@
         return false;
     }
     
-    ClangExpressionParser parser(exe_ctx.process, *this);
+    Process *process = exe_ctx.GetProcessPtr();
+    ClangExpressionParser parser(process, *this);
     
     unsigned num_errors = parser.Parse (error_stream);
     
@@ -285,8 +287,8 @@
     // Prepare the output of the parser for execution, evaluating it statically if possible
     //
         
-    if (execution_policy != eExecutionPolicyNever && exe_ctx.process)
-        m_data_allocator.reset(new ProcessDataAllocator(*exe_ctx.process));
+    if (execution_policy != eExecutionPolicyNever && process)
+        m_data_allocator.reset(new ProcessDataAllocator(*process));
     
     Error jit_error = parser.PrepareForExecution (m_jit_alloc,
                                                   m_jit_start_addr,
@@ -309,8 +311,8 @@
     
     if (jit_error.Success())
     {
-        if (exe_ctx.process && m_jit_alloc != LLDB_INVALID_ADDRESS)
-            m_jit_process_sp = exe_ctx.process->GetSP();        
+        if (process && m_jit_alloc != LLDB_INVALID_ADDRESS)
+            m_jit_process_sp = process->GetSP();        
         return true;
     }
     else
@@ -505,7 +507,7 @@
         const bool try_all_threads = true;
         
         Address wrapper_address (NULL, m_jit_start_addr);
-        lldb::ThreadPlanSP call_plan_sp(new ThreadPlanCallUserExpression (*(exe_ctx.thread), 
+        lldb::ThreadPlanSP call_plan_sp(new ThreadPlanCallUserExpression (exe_ctx.GetThreadRef(), 
                                                                           wrapper_address, 
                                                                           struct_address, 
                                                                           stop_others, 
@@ -526,13 +528,13 @@
         if (log)
             log->Printf("-- [ClangUserExpression::Execute] Execution of expression begins --");
         
-        ExecutionResults execution_result = exe_ctx.process->RunThreadPlan (exe_ctx, 
-                                                                            call_plan_sp, 
-                                                                            stop_others, 
-                                                                            try_all_threads, 
-                                                                            discard_on_error,
-                                                                            single_thread_timeout_usec, 
-                                                                            error_stream);
+        ExecutionResults execution_result = exe_ctx.GetProcessRef().RunThreadPlan (exe_ctx, 
+                                                                                   call_plan_sp, 
+                                                                                   stop_others, 
+                                                                                   try_all_threads, 
+                                                                                   discard_on_error,
+                                                                                   single_thread_timeout_usec, 
+                                                                                   error_stream);
         
         if (log)
             log->Printf("-- [ClangUserExpression::Execute] Execution of expression completed --");
@@ -602,7 +604,9 @@
 
     ExecutionResults execution_results = eExecutionSetupError;
     
-    if (exe_ctx.process == NULL || exe_ctx.process->GetState() != lldb::eStateStopped)
+    Process *process = exe_ctx.GetProcessPtr();
+
+    if (process == NULL || process->GetState() != lldb::eStateStopped)
     {
         if (execution_policy == eExecutionPolicyAlways)
         {
@@ -615,7 +619,7 @@
         }
     }
     
-    if (exe_ctx.process == NULL || !exe_ctx.process->CanJIT())
+    if (process == NULL || !process->CanJIT())
         execution_policy = eExecutionPolicyNever;
     
     ClangUserExpressionSP user_expression_sp (new ClangUserExpression (expr_cstr, expr_prefix));
diff --git a/source/Expression/ClangUtilityFunction.cpp b/source/Expression/ClangUtilityFunction.cpp
index 0d11c91..6f31d4c 100644
--- a/source/Expression/ClangUtilityFunction.cpp
+++ b/source/Expression/ClangUtilityFunction.cpp
@@ -77,7 +77,7 @@
     // Set up the target and compiler
     //
     
-    Target *target = exe_ctx.target;
+    Target *target = exe_ctx.GetTargetPtr();
     
     if (!target)
     {
@@ -85,7 +85,7 @@
         return false;
     }
     
-    Process *process = exe_ctx.process;
+    Process *process = exe_ctx.GetProcessPtr();
     
     if (!process)
     {
@@ -101,7 +101,7 @@
     
     m_expr_decl_map.reset(new ClangExpressionDeclMap(keep_result_in_memory));
     
-    m_data_allocator.reset(new ProcessDataAllocator(*exe_ctx.process));
+    m_data_allocator.reset(new ProcessDataAllocator(*process));
     
     if (!m_expr_decl_map->WillParse(exe_ctx))
     {
@@ -147,8 +147,8 @@
         log->Printf("Data buffer contents:\n%s", dump_string.GetString().c_str());
     }
     
-    if (exe_ctx.process && m_jit_start_addr != LLDB_INVALID_ADDRESS)
-        m_jit_process_sp = exe_ctx.process->GetSP();
+    if (m_jit_start_addr != LLDB_INVALID_ADDRESS)
+        m_jit_process_sp = process->GetSP();
     
 #if 0
 	// jingham: look here
diff --git a/source/Expression/DWARFExpression.cpp b/source/Expression/DWARFExpression.cpp
index 037fbc1..9b7f93e 100644
--- a/source/Expression/DWARFExpression.cpp
+++ b/source/Expression/DWARFExpression.cpp
@@ -930,10 +930,14 @@
     {
         uint32_t offset = 0;
         addr_t pc;
+        StackFrame *frame = NULL;
         if (reg_ctx)
             pc = reg_ctx->GetPC();
         else
-            pc = exe_ctx->frame->GetRegisterContext()->GetPC();
+        {
+            frame = exe_ctx->GetFramePtr();
+            pc = frame->GetRegisterContext()->GetPC();
+        }
 
         if (loclist_base_load_addr != LLDB_INVALID_ADDRESS)
         {
@@ -1000,8 +1004,16 @@
 {
     std::vector<Value> stack;
 
-    if (reg_ctx == NULL && exe_ctx && exe_ctx->frame)
-        reg_ctx = exe_ctx->frame->GetRegisterContext().get();
+    Process *process = NULL;
+    StackFrame *frame = NULL;
+    
+    if (exe_ctx)
+    {
+        process = exe_ctx->GetProcessPtr();
+        frame = exe_ctx->GetFramePtr();
+    }
+    if (reg_ctx == NULL && frame)
+        reg_ctx = frame->GetRegisterContext().get();
 
     if (initial_value_ptr)
         stack.push_back(*initial_value_ptr);
@@ -1110,15 +1122,15 @@
                 case Value::eValueTypeLoadAddress:
                     if (exe_ctx)
                     {
-                        if (exe_ctx->process)
+                        if (process)
                         {
                             lldb::addr_t pointer_addr = stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
                             uint8_t addr_bytes[sizeof(lldb::addr_t)];
-                            uint32_t addr_size = exe_ctx->process->GetAddressByteSize();
+                            uint32_t addr_size = process->GetAddressByteSize();
                             Error error;
-                            if (exe_ctx->process->ReadMemory(pointer_addr, &addr_bytes, addr_size, error) == addr_size)
+                            if (process->ReadMemory(pointer_addr, &addr_bytes, addr_size, error) == addr_size)
                             {
-                                DataExtractor addr_data(addr_bytes, sizeof(addr_bytes), exe_ctx->process->GetByteOrder(), addr_size);
+                                DataExtractor addr_data(addr_bytes, sizeof(addr_bytes), process->GetByteOrder(), addr_size);
                                 uint32_t addr_data_offset = 0;
                                 stack.back().GetScalar() = addr_data.GetPointer(&addr_data_offset);
                                 stack.back().ClearContext();
@@ -1202,14 +1214,14 @@
                 case Value::eValueTypeLoadAddress:
                     if (exe_ctx)
                     {
-                        if (exe_ctx->process)
+                        if (process)
                         {
                             lldb::addr_t pointer_addr = stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
                             uint8_t addr_bytes[sizeof(lldb::addr_t)];
                             Error error;
-                            if (exe_ctx->process->ReadMemory(pointer_addr, &addr_bytes, size, error) == size)
+                            if (process->ReadMemory(pointer_addr, &addr_bytes, size, error) == size)
                             {
-                                DataExtractor addr_data(addr_bytes, sizeof(addr_bytes), exe_ctx->process->GetByteOrder(), size);
+                                DataExtractor addr_data(addr_bytes, sizeof(addr_bytes), process->GetByteOrder(), size);
                                 uint32_t addr_data_offset = 0;
                                 switch (size)
                                 {
@@ -2170,25 +2182,35 @@
             break;
 
         case DW_OP_fbreg:
-            if (exe_ctx && exe_ctx->frame)
+            if (exe_ctx)
             {
-                Scalar value;
-                if (exe_ctx->frame->GetFrameBaseValue(value, error_ptr))
+                if (frame)
                 {
-                    int64_t fbreg_offset = opcodes.GetSLEB128(&offset);
-                    value += fbreg_offset;
-                    stack.push_back(value);
-                    stack.back().SetValueType (Value::eValueTypeLoadAddress);
+                    Scalar value;
+                    if (frame->GetFrameBaseValue(value, error_ptr))
+                    {
+                        int64_t fbreg_offset = opcodes.GetSLEB128(&offset);
+                        value += fbreg_offset;
+                        stack.push_back(value);
+                        stack.back().SetValueType (Value::eValueTypeLoadAddress);
+                    }
+                    else
+                        return false;
                 }
                 else
+                {
+                    if (error_ptr)
+                        error_ptr->SetErrorString ("Invalid stack frame in context for DW_OP_fbreg opcode.");
                     return false;
+                }
             }
             else
             {
                 if (error_ptr)
-                    error_ptr->SetErrorString ("Invalid stack frame in context for DW_OP_fbreg opcode.");
+                    error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_fbreg.\n");
                 return false;
             }
+
             break;
 
         //----------------------------------------------------------------------
@@ -2474,14 +2496,14 @@
                                         data.SetByteSize(byte_size);
                                         
                                         Error error;
-                                        if (exe_ctx->process->ReadMemory (source_addr, data.GetBytes(), byte_size, error) != byte_size)
+                                        if (process->ReadMemory (source_addr, data.GetBytes(), byte_size, error) != byte_size)
                                         {
                                             if (error_ptr)
                                                 error_ptr->SetErrorStringWithFormat ("Couldn't read a composite type from the target: %s", error.AsCString());
                                             return false;
                                         }
                                         
-                                        if (exe_ctx->process->WriteMemory (target_addr, data.GetBytes(), byte_size, error) != byte_size)
+                                        if (process->WriteMemory (target_addr, data.GetBytes(), byte_size, error) != byte_size)
                                         {
                                             if (error_ptr)
                                                 error_ptr->SetErrorStringWithFormat ("Couldn't write a composite type to the target: %s", error.AsCString());
@@ -2490,7 +2512,7 @@
                                     }
                                     break;
                                 case Value::eValueTypeHostAddress:
-                                    if (exe_ctx->process->GetByteOrder() != lldb::endian::InlHostByteOrder())
+                                    if (process->GetByteOrder() != lldb::endian::InlHostByteOrder())
                                     {
                                         if (error_ptr)
                                             error_ptr->SetErrorStringWithFormat ("Copy of composite types between incompatible byte orders is unimplemented");
@@ -2499,7 +2521,7 @@
                                     else
                                     {
                                         Error error;
-                                        if (exe_ctx->process->ReadMemory (source_addr, (uint8_t*)target_addr, byte_size, error) != byte_size)
+                                        if (process->ReadMemory (source_addr, (uint8_t*)target_addr, byte_size, error) != byte_size)
                                         {
                                             if (error_ptr)
                                                 error_ptr->SetErrorStringWithFormat ("Couldn't read a composite type from the target: %s", error.AsCString());
@@ -2515,7 +2537,7 @@
                                 switch (target_value_type)
                                 {
                                 case Value::eValueTypeLoadAddress:
-                                    if (exe_ctx->process->GetByteOrder() != lldb::endian::InlHostByteOrder())
+                                    if (process->GetByteOrder() != lldb::endian::InlHostByteOrder())
                                     {
                                         if (error_ptr)
                                             error_ptr->SetErrorStringWithFormat ("Copy of composite types between incompatible byte orders is unimplemented");
@@ -2524,7 +2546,7 @@
                                     else
                                     {
                                         Error error;
-                                        if (exe_ctx->process->WriteMemory (target_addr, (uint8_t*)source_addr, byte_size, error) != byte_size)
+                                        if (process->WriteMemory (target_addr, (uint8_t*)source_addr, byte_size, error) != byte_size)
                                         {
                                             if (error_ptr)
                                                 error_ptr->SetErrorStringWithFormat ("Couldn't write a composite type to the target: %s", error.AsCString());
diff --git a/source/Expression/IRDynamicChecks.cpp b/source/Expression/IRDynamicChecks.cpp
index 22624ea..2af5e5e 100644
--- a/source/Expression/IRDynamicChecks.cpp
+++ b/source/Expression/IRDynamicChecks.cpp
@@ -56,9 +56,11 @@
     if (!m_valid_pointer_check->Install(error_stream, exe_ctx))
         return false;
     
-    if (exe_ctx.process)
+    Process *process = exe_ctx.GetProcessPtr();
+
+    if (process)
     {
-        ObjCLanguageRuntime *objc_language_runtime = exe_ctx.process->GetObjCLanguageRuntime();
+        ObjCLanguageRuntime *objc_language_runtime = process->GetObjCLanguageRuntime();
         
         if (objc_language_runtime)
         {