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/Target/ExecutionContext.cpp b/source/Target/ExecutionContext.cpp
index 72c0410..41cf04d 100644
--- a/source/Target/ExecutionContext.cpp
+++ b/source/Target/ExecutionContext.cpp
@@ -17,36 +17,57 @@
 using namespace lldb_private;
 
 ExecutionContext::ExecutionContext() :
-    target (NULL),
-    process (NULL),
-    thread (NULL),
-    frame (NULL)
+    m_target_sp (),
+    m_process_sp (),
+    m_thread_sp (),
+    m_frame_sp ()
 {
 }
 
+ExecutionContext::ExecutionContext (const ExecutionContext &rhs) :
+    m_target_sp (rhs.m_target_sp),
+    m_process_sp(rhs.m_process_sp),
+    m_thread_sp (rhs.m_thread_sp),
+    m_frame_sp  (rhs.m_frame_sp)
+{
+}
+
+ExecutionContext &
+ExecutionContext::operator =(const ExecutionContext &rhs)
+{
+    if (this != &rhs)
+    {
+        m_target_sp  = rhs.m_target_sp;
+        m_process_sp = rhs.m_process_sp;
+        m_thread_sp  = rhs.m_thread_sp;
+        m_frame_sp   = rhs.m_frame_sp;
+    }
+    return *this;
+}
+
 ExecutionContext::ExecutionContext (Target* t, bool fill_current_process_thread_frame) :
-    target (t),
-    process (NULL),
-    thread (NULL),
-    frame (NULL)
+    m_target_sp (t),
+    m_process_sp (),
+    m_thread_sp (),
+    m_frame_sp ()
 {
     if (t && fill_current_process_thread_frame)
     {
-        process = t->GetProcessSP().get();
-        if (process)
+        m_process_sp = t->GetProcessSP();
+        if (m_process_sp)
         {
-            thread = process->GetThreadList().GetSelectedThread().get();
-            if (thread)
-                frame = thread->GetSelectedFrame().get();
+            m_thread_sp = m_process_sp->GetThreadList().GetSelectedThread();
+            if (m_thread_sp)
+                m_frame_sp = m_thread_sp->GetSelectedFrame().get();
         }
     }
 }
 
-ExecutionContext::ExecutionContext(Process* p, Thread *t, StackFrame *f) :
-    target (p ? &p->GetTarget() : NULL),
-    process (p),
-    thread (t),
-    frame (f)
+ExecutionContext::ExecutionContext(Process* process, Thread *thread, StackFrame *frame) :
+    m_target_sp (process ? &process->GetTarget() : NULL),
+    m_process_sp (process),
+    m_thread_sp (thread),
+    m_frame_sp (frame)
 {
 }
 
@@ -56,10 +77,10 @@
         exe_scope_ptr->CalculateExecutionContext (*this);
     else
     {
-        target  = NULL;
-        process = NULL;
-        thread  = NULL;
-        frame   = NULL;
+        m_target_sp.reset();
+        m_process_sp.reset();
+        m_thread_sp.reset();
+        m_frame_sp.reset();
     }
 }
 
@@ -71,41 +92,132 @@
 void
 ExecutionContext::Clear()
 {
-    target  = NULL;
-    process = NULL;
-    thread  = NULL;
-    frame   = NULL;
+    m_target_sp.reset();
+    m_process_sp.reset();
+    m_thread_sp.reset();
+    m_frame_sp.reset();
+}
+
+ExecutionContext::~ExecutionContext()
+{
 }
 
 
 RegisterContext *
 ExecutionContext::GetRegisterContext () const
 {
-    if (frame)
-        return frame->GetRegisterContext().get();
-    else if (thread)
-        return thread->GetRegisterContext().get();
+    if (m_frame_sp)
+        return m_frame_sp->GetRegisterContext().get();
+    else if (m_thread_sp)
+        return m_thread_sp->GetRegisterContext().get();
+    return NULL;
+}
+
+Target *
+ExecutionContext::GetTargetPtr () const
+{
+    if (m_target_sp)
+        return m_target_sp.get();
+    if (m_process_sp)
+        return &m_process_sp->GetTarget();
+    return NULL;
+}
+
+Process *
+ExecutionContext::GetProcessPtr () const
+{
+    if (m_process_sp)
+        return m_process_sp.get();
+    if (m_target_sp)
+        return m_target_sp->GetProcessSP().get();
     return NULL;
 }
 
 ExecutionContextScope *
 ExecutionContext::GetBestExecutionContextScope () const
 {
-    if (frame)
-        return frame;
-    if (thread)
-        return thread;
-    if (process)
-        return process;
-    return target;
+    if (m_frame_sp)
+        return m_frame_sp.get();
+    if (m_thread_sp)
+        return m_thread_sp.get();
+    if (m_process_sp)
+        return m_process_sp.get();
+    return m_target_sp.get();
 }
 
-Process *
-ExecutionContext::GetProcess () const
+Target &
+ExecutionContext::GetTargetRef () const
 {
-    if (process)
-        return process;
-    if (target)
-        return target->GetProcessSP().get();
-    return NULL;
+    assert (m_target_sp.get());
+    return *m_target_sp;
 }
+
+Process &
+ExecutionContext::GetProcessRef () const
+{
+    assert (m_process_sp.get());
+    return *m_process_sp;
+}
+
+Thread &
+ExecutionContext::GetThreadRef () const
+{
+    assert (m_thread_sp.get());
+    return *m_thread_sp;
+}
+
+StackFrame &
+ExecutionContext::GetFrameRef () const
+{
+    assert (m_frame_sp.get());
+    return *m_frame_sp;
+}
+
+void
+ExecutionContext::SetTargetSP (const lldb::TargetSP &target_sp)
+{
+    m_target_sp = target_sp;
+}
+
+void
+ExecutionContext::SetProcessSP (const lldb::ProcessSP &process_sp)
+{
+    m_process_sp = process_sp;
+}
+
+void
+ExecutionContext::SetThreadSP (const lldb::ThreadSP &thread_sp)
+{
+    m_thread_sp = thread_sp;
+}
+
+void
+ExecutionContext::SetFrameSP (const lldb::StackFrameSP &frame_sp)
+{
+    m_frame_sp = frame_sp;
+}
+
+void
+ExecutionContext::SetTargetPtr (Target* target)
+{
+    m_target_sp = target;
+}
+
+void
+ExecutionContext::SetProcessPtr (Process *process)
+{
+    m_process_sp = process;
+}
+
+void
+ExecutionContext::SetThreadPtr (Thread *thread)
+{
+    m_thread_sp = thread;
+}
+
+void
+ExecutionContext::SetFramePtr (StackFrame *frame)
+{
+    m_frame_sp = frame;
+}
+