Thread hardening part 3. Now lldb_private::Thread objects have std::weak_ptr
objects for the backlink to the lldb_private::Process. The issues we were
running into before was someone was holding onto a shared pointer to a 
lldb_private::Thread for too long, and the lldb_private::Process parent object
would get destroyed and the lldb_private::Thread had a "Process &m_process"
member which would just treat whatever memory that used to be a Process as a
valid Process. This was mostly happening for lldb_private::StackFrame objects
that had a member like "Thread &m_thread". So this completes the internal
strong/weak changes.

Documented the ExecutionContext and ExecutionContextRef classes so that our
LLDB developers can understand when and where to use ExecutionContext and 
ExecutionContextRef objects.



git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@151009 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/Process/Utility/RegisterContextLLDB.cpp b/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
index 3ae19f9..1b23087 100644
--- a/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
@@ -85,7 +85,9 @@
 void
 RegisterContextLLDB::InitializeZerothFrame()
 {
+    ExecutionContext exe_ctx(m_thread.shared_from_this());
     StackFrameSP frame_sp (m_thread.GetStackFrameAtIndex (0));
+    exe_ctx.SetFrameSP (frame_sp);
 
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND));
 
@@ -158,7 +160,7 @@
         if (active_row && log)
         {
             StreamString active_row_strm;
-            active_row->Dump(active_row_strm, m_full_unwind_plan_sp.get(), &m_thread, m_start_pc.GetLoadAddress(&m_thread.GetProcess().GetTarget()));
+            active_row->Dump(active_row_strm, m_full_unwind_plan_sp.get(), &m_thread, m_start_pc.GetLoadAddress(exe_ctx.GetTargetPtr()));
             log->Printf("%*sFrame %u active row: %s",
                         m_frame_number < 100 ? m_frame_number : 100, "", m_frame_number, active_row_strm.GetString().c_str());
         }
@@ -210,7 +212,7 @@
                     m_frame_number < 100 ? m_frame_number : 100, "", 
                     m_thread.GetIndexID(), 
                     m_frame_number,
-                    (uint64_t) m_current_pc.GetLoadAddress (&m_thread.GetProcess().GetTarget()), 
+                    (uint64_t) m_current_pc.GetLoadAddress (exe_ctx.GetTargetPtr()), 
                     (uint64_t) m_cfa,
                     m_full_unwind_plan_sp->GetSourceName().GetCString());
     }
@@ -274,13 +276,15 @@
         return;
     }
     
+    ExecutionContext exe_ctx(m_thread.shared_from_this());
+    Process *process = exe_ctx.GetProcessPtr();
     // Let ABIs fixup code addresses to make sure they are valid. In ARM ABIs
     // this will strip bit zero in case we read a PC from memory or from the LR.   
-    ABI *abi = m_thread.GetProcess().GetABI().get();
+    ABI *abi = process->GetABI().get();
     if (abi)
         pc = abi->FixCodeAddress(pc);
 
-    m_thread.GetProcess().GetTarget().GetSectionLoadList().ResolveLoadAddress (pc, m_current_pc);
+    process->GetTarget().GetSectionLoadList().ResolveLoadAddress (pc, m_current_pc);
 
     // If we don't have a Module for some reason, we're not going to find symbol/function information - just
     // stick in some reasonable defaults and hope we can unwind past this frame.
@@ -294,7 +298,7 @@
         
         // Test the pc value to see if we know it's in an unmapped/non-executable region of memory.
         uint32_t permissions;
