[Lldb-commits] [lldb] r149231 - in /lldb/trunk: include/lldb/ include/lldb/API/ include/lldb/Core/ include/lldb/Target/ source/API/ source/Core/ source/Target/

Greg Clayton gclayton at apple.com
Sun Jan 29 23:41:32 PST 2012


Author: gclayton
Date: Mon Jan 30 01:41:31 2012
New Revision: 149231

URL: http://llvm.org/viewvc/llvm-project?rev=149231&view=rev
Log:
SBFrame is now threadsafe using some extra tricks. One issue is that stack
frames might go away (the object itself, not the actual logical frame) when
we are single stepping due to the way we currently sometimes end up flushing
frames when stepping in/out/over. They later will come back to life 
represented by another object yet they have the same StackID. Now when you get
a lldb::SBFrame object, it will track the frame it is initialized with until 
the thread goes away or the StackID no longer exists in the stack for the 
thread it was created on. It uses a weak_ptr to both the frame and thread and
also stores the StackID. These three items allow us to determine when the
stack frame object has gone away (the weak_ptr will be NULL) and allows us to
find the correct frame again. In our test suite we had such cases where we
were just getting lucky when something like this happened:

1 - stop at breakpoint
2 - get first frame in thread where we stopped
3 - run an expression that causes the program to JIT and run code
4 - run more expressions on the frame from step 2 which was very very luckily
    still around inside a shared pointer, yet, not part of the current 
    thread (a new stack frame object had appeared with the same stack ID and
    depth). 
    
We now avoid all such issues and properly keep up to date, or we start 
returning errors when the frame doesn't exist and always responds with
invalid answers.

Also fixed the UserSettingsController  (not going to rewrite this just yet)
so that it doesn't crash on shutdown. Using weak_ptr's came in real handy to
track when the master controller has already gone away and this allowed me to
pull out the previous NotifyOwnerIsShuttingDown() patch as it is no longer 
needed.



Modified:
    lldb/trunk/include/lldb/API/SBFrame.h
    lldb/trunk/include/lldb/API/SBProcess.h
    lldb/trunk/include/lldb/API/SBTarget.h
    lldb/trunk/include/lldb/Core/Debugger.h
    lldb/trunk/include/lldb/Core/UserSettingsController.h
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/include/lldb/Target/Thread.h
    lldb/trunk/include/lldb/lldb-forward.h
    lldb/trunk/source/API/SBAddress.cpp
    lldb/trunk/source/API/SBCommandInterpreter.cpp
    lldb/trunk/source/API/SBDebugger.cpp
    lldb/trunk/source/API/SBFrame.cpp
    lldb/trunk/source/API/SBFunction.cpp
    lldb/trunk/source/API/SBInstruction.cpp
    lldb/trunk/source/API/SBModule.cpp
    lldb/trunk/source/API/SBProcess.cpp
    lldb/trunk/source/API/SBSourceManager.cpp
    lldb/trunk/source/API/SBSymbol.cpp
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/source/API/SBThread.cpp
    lldb/trunk/source/API/SBValue.cpp
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Core/UserSettingsController.cpp
    lldb/trunk/source/Target/Process.cpp
    lldb/trunk/source/Target/Target.cpp
    lldb/trunk/source/Target/Thread.cpp

Modified: lldb/trunk/include/lldb/API/SBFrame.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFrame.h?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBFrame.h (original)
+++ lldb/trunk/include/lldb/API/SBFrame.h Mon Jan 30 01:41:31 2012
@@ -19,6 +19,7 @@
 class SBFrame
 {
 public:
+    typedef SHARED_PTR(lldb_private::StackFrameImpl) StackFrameImplSP;
     SBFrame ();
 
     SBFrame (const lldb::SBFrame &rhs);
@@ -207,24 +208,13 @@
     friend class lldb_private::ScriptInterpreterPython;
 #endif
 
-#ifndef SWIG
-
-    lldb_private::StackFrame *
-    operator->() const;
-
-    // Mimic shared pointer...
-    lldb_private::StackFrame *
-    get() const;
-
-    lldb::StackFrameSP &
-    get_sp();
-    
-#endif
+    lldb::StackFrameSP
+    GetFrameSP() const;
 
     void
-    SetFrame (const lldb::StackFrameSP &lldb_object_sp);
+    SetFrameSP (const lldb::StackFrameSP &lldb_object_sp);
 
-    lldb::StackFrameSP m_opaque_sp;
+    StackFrameImplSP m_opaque_sp;
 };
 
 } // namespace lldb

Modified: lldb/trunk/include/lldb/API/SBProcess.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBProcess.h?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBProcess.h (original)
+++ lldb/trunk/include/lldb/API/SBProcess.h Mon Jan 30 01:41:31 2012
@@ -197,22 +197,13 @@
     friend class SBThread;
     friend class SBValue;
 
-#ifndef SWIG
-
-    lldb_private::Process *
-    operator->() const;
-
-    // Mimic shared pointer...
-    lldb_private::Process *
-    get() const;
-
-#endif
-
-
     SBProcess (const lldb::ProcessSP &process_sp);
 
+    lldb::ProcessSP
+    GetSP() const;
+    
     void
-    SetProcess (const lldb::ProcessSP &process_sp);
+    SetSP (const lldb::ProcessSP &process_sp);
 
     lldb::ProcessSP m_opaque_sp;
 };

Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Mon Jan 30 01:41:31 2012
@@ -540,17 +540,12 @@
 
     SBTarget (const lldb::TargetSP& target_sp);
 
-    void
-    reset (const lldb::TargetSP& target_sp);
-
-    lldb_private::Target *
-    operator ->() const;
+    lldb::TargetSP
+    GetSP () const;
 
-    lldb_private::Target *
-    get() const;
+    void
+    SetSP (const lldb::TargetSP& target_sp);
 
-    const lldb::TargetSP &
-    get_sp () const;
 
 private:
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Core/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Debugger.h (original)
+++ lldb/trunk/include/lldb/Core/Debugger.h Mon Jan 30 01:41:31 2012
@@ -52,7 +52,7 @@
     };
     
 
-    DebuggerInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL);
+    DebuggerInstanceSettings (const lldb::UserSettingsControllerSP &m_owner_sp, bool live_instance = true, const char *name = NULL);
 
     DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs);
 

Modified: lldb/trunk/include/lldb/Core/UserSettingsController.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/UserSettingsController.h?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/UserSettingsController.h (original)
+++ lldb/trunk/include/lldb/Core/UserSettingsController.h Mon Jan 30 01:41:31 2012
@@ -49,7 +49,8 @@
     std::vector<SettingEntry> instance_settings;
 } UserSettingDefinition;
 
-class UserSettingsController
+class UserSettingsController : 
+    public std::tr1::enable_shared_from_this<UserSettingsController>
 {
 public:
 
@@ -130,6 +131,11 @@
     void
     RenameInstanceSettings (const char *old_name, const char *new_name);
 
+    void
+    SetDefaultInstanceSettings (const lldb::InstanceSettingsSP &instance_settings_sp)
+    {
+        m_default_settings = instance_settings_sp;
+    }
     // -------------------------------------------------------------------------
     // Public static methods
     // -------------------------------------------------------------------------
@@ -387,7 +393,7 @@
 {
 public:
 
-    InstanceSettings (UserSettingsController &owner, const char *instance_name, bool live_instance = true);
+    InstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, const char *instance_name, bool live_instance = true);
 
     InstanceSettings (const InstanceSettings &rhs);
 
@@ -400,9 +406,6 @@
     // Begin Pure Virtual Functions
 
     virtual void
-    NotifyOwnerIsShuttingDown ();
-
-    virtual void
     UpdateInstanceSettingsVariable (const ConstString &var_name,
                                     const char *index_value,
                                     const char *value,
@@ -442,8 +445,7 @@
 
 protected:
 
-    UserSettingsController &m_owner;
-    bool m_owner_is_live;
+    lldb::UserSettingsControllerWP m_owner_wp;
     ConstString m_instance_name;
 };
 

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Mon Jan 30 01:41:31 2012
@@ -54,7 +54,7 @@
 {
 public:
 
-    ProcessInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL);
+    ProcessInstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, bool live_instance = true, const char *name = NULL);
   
     ProcessInstanceSettings (const ProcessInstanceSettings &rhs);
 

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Mon Jan 30 01:41:31 2012
@@ -43,7 +43,7 @@
 public:
     static OptionEnumValueElement g_dynamic_value_types[];
 
-    TargetInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL);
+    TargetInstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, bool live_instance = true, const char *name = NULL);
 
     TargetInstanceSettings (const TargetInstanceSettings &rhs);
 

Modified: lldb/trunk/include/lldb/Target/Thread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Thread.h (original)
+++ lldb/trunk/include/lldb/Target/Thread.h Mon Jan 30 01:41:31 2012
@@ -25,7 +25,7 @@
 {
 public:
 
-    ThreadInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL);
+    ThreadInstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, bool live_instance = true, const char *name = NULL);
   
     ThreadInstanceSettings (const ThreadInstanceSettings &rhs);
 

Modified: lldb/trunk/include/lldb/lldb-forward.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-forward.h (original)
+++ lldb/trunk/include/lldb/lldb-forward.h Mon Jan 30 01:41:31 2012
@@ -142,6 +142,7 @@
 class   SourceManager;
 class   SourceManagerImpl;
 class   StackFrame;
+class   StackFrameImpl;
 class   StackFrameList;
 class   StackID;
 class   StopInfo;
@@ -293,6 +294,7 @@
     typedef std::tr1::shared_ptr<lldb_private::TypeImpl> TypeImplSP;
     typedef std::tr1::shared_ptr<lldb_private::FuncUnwinders> FuncUnwindersSP;
     typedef std::tr1::shared_ptr<lldb_private::UserSettingsController> UserSettingsControllerSP;
+    typedef std::tr1::weak_ptr<lldb_private::UserSettingsController> UserSettingsControllerWP;
     typedef std::tr1::shared_ptr<lldb_private::UnwindPlan> UnwindPlanSP;
     typedef lldb_private::SharingPtr<lldb_private::ValueObject> ValueObjectSP;
     typedef std::tr1::shared_ptr<lldb_private::Value> ValueSP;

Modified: lldb/trunk/source/API/SBAddress.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBAddress.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/API/SBAddress.cpp (original)
+++ lldb/trunk/source/API/SBAddress.cpp Mon Jan 30 01:41:31 2012
@@ -170,18 +170,19 @@
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
     lldb::addr_t addr = LLDB_INVALID_ADDRESS;
+    TargetSP target_sp (target.GetSP());
     if (m_opaque_ap.get())
     {
-        Mutex::Locker api_locker (target->GetAPIMutex());
-        addr = m_opaque_ap->GetAddress().GetLoadAddress (target.get());
+        Mutex::Locker api_locker (target_sp->GetAPIMutex());
+        addr = m_opaque_ap->GetAddress().GetLoadAddress (target_sp.get());
     }
     
     if (log)
     {
         if (addr == LLDB_INVALID_ADDRESS)
-            log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => LLDB_INVALID_ADDRESS", target.get());
+            log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => LLDB_INVALID_ADDRESS", target_sp.get());
         else
-            log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => 0x%llx", target.get(), addr);
+            log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => 0x%llx", target_sp.get(), addr);
     }
 
     return addr;

