diff options
27 files changed, 653 insertions, 503 deletions
diff --git a/lldb/include/lldb/API/SBFrame.h b/lldb/include/lldb/API/SBFrame.h index bd4636c0df1..d7d221a1f6f 100644 --- a/lldb/include/lldb/API/SBFrame.h +++ b/lldb/include/lldb/API/SBFrame.h @@ -19,6 +19,7 @@ namespace lldb { class SBFrame { public: + typedef SHARED_PTR(lldb_private::StackFrameImpl) StackFrameImplSP; SBFrame (); SBFrame (const lldb::SBFrame &rhs); @@ -207,24 +208,13 @@ private: 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 diff --git a/lldb/include/lldb/API/SBProcess.h b/lldb/include/lldb/API/SBProcess.h index 9a70566d0e6..3880c2cd331 100644 --- a/lldb/include/lldb/API/SBProcess.h +++ b/lldb/include/lldb/API/SBProcess.h @@ -197,22 +197,13 @@ protected: 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; }; diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h index e0ffb28ecd1..d75035d6553 100644 --- a/lldb/include/lldb/API/SBTarget.h +++ b/lldb/include/lldb/API/SBTarget.h @@ -540,17 +540,12 @@ protected: 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: //------------------------------------------------------------------ diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h index f17e5f0a1c6..bf7379c67f3 100644 --- a/lldb/include/lldb/Core/Debugger.h +++ b/lldb/include/lldb/Core/Debugger.h @@ -52,7 +52,7 @@ public: }; - 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); diff --git a/lldb/include/lldb/Core/UserSettingsController.h b/lldb/include/lldb/Core/UserSettingsController.h index 878abd20ddd..370bfad516a 100644 --- a/lldb/include/lldb/Core/UserSettingsController.h +++ b/lldb/include/lldb/Core/UserSettingsController.h @@ -49,7 +49,8 @@ typedef struct std::vector<SettingEntry> instance_settings; } UserSettingDefinition; -class UserSettingsController +class UserSettingsController : + public std::tr1::enable_shared_from_this<UserSettingsController> { public: @@ -130,6 +131,11 @@ public: 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 @@ class InstanceSettings { 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 @@ public: // 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 @@ public: protected: - UserSettingsController &m_owner; - bool m_owner_is_live; + lldb::UserSettingsControllerWP m_owner_wp; ConstString m_instance_name; }; diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index 20f58489d2e..8a1438c0b79 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -54,7 +54,7 @@ class ProcessInstanceSettings : public InstanceSettings { 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); diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index a6132d891e4..1c8afc2946c 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -43,7 +43,7 @@ class TargetInstanceSettings : public InstanceSettings 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); diff --git a/lldb/include/lldb/Target/Thread.h b/lldb/include/lldb/Target/Thread.h index 43745674820..dad97c9ae3d 100644 --- a/lldb/include/lldb/Target/Thread.h +++ b/lldb/include/lldb/Target/Thread.h @@ -25,7 +25,7 @@ class ThreadInstanceSettings : public InstanceSettings { 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); diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h index 3052c532618..5440e082829 100644 --- a/lldb/include/lldb/lldb-forward.h +++ b/lldb/include/lldb/lldb-forward.h @@ -142,6 +142,7 @@ class SectionList; class SourceManager; class SourceManagerImpl; class StackFrame; +class StackFrameImpl; class StackFrameList; class StackID; class StopInfo; @@ -293,6 +294,7 @@ namespace lldb { 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; diff --git a/lldb/source/API/SBAddress.cpp b/lldb/source/API/SBAddress.cpp index 6e6a806de48..7cb0d902dfb 100644 --- a/lldb/source/API/SBAddress.cpp +++ b/lldb/source/API/SBAddress.cpp @@ -170,18 +170,19 @@ SBAddress::GetLoadAddress (const SBTarget &target) const 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; diff --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp index 7fbf5c2c73d..e6054789090 100644 --- a/lldb/source/API/SBCommandInterpreter.cpp +++ b/lldb/source/API/SBCommandInterpreter.cpp @@ -188,24 +188,26 @@ SBCommandInterpreter::HasAliasOptions () 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 * diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index ce72631ce65..9c2eea065ce 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -302,11 +302,12 @@ SBDebugger::HandleCommand (const char *command) 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 @@ SBDebugger::HandleProcessEvent (const SBProcess &process, const SBEvent &event, 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 @@ SBDebugger::CreateTarget (const char *filename, lldb::SBError& sb_error) { SBTarget sb_target; + TargetSP target_sp; if (m_opaque_sp) { sb_error.Clear(); @@ -481,7 +487,6 @@ SBDebugger::CreateTarget (const char *filename, 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 @@ SBDebugger::CreateTarget (const char *filename, target_sp); if (sb_error.Success()) - sb_target.reset (target_sp); + sb_target.SetSP (target_sp); } else { @@ -507,7 +512,7 @@ SBDebugger::CreateTarget (const char *filename, platform_name, add_dependent_modules, sb_error.GetCString(), - sb_target.get()); + target_sp.get()); } return sb_target; @@ -517,7 +522,8 @@ SBTarget 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 @@ SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename, 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 @@ SBDebugger::CreateTargetWithFileAndArch (const char *filename, const char *arch_ { 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 @@ SBDebugger::CreateTargetWithFileAndArch (const char *filename, const char *arch_ 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 @@ SBDebugger::CreateTarget (const char *filename) 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 @@ SBDebugger::GetTargetAtIndex (uint32_t idx) 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 @@ SBDebugger::FindTargetWithProcessID (pid_t pid) 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 @@ SBDebugger::FindTargetWithFileAndArch (const char *filename, const char *arch_na // 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 @@ SBDebugger::FindTargetWithLLDBProcess (const ProcessSP &process_sp) 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 @@ SBDebugger::GetSelectedTarget () 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 @@ SBDebugger::GetSelectedTarget () 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 @@ SBDebugger::SetSelectedTarget (SBTarget &sb_target) { 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()); } } diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp index 38fcc4eb88a..564cf7736f2 100644 --- a/lldb/source/API/SBFrame.cpp +++ b/lldb/source/API/SBFrame.cpp @@ -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 @@ SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) : 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 @@ SBFrame::~SBFrame() { } +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 @@ SBFrame::GetSymbolContext (uint32_t resolve_scope) const { 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 @@ SBModule 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 @@ SBCompileUnit 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 @@ SBFunction 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 @@ SBSymbol 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 @@ SBBlock 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 @@ SBBlock 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 @@ SBLineEntry 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 @@ addr_t 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 @@ bool 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 @@ addr_t 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 @@ addr_t 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 @@ SBAddress 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 @@ SBValue 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 @@ SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic) { 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 @@ SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic) } 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 @@ SBValue 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 @@ SBValue 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 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy 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 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy 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 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy 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 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy ((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 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy 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 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy ((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 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy 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 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy 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 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy 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 @@ SBFrame::GetThread () const 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 @@ SBFrame::GetThread () const { 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 @@ const char * 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 @@ SBFrame::GetVariables (bool arguments, 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 @@ SBFrame::GetVariables (bool arguments, { 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 @@ SBFrame::GetVariables (bool arguments, } 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 @@ SBFrame::GetVariables (bool arguments, 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 @@ SBFrame::GetRegisters () 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 @@ SBFrame::GetDescription (SBStream &description) { 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 @@ SBValue 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 @@ SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dyna 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 @@ SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dyna 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 @@ SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dyna 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 @@ SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dyna 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 @@ const char * 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 (); diff --git a/lldb/source/API/SBFunction.cpp b/lldb/source/API/SBFunction.cpp index f55b2147741..e3e56a53011 100644 --- a/lldb/source/API/SBFunction.cpp +++ b/lldb/source/API/SBFunction.cpp @@ -127,11 +127,12 @@ SBFunction::GetInstructions (SBTarget target) { 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) diff --git a/lldb/source/API/SBInstruction.cpp b/lldb/source/API/SBInstruction.cpp index 26f8d1aa005..f384b5b97b4 100644 --- a/lldb/source/API/SBInstruction.cpp +++ b/lldb/source/API/SBInstruction.cpp @@ -75,11 +75,12 @@ SBInstruction::GetMnemonic(SBTarget target) { 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 @@ SBInstruction::GetOperands(SBTarget target) { 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 @@ SBInstruction::GetComment(SBTarget target) { 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 @@ SBInstruction::GetData (SBTarget target) 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 @@ SBInstruction::Print (FILE *out) 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; } diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp index 0c1307ccc76..28180fce63a 100644 --- a/lldb/source/API/SBModule.cpp +++ b/lldb/source/API/SBModule.cpp @@ -381,10 +381,8 @@ SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_ 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); } diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp index 91731bcd3b7..3422efbdb94 100644 --- a/lldb/source/API/SBProcess.cpp +++ b/lldb/source/API/SBProcess.cpp @@ -74,8 +74,14 @@ SBProcess::~SBProcess() { } +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 @@ SBProcess::GetTarget() const 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 @@ SBProcess::GetBroadcaster () const 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 @@ SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &s return bytes_written; } -// Mimic shared pointer... -lldb_private::Process * -SBProcess::get() const -{ - return m_opaque_sp.get(); -} - bool SBProcess::GetDescription (SBStream &description) { diff --git a/lldb/source/API/SBSourceManager.cpp b/lldb/source/API/SBSourceManager.cpp index f9926dc825b..743d5651bbb 100644 --- a/lldb/source/API/SBSourceManager.cpp +++ b/lldb/source/API/SBSourceManager.cpp @@ -89,7 +89,7 @@ SBSourceManager::SBSourceManager (const SBDebugger &debugger) 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) diff --git a/lldb/source/API/SBSymbol.cpp b/lldb/source/API/SBSymbol.cpp index 51bb98c194a..697fff8e101 100644 --- a/lldb/source/API/SBSymbol.cpp +++ b/lldb/source/API/SBSymbol.cpp @@ -123,10 +123,11 @@ SBSymbol::GetInstructions (SBTarget target) { 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) diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index f594827a1e2..dc06e7c9e5e 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -96,19 +96,19 @@ SBTarget::IsValid () const 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 @@ SBTarget::Launch error.get()); } SBProcess sb_process; + ProcessSP process_sp; if (m_opaque_sp) { Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); @@ -190,18 +191,17 @@ SBTarget::Launch 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 @@ SBTarget::Launch 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 @@ SBTarget::Launch 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 @@ SBTarget::Launch 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 @@ SBTarget::Launch 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 @@ SBTarget::AttachToProcessWithID ) { 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 @@ SBTarget::AttachToProcessWithID 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 @@ SBTarget::AttachToProcessWithName ) { 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 @@ SBTarget::AttachToProcessWithName 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 @@ SBTarget::ConnectRemote ) { 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 @@ SBTarget::operator != (const SBTarget &rhs) const 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; } diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp index 73f1d19b6b3..023e81fbcd8 100644 --- a/lldb/source/API/SBThread.cpp +++ b/lldb/source/API/SBThread.cpp @@ -557,11 +557,12 @@ SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame) 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 @@ SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame) 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 @@ SBThread::StepOverUntil (lldb::SBFrame &sb_frame, 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 @@ SBThread::StepOverUntil (lldb::SBFrame &sb_frame, 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 @@ SBThread::StepOverUntil (lldb::SBFrame &sb_frame, } 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 @@ SBProcess 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 @@ SBThread::GetFrameAtIndex (uint32_t idx) 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 @@ SBThread::GetFrameAtIndex (uint32_t idx) 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 @@ SBThread::GetSelectedFrame () 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 @@ SBThread::GetSelectedFrame () 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 @@ SBThread::SetSelectedFrame (uint32_t idx) 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 @@ SBThread::SetSelectedFrame (uint32_t idx) 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; } diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index 858b8f1144d..b72c8f181b8 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -88,6 +88,8 @@ SBValue::GetError() 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 @@ SBValue::GetOpaqueType() 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 @@ SBValue::GetThread() 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 @@ SBValue::WatchValue(bool read, bool write, bool watch_pointee) 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 @@ SBValue::WatchValue(bool read, bool write, bool watch_pointee) 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; diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index f979c8d5877..060e579eadc 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -156,8 +156,21 @@ DebuggerInstanceSettings::g_show_disassembly_enum_values[] = 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 @@ Debugger::SettingsInitialize () 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::FindTargetWithProcess (Process *process) 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::FormatPrompt Debugger::SettingsController::SettingsController () : UserSettingsController ("", UserSettingsControllerSP()) { - m_default_settings.reset (new DebuggerInstanceSettings (*this, false, - InstanceSettings::GetDefaultName().AsCString())); } Debugger::SettingsController::~SettingsController () @@ -2294,9 +2303,9 @@ Debugger::SettingsController::~SettingsController () 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 @@ Debugger::SettingsController::CreateInstanceSettings (const char *instance_name) 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 @@ DebuggerInstanceSettings::DebuggerInstanceSettings 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 @@ DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettin 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 () diff --git a/lldb/source/Core/UserSettingsController.cpp b/lldb/source/Core/UserSettingsController.cpp index cdacad020e6..96d1f19c70b 100644 --- a/lldb/source/Core/UserSettingsController.cpp +++ b/lldb/source/Core/UserSettingsController.cpp @@ -83,10 +83,6 @@ UserSettingsController::UserSettingsController (const char *level_name, 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 @@ UserSettingsController::RenameInstanceSettings (const char *old_name, const char // 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 & diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index e991437366e..e597b8b7604 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -741,7 +741,7 @@ Process::FindPlugin (Target &target, const char *plugin_name, Listener &listener 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 @@ Process::SettingsTerminate () 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::GetThreadStatus (Stream &strm, 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 @@ Process::SettingsController::~SettingsController () 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 @@ Process::SettingsController::CreateInstanceSettings (const char *instance_name) 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 @@ ProcessInstanceSettings::ProcessInstanceSettings 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); + } } } diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index f4159de5cd9..c533ba580b4 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -47,7 +47,7 @@ using namespace lldb_private; 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 @@ Target::GetClangASTImporter() 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 @@ Target::SettingsTerminate () 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 @@ Target::SettingsController::SettingsController () : 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 @@ Target::SettingsController::~SettingsController () 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 @@ Target::SettingsController::GetGlobalVariable (const ConstString &var_name, 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 @@ TargetInstanceSettings::TargetInstanceSettings 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 @@ TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rh { 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); } } diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp index 5d7c9056263..2a675e51f50 100644 --- a/lldb/source/Target/Thread.cpp +++ b/lldb/source/Target/Thread.cpp @@ -45,7 +45,7 @@ using namespace lldb_private; 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 @@ Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx) 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 @@ Thread::SettingsTerminate () 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::GetUnwinder () 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 @@ Thread::SettingsController::~SettingsController () 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 @@ Thread::SettingsController::CreateInstanceSettings (const char *instance_name) // 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 @@ ThreadInstanceSettings::ThreadInstanceSettings (UserSettingsController &owner, b 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())); |