-        if (m_thread.GetProcess().GetLoadAddressPermissions(pc, permissions)
+        if (process->GetLoadAddressPermissions(pc, permissions)
             && (permissions & ePermissionsExecutable) == 0)
         {
             // If this is the second frame off the stack, we may have unwound the first frame
@@ -366,7 +370,7 @@
 
                 // cfa_regval should point into the stack memory; if we can query memory region permissions,
                 // see if the memory is allocated & readable.
-                if (m_thread.GetProcess().GetLoadAddressPermissions(cfa_regval, permissions)
+                if (process->GetLoadAddressPermissions(cfa_regval, permissions)
                     && (permissions & ePermissionsReadable) == 0)
                 {
                     m_frame_type = eNotAValidFrame;
@@ -495,7 +499,7 @@
         if (active_row && log)
         {
             StreamString active_row_strm;
-            active_row->Dump(active_row_strm, m_full_unwind_plan_sp.get(), &m_thread, m_start_pc.GetLoadAddress(&m_thread.GetProcess().GetTarget()));
+            active_row->Dump(active_row_strm, m_full_unwind_plan_sp.get(), &m_thread, m_start_pc.GetLoadAddress(exe_ctx.GetTargetPtr()));
             log->Printf("%*sFrame %u active row: %s",
                         m_frame_number < 100 ? m_frame_number : 100, "", m_frame_number, active_row_strm.GetString().c_str());
         }
@@ -510,7 +514,7 @@
             if (active_row && log)
             {
                 StreamString active_row_strm;
-                active_row->Dump(active_row_strm, m_full_unwind_plan_sp.get(), &m_thread, m_start_pc.GetLoadAddress(&m_thread.GetProcess().GetTarget()));
+                active_row->Dump(active_row_strm, m_full_unwind_plan_sp.get(), &m_thread, m_start_pc.GetLoadAddress(exe_ctx.GetTargetPtr()));
                 log->Printf("%*sFrame %u active row: %s",
                             m_frame_number < 100 ? m_frame_number : 100, "", m_frame_number, active_row_strm.GetString().c_str());
             }
@@ -594,7 +598,7 @@
     {
         log->Printf("%*sFrame %u initialized frame current pc is 0x%llx cfa is 0x%llx", 
                     m_frame_number < 100 ? m_frame_number : 100, "", m_frame_number,
-                    (uint64_t) m_current_pc.GetLoadAddress (&m_thread.GetProcess().GetTarget()), (uint64_t) m_cfa);
+                    (uint64_t) m_current_pc.GetLoadAddress (exe_ctx.GetTargetPtr()), (uint64_t) m_cfa);
     }
 }
 
@@ -671,8 +675,9 @@
     UnwindPlanSP unwind_plan_sp;
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND));
     UnwindPlanSP arch_default_unwind_plan_sp;