Modified: lldb/trunk/source/API/SBCommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandInterpreter.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/API/SBCommandInterpreter.cpp (original)
+++ lldb/trunk/source/API/SBCommandInterpreter.cpp Mon Jan 30 01:41:31 2012
@@ -188,24 +188,26 @@
 SBProcess
 SBCommandInterpreter::GetProcess ()
 {
-    SBProcess process;
+    SBProcess sb_process;
+    ProcessSP process_sp;
     if (m_opaque_ptr)
     {
         TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
         if (target_sp)
         {
             Mutex::Locker api_locker(target_sp->GetAPIMutex());
-            process.SetProcess(target_sp->GetProcessSP());
+            process_sp = target_sp->GetProcessSP();
+            sb_process.SetSP(process_sp);
         }
     }
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
     if (log)
         log->Printf ("SBCommandInterpreter(%p)::GetProcess () => SBProcess(%p)", 
-                     m_opaque_ptr, process.get());
+                     m_opaque_ptr, process_sp.get());
 
     
-    return process;
+    return sb_process;
 }
 
 CommandInterpreter *

Modified: lldb/trunk/source/API/SBDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/API/SBDebugger.cpp (original)
+++ lldb/trunk/source/API/SBDebugger.cpp Mon Jan 30 01:41:31 2012
@@ -302,11 +302,12 @@
         if (m_opaque_sp->GetAsyncExecution() == false)
         {
             SBProcess process(GetCommandInterpreter().GetProcess ());
-            if (process.IsValid())
+            ProcessSP process_sp (process.GetSP());
+            if (process_sp)
             {
                 EventSP event_sp;
                 Listener &lldb_listener = m_opaque_sp->GetListener();
-                while (lldb_listener.GetNextEventForBroadcaster (process.get(), event_sp))
+                while (lldb_listener.GetNextEventForBroadcaster (process_sp.get(), event_sp))
                 {
                     SBEvent event(event_sp);
                     HandleProcessEvent (process, event, GetOutputFileHandle(), GetErrorFileHandle());
@@ -338,11 +339,15 @@
     if (!process.IsValid())
         return;
 
+    TargetSP target_sp (process.GetTarget().GetSP());
+    if (!target_sp)
+        return;
+
     const uint32_t event_type = event.GetType();
     char stdio_buffer[1024];
     size_t len;
 
-    Mutex::Locker api_locker (process.GetTarget()->GetAPIMutex());
+    Mutex::Locker api_locker (target_sp->GetAPIMutex());
     
     if (event_type & (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged))
     {
@@ -474,6 +479,7 @@
                           lldb::SBError& sb_error)
 {
     SBTarget sb_target;
+    TargetSP target_sp;
     if (m_opaque_sp)
     {
         sb_error.Clear();
@@ -481,7 +487,6 @@
         OptionGroupPlatform platform_options (false);
         platform_options.SetPlatformName (platform_name);
         
-        TargetSP target_sp;
         sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, 
                                                                     filename_spec, 
                                                                     target_triple, 
@@ -490,7 +495,7 @@
                                                                     target_sp);
     
         if (sb_error.Success())
-            sb_target.reset (target_sp);
+            sb_target.SetSP (target_sp);
     }
     else
     {
@@ -507,7 +512,7 @@
                      platform_name,
                      add_dependent_modules,
                      sb_error.GetCString(),
-                     sb_target.get());
+                     target_sp.get());
     }
     
     return sb_target;
@@ -517,7 +522,8 @@
 SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename,
                                                  const char *target_triple)
 {
-    SBTarget target;
+    SBTarget sb_target;
+    TargetSP target_sp;
     if (m_opaque_sp)
     {
         FileSpec file_spec (filename, true);
@@ -529,17 +535,17 @@
                                                                 add_dependent_modules, 
                                                                 NULL,
                                                                 target_sp));
-        target.reset (target_sp);
+        sb_target.SetSP (target_sp);
     }
     
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
     {
         log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndTargetTriple (filename=\"%s\", triple=%s) => SBTarget(%p)", 
-                     m_opaque_sp.get(), filename, target_triple, target.get());
+                     m_opaque_sp.get(), filename, target_triple, target_sp.get());
     }
 
-    return target;
+    return sb_target;
 }
 
 SBTarget
@@ -547,11 +553,11 @@
 {
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
-    SBTarget target;
+    SBTarget sb_target;
+    TargetSP target_sp;
     if (m_opaque_sp)
     {
         FileSpec file (filename, true);
-        TargetSP target_sp;
         Error error;
         const bool add_dependent_modules = true;
 
@@ -565,28 +571,28 @@
         if (error.Success())
         {
             m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
-            target.reset(target_sp);
+            sb_target.SetSP (target_sp);
         }
     }
 
     if (log)
     {
         log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", arch=%s) => SBTarget(%p)", 
-                     m_opaque_sp.get(), filename, arch_cstr, target.get());
+                     m_opaque_sp.get(), filename, arch_cstr, target_sp.get());
     }
 
-    return target;
+    return sb_target;
 }
 
 SBTarget
 SBDebugger::CreateTarget (const char *filename)
 {
-    SBTarget target;
+    SBTarget sb_target;
+    TargetSP target_sp;
     if (m_opaque_sp)
     {
         FileSpec file (filename, true);
         ArchSpec arch = Target::GetDefaultArchitecture ();
-        TargetSP target_sp;
         Error error;
         const bool add_dependent_modules = true;
 
@@ -600,29 +606,33 @@
         if (error.Success())
         {
             m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
-            target.reset (target_sp);
+            sb_target.SetSP (target_sp);
         }
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
     {
         log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)", 
-                     m_opaque_sp.get(), filename, target.get());
+                     m_opaque_sp.get(), filename, target_sp.get());
     }
-    return target;
+    return sb_target;
 }
 
 bool
 SBDebugger::DeleteTarget (lldb::SBTarget &target)
 {
     bool result = false;
-    if (m_opaque_sp && target.IsValid())
+    if (m_opaque_sp)
     {
-        // No need to lock, the target list is thread safe
-        result = m_opaque_sp->GetTargetList().DeleteTarget (target.m_opaque_sp);
-        target->Destroy();
-        target.Clear();
-        ModuleList::RemoveOrphanSharedModules();
+        TargetSP target_sp(target.GetSP());
+        if (target_sp)
+        {
+            // No need to lock, the target list is thread safe
+            result = m_opaque_sp->GetTargetList().DeleteTarget (target_sp);
+            target_sp->Destroy();
+            target.Clear();
+            ModuleList::RemoveOrphanSharedModules();
+        }
     }
 
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
@@ -640,7 +650,7 @@
     if (m_opaque_sp)
     {
         // No need to lock, the target list is thread safe
-        sb_target.reset(m_opaque_sp->GetTargetList().GetTargetAtIndex (idx));
+        sb_target.SetSP (m_opaque_sp->GetTargetList().GetTargetAtIndex (idx));
     }
     return sb_target;
 }
@@ -652,7 +662,7 @@
     if (m_opaque_sp)
     {
         // No need to lock, the target list is thread safe
-        sb_target.reset(m_opaque_sp->GetTargetList().FindTargetWithProcessID (pid));
+        sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcessID (pid));
     }
     return sb_target;
 }
@@ -666,7 +676,7 @@
         // No need to lock, the target list is thread safe
         ArchSpec arch (arch_name, m_opaque_sp->GetPlatformList().GetSelectedPlatform().get());
         TargetSP target_sp (m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture (FileSpec(filename, false), arch_name ? &arch : NULL));
-        sb_target.reset(target_sp);
+        sb_target.SetSP (target_sp);
     }
     return sb_target;
 }
@@ -678,7 +688,7 @@
     if (m_opaque_sp)
     {
         // No need to lock, the target list is thread safe
-        sb_target.reset(m_opaque_sp->GetTargetList().FindTargetWithProcess (process_sp.get()));
+        sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcess (process_sp.get()));
     }
     return sb_target;
 }
@@ -701,10 +711,12 @@
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
     SBTarget sb_target;
+    TargetSP target_sp;
     if (m_opaque_sp)
     {
         // No need to lock, the target list is thread safe
-        sb_target.reset(m_opaque_sp->GetTargetList().GetSelectedTarget ());
+        target_sp = m_opaque_sp->GetTargetList().GetSelectedTarget ();
+        sb_target.SetSP (target_sp);
     }
 
     if (log)
@@ -712,7 +724,7 @@
         SBStream sstr;
         sb_target.GetDescription (sstr, eDescriptionLevelBrief);
         log->Printf ("SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s", m_opaque_sp.get(),
-                     sb_target.get(), sstr.GetData());
+                     target_sp.get(), sstr.GetData());
     }
 
     return sb_target;
@@ -723,16 +735,17 @@
 {
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
+    TargetSP target_sp (sb_target.GetSP());
     if (m_opaque_sp)
     {
-        m_opaque_sp->GetTargetList().SetSelectedTarget (sb_target.get());
+        m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
     }
     if (log)
     {
         SBStream sstr;
         sb_target.GetDescription (sstr, eDescriptionLevelBrief);
         log->Printf ("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s", m_opaque_sp.get(),
-                     sb_target.get(), sstr.GetData());
+                     target_sp.get(), sstr.GetData());
     }
 }
 

Modified: lldb/trunk/source/API/SBFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFrame.cpp (original)
+++ lldb/trunk/source/API/SBFrame.cpp Mon Jan 30 01:41:31 2012
@@ -32,6 +32,7 @@
 #include "lldb/Target/Process.h"
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Target/StackFrame.h"
+#include "lldb/Target/StackID.h"
 #include "lldb/Target/Thread.h"
 
 #include "lldb/API/SBDebugger.h"
@@ -41,16 +42,91 @@
 #include "lldb/API/SBSymbolContext.h"
 #include "lldb/API/SBThread.h"
 
+namespace lldb_private {
+
+    class StackFrameImpl
+    {
+    public:
+        StackFrameImpl (const lldb::StackFrameSP &frame_sp) :
+            m_frame_wp (frame_sp),
+            m_thread_wp (),
+            m_stack_id ()
+        {
+            if (frame_sp)
+            {
+                m_thread_wp = frame_sp->GetThread().shared_from_this();
+                m_stack_id = frame_sp->GetStackID();
+            }
+        }
+        
+        ~StackFrameImpl()
+        {
+        }
+
+        lldb::StackFrameSP
+        GetFrameSP ()
+        {
+            lldb::StackFrameSP frame_sp;
+            // We have a weak pointer to our thread, which might
+            // be NULL'ed out if the thread went away, so first
+            // make sure our thread is still alive.
+            lldb::ThreadSP thread_sp (m_thread_wp.lock());
+            if (thread_sp)
+            {
+                // Our thread is still here, check if our frame
+                // is still alive as well.
+                frame_sp = m_frame_wp.lock();
+                if (frame_sp)
+                {
+                    // Our frame is still alive, make sure that our thread
+                    // still has this exact frame...
+                    lldb::StackFrameSP tmp_frame_sp (thread_sp->GetStackFrameAtIndex (frame_sp->GetFrameIndex()));
+                    if (tmp_frame_sp.get() == frame_sp.get())
+                        return frame_sp;
+                }
+                // The original stack frame might have gone away,
+                // we need to check for the stac
+                frame_sp = thread_sp->GetFrameWithStackID (m_stack_id);
+                m_frame_wp = frame_sp;
+            }
+            return frame_sp;
+        }
+
+        void
+        SetFrameSP (const lldb::StackFrameSP &frame_sp)
+        {
+            if (frame_sp)
+            {
+                m_frame_wp = frame_sp;
+                m_thread_wp = frame_sp->GetThread().shared_from_this();
+                m_stack_id = frame_sp->GetStackID();
+            }
+            else
+            {
+                m_frame_wp.reset();
+                m_thread_wp.reset();
+                m_stack_id.Clear();
+            }
+        }
+
+    protected:
+        lldb::StackFrameWP m_frame_wp;
+        lldb::ThreadWP m_thread_wp;
+        StackID m_stack_id;
+    };
+} // namespace lldb_private
+
 using namespace lldb;
 using namespace lldb_private;
 
