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/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