-
-    ABI *abi = m_thread.GetProcess().GetABI().get();
+    ExecutionContext exe_ctx(m_thread.shared_from_this());
+    Process *process = exe_ctx.GetProcessPtr();
+    ABI *abi = process ? process->GetABI().get() : NULL;
     if (abi)
     {
         arch_default_unwind_plan_sp.reset (new UnwindPlan (lldb::eRegisterKindGeneric));
@@ -699,9 +704,9 @@
     if ((!m_sym_ctx_valid  || m_sym_ctx.function == NULL) && behaves_like_zeroth_frame && m_current_pc.IsValid())
     {
         uint32_t permissions;
-        addr_t current_pc_addr = m_current_pc.GetLoadAddress (&m_thread.GetProcess().GetTarget());
+        addr_t current_pc_addr = m_current_pc.GetLoadAddress (exe_ctx.GetTargetPtr());
         if (current_pc_addr == 0
-            || (m_thread.GetProcess().GetLoadAddressPermissions(current_pc_addr, permissions)
+            || (process->GetLoadAddressPermissions(current_pc_addr, permissions)
                 && (permissions & ePermissionsExecutable) == 0))
         {
             unwind_plan_sp.reset (new UnwindPlan (lldb::eRegisterKindGeneric));
@@ -749,8 +754,7 @@
     // right thing.  It'd be nice if there was a way to ask the eh_frame directly if it is asynchronous
     // (can be trusted at every instruction point) or synchronous (the normal case - only at call sites).
     // But there is not.
-    if (m_thread.GetProcess().GetDynamicLoader() 
-        && m_thread.GetProcess().GetDynamicLoader()->AlwaysRelyOnEHUnwindInfo (m_sym_ctx))
+    if (process->GetDynamicLoader() && process->GetDynamicLoader()->AlwaysRelyOnEHUnwindInfo (m_sym_ctx))
     {
         unwind_plan_sp = func_unwinders_sp->GetUnwindPlanAtCallSite (m_current_offset_backed_up_one);
         if (unwind_plan_sp && unwind_plan_sp->PlanValidAtAddress (m_current_pc))
@@ -1075,12 +1079,15 @@
             }
         }
     }
-
+    
+    
+    ExecutionContext exe_ctx(m_thread.shared_from_this());
+    Process *process = exe_ctx.GetProcessPtr();
     if (have_unwindplan_regloc == false)
     {
         // If a volatile register is being requested, we don't want to forward the next frame's register contents 
         // up the stack -- the register is not retrievable at this frame.
-        ABI *abi = m_thread.GetProcess().GetABI().get();
+        ABI *abi = process ? process->GetABI().get() : NULL;
         if (abi)
         {
             const RegisterInfo *reg_info = GetRegisterInfoAtIndex(lldb_regnum);
@@ -1198,10 +1205,9 @@
     {
         DataExtractor dwarfdata (unwindplan_regloc.GetDWARFExpressionBytes(), 
                                  unwindplan_regloc.GetDWARFExpressionLength(), 
-                                 m_thread.GetProcess().GetByteOrder(), m_thread.GetProcess().GetAddressByteSize());
+                                 process->GetByteOrder(), process->GetAddressByteSize());
         DWARFExpression dwarfexpr (dwarfdata, 0, unwindplan_regloc.GetDWARFExpressionLength());
         dwarfexpr.SetRegisterKind (unwindplan_registerkind);
-        ExecutionContext exe_ctx (&m_thread.GetProcess(), &m_thread, NULL);
         Value result;
         Error error;
         if (dwarfexpr.Evaluate (&exe_ctx, NULL, NULL, NULL, this, 0, NULL, result, &error))
@@ -1432,7 +1438,7 @@
     {
         return ReadPC (start_pc); 
     }
-    start_pc = m_start_pc.GetLoadAddress (&m_thread.GetProcess().GetTarget());
+    start_pc = m_start_pc.GetLoadAddress (CalculateTarget().get());
     return true;
 }
 
diff --git a/source/Plugins/Process/Utility/RegisterContextMemory.cpp b/source/Plugins/Process/Utility/RegisterContextMemory.cpp
index ff077b4..03610a2 100644
--- a/source/Plugins/Process/Utility/RegisterContextMemory.cpp
+++ b/source/Plugins/Process/Utility/RegisterContextMemory.cpp
@@ -134,11 +134,15 @@
 {
     if (m_reg_data_addr != LLDB_INVALID_ADDRESS)
     {
-        Error error;
-        if (m_thread.GetProcess().ReadMemory(m_reg_data_addr, data_sp->GetBytes(), data_sp->GetByteSize(), error) == data_sp->GetByteSize())
+        ProcessSP process_sp (CalculateProcess());
+        if (process_sp)
         {
-            SetAllRegisterValid (true);
-            return true;
+            Error error;
+            if (process_sp->ReadMemory(m_reg_data_addr, data_sp->GetBytes(), data_sp->GetByteSize(), error) == data_sp->GetByteSize())
+            {
+                SetAllRegisterValid (true);
+                return true;
+            }
         }
     }
     return false;
@@ -149,10 +153,14 @@
 {
     if (m_reg_data_addr != LLDB_INVALID_ADDRESS)
     {
-        Error error;
-        SetAllRegisterValid (false);
-        if (m_thread.GetProcess().WriteMemory(m_reg_data_addr, data_sp->GetBytes(), data_sp->GetByteSize(), error) == data_sp->GetByteSize())
-            return true;
+        ProcessSP process_sp (CalculateProcess());
+        if (process_sp)
+        {
+            Error error;
+            SetAllRegisterValid (false);
+            if (process_sp->WriteMemory(m_reg_data_addr, data_sp->GetBytes(), data_sp->GetByteSize(), error) == data_sp->GetByteSize())
+                return true;
+        }
     }
     return false;
 }
diff --git a/source/Plugins/Process/Utility/StopInfoMachException.cpp b/source/Plugins/Process/Utility/StopInfoMachException.cpp
index 8915dd7..95f3633 100644
--- a/source/Plugins/Process/Utility/StopInfoMachException.cpp
+++ b/source/Plugins/Process/Utility/StopInfoMachException.cpp
@@ -16,6 +16,7 @@
 #include "lldb/Breakpoint/Watchpoint.h"
 #include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/StreamString.h"
+#include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Target/Target.h"
@@ -31,7 +32,9 @@
 {
     if (m_description.empty() && m_value != 0)
     {
-        const llvm::Triple::ArchType cpu = m_thread.GetProcess().GetTarget().GetArchitecture().GetMachine();
+        ExecutionContext exe_ctx (m_thread.shared_from_this());
+        Target *target = exe_ctx.GetTargetPtr();
+        const llvm::Triple::ArchType cpu = target ? target->GetArchitecture().GetMachine() : llvm::Triple::InvalidArch;
 
         const char *exc_desc = NULL;
         const char *code_label = "code";
@@ -252,7 +255,9 @@
 {
     if (exc_type != 0)
     {
-        const llvm::Triple::ArchType cpu = thread.GetProcess().GetTarget().GetArchitecture().GetMachine();
+        ExecutionContext exe_ctx (thread.shared_from_this());
+        Target *target = exe_ctx.GetTargetPtr();
+        const llvm::Triple::ArchType cpu = target ? target->GetArchitecture().GetMachine() : llvm::Triple::InvalidArch;
 
         switch (exc_type)
         {
@@ -306,8 +311,9 @@
 
                         // It's a watchpoint, then.
                         // The exc_sub_code indicates the data break address.
-                        lldb::WatchpointSP wp_sp =
-                            thread.GetProcess().GetTarget().GetWatchpointList().FindByAddress((lldb::addr_t)exc_sub_code);
+                        lldb::WatchpointSP wp_sp;
+                        if (target)
+                            wp_sp = target->GetWatchpointList().FindByAddress((lldb::addr_t)exc_sub_code);
                         if (wp_sp)
                         {
                             // Debugserver may piggyback the hardware index of the fired watchpoint in the exception data.
@@ -345,7 +351,11 @@
                 if (is_software_breakpoint)
                 {
                     addr_t pc = thread.GetRegisterContext()->GetPC();
-                    lldb::BreakpointSiteSP bp_site_sp = thread.GetProcess().GetBreakpointSiteList().FindByAddress(pc);
+                    ProcessSP process_sp (thread.CalculateProcess());
+
+                    lldb::BreakpointSiteSP bp_site_sp;
+                    if (process_sp)
+                        bp_site_sp = process_sp->GetBreakpointSiteList().FindByAddress(pc);
                     if (bp_site_sp)
                     {
                         // If the breakpoint is for this thread, then we'll report the hit, but if it is for another thread,
diff --git a/source/Plugins/Process/Utility/ThreadMemory.cpp b/source/Plugins/Process/Utility/ThreadMemory.cpp
index 95f05fd..dfcc2b0 100644
--- a/source/Plugins/Process/Utility/ThreadMemory.cpp
+++ b/source/Plugins/Process/Utility/ThreadMemory.cpp
@@ -17,10 +17,10 @@
 using namespace lldb;
 using namespace lldb_private;
 
-ThreadMemory::ThreadMemory (Process &process, 
+ThreadMemory::ThreadMemory (const ProcessSP &process_sp, 
                               tid_t tid, 
                               const ValueObjectSP &thread_info_valobj_sp) :
-    Thread (process, tid),
+    Thread (process_sp, tid),
     m_thread_info_valobj_sp (thread_info_valobj_sp)
 {
 }
@@ -47,9 +47,13 @@
 {
     if (!m_reg_context_sp)
     {
-        OperatingSystem *os = m_process.GetOperatingSystem ();
-        if (os)
-            m_reg_context_sp = os->CreateRegisterContextForThread (this);
+        ProcessSP process_sp (GetProcess());
+        if (process_sp)
+        {
+            OperatingSystem *os = process_sp->GetOperatingSystem ();
+            if (os)
+                m_reg_context_sp = os->CreateRegisterContextForThread (this);
+        }
     }
     return m_reg_context_sp;
 }
@@ -77,24 +81,29 @@
 lldb::StopInfoSP
 ThreadMemory::GetPrivateStopReason ()
 {
-    const uint32_t process_stop_id = GetProcess().GetStopID();
-    if (m_thread_stop_reason_stop_id != process_stop_id ||
-        (m_actual_stop_info_sp && !m_actual_stop_info_sp->IsValid()))
+    ProcessSP process_sp (GetProcess());
+
+    if (process_sp)
     {
-        // If GetGDBProcess().SetThreadStopInfo() doesn't find a stop reason
-        // for this thread, then m_actual_stop_info_sp will not ever contain
-        // a valid stop reason and the "m_actual_stop_info_sp->IsValid() == false"
-        // check will never be able to tell us if we have the correct stop info
-        // for this thread and we will continually send qThreadStopInfo packets
-        // down to the remote GDB server, so we need to keep our own notion
-        // of the stop ID that m_actual_stop_info_sp is valid for (even if it
-        // contains nothing). We use m_thread_stop_reason_stop_id for this below.
-        m_thread_stop_reason_stop_id = process_stop_id;
-        m_actual_stop_info_sp.reset();
-        
-        OperatingSystem *os = m_process.GetOperatingSystem ();
-        if (os)
-            m_actual_stop_info_sp = os->CreateThreadStopReason (this);
+        const uint32_t process_stop_id = process_sp->GetStopID();
+        if (m_thread_stop_reason_stop_id != process_stop_id ||
+            (m_actual_stop_info_sp && !m_actual_stop_info_sp->IsValid()))
+        {
+            // If GetGDBProcess().SetThreadStopInfo() doesn't find a stop reason
+            // for this thread, then m_actual_stop_info_sp will not ever contain
+            // a valid stop reason and the "m_actual_stop_info_sp->IsValid() == false"
+            // check will never be able to tell us if we have the correct stop info
+            // for this thread and we will continually send qThreadStopInfo packets
+            // down to the remote GDB server, so we need to keep our own notion
+            // of the stop ID that m_actual_stop_info_sp is valid for (even if it
+            // contains nothing). We use m_thread_stop_reason_stop_id for this below.
+            m_thread_stop_reason_stop_id = process_stop_id;
+            m_actual_stop_info_sp.reset();
+            
+            OperatingSystem *os = process_sp->GetOperatingSystem ();
+            if (os)
+                m_actual_stop_info_sp = os->CreateThreadStopReason (this);
+        }
     }
     return m_actual_stop_info_sp;
     
diff --git a/source/Plugins/Process/Utility/ThreadMemory.h b/source/Plugins/Process/Utility/ThreadMemory.h
index 93cc255..96b40a0 100644
--- a/source/Plugins/Process/Utility/ThreadMemory.h
+++ b/source/Plugins/Process/Utility/ThreadMemory.h
@@ -17,9 +17,9 @@
 {
 public:
 
-    ThreadMemory (lldb_private::Process &process, 
-                   lldb::tid_t tid,
-                   const lldb::ValueObjectSP &thread_info_valobj_sp);
+    ThreadMemory (const lldb::ProcessSP &process_sp, 
+                  lldb::tid_t tid,
+                  const lldb::ValueObjectSP &thread_info_valobj_sp);
 
     virtual 
     ~ThreadMemory();
diff --git a/source/Plugins/Process/Utility/UnwindLLDB.cpp b/source/Plugins/Process/Utility/UnwindLLDB.cpp
index bf71b00..1ba3f0f 100644
--- a/source/Plugins/Process/Utility/UnwindLLDB.cpp
+++ b/source/Plugins/Process/Utility/UnwindLLDB.cpp
@@ -42,7 +42,8 @@
         if (!AddFirstFrame ())
             return 0;
 
-        ABI *abi = m_thread.GetProcess().GetABI().get();
+        ProcessSP process_sp (m_thread.GetProcess());
+        ABI *abi = process_sp ? process_sp->GetABI().get() : NULL;
 
         while (AddOneMoreFrame (abi))
         {
@@ -186,7 +187,8 @@
             return false;
     }
 
-    ABI *abi = m_thread.GetProcess().GetABI().get();
+    ProcessSP process_sp (m_thread.GetProcess());
+    ABI *abi = process_sp ? process_sp->GetABI().get() : NULL;
 
     while (idx >= m_frames.size() && AddOneMoreFrame (abi))
         ;
@@ -217,7 +219,8 @@
             return reg_ctx_sp;
     }
 
-    ABI *abi = m_thread.GetProcess().GetABI().get();
+    ProcessSP process_sp (m_thread.GetProcess());
+    ABI *abi = process_sp ? process_sp->GetABI().get() : NULL;
 
     while (idx >= m_frames.size())
     {
diff --git a/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp b/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp
index 5706c6d..f1cb915 100644
--- a/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp
+++ b/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.cpp
@@ -12,9 +12,10 @@
 // Other libraries and framework includes
 // Project includes
 #include "lldb/Core/ArchSpec.h"
-#include "lldb/Target/Thread.h"
+#include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
 
 #include "RegisterContextMacOSXFrameBackchain.h"
 
@@ -32,14 +33,19 @@
 {
     if (m_cursors.empty())
     {
-        const ArchSpec& target_arch = m_thread.GetProcess().GetTarget().GetArchitecture ();
-        // Frame zero should always be supplied by the thread...
-        StackFrameSP frame_sp (m_thread.GetStackFrameAtIndex (0));
-        
-        if (target_arch.GetAddressByteSize() == 8)
-            GetStackFrameData_x86_64 (frame_sp.get());
-        else
-            GetStackFrameData_i386 (frame_sp.get());
+        ExecutionContext exe_ctx (m_thread.shared_from_this());
+        Target *target = exe_ctx.GetTargetPtr();
+        if (target)
+        {
+            const ArchSpec& target_arch = target->GetArchitecture ();
+            // Frame zero should always be supplied by the thread...
+            exe_ctx.SetFrameSP (m_thread.GetStackFrameAtIndex (0));
+            
+            if (target_arch.GetAddressByteSize() == 8)
+                GetStackFrameData_x86_64 (exe_ctx);
+            else
+                GetStackFrameData_i386 (exe_ctx);
+        }
     }
     return m_cursors.size();
 }
@@ -75,10 +81,16 @@
 }
 
 size_t
-UnwindMacOSXFrameBackchain::GetStackFrameData_i386 (StackFrame *first_frame)
+UnwindMacOSXFrameBackchain::GetStackFrameData_i386 (const ExecutionContext &exe_ctx)
 {
     m_cursors.clear();
+    
+    StackFrame *first_frame = exe_ctx.GetFramePtr();
 
+    Process *process = exe_ctx.GetProcessPtr();
+    if (process == NULL)
+        return 0;
+    
     std::pair<lldb::addr_t, lldb::addr_t> fp_pc_pair;
 
     struct Frame_i386
@@ -103,7 +115,7 @@
     while (frame.fp != 0 && frame.pc != 0 && ((frame.fp & 7) == 0))
     {
         // Read both the FP and PC (8 bytes)
-        if (m_thread.GetProcess().ReadMemory (frame.fp, &frame.fp, k_frame_size, error) != k_frame_size)
+        if (process->ReadMemory (frame.fp, &frame.fp, k_frame_size, error) != k_frame_size)
             break;
         if (frame.pc >= 0x1000)
         {
@@ -137,7 +149,7 @@
                     // previous PC by dereferencing the SP
                     lldb::addr_t first_frame_sp = reg_ctx->GetSP (0);
                     // Read the real second frame return address into frame.pc
-                    if (first_frame_sp && m_thread.GetProcess().ReadMemory (first_frame_sp, &frame.pc, sizeof(frame.pc), error) == sizeof(frame.pc))
+                    if (first_frame_sp && process->ReadMemory (first_frame_sp, &frame.pc, sizeof(frame.pc), error) == sizeof(frame.pc))
                     {
                         cursor.fp = m_cursors.front().fp;
                         cursor.pc = frame.pc;           // Set the new second frame PC
@@ -163,10 +175,16 @@
 
 
 size_t
-UnwindMacOSXFrameBackchain::GetStackFrameData_x86_64 (StackFrame *first_frame)
+UnwindMacOSXFrameBackchain::GetStackFrameData_x86_64 (const ExecutionContext &exe_ctx)
 {
     m_cursors.clear();
 
+    Process *process = exe_ctx.GetProcessPtr();
+    if (process == NULL)
+        return 0;
+    
+    StackFrame *first_frame = exe_ctx.GetFramePtr();
+
     std::pair<lldb::addr_t, lldb::addr_t> fp_pc_pair;
 
     struct Frame_x86_64
@@ -190,7 +208,7 @@
     while (frame.fp != 0 && frame.pc != 0 && ((frame.fp & 7) == 0))
     {
         // Read both the FP and PC (16 bytes)
-        if (m_thread.GetProcess().ReadMemory (frame.fp, &frame.fp, k_frame_size, error) != k_frame_size)
+        if (process->ReadMemory (frame.fp, &frame.fp, k_frame_size, error) != k_frame_size)
             break;
 
         if (frame.pc >= 0x1000)
@@ -225,7 +243,7 @@
                     // previous PC by dereferencing the SP
                     lldb::addr_t first_frame_sp = reg_ctx->GetSP (0);
                     // Read the real second frame return address into frame.pc
-                    if (m_thread.GetProcess().ReadMemory (first_frame_sp, &frame.pc, sizeof(frame.pc), error) == sizeof(frame.pc))
+                    if (process->ReadMemory (first_frame_sp, &frame.pc, sizeof(frame.pc), error) == sizeof(frame.pc))
                     {
                         cursor.fp = m_cursors.front().fp;
                         cursor.pc = frame.pc;           // Set the new second frame PC
diff --git a/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.h b/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.h
index 5667aaf..2695376 100644
--- a/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.h
+++ b/source/Plugins/Process/Utility/UnwindMacOSXFrameBackchain.h
@@ -60,10 +60,10 @@
     std::vector<Cursor> m_cursors;
 
     size_t
-    GetStackFrameData_i386 (lldb_private::StackFrame *first_frame);
+    GetStackFrameData_i386 (const lldb_private::ExecutionContext &exe_ctx);
 
     size_t
-    GetStackFrameData_x86_64 (lldb_private::StackFrame *first_frame);
+    GetStackFrameData_x86_64 (const lldb_private::ExecutionContext &exe_ctx);
 
     //------------------------------------------------------------------
     // For UnwindMacOSXFrameBackchain only