+
 SBFrame::SBFrame () :
     m_opaque_sp ()
 {
 }
 
 SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) :
-    m_opaque_sp (lldb_object_sp)
+    m_opaque_sp (new StackFrameImpl (lldb_object_sp))
 {
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
@@ -59,7 +135,7 @@
         SBStream sstr;
         GetDescription (sstr);
         log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s", 
-                     lldb_object_sp.get(), m_opaque_sp.get(), sstr.GetData());
+                     lldb_object_sp.get(), lldb_object_sp.get(), sstr.GetData());
                      
     }
 }
@@ -81,27 +157,45 @@
 {
 }
 
+StackFrameSP
+SBFrame::GetFrameSP() const
+{
+    StackFrameImplSP impl_sp (m_opaque_sp);
+    StackFrameSP frame_sp;
+    if (impl_sp)
+        frame_sp = impl_sp->GetFrameSP();
+    return frame_sp;
+}
 
 void
-SBFrame::SetFrame (const StackFrameSP &lldb_object_sp)
+SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp)
 {
-    void *old_ptr = m_opaque_sp.get();
-    m_opaque_sp = lldb_object_sp;
-    LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
-
-    if (log)
+    if (lldb_object_sp)
     {
-        log->Printf ("SBFrame(%p)::SetFrame(sp=%p) := SBFrame(%p)", 
-                     old_ptr, lldb_object_sp.get(), m_opaque_sp.get());
+        if (m_opaque_sp)
+        {
+            StackFrameImplSP impl_sp (m_opaque_sp);
+            if (impl_sp)
+                impl_sp->SetFrameSP (lldb_object_sp);
+        }
+        else
+        {
+            m_opaque_sp = StackFrameImplSP (new StackFrameImpl(lldb_object_sp));
+        }
+    }
+    else
+    {
+        m_opaque_sp.reset();
     }
-
 }
 
-
 bool
 SBFrame::IsValid() const
 {
-    return (m_opaque_sp.get() != NULL);
+    StackFrameImplSP impl_sp (m_opaque_sp);
+    if (impl_sp)
+        return (impl_sp->GetFrameSP().get() != NULL);
+    return false;
 }
 
 SBSymbolContext
@@ -109,16 +203,17 @@
 {
 
     SBSymbolContext sb_sym_ctx;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        sb_sym_ctx.SetSymbolContext(&m_opaque_sp->GetSymbolContext (resolve_scope));
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        sb_sym_ctx.SetSymbolContext(&frame_sp->GetSymbolContext (resolve_scope));
     }
 
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)", 
-                     m_opaque_sp.get(), resolve_scope, sb_sym_ctx.get());
+                     frame_sp.get(), resolve_scope, sb_sym_ctx.get());
 
     return sb_sym_ctx;
 }
@@ -127,16 +222,17 @@
 SBFrame::GetModule () const
 {
     SBModule sb_module;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        *sb_module = m_opaque_sp->GetSymbolContext (eSymbolContextModule).module_sp;
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        *sb_module = frame_sp->GetSymbolContext (eSymbolContextModule).module_sp;
     }
 
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)", 
-                     m_opaque_sp.get(), sb_module.get());
+                     frame_sp.get(), sb_module.get());
 
     return sb_module;
 }
@@ -145,15 +241,16 @@
 SBFrame::GetCompileUnit () const
 {
     SBCompileUnit sb_comp_unit;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        sb_comp_unit.reset (m_opaque_sp->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        sb_comp_unit.reset (frame_sp->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetModule () => SBCompileUnit(%p)", 
-                     m_opaque_sp.get(), sb_comp_unit.get());
+                     frame_sp.get(), sb_comp_unit.get());
 
     return sb_comp_unit;
 }
@@ -162,15 +259,16 @@
 SBFrame::GetFunction () const
 {
     SBFunction sb_function;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        sb_function.reset(m_opaque_sp->GetSymbolContext (eSymbolContextFunction).function);
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        sb_function.reset(frame_sp->GetSymbolContext (eSymbolContextFunction).function);
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)", 
-                     m_opaque_sp.get(), sb_function.get());
+                     frame_sp.get(), sb_function.get());
 
     return sb_function;
 }
@@ -179,15 +277,16 @@
 SBFrame::GetSymbol () const
 {
     SBSymbol sb_symbol;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        sb_symbol.reset(m_opaque_sp->GetSymbolContext (eSymbolContextSymbol).symbol);
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        sb_symbol.reset(frame_sp->GetSymbolContext (eSymbolContextSymbol).symbol);
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)", 
-                     m_opaque_sp.get(), sb_symbol.get());
+                     frame_sp.get(), sb_symbol.get());
     return sb_symbol;
 }
 
@@ -195,15 +294,16 @@
 SBFrame::GetBlock () const
 {
     SBBlock sb_block;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        sb_block.reset (m_opaque_sp->GetSymbolContext (eSymbolContextBlock).block);
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        sb_block.reset (frame_sp->GetSymbolContext (eSymbolContextBlock).block);
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)", 
-                     m_opaque_sp.get(), sb_block.get());
+                     frame_sp.get(), sb_block.get());
     return sb_block;
 }
 
@@ -211,15 +311,16 @@
 SBFrame::GetFrameBlock () const
 {
     SBBlock sb_block;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        sb_block.reset(m_opaque_sp->GetFrameBlock ());
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        sb_block.reset(frame_sp->GetFrameBlock ());
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)", 
-                     m_opaque_sp.get(), sb_block.get());
+                     frame_sp.get(), sb_block.get());
     return sb_block;    
 }
 
@@ -227,27 +328,33 @@
 SBFrame::GetLineEntry () const
 {
     SBLineEntry sb_line_entry;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        sb_line_entry.SetLineEntry (m_opaque_sp->GetSymbolContext (eSymbolContextLineEntry).line_entry);
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        sb_line_entry.SetLineEntry (frame_sp->GetSymbolContext (eSymbolContextLineEntry).line_entry);
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)", 
-                     m_opaque_sp.get(), sb_line_entry.get());
+                     frame_sp.get(), sb_line_entry.get());
     return sb_line_entry;
 }
 
 uint32_t
 SBFrame::GetFrameID () const
 {
-    uint32_t frame_idx = m_opaque_sp ? m_opaque_sp->GetFrameIndex () : UINT32_MAX;
+    uint32_t frame_idx = UINT32_MAX;
+    
+    
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
+        frame_idx = frame_sp->GetFrameIndex ();
     
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetFrameID () => %u", 
-                     m_opaque_sp.get(), frame_idx);
+                     frame_sp.get(), frame_idx);
     return frame_idx;
 }
 
@@ -255,15 +362,16 @@
 SBFrame::GetPC () const
 {
     addr_t addr = LLDB_INVALID_ADDRESS;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        addr = m_opaque_sp->GetFrameCodeAddress().GetOpcodeLoadAddress (&m_opaque_sp->GetThread().GetProcess().GetTarget());
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        addr = frame_sp->GetFrameCodeAddress().GetOpcodeLoadAddress (&frame_sp->GetThread().GetProcess().GetTarget());
     }
 
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
-        log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", m_opaque_sp.get(), addr);
+        log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", frame_sp.get(), addr);
 
     return addr;
 }
@@ -272,16 +380,17 @@
 SBFrame::SetPC (addr_t new_pc)
 {
     bool ret_val = false;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        ret_val = m_opaque_sp->GetRegisterContext()->SetPC (new_pc);
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        ret_val = frame_sp->GetRegisterContext()->SetPC (new_pc);
     }
 
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%llx) => %i", 
-                     m_opaque_sp.get(), new_pc, ret_val);
+                     frame_sp.get(), new_pc, ret_val);
 
     return ret_val;
 }
@@ -290,14 +399,15 @@
 SBFrame::GetSP () const
 {
     addr_t addr = LLDB_INVALID_ADDRESS;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        addr = m_opaque_sp->GetRegisterContext()->GetSP();
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        addr = frame_sp->GetRegisterContext()->GetSP();
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
-        log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", m_opaque_sp.get(), addr);
+        log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", frame_sp.get(), addr);
 
     return addr;
 }
@@ -307,15 +417,16 @@
 SBFrame::GetFP () const
 {
     addr_t addr = LLDB_INVALID_ADDRESS;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        addr = m_opaque_sp->GetRegisterContext()->GetFP();
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        addr = frame_sp->GetRegisterContext()->GetFP();
     }
 
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
-        log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", m_opaque_sp.get(), addr);
+        log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", frame_sp.get(), addr);
     return addr;
 }
 
@@ -324,14 +435,15 @@
 SBFrame::GetPCAddress () const
 {
     SBAddress sb_addr;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        sb_addr.SetAddress (&m_opaque_sp->GetFrameCodeAddress());
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        sb_addr.SetAddress (&frame_sp->GetFrameCodeAddress());
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
-        log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", m_opaque_sp.get(), sb_addr.get());
+        log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame_sp.get(), sb_addr.get());
     return sb_addr;
 }
 
@@ -345,9 +457,10 @@
 SBFrame::FindVariable (const char *name)
 {
     SBValue value;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        lldb::DynamicValueType  use_dynamic = m_opaque_sp->CalculateTarget()->GetPreferDynamicValue();
+        lldb::DynamicValueType  use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
         value = FindVariable (name, use_dynamic);
     }
     return value;
@@ -358,12 +471,12 @@
 {
     VariableSP var_sp;
     SBValue sb_value;
-    
-    if (m_opaque_sp && name && name[0])
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp && name && name[0])
     {
         VariableList variable_list;
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        SymbolContext sc (m_opaque_sp->GetSymbolContext (eSymbolContextBlock));
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock));
 
         if (sc.block)
         {
@@ -381,14 +494,14 @@
         }
 
         if (var_sp)
-            *sb_value = ValueObjectSP (m_opaque_sp->GetValueObjectForFrameVariable(var_sp, use_dynamic));
+            *sb_value = ValueObjectSP (frame_sp->GetValueObjectForFrameVariable(var_sp, use_dynamic));
         
     }
     
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)", 
-                     m_opaque_sp.get(), name, sb_value.get());
+                     frame_sp.get(), name, sb_value.get());
 
     return sb_value;
 }
@@ -397,9 +510,10 @@
 SBFrame::FindValue (const char *name, ValueType value_type)
 {
     SBValue value;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        lldb::DynamicValueType use_dynamic = m_opaque_sp->CalculateTarget()->GetPreferDynamicValue();
+        lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
         value = FindValue (name, value_type, use_dynamic);
     }
     return value;
@@ -409,9 +523,10 @@
 SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic)
 {
     SBValue sb_value;
-    if (m_opaque_sp && name && name[0])
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp && name && name[0])
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
     
         switch (value_type)
         {
@@ -420,9 +535,9 @@
         case eValueTypeVariableArgument:    // function argument variables
         case eValueTypeVariableLocal:       // function local variables
             {
-                VariableList *variable_list = m_opaque_sp->GetVariableList(true);
+                VariableList *variable_list = frame_sp->GetVariableList(true);
 
-                SymbolContext sc (m_opaque_sp->GetSymbolContext (eSymbolContextBlock));
+                SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock));
 
                 const bool can_create = true;
                 const bool get_parent_variables = true;
@@ -442,7 +557,7 @@
                             variable_sp->GetScope() == value_type &&
                             variable_sp->GetName() == const_name)
                         {
-                            *sb_value = ValueObjectSP (m_opaque_sp->GetValueObjectForFrameVariable(variable_sp, 
+                            *sb_value = ValueObjectSP (frame_sp->GetValueObjectForFrameVariable(variable_sp, 
                                                                                                    use_dynamic));
                             break;
                         }
@@ -453,7 +568,7 @@
 
         case eValueTypeRegister:            // stack frame register value
             {
-                RegisterContextSP reg_ctx (m_opaque_sp->GetRegisterContext());
+                RegisterContextSP reg_ctx (frame_sp->GetRegisterContext());
                 if (reg_ctx)
                 {
                     const uint32_t num_regs = reg_ctx->GetRegisterCount();
@@ -464,7 +579,7 @@
                             ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
                              (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
                         {
-                            *sb_value = ValueObjectRegister::Create (m_opaque_sp.get(), reg_ctx, reg_idx);
+                            *sb_value = ValueObjectRegister::Create (frame_sp.get(), reg_ctx, reg_idx);
                         }
                     }
                 }
@@ -473,7 +588,7 @@
 
         case eValueTypeRegisterSet:         // A collection of stack frame register values
             {
-                RegisterContextSP reg_ctx (m_opaque_sp->GetRegisterContext());
+                RegisterContextSP reg_ctx (frame_sp->GetRegisterContext());
                 if (reg_ctx)
                 {
                     const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
@@ -484,7 +599,7 @@
                             ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
                              (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
                         {
-                            *sb_value = ValueObjectRegisterSet::Create (m_opaque_sp.get(), reg_ctx, set_idx);
+                            *sb_value = ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx);
                         }
                     }
                 }
@@ -494,7 +609,7 @@
         case eValueTypeConstResult:         // constant result variables
             {
                 ConstString const_name(name);
-                ClangExpressionVariableSP expr_var_sp (m_opaque_sp->GetThread().GetProcess().GetTarget().GetPersistentVariables().GetVariable (const_name));
+                ClangExpressionVariableSP expr_var_sp (frame_sp->GetThread().GetProcess().GetTarget().GetPersistentVariables().GetVariable (const_name));
                 if (expr_var_sp)
                     *sb_value = expr_var_sp->GetValueObject();
             }
@@ -508,7 +623,7 @@
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)", 
-                     m_opaque_sp.get(), name, value_type, sb_value.get());
+                     frame_sp.get(), name, value_type, sb_value.get());
 
     
     return sb_value;
@@ -517,31 +632,13 @@
 bool
 SBFrame::operator == (const SBFrame &rhs) const
 {
-    return m_opaque_sp.get() == rhs.m_opaque_sp.get();
+    return GetFrameSP().get() == rhs.GetFrameSP().get();
 }
 
 bool
 SBFrame::operator != (const SBFrame &rhs) const
 {
-    return m_opaque_sp.get() != rhs.m_opaque_sp.get();
-}
-
-lldb_private::StackFrame *
-SBFrame::operator->() const
-{
-    return m_opaque_sp.get();
-}
-
-lldb_private::StackFrame *
-SBFrame::get() const
-{
-    return m_opaque_sp.get();
-}
-
-lldb::StackFrameSP &
-SBFrame::get_sp()
-{
-    return m_opaque_sp;
+    return GetFrameSP().get() != rhs.GetFrameSP().get();
 }
 
 SBThread
@@ -551,10 +648,11 @@
 
     SBThread sb_thread;
     ThreadSP thread_sp;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        thread_sp = m_opaque_sp->GetThread().shared_from_this();
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        thread_sp = frame_sp->GetThread().shared_from_this();
         sb_thread.SetThread (thread_sp);
     }
 
@@ -562,7 +660,7 @@
     {
         SBStream sstr;
         sb_thread.GetDescription (sstr);
-        log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", m_opaque_sp.get(), 
+        log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", frame_sp.get(), 
                      thread_sp.get(), sstr.GetData());
     }
 
@@ -573,15 +671,16 @@
 SBFrame::Disassemble () const
 {
     const char *disassembly = NULL;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        disassembly = m_opaque_sp->Disassemble();
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        disassembly = frame_sp->Disassemble();
     }
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
     if (log)
-        log->Printf ("SBFrame(%p)::Disassemble () => %s", m_opaque_sp.get(), disassembly);
+        log->Printf ("SBFrame(%p)::Disassemble () => %s", frame_sp.get(), disassembly);
 
     return disassembly;
 }
@@ -594,9 +693,10 @@
                        bool in_scope_only)
 {
     SBValueList value_list;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        lldb::DynamicValueType use_dynamic = m_opaque_sp->CalculateTarget()->GetPreferDynamicValue();
+        lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
         value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic);
     }
     return value_list;
@@ -611,24 +711,26 @@
 {
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
+    SBValueList value_list;
+    StackFrameSP frame_sp(GetFrameSP());
+
     if (log)
         log->Printf ("SBFrame(%p)::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)", 
-                     m_opaque_sp.get(), 
+                     frame_sp.get(), 
                      arguments,
                      locals,
                      statics,
                      in_scope_only);
-
-    SBValueList value_list;
-    if (m_opaque_sp)
+    
+    if (frame_sp)
     {
 
         size_t i;
         VariableList *variable_list = NULL;
         // Scope for locker
         {
-            Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-            variable_list = m_opaque_sp->GetVariableList(true);
+            Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+            variable_list = frame_sp->GetVariableList(true);
         }
         if (variable_list)
         {
@@ -661,10 +763,10 @@
                         }
                         if (add_variable)
                         {
-                            if (in_scope_only && !variable_sp->IsInScope(m_opaque_sp.get()))
+                            if (in_scope_only && !variable_sp->IsInScope(frame_sp.get()))
                                 continue;
 
-                            value_list.Append(m_opaque_sp->GetValueObjectForFrameVariable (variable_sp, use_dynamic));
+                            value_list.Append(frame_sp->GetValueObjectForFrameVariable (variable_sp, use_dynamic));
                         }
                     }
                 }
@@ -674,7 +776,7 @@
 
     if (log)
     {
-        log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", m_opaque_sp.get(),
+        log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame_sp.get(),
                      value_list.get());
     }
 
@@ -687,22 +789,23 @@
     LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
     SBValueList value_list;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        RegisterContextSP reg_ctx (m_opaque_sp->GetRegisterContext());
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        RegisterContextSP reg_ctx (frame_sp->GetRegisterContext());
         if (reg_ctx)
         {
             const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
             for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
             {
-                value_list.Append(ValueObjectRegisterSet::Create (m_opaque_sp.get(), reg_ctx, set_idx));
+                value_list.Append(ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx));
             }
         }
     }
 
     if (log)
-        log->Printf ("SBFrame(%p)::Registers () => SBValueList(%p)", m_opaque_sp.get(), value_list.get());
+        log->Printf ("SBFrame(%p)::Registers () => SBValueList(%p)", frame_sp.get(), value_list.get());
 
     return value_list;
 }
@@ -712,10 +815,11 @@
 {
     Stream &strm = description.ref();
 
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
-        m_opaque_sp->DumpUsingSettingsFormat (&strm);
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        frame_sp->DumpUsingSettingsFormat (&strm);
     }
     else
         strm.PutCString ("No value");
@@ -727,9 +831,10 @@
 SBFrame::EvaluateExpression (const char *expr)
 {
     SBValue result;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        lldb::DynamicValueType use_dynamic = m_opaque_sp->CalculateTarget()->GetPreferDynamicValue();
+        lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue();
         result = EvaluateExpression (expr, use_dynamic);
     }
     return result;
@@ -744,16 +849,18 @@
 
     ExecutionResults exe_results;
     SBValue expr_result;
+
+    StackFrameSP frame_sp(GetFrameSP());
     if (log)
-        log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", m_opaque_sp.get(), expr);
+        log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", frame_sp.get(), expr);
 
-    if (m_opaque_sp)
+    if (frame_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
+        Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex());
         
         
         StreamString frame_description;
-        m_opaque_sp->DumpUsingSettingsFormat (&frame_description);
+        frame_sp->DumpUsingSettingsFormat (&frame_description);
 
         Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
                                              expr, fetch_dynamic_value, frame_description.GetString().c_str());
@@ -762,14 +869,14 @@
         const bool unwind_on_error = true;
         const bool keep_in_memory = false;
 
-        exe_results = m_opaque_sp->GetThread().GetProcess().GetTarget().EvaluateExpression(expr, 
-                                                                                           m_opaque_sp.get(),
-                                                                                           eExecutionPolicyOnlyWhenNeeded,
-                                                                                           coerce_to_id,
-                                                                                           unwind_on_error, 
-                                                                                           keep_in_memory, 
-                                                                                           fetch_dynamic_value, 
-                                                                                           *expr_result);
+        exe_results = frame_sp->GetThread().GetProcess().GetTarget().EvaluateExpression(expr, 
+                                                                                        frame_sp.get(),
+                                                                                        eExecutionPolicyOnlyWhenNeeded,
+                                                                                        coerce_to_id,
+                                                                                        unwind_on_error, 
+                                                                                        keep_in_memory, 
+                                                                                        fetch_dynamic_value, 
+                                                                                        *expr_result);
         
         Host::SetCrashDescription (NULL);
     }
@@ -780,7 +887,7 @@
                          expr_result.GetSummary());
     
     if (log)
-        log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", m_opaque_sp.get(), 
+        log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", frame_sp.get(), 
                      expr, 
                      expr_result.get(),
                      exe_results);
@@ -791,9 +898,10 @@
 bool
 SBFrame::IsInlined()
 {
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        Block *block = m_opaque_sp->GetSymbolContext(eSymbolContextBlock).block;
+        Block *block = frame_sp->GetSymbolContext(eSymbolContextBlock).block;
         if (block)
             return block->GetContainingInlinedBlock () != NULL;
     }
@@ -804,9 +912,10 @@
 SBFrame::GetFunctionName()
 {
     const char *name = NULL;
-    if (m_opaque_sp)
+    StackFrameSP frame_sp(GetFrameSP());
+    if (frame_sp)
     {
-        SymbolContext sc (m_opaque_sp->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
+        SymbolContext sc (frame_sp->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol));
         if (sc.block)
         {
             Block *inlined_block = sc.block->GetContainingInlinedBlock ();

Modified: lldb/trunk/source/API/SBFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFunction.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFunction.cpp (original)
+++ lldb/trunk/source/API/SBFunction.cpp Mon Jan 30 01:41:31 2012
@@ -127,11 +127,12 @@
     {
         Mutex::Locker api_locker;
         ExecutionContext exe_ctx;
-        if (target.IsValid())
+        TargetSP target_sp (target.GetSP());
+        if (target_sp)
         {
-            api_locker.Reset (target->GetAPIMutex().GetMutex());
-            target->CalculateExecutionContext (exe_ctx);
-            exe_ctx.SetProcessSP(target->GetProcessSP());
+            api_locker.Reset (target_sp->GetAPIMutex().GetMutex());
+            target_sp->CalculateExecutionContext (exe_ctx);
+            exe_ctx.SetProcessSP(target_sp->GetProcessSP());
         }
         ModuleSP module_sp = m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModuleSP();
         if (module_sp)

Modified: lldb/trunk/source/API/SBInstruction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBInstruction.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/API/SBInstruction.cpp (original)
+++ lldb/trunk/source/API/SBInstruction.cpp Mon Jan 30 01:41:31 2012
@@ -75,11 +75,12 @@
     {        
         Mutex::Locker api_locker;
         ExecutionContext exe_ctx;
-        if (target.IsValid())
+        TargetSP target_sp (target.GetSP());
+        if (target_sp)
         {
-            api_locker.Reset (target->GetAPIMutex().GetMutex());
-            target->CalculateExecutionContext (exe_ctx);
-            exe_ctx.SetProcessSP(target->GetProcessSP());
+            api_locker.Reset (target_sp->GetAPIMutex().GetMutex());
+            target_sp->CalculateExecutionContext (exe_ctx);
+            exe_ctx.SetProcessSP(target_sp->GetProcessSP());
         }
         return m_opaque_sp->GetMnemonic(exe_ctx.GetBestExecutionContextScope());
     }
@@ -93,11 +94,12 @@
     {
         Mutex::Locker api_locker;
         ExecutionContext exe_ctx;
-        if (target.IsValid())
+        TargetSP target_sp (target.GetSP());
+        if (target_sp)
         {
-            api_locker.Reset (target->GetAPIMutex().GetMutex());
-            target->CalculateExecutionContext (exe_ctx);
-            exe_ctx.SetProcessSP(target->GetProcessSP());
+            api_locker.Reset (target_sp->GetAPIMutex().GetMutex());
+            target_sp->CalculateExecutionContext (exe_ctx);
+            exe_ctx.SetProcessSP(target_sp->GetProcessSP());
         }
         return m_opaque_sp->GetOperands(exe_ctx.GetBestExecutionContextScope());
     }
@@ -111,11 +113,12 @@
     {
         Mutex::Locker api_locker;
         ExecutionContext exe_ctx;
-        if (target.IsValid())
+        TargetSP target_sp (target.GetSP());
+        if (target_sp)
         {
-            api_locker.Reset (target->GetAPIMutex().GetMutex());
-            target->CalculateExecutionContext (exe_ctx);
-            exe_ctx.SetProcessSP(target->GetProcessSP());
+            api_locker.Reset (target_sp->GetAPIMutex().GetMutex());
+            target_sp->CalculateExecutionContext (exe_ctx);
+            exe_ctx.SetProcessSP(target_sp->GetProcessSP());
         }
         return m_opaque_sp->GetComment(exe_ctx.GetBestExecutionContextScope());
     }
@@ -142,12 +145,13 @@
         if (opcode_data && opcode_data_size > 0)
         {
             ByteOrder data_byte_order = opcode.GetDataByteOrder();
-            if (data_byte_order == eByteOrderInvalid)
-                data_byte_order = target->GetArchitecture().GetByteOrder();
+            TargetSP target_sp (target.GetSP());
+            if (data_byte_order == eByteOrderInvalid && target_sp)
+                data_byte_order = target_sp->GetArchitecture().GetByteOrder();
             DataBufferSP data_buffer_sp (new DataBufferHeap (opcode_data, opcode_data_size));
             DataExtractorSP data_extractor_sp (new DataExtractor (data_buffer_sp, 
                                                                   data_byte_order,
-                                                                  target.IsValid() ? target->GetArchitecture().GetAddressByteSize() : sizeof(void*)));
+                                                                  target_sp ? target_sp->GetArchitecture().GetAddressByteSize() : sizeof(void*)));
             sb_data.SetOpaque (data_extractor_sp);
         }
     }
@@ -199,20 +203,25 @@
 bool
 SBInstruction::EmulateWithFrame (lldb::SBFrame &frame, uint32_t evaluate_options)
 {
-    if (m_opaque_sp && frame.get())
+    if (m_opaque_sp)
     {
-        lldb_private::ExecutionContext exe_ctx;
-        frame->CalculateExecutionContext (exe_ctx);
-        lldb_private::Target *target = exe_ctx.GetTargetPtr();
-        lldb_private::ArchSpec arch = target->GetArchitecture();
-        
-        return m_opaque_sp->Emulate (arch, 
-                                     evaluate_options,
-                                     (void *) frame.get(), 
-                                     &lldb_private::EmulateInstruction::ReadMemoryFrame,
-                                     &lldb_private::EmulateInstruction::WriteMemoryFrame,
-                                     &lldb_private::EmulateInstruction::ReadRegisterFrame,
-                                     &lldb_private::EmulateInstruction::WriteRegisterFrame);
+        lldb::StackFrameSP frame_sp (frame.GetFrameSP());
+
+        if (frame_sp)
+        {
+            lldb_private::ExecutionContext exe_ctx;
+            frame_sp->CalculateExecutionContext (exe_ctx);
+            lldb_private::Target *target = exe_ctx.GetTargetPtr();
+            lldb_private::ArchSpec arch = target->GetArchitecture();
+            
+            return m_opaque_sp->Emulate (arch, 
+                                         evaluate_options,
+                                         (void *) frame_sp.get(), 
+                                         &lldb_private::EmulateInstruction::ReadMemoryFrame,
+                                         &lldb_private::EmulateInstruction::WriteMemoryFrame,
+                                         &lldb_private::EmulateInstruction::ReadRegisterFrame,
+                                         &lldb_private::EmulateInstruction::WriteRegisterFrame);
+        }
     }
     return false;
 }

Modified: lldb/trunk/source/API/SBModule.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBModule.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/API/SBModule.cpp (original)
+++ lldb/trunk/source/API/SBModule.cpp Mon Jan 30 01:41:31 2012
@@ -381,10 +381,8 @@
             for (uint32_t i=0; i<match_count; ++i)
             {
                 lldb::ValueObjectSP valobj_sp;
-                if (target.IsValid())
-                    valobj_sp = ValueObjectVariable::Create (target.get(), variable_list.GetVariableAtIndex(i));
-                else
-                    valobj_sp = ValueObjectVariable::Create (NULL, variable_list.GetVariableAtIndex(i));
+                TargetSP target_sp (target.GetSP());
+                valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i));
                 if (valobj_sp)
                     value_object_list.Append(valobj_sp);
             }

Modified: lldb/trunk/source/API/SBProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcess.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/API/SBProcess.cpp (original)
+++ lldb/trunk/source/API/SBProcess.cpp Mon Jan 30 01:41:31 2012
@@ -74,8 +74,14 @@
 {
 }
 
+lldb::ProcessSP
+SBProcess::GetSP() const
+{
+    return m_opaque_sp;
+}
+
 void
-SBProcess::SetProcess (const ProcessSP &process_sp)
+SBProcess::SetSP (const ProcessSP &process_sp)
 {
     m_opaque_sp = process_sp;
 }
@@ -239,11 +245,15 @@
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
     SBTarget sb_target;
+    TargetSP target_sp;
     if (m_opaque_sp)
-        sb_target = m_opaque_sp->GetTarget().shared_from_this();
+    {
+        target_sp = m_opaque_sp->GetTarget().shared_from_this();
+        sb_target.SetSP (target_sp);
+    }
     
     if (log)
-        log->Printf ("SBProcess(%p)::GetTarget () => SBTarget(%p)", m_opaque_sp.get(), sb_target.get());
+        log->Printf ("SBProcess(%p)::GetTarget () => SBTarget(%p)", m_opaque_sp.get(), target_sp.get());
 
     return sb_target;
 }
@@ -717,12 +727,6 @@
     return broadcaster;
 }
 
-lldb_private::Process *
-SBProcess::operator->() const
-{
-    return m_opaque_sp.get();
-}
-
 size_t
 SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error)
 {
@@ -864,13 +868,6 @@
     return bytes_written;
 }
 
-// Mimic shared pointer...
-lldb_private::Process *
-SBProcess::get() const
-{
-    return m_opaque_sp.get();
-}
-
 bool
 SBProcess::GetDescription (SBStream &description)
 {

Modified: lldb/trunk/source/API/SBSourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSourceManager.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/API/SBSourceManager.cpp (original)
+++ lldb/trunk/source/API/SBSourceManager.cpp Mon Jan 30 01:41:31 2012
@@ -89,7 +89,7 @@
 
 SBSourceManager::SBSourceManager (const SBTarget &target)
 {
-    m_opaque_ap.reset(new SourceManagerImpl (target.get_sp()));
+    m_opaque_ap.reset(new SourceManagerImpl (target.GetSP()));
 }
 
 SBSourceManager::SBSourceManager (const SBSourceManager &rhs)

Modified: lldb/trunk/source/API/SBSymbol.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSymbol.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/API/SBSymbol.cpp (original)
+++ lldb/trunk/source/API/SBSymbol.cpp Mon Jan 30 01:41:31 2012
@@ -123,10 +123,11 @@
     {
         Mutex::Locker api_locker;
         ExecutionContext exe_ctx;
-        if (target.IsValid())
+        TargetSP target_sp (target.GetSP());
+        if (target_sp)
         {
-            api_locker.Reset (target->GetAPIMutex().GetMutex());
-            target->CalculateExecutionContext (exe_ctx);
+            api_locker.Reset (target_sp->GetAPIMutex().GetMutex());
+            target_sp->CalculateExecutionContext (exe_ctx);
         }
         const AddressRange *symbol_range = m_opaque_ptr->GetAddressRangePtr();
         if (symbol_range)

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Mon Jan 30 01:41:31 2012
@@ -96,19 +96,19 @@
 SBProcess
 SBTarget::GetProcess ()
 {
-
     SBProcess sb_process;
+    ProcessSP process_sp;
     if (m_opaque_sp)
     {
-        Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
-        sb_process.SetProcess (m_opaque_sp->GetProcessSP());
+        process_sp = m_opaque_sp->GetProcessSP();
+        sb_process.SetSP (process_sp);
     }
 
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
     {
         log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)", 
-                     m_opaque_sp.get(), sb_process.get());
+                     m_opaque_sp.get(), process_sp.get());
     }
 
     return sb_process;
@@ -182,6 +182,7 @@
                      error.get());
     }
     SBProcess sb_process;
+    ProcessSP process_sp;
     if (m_opaque_sp)
     {
         Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
@@ -190,18 +191,17 @@
             launch_flags |= eLaunchFlagDisableASLR;
 
         StateType state = eStateInvalid;
-        sb_process.SetProcess (m_opaque_sp->GetProcessSP());
-        if (sb_process.IsValid())
+        process_sp = m_opaque_sp->GetProcessSP();
+        if (process_sp)
         {
-            state = sb_process->GetState();
+            state = process_sp->GetState();
             
-            if (sb_process->IsAlive() && state != eStateConnected)
+            if (process_sp->IsAlive() && state != eStateConnected)
             {       
                 if (state == eStateAttaching)
                     error.SetErrorString ("process attach is in progress");
                 else
                     error.SetErrorString ("a process is already being debugged");
-                sb_process.Clear();
                 return sb_process;
             }            
         }
@@ -214,20 +214,20 @@
             if (listener.IsValid())
             {
                 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
-                sb_process.Clear();
                 return sb_process;
             }
         }
         else
         {
             if (listener.IsValid())
-                sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
+                process_sp = m_opaque_sp->CreateProcess (listener.ref());
             else
-                sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
+                process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener());
         }
 
-        if (sb_process.IsValid())
+        if (process_sp)
         {
+            sb_process.SetSP (process_sp);
             if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
                 launch_flags |= eLaunchFlagDisableSTDIO;
 
@@ -241,7 +241,7 @@
             if (envp)
                 launch_info.GetEnvironmentEntries ().SetArguments (envp);
 
-            error.SetError (sb_process->Launch (launch_info));
+            error.SetError (process_sp->Launch (launch_info));
             if (error.Success())
             {
                 // We we are stopping at the entry point, we can return now!
@@ -249,17 +249,17 @@
                     return sb_process;
                 
                 // Make sure we are stopped at the entry
-                StateType state = sb_process->WaitForProcessToStop (NULL);
+                StateType state = process_sp->WaitForProcessToStop (NULL);
                 if (state == eStateStopped)
                 {
                     // resume the process to skip the entry point
-                    error.SetError (sb_process->Resume());
+                    error.SetError (process_sp->Resume());
                     if (error.Success())
                     {
                         // If we are doing synchronous mode, then wait for the
                         // process to stop yet again!
                         if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
-                            sb_process->WaitForProcessToStop (NULL);
+                            process_sp->WaitForProcessToStop (NULL);
                     }
                 }
             }
@@ -278,7 +278,7 @@
     if (log)
     {
         log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)", 
-                     m_opaque_sp.get(), sb_process.get());
+                     m_opaque_sp.get(), process_sp.get());
     }
 
     return sb_process;
@@ -305,23 +305,23 @@
 )
 {
     SBProcess sb_process;
+    ProcessSP process_sp;
     if (m_opaque_sp)
     {
         Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
 
         StateType state = eStateInvalid;
-        sb_process.SetProcess (m_opaque_sp->GetProcessSP());
-        if (sb_process.IsValid())
+        process_sp = m_opaque_sp->GetProcessSP();
+        if (process_sp)
         {
-            state = sb_process->GetState();
+            state = process_sp->GetState();
             
-            if (sb_process->IsAlive() && state != eStateConnected)
+            if (process_sp->IsAlive() && state != eStateConnected)
             {       
                 if (state == eStateAttaching)
                     error.SetErrorString ("process attach is in progress");
                 else
                     error.SetErrorString ("a process is already being debugged");
-                sb_process.Clear();
                 return sb_process;
             }            
         }
@@ -334,27 +334,27 @@
             if (listener.IsValid())
             {
                 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
-                sb_process.Clear();
                 return sb_process;
             }
         }
         else
         {
             if (listener.IsValid())
-                sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
+                process_sp = m_opaque_sp->CreateProcess (listener.ref());
             else
-                sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
+                process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener());
         }
-
-        if (sb_process.IsValid())
+        if (process_sp)
         {
+            sb_process.SetSP (process_sp);
+            
             ProcessAttachInfo attach_info;
             attach_info.SetProcessID (pid);
-            error.SetError (sb_process->Attach (attach_info));            
+            error.SetError (process_sp->Attach (attach_info));            
             // If we are doing synchronous mode, then wait for the
             // process to stop!
             if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
-                sb_process->WaitForProcessToStop (NULL);
+                process_sp->WaitForProcessToStop (NULL);
         }
         else
         {
@@ -379,23 +379,23 @@
 )
 {
     SBProcess sb_process;
+    ProcessSP process_sp;
     if (name && m_opaque_sp)
     {
         Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
 
         StateType state = eStateInvalid;
-        sb_process.SetProcess (m_opaque_sp->GetProcessSP());
-        if (sb_process.IsValid())
+        process_sp = m_opaque_sp->GetProcessSP();
+        if (process_sp)
         {
-            state = sb_process->GetState();
+            state = process_sp->GetState();
             
-            if (sb_process->IsAlive() && state != eStateConnected)
+            if (process_sp->IsAlive() && state != eStateConnected)
             {       
                 if (state == eStateAttaching)
                     error.SetErrorString ("process attach is in progress");
                 else
                     error.SetErrorString ("a process is already being debugged");
-                sb_process.Clear();
                 return sb_process;
             }            
         }
@@ -408,28 +408,28 @@
             if (listener.IsValid())
             {
                 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
-                sb_process.Clear();
                 return sb_process;
             }
         }
         else
         {
             if (listener.IsValid())
-                sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
+                process_sp = m_opaque_sp->CreateProcess (listener.ref());
             else
-                sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
+                process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener());
         }
 
-        if (sb_process.IsValid())
+        if (process_sp)
         {
+            sb_process.SetSP (process_sp);
             ProcessAttachInfo attach_info;
             attach_info.GetExecutableFile().SetFile(name, false);
             attach_info.SetWaitForLaunch(wait_for);
-            error.SetError (sb_process->Attach (attach_info));
+            error.SetError (process_sp->Attach (attach_info));
             // If we are doing synchronous mode, then wait for the
             // process to stop!
             if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false)
-                sb_process->WaitForProcessToStop (NULL);
+                process_sp->WaitForProcessToStop (NULL);
         }
         else
         {
@@ -454,18 +454,20 @@
 )
 {
     SBProcess sb_process;
+    ProcessSP process_sp;
     if (m_opaque_sp)
     {
         Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
         if (listener.IsValid())
-            sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref(), plugin_name));
+            process_sp = m_opaque_sp->CreateProcess (listener.ref(), plugin_name);
         else
-            sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name));
+            process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name);
         
         
-        if (sb_process.IsValid())
+        if (process_sp)
         {
-            error.SetError (sb_process->ConnectRemote (url));
+            sb_process.SetSP (process_sp);
+            error.SetError (process_sp->ConnectRemote (url));
         }
         else
         {
@@ -513,26 +515,14 @@
     return m_opaque_sp.get() != rhs.m_opaque_sp.get();
 }
 
-lldb_private::Target *
-SBTarget::operator ->() const
-{
-    return m_opaque_sp.get();
-}
-
-lldb_private::Target *
-SBTarget::get() const
-{
-    return m_opaque_sp.get();
-}
-
-const lldb::TargetSP &
-SBTarget::get_sp () const
+lldb::TargetSP
+SBTarget::GetSP () const
 {
     return m_opaque_sp;
 }
 
 void
-SBTarget::reset (const lldb::TargetSP& target_sp)
+SBTarget::SetSP (const lldb::TargetSP& target_sp)
 {
     m_opaque_sp = target_sp;
 }

Modified: lldb/trunk/source/API/SBThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBThread.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/API/SBThread.cpp (original)
+++ lldb/trunk/source/API/SBThread.cpp Mon Jan 30 01:41:31 2012
@@ -557,11 +557,12 @@
 
     ThreadSP thread_sp(m_opaque_wp.lock());
 
+    StackFrameSP frame_sp (sb_frame.GetFrameSP());
     if (log)
     {
         SBStream frame_desc_strm;
         sb_frame.GetDescription (frame_desc_strm);
-        log->Printf ("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)", thread_sp.get(), sb_frame.get(), frame_desc_strm.GetData());
+        log->Printf ("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)", thread_sp.get(), frame_sp.get(), frame_desc_strm.GetData());
     }
 
     if (thread_sp)
@@ -576,7 +577,7 @@
                                               stop_other_threads, 
                                               eVoteYes, 
                                               eVoteNoOpinion,
-                                              sb_frame->GetFrameIndex());
+                                              frame_sp->GetFrameIndex());
         
         Process &process = thread_sp->GetProcess();
         process.GetThreadList().SetSelectedThreadByID (thread_sp->GetID());
@@ -658,8 +659,9 @@
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     char path[PATH_MAX];
     
-    ThreadSP thread_sp(m_opaque_wp.lock());
-    
+    ThreadSP thread_sp(m_opaque_wp.lock());    
+    StackFrameSP frame_sp (sb_frame.GetFrameSP());
+
     if (log)
     {
         SBStream frame_desc_strm;
@@ -667,7 +669,7 @@
         sb_file_spec->GetPath (path, sizeof(path));
         log->Printf ("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, file+line = %s:%u)", 
                      thread_sp.get(), 
-                     sb_frame.get(), 
+                     frame_sp.get(), 
                      frame_desc_strm.GetData(),
                      path, line);
     }
@@ -683,9 +685,7 @@
         }
         
         StackFrameSP frame_sp;
-        if (sb_frame.IsValid())
-            frame_sp = sb_frame.get_sp();
-        else
+        if (!frame_sp)
         {
             frame_sp = thread_sp->GetSelectedFrame ();
             if (!frame_sp)
@@ -843,24 +843,26 @@
 SBThread::GetProcess ()
 {
 
-    SBProcess process;
+    SBProcess sb_process;
+    ProcessSP process_sp;
     ThreadSP thread_sp(m_opaque_wp.lock());
     if (thread_sp)
     {
         // Have to go up to the target so we can get a shared pointer to our process...
-        process.SetProcess(thread_sp->GetProcess().GetTarget().GetProcessSP());
+        process_sp = thread_sp->GetProcess().GetTarget().GetProcessSP();
+        sb_process.SetSP (process_sp);
     }
 
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
     {
         SBStream frame_desc_strm;
-        process.GetDescription (frame_desc_strm);
+        sb_process.GetDescription (frame_desc_strm);
         log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", thread_sp.get(),
-                     process.get(), frame_desc_strm.GetData());
+                     process_sp.get(), frame_desc_strm.GetData());
     }
 
-    return process;
+    return sb_process;
 }
 
 uint32_t
@@ -888,11 +890,13 @@
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
     SBFrame sb_frame;
+    StackFrameSP frame_sp;
     ThreadSP thread_sp(m_opaque_wp.lock());
     if (thread_sp)
     {
         Mutex::Locker api_locker (thread_sp->GetProcess().GetTarget().GetAPIMutex());
-        sb_frame.SetFrame (thread_sp->GetStackFrameAtIndex (idx));
+        frame_sp = thread_sp->GetStackFrameAtIndex (idx);
+        sb_frame.SetFrameSP (frame_sp);
     }
 
     if (log)
@@ -900,7 +904,7 @@
         SBStream frame_desc_strm;
         sb_frame.GetDescription (frame_desc_strm);
         log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s", 
-                     thread_sp.get(), idx, sb_frame.get(), frame_desc_strm.GetData());
+                     thread_sp.get(), idx, frame_sp.get(), frame_desc_strm.GetData());
     }
 
     return sb_frame;
@@ -912,11 +916,13 @@
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
     SBFrame sb_frame;
+    StackFrameSP frame_sp;
     ThreadSP thread_sp(m_opaque_wp.lock());
     if (thread_sp)
     {
         Mutex::Locker api_locker (thread_sp->GetProcess().GetTarget().GetAPIMutex());
-        sb_frame.SetFrame (thread_sp->GetSelectedFrame ());
+        frame_sp = thread_sp->GetSelectedFrame ();
+        sb_frame.SetFrameSP (frame_sp);
     }
 
     if (log)
@@ -924,7 +930,7 @@
         SBStream frame_desc_strm;
         sb_frame.GetDescription (frame_desc_strm);
         log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s", 
-                     thread_sp.get(), sb_frame.get(), frame_desc_strm.GetData());
+                     thread_sp.get(), frame_sp.get(), frame_desc_strm.GetData());
     }
 
     return sb_frame;
@@ -936,15 +942,16 @@
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
     SBFrame sb_frame;
+    StackFrameSP frame_sp;
     ThreadSP thread_sp(m_opaque_wp.lock());
     if (thread_sp)
     {
         Mutex::Locker api_locker (thread_sp->GetProcess().GetTarget().GetAPIMutex());
-        lldb::StackFrameSP frame_sp (thread_sp->GetStackFrameAtIndex (idx));
+        frame_sp = thread_sp->GetStackFrameAtIndex (idx);
         if (frame_sp)
         {
             thread_sp->SetSelectedFrame (frame_sp.get());
-            sb_frame.SetFrame (frame_sp);
+            sb_frame.SetFrameSP (frame_sp);
         }
     }
 
@@ -953,7 +960,7 @@
         SBStream frame_desc_strm;
         sb_frame.GetDescription (frame_desc_strm);
         log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s", 
-                     thread_sp.get(), idx, sb_frame.get(), frame_desc_strm.GetData());
+                     thread_sp.get(), idx, frame_sp.get(), frame_desc_strm.GetData());
     }
     return sb_frame;
 }

Modified: lldb/trunk/source/API/SBValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/API/SBValue.cpp (original)
+++ lldb/trunk/source/API/SBValue.cpp Mon Jan 30 01:41:31 2012
@@ -88,6 +88,8 @@
     
     if (m_opaque_sp.get())
         sb_error.SetError(m_opaque_sp->GetError());
+    else
+        sb_error.SetErrorString("error: invalid value");
     
     return sb_error;
 }
@@ -833,46 +835,44 @@
 lldb::SBTarget
 SBValue::GetTarget()
 {
-    SBTarget result;
+    SBTarget sb_target;
+    TargetSP target_sp;
     if (m_opaque_sp)
     {
-        if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
-        {
-            result = SBTarget(lldb::TargetSP(m_opaque_sp->GetUpdatePoint().GetTargetSP()));
-        }
+        target_sp = m_opaque_sp->GetUpdatePoint().GetTargetSP();
+        sb_target.SetSP (target_sp);
     }
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
     {
-        if (result.get() == NULL)
+        if (target_sp.get() == NULL)
             log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get());
         else
-            log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), result.get());
+            log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), target_sp.get());
     }
-    return result;
+    return sb_target;
 }
 
 lldb::SBProcess
 SBValue::GetProcess()
 {
-    SBProcess result;
+    SBProcess sb_process;
+    ProcessSP process_sp;
     if (m_opaque_sp)
     {
-        Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
-        if (target)
-        {
-            result = SBProcess(lldb::ProcessSP(target->GetProcessSP()));
-        }
+        process_sp = m_opaque_sp->GetUpdatePoint().GetProcessSP();
+        if (process_sp)
+            sb_process.SetSP (process_sp);
     }
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
     {
-        if (result.get() == NULL)
+        if (process_sp.get() == NULL)
             log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get());
         else
-            log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), result.get());
+            log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), process_sp.get());
     }
-    return result;
+    return sb_process;
 }
 
 lldb::SBThread
@@ -902,23 +902,25 @@
 lldb::SBFrame
 SBValue::GetFrame()
 {
-    SBFrame result;
+    SBFrame sb_frame;
+    StackFrameSP frame_sp;
     if (m_opaque_sp)
     {
         if (m_opaque_sp->GetExecutionContextScope())
         {
-            result.SetFrame (m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame()->shared_from_this());
+            frame_sp = m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame()->shared_from_this();
+            sb_frame.SetFrameSP (frame_sp);
         }
     }
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
     {
-        if (result.get() == NULL)
+        if (frame_sp.get() == NULL)
             log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get());
         else
-            log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), result.get());
+            log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), frame_sp.get());
     }
-    return result;
+    return sb_frame;
 }
 
 
@@ -1191,17 +1193,25 @@
     SBWatchpoint sb_wp_empty;
 
     // If the SBValue is not valid, there's no point in even trying to watch it.
-    if (!IsValid() || !GetFrame().IsValid())
+    if (!IsValid())
         return sb_wp_empty;
 
     // Read and Write cannot both be false.
     if (!read && !write)
         return sb_wp_empty;
-
+    
     // If we are watching the pointee, check that the SBValue is a pointer type.
     if (watch_pointee && !GetType().IsPointerType())
         return sb_wp_empty;
 
+    TargetSP target_sp (GetTarget().GetSP());
+    if (!target_sp)
+        return sb_wp_empty;
+    
+    StackFrameSP frame_sp (GetFrame().GetFrameSP());
+    if (!frame_sp)
+        return sb_wp_empty;
+    
     addr_t addr;
     size_t size;
     if (watch_pointee) {
@@ -1218,12 +1228,11 @@
 
     uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) |
         (write ? LLDB_WATCH_TYPE_WRITE : 0);
-    WatchpointSP wp_sp = GetFrame().m_opaque_sp->GetThread().GetProcess().GetTarget().
-        CreateWatchpoint(addr, size, watch_type);
+    WatchpointSP wp_sp = target_sp->CreateWatchpoint(addr, size, watch_type);
 
     if (wp_sp) {
         // StackFrame::GetInScopeVariableList(true) to get file globals as well.
-        VariableListSP var_list_sp(GetFrame().m_opaque_sp->GetInScopeVariableList(true));
+        VariableListSP var_list_sp(frame_sp->GetInScopeVariableList(true));
         VariableSP var_sp = var_list_sp->FindVariable(ConstString(GetName()));
         if (var_sp && var_sp->GetDeclaration().GetFile()) {
             StreamString ss;

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Mon Jan 30 01:41:31 2012
@@ -156,8 +156,21 @@
 UserSettingsControllerSP &
 Debugger::GetSettingsController ()
 {
-    static UserSettingsControllerSP g_settings_controller;
-    return g_settings_controller;
+    static UserSettingsControllerSP g_settings_controller_sp;
+    if (!g_settings_controller_sp)
+    {
+        g_settings_controller_sp.reset (new Debugger::SettingsController);
+    
+        // The first shared pointer to Debugger::SettingsController in
+        // g_settings_controller_sp must be fully created above so that 
+        // the DebuggerInstanceSettings can use a weak_ptr to refer back 
+        // to the master setttings controller
+        InstanceSettingsSP default_instance_settings_sp (new DebuggerInstanceSettings (g_settings_controller_sp, 
+                                                                                       false, 
+                                                                                       InstanceSettings::GetDefaultName().AsCString()));
+        g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
+    }
+    return g_settings_controller_sp;
 }
 
 int
@@ -203,9 +216,7 @@
     if (!g_initialized)
     {
         g_initialized = true;
-        UserSettingsControllerSP &usc = GetSettingsController();
-        usc.reset (new SettingsController);
-        UserSettingsController::InitializeSettingsController (usc,
+        UserSettingsController::InitializeSettingsController (GetSettingsController(),
                                                               SettingsController::global_settings_table,
                                                               SettingsController::instance_settings_table);
         // Now call SettingsInitialize for each settings 'child' of Debugger
@@ -317,7 +328,7 @@
 
 Debugger::Debugger () :
     UserID (g_unique_id++),
-    DebuggerInstanceSettings (*GetSettingsController()),
+    DebuggerInstanceSettings (GetSettingsController()),
     m_input_comm("debugger.input"),
     m_input_file (),
     m_output_file (),
@@ -2282,8 +2293,6 @@
 Debugger::SettingsController::SettingsController () :
     UserSettingsController ("", UserSettingsControllerSP())
 {
-    m_default_settings.reset (new DebuggerInstanceSettings (*this, false, 
-                                                            InstanceSettings::GetDefaultName().AsCString()));
 }
 
 Debugger::SettingsController::~SettingsController ()
@@ -2294,9 +2303,9 @@
 InstanceSettingsSP
 Debugger::SettingsController::CreateInstanceSettings (const char *instance_name)
 {
-    DebuggerInstanceSettings *new_settings = new DebuggerInstanceSettings (*GetSettingsController(),
-                                                                           false, instance_name);
-    InstanceSettingsSP new_settings_sp (new_settings);
+    InstanceSettingsSP new_settings_sp (new DebuggerInstanceSettings (GetSettingsController(),
+                                                                      false, 
+                                                                      instance_name));
     return new_settings_sp;
 }
 
@@ -2307,11 +2316,11 @@
 
 DebuggerInstanceSettings::DebuggerInstanceSettings 
 (
-    UserSettingsController &owner, 
+    const UserSettingsControllerSP &m_owner_sp, 
     bool live_instance,
     const char *name
 ) :
-    InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
+    InstanceSettings (m_owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
     m_term_width (80),
     m_stop_source_before_count (3),
     m_stop_source_after_count (3),
@@ -2332,18 +2341,18 @@
     if (GetInstanceName() == InstanceSettings::InvalidName())
     {
         ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
-        m_owner.RegisterInstanceSettings (this);
+        m_owner_sp->RegisterInstanceSettings (this);
     }
 
     if (live_instance)
     {
-        const InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
+        const InstanceSettingsSP &pending_settings = m_owner_sp->FindPendingSettings (m_instance_name);
         CopyInstanceSettings (pending_settings, false);
     }
 }
 
 DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
-    InstanceSettings (*Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
+    InstanceSettings (Debugger::GetSettingsController(), CreateInstanceName ().AsCString()),
     m_prompt (rhs.m_prompt),
     m_frame_format (rhs.m_frame_format),
     m_thread_format (rhs.m_thread_format),
@@ -2351,9 +2360,12 @@
     m_use_external_editor (rhs.m_use_external_editor),
     m_auto_confirm_on(rhs.m_auto_confirm_on)
 {
-    const InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
-    CopyInstanceSettings (pending_settings, false);
-    m_owner.RemovePendingSettings (m_instance_name);
+    UserSettingsControllerSP owner_sp (m_owner_wp.lock());
+    if (owner_sp)
+    {
+        CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false);
+        owner_sp->RemovePendingSettings (m_instance_name);
+    }
 }
 
 DebuggerInstanceSettings::~DebuggerInstanceSettings ()

Modified: lldb/trunk/source/Core/UserSettingsController.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/UserSettingsController.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/Core/UserSettingsController.cpp (original)
+++ lldb/trunk/source/Core/UserSettingsController.cpp Mon Jan 30 01:41:31 2012
@@ -83,10 +83,6 @@
 UserSettingsController::~UserSettingsController ()
 {
     Mutex::Locker locker (m_live_settings_mutex);
-
-    // Notify all instance settings that their owner is shutting down, first.
-    for (InstanceSettingsMap::iterator pos = m_live_settings.begin(); pos != m_live_settings.end(); ++pos)
-        pos->second->NotifyOwnerIsShuttingDown();
     m_live_settings.clear();
 }
 
@@ -2460,27 +2456,24 @@
 // class InstanceSettings
 //----------------------------------------------------------------------
 
-InstanceSettings::InstanceSettings (UserSettingsController &owner, const char *instance_name, bool live_instance) :
-    m_owner (owner),
-    m_instance_name (instance_name),
-    m_owner_is_live (true)
+InstanceSettings::InstanceSettings (const UserSettingsControllerSP &owner_sp, const char *instance_name, bool live_instance) :
+    m_owner_wp (owner_sp),
+    m_instance_name (instance_name)
 {
     if ((m_instance_name != InstanceSettings::GetDefaultName())
         && (m_instance_name !=  InstanceSettings::InvalidName())
         && live_instance)
-        m_owner.RegisterInstanceSettings (this);
+        owner_sp->RegisterInstanceSettings (this);
 }
 
 InstanceSettings::~InstanceSettings ()
 {
-    if (m_instance_name != InstanceSettings::GetDefaultName() && m_owner_is_live)
-        m_owner.UnregisterInstanceSettings (this);
-}
-
-void
-InstanceSettings::NotifyOwnerIsShuttingDown()
-{
-    m_owner_is_live = false;
+    if (m_instance_name != InstanceSettings::GetDefaultName())
+    {
+        UserSettingsControllerSP owner_sp (m_owner_wp.lock());
+        if (owner_sp)
+            owner_sp->UnregisterInstanceSettings (this);
+    }
 }
 
 const ConstString &

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Mon Jan 30 01:41:31 2012
@@ -741,7 +741,7 @@
 Process::Process(Target &target, Listener &listener) :
     UserID (LLDB_INVALID_PROCESS_ID),
     Broadcaster ("lldb.process"),
-    ProcessInstanceSettings (*GetSettingsController()),
+    ProcessInstanceSettings (GetSettingsController()),
     m_target (target),
     m_public_state (eStateUnloaded),
     m_private_state (eStateUnloaded),
@@ -3666,8 +3666,21 @@
 UserSettingsControllerSP &
 Process::GetSettingsController ()
 {
-    static UserSettingsControllerSP g_settings_controller;
-    return g_settings_controller;
+    static UserSettingsControllerSP g_settings_controller_sp;
+    if (!g_settings_controller_sp)
+    {
+        g_settings_controller_sp.reset (new Process::SettingsController);
+        // The first shared pointer to Process::SettingsController in
+        // g_settings_controller_sp must be fully created above so that 
+        // the TargetInstanceSettings can use a weak_ptr to refer back 
+        // to the master setttings controller
+        InstanceSettingsSP default_instance_settings_sp (new ProcessInstanceSettings (g_settings_controller_sp, 
+                                                                                      false,
+                                                                                      InstanceSettings::GetDefaultName().AsCString()));
+        g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
+    }
+    return g_settings_controller_sp;
+
 }
 
 void
@@ -4350,9 +4363,6 @@
 Process::SettingsController::SettingsController () :
     UserSettingsController ("process", Target::GetSettingsController())
 {
-    m_default_settings.reset (new ProcessInstanceSettings (*this, 
-                                                           false,
-                                                           InstanceSettings::GetDefaultName().AsCString()));
 }
 
 Process::SettingsController::~SettingsController ()
@@ -4362,10 +4372,9 @@
 lldb::InstanceSettingsSP
 Process::SettingsController::CreateInstanceSettings (const char *instance_name)
 {
-    ProcessInstanceSettings *new_settings = new ProcessInstanceSettings (*GetSettingsController(),
-                                                                         false, 
-                                                                         instance_name);
-    lldb::InstanceSettingsSP new_settings_sp (new_settings);
+    lldb::InstanceSettingsSP new_settings_sp (new ProcessInstanceSettings (GetSettingsController(),
+                                                                           false, 
+                                                                           instance_name));
     return new_settings_sp;
 }
 
@@ -4375,11 +4384,11 @@
 
 ProcessInstanceSettings::ProcessInstanceSettings
 (
-    UserSettingsController &owner, 
+    const UserSettingsControllerSP &owner_sp, 
     bool live_instance, 
     const char *name
 ) :
-    InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance)
+    InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance)
 {
     // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
     // until the vtables for ProcessInstanceSettings are properly set up, i.e. AFTER all the initializers.
@@ -4389,25 +4398,27 @@
     if (GetInstanceName () == InstanceSettings::InvalidName())
     {
         ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
-        m_owner.RegisterInstanceSettings (this);
+        owner_sp->RegisterInstanceSettings (this);
     }
     
     if (live_instance)
     {
-        const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
+        const lldb::InstanceSettingsSP &pending_settings = owner_sp->FindPendingSettings (m_instance_name);
         CopyInstanceSettings (pending_settings,false);
-        //m_owner.RemovePendingSettings (m_instance_name);
     }
 }
 
 ProcessInstanceSettings::ProcessInstanceSettings (const ProcessInstanceSettings &rhs) :
-    InstanceSettings (*Process::GetSettingsController(), CreateInstanceName().AsCString())
+    InstanceSettings (Process::GetSettingsController(), CreateInstanceName().AsCString())
 {
     if (m_instance_name != InstanceSettings::GetDefaultName())
     {
-        const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
-        CopyInstanceSettings (pending_settings,false);
-        m_owner.RemovePendingSettings (m_instance_name);
+        UserSettingsControllerSP owner_sp (m_owner_wp.lock());
+        if (owner_sp)
+        {
+            CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false);
+            owner_sp->RemovePendingSettings (m_instance_name);
+        }
     }
 }
 

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Mon Jan 30 01:41:31 2012
@@ -47,7 +47,7 @@
 Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
     Broadcaster ("lldb.target"),
     ExecutionContextScope (),
-    TargetInstanceSettings (*GetSettingsController()),
+    TargetInstanceSettings (GetSettingsController()),
     m_debugger (debugger),
     m_platform_sp (platform_sp),
     m_mutex (Mutex::eMutexTypeRecursive), 
@@ -1353,9 +1353,7 @@
 void
 Target::SettingsInitialize ()
 {
-    UserSettingsControllerSP &usc = GetSettingsController();
-    usc.reset (new SettingsController);
-    UserSettingsController::InitializeSettingsController (usc,
+    UserSettingsController::InitializeSettingsController (GetSettingsController(),
                                                           SettingsController::global_settings_table,
                                                           SettingsController::instance_settings_table);
                                                           
@@ -1381,8 +1379,20 @@
 UserSettingsControllerSP &
 Target::GetSettingsController ()
 {
-    static UserSettingsControllerSP g_settings_controller;
-    return g_settings_controller;
+    static UserSettingsControllerSP g_settings_controller_sp;
+    if (!g_settings_controller_sp)
+    {
+        g_settings_controller_sp.reset (new Target::SettingsController);
+        // The first shared pointer to Target::SettingsController in
+        // g_settings_controller_sp must be fully created above so that 
+        // the TargetInstanceSettings can use a weak_ptr to refer back 
+        // to the master setttings controller
+        InstanceSettingsSP default_instance_settings_sp (new TargetInstanceSettings (g_settings_controller_sp, 
+                                                                                     false,
+                                                                                     InstanceSettings::GetDefaultName().AsCString()));
+        g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
+    }
+    return g_settings_controller_sp;
 }
 
 ArchSpec
@@ -1985,8 +1995,6 @@
     UserSettingsController ("target", Debugger::GetSettingsController()),
     m_default_architecture ()
 {
-    m_default_settings.reset (new TargetInstanceSettings (*this, false,
-                                                          InstanceSettings::GetDefaultName().AsCString()));
 }
 
 Target::SettingsController::~SettingsController ()
@@ -1996,10 +2004,9 @@
 lldb::InstanceSettingsSP
 Target::SettingsController::CreateInstanceSettings (const char *instance_name)
 {
-    TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(),
-                                                                       false, 
-                                                                       instance_name);
-    lldb::InstanceSettingsSP new_settings_sp (new_settings);
+    lldb::InstanceSettingsSP new_settings_sp (new TargetInstanceSettings (GetSettingsController(),
+                                                                          false, 
+                                                                          instance_name));
     return new_settings_sp;
 }
 
@@ -2176,11 +2183,11 @@
 
 TargetInstanceSettings::TargetInstanceSettings
 (
-    UserSettingsController &owner, 
+    const lldb::UserSettingsControllerSP &owner_sp, 
     bool live_instance, 
     const char *name
 ) :
-    InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
+    InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
     m_expr_prefix_file (),
     m_expr_prefix_contents (),
     m_prefer_dynamic_value (2),
@@ -2207,18 +2214,18 @@
     if (GetInstanceName () == InstanceSettings::InvalidName())
     {
         ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
-        m_owner.RegisterInstanceSettings (this);
+        owner_sp->RegisterInstanceSettings (this);
     }
 
     if (live_instance)
     {
-        const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
+        const lldb::InstanceSettingsSP &pending_settings = owner_sp->FindPendingSettings (m_instance_name);
         CopyInstanceSettings (pending_settings,false);
     }
 }
 
 TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
-    InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()),
+    InstanceSettings (Target::GetSettingsController(), CreateInstanceName().AsCString()),
     m_expr_prefix_file (rhs.m_expr_prefix_file),
     m_expr_prefix_contents (rhs.m_expr_prefix_contents),
     m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
@@ -2238,8 +2245,9 @@
 {
     if (m_instance_name != InstanceSettings::GetDefaultName())
     {
-        const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
-        CopyInstanceSettings (pending_settings,false);
+        UserSettingsControllerSP owner_sp (m_owner_wp.lock());
+        if (owner_sp)
+            CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name),false);
     }
 }
 

Modified: lldb/trunk/source/Target/Thread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=149231&r1=149230&r2=149231&view=diff
==============================================================================
--- lldb/trunk/source/Target/Thread.cpp (original)
+++ lldb/trunk/source/Target/Thread.cpp Mon Jan 30 01:41:31 2012
@@ -45,7 +45,7 @@
 
 Thread::Thread (Process &process, lldb::tid_t tid) :
     UserID (tid),
-    ThreadInstanceSettings (*GetSettingsController()),
+    ThreadInstanceSettings (GetSettingsController()),
     m_process (process),
     m_actual_stop_info_sp (),
     m_index_id (process.GetNextThreadIndexID ()),
@@ -1033,9 +1033,7 @@
 void
 Thread::SettingsInitialize ()
 {
-    UserSettingsControllerSP &usc = GetSettingsController();
-    usc.reset (new SettingsController);
-    UserSettingsController::InitializeSettingsController (usc,
+    UserSettingsController::InitializeSettingsController (GetSettingsController(),
                                                           SettingsController::global_settings_table,
                                                           SettingsController::instance_settings_table);
                                                           
@@ -1059,8 +1057,21 @@
 UserSettingsControllerSP &
 Thread::GetSettingsController ()
 {
-    static UserSettingsControllerSP g_settings_controller;
-    return g_settings_controller;
+    static UserSettingsControllerSP g_settings_controller_sp;
+    if (!g_settings_controller_sp)
+    {
+        g_settings_controller_sp.reset (new Thread::SettingsController);
+        // The first shared pointer to Target::SettingsController in
+        // g_settings_controller_sp must be fully created above so that 
+        // the TargetInstanceSettings can use a weak_ptr to refer back 
+        // to the master setttings controller
+        InstanceSettingsSP default_instance_settings_sp (new ThreadInstanceSettings (g_settings_controller_sp, 
+                                                                                     false, 
+                                                                                     InstanceSettings::GetDefaultName().AsCString()));
+
+        g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
+    }
+    return g_settings_controller_sp;
 }
 
 void
@@ -1243,8 +1254,6 @@
 Thread::SettingsController::SettingsController () :
     UserSettingsController ("thread", Process::GetSettingsController())
 {
-    m_default_settings.reset (new ThreadInstanceSettings (*this, false, 
-                                                          InstanceSettings::GetDefaultName().AsCString()));
 }
 
 Thread::SettingsController::~SettingsController ()
@@ -1254,10 +1263,9 @@
 lldb::InstanceSettingsSP
 Thread::SettingsController::CreateInstanceSettings (const char *instance_name)
 {
-    ThreadInstanceSettings *new_settings = new ThreadInstanceSettings (*GetSettingsController(),
-                                                                       false, 
-                                                                       instance_name);
-    lldb::InstanceSettingsSP new_settings_sp (new_settings);
+    lldb::InstanceSettingsSP new_settings_sp (new ThreadInstanceSettings (GetSettingsController(),
+                                                                          false, 
+                                                                          instance_name));
     return new_settings_sp;
 }
 
@@ -1266,8 +1274,8 @@
 // class ThreadInstanceSettings
 //--------------------------------------------------------------
 
-ThreadInstanceSettings::ThreadInstanceSettings (UserSettingsController &owner, bool live_instance, const char *name) :
-    InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance), 
+ThreadInstanceSettings::ThreadInstanceSettings (const UserSettingsControllerSP &owner_sp, bool live_instance, const char *name) :
+    InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance), 
     m_avoid_regexp_ap (),
     m_trace_enabled (false)
 {
@@ -1279,27 +1287,28 @@
     if (GetInstanceName() == InstanceSettings::InvalidName())
     {
         ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
-        m_owner.RegisterInstanceSettings (this);
+        owner_sp->RegisterInstanceSettings (this);
     }
 
     if (live_instance)
     {
-        const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
-        CopyInstanceSettings (pending_settings,false);
-        //m_owner.RemovePendingSettings (m_instance_name);
+        CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name),false);
     }
 }
 
 ThreadInstanceSettings::ThreadInstanceSettings (const ThreadInstanceSettings &rhs) :
-    InstanceSettings (*Thread::GetSettingsController(), CreateInstanceName().AsCString()),
+    InstanceSettings (Thread::GetSettingsController(), CreateInstanceName().AsCString()),
     m_avoid_regexp_ap (),
     m_trace_enabled (rhs.m_trace_enabled)
 {
     if (m_instance_name != InstanceSettings::GetDefaultName())
     {
-        const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
-        CopyInstanceSettings (pending_settings,false);
-        m_owner.RemovePendingSettings (m_instance_name);
+        UserSettingsControllerSP owner_sp (m_owner_wp.lock());
+        if (owner_sp)
+        {
+            CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false);
+            owner_sp->RemovePendingSettings (m_instance_name);
+        }
     }
     if (rhs.m_avoid_regexp_ap.get() != NULL)
         m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText()));





More information about the lldb-commits mailing list