diff --git a/lldb/include/lldb/Core/FormatNavigator.h b/lldb/include/lldb/Core/FormatNavigator.h index 4e80ec6d0a79..a7390a85275b 100644 --- a/lldb/include/lldb/Core/FormatNavigator.h +++ b/lldb/include/lldb/Core/FormatNavigator.h @@ -487,8 +487,7 @@ protected: log->Printf("going to an Objective-C dynamic scanning"); if (!process_sp) return false; - Process* process = process_sp.get(); - ObjCLanguageRuntime* runtime = process->GetObjCLanguageRuntime(); + ObjCLanguageRuntime* runtime = process_sp->GetObjCLanguageRuntime(); if (runtime == NULL) { if (log) @@ -640,8 +639,7 @@ protected: return false; if (log) log->Printf("this is an ObjC 'id', let's do dynamic search"); - Process* process = process_sp.get(); - ObjCLanguageRuntime* runtime = process->GetObjCLanguageRuntime(); + ObjCLanguageRuntime* runtime = process_sp->GetObjCLanguageRuntime(); if (runtime == NULL) { if (log) @@ -751,7 +749,7 @@ protected: } } - lldb::ProcessSP process_sp = valobj.GetUpdatePoint().GetProcessSP(); + lldb::ProcessSP process_sp = valobj.GetProcessSP(); if (use_dynamic != lldb::eNoDynamicValues && ClangASTType::GetMinimumLanguage(valobj.GetClangAST(), valobj.GetClangType()) == lldb::eLanguageTypeObjC) diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index 90161a3e4d54..566d9e59ddfe 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -338,7 +338,7 @@ public: }; - class EvaluationPoint : public ExecutionContextScope + class EvaluationPoint { public: @@ -350,25 +350,19 @@ public: ~EvaluationPoint (); - const lldb::TargetSP & - GetTargetSP () const + const ExecutionContextRef & + GetExecutionContextRef() const { - return m_target_sp; + return m_exe_ctx_ref; } - - const lldb::ProcessSP & - GetProcessSP () const - { - return m_process_sp; - } - + // Set the EvaluationPoint to the values in exe_scope, // Return true if the Evaluation Point changed. // Since the ExecutionContextScope is always going to be valid currently, // the Updated Context will also always be valid. - bool - SetContext (ExecutionContextScope *exe_scope); +// bool +// SetContext (ExecutionContextScope *exe_scope); void SetIsConstant () @@ -442,39 +436,14 @@ public: } - // If this EvaluationPoint is created without a target, then we could have it - // hand out a NULL ExecutionContextScope. But then everybody would have to check that before - // calling through it, which is annoying. So instead, we make the EvaluationPoint BE an - // ExecutionContextScope, and it hands out the right things. - virtual Target *CalculateTarget (); - - virtual Process *CalculateProcess (); - - virtual Thread *CalculateThread (); - - virtual StackFrame *CalculateStackFrame (); - - virtual void CalculateExecutionContext (ExecutionContext &exe_ctx); - private: bool - SyncWithProcessState () - { - ExecutionContextScope *exe_scope; - return SyncWithProcessState(exe_scope); - } - - bool - SyncWithProcessState (ExecutionContextScope *&exe_scope); + SyncWithProcessState (); - bool m_needs_update; - bool m_first_update; - - lldb::TargetSP m_target_sp; - lldb::ProcessSP m_process_sp; - lldb::user_id_t m_thread_id; - StackID m_stack_id; - ProcessModID m_mod_id; // This is the stop id when this ValueObject was last evaluated. + ProcessModID m_mod_id; // This is the stop id when this ValueObject was last evaluated. + ExecutionContextRef m_exe_ctx_ref; + bool m_needs_update; + bool m_first_update; }; const EvaluationPoint & @@ -489,12 +458,36 @@ public: return m_update_point; } - ExecutionContextScope * - GetExecutionContextScope () + const ExecutionContextRef & + GetExecutionContextRef() const { - return &m_update_point; + return m_update_point.GetExecutionContextRef(); } - + + lldb::TargetSP + GetTargetSP() const + { + return m_update_point.GetExecutionContextRef().GetTargetSP(); + } + + lldb::ProcessSP + GetProcessSP() const + { + return m_update_point.GetExecutionContextRef().GetProcessSP(); + } + + lldb::ThreadSP + GetThreadSP() const + { + return m_update_point.GetExecutionContextRef().GetThreadSP(); + } + + lldb::StackFrameSP + GetFrameSP() const + { + return m_update_point.GetExecutionContextRef().GetFrameSP(); + } + void SetNeedsUpdate (); diff --git a/lldb/include/lldb/Target/ExecutionContext.h b/lldb/include/lldb/Target/ExecutionContext.h index 4022fee2792c..37162091c8ea 100644 --- a/lldb/include/lldb/Target/ExecutionContext.h +++ b/lldb/include/lldb/Target/ExecutionContext.h @@ -12,9 +12,122 @@ #define liblldb_ExecutionContext_h_ #include "lldb/lldb-private.h" +#include "lldb/Target/StackID.h" namespace lldb_private { +class ExecutionContextRef +{ +public: + //------------------------------------------------------------------ + /// Default Constructor. + /// + /// Initialize with NULL process and thread, and invalid frame + /// index. + //------------------------------------------------------------------ + ExecutionContextRef(); + + ExecutionContextRef (const ExecutionContextRef &rhs); + + ExecutionContextRef (const ExecutionContext *exe_ctx); + + ExecutionContextRef (const ExecutionContext &exe_ctx); + + ExecutionContextRef & + operator =(const ExecutionContextRef &rhs); + + ExecutionContextRef & + operator =(const ExecutionContext &exe_ctx); + + // Init using the target and all the selected items inside of it + // (the process and its selected thread, and the thread's selected + // frame). If there is no selected thread, default to the first thread + // If there is no selected frame, default to the first frame. + ExecutionContextRef (Target *target, bool adopt_selected); + + ExecutionContextRef (ExecutionContextScope *exe_scope); + + ExecutionContextRef (ExecutionContextScope &exe_scope); + + ~ExecutionContextRef(); + //------------------------------------------------------------------ + /// Clear the object's state. + /// + /// Sets the process and thread to NULL, and the frame index to an + /// invalid value. + //------------------------------------------------------------------ + void + Clear (); + + void + SetTargetSP (const lldb::TargetSP &target_sp); + + void + SetProcessSP (const lldb::ProcessSP &process_sp); + + void + SetThreadSP (const lldb::ThreadSP &thread_sp); + + void + SetFrameSP (const lldb::StackFrameSP &frame_sp); + + void + SetTargetPtr (Target* target, bool adopt_selected); + + void + SetProcessPtr (Process *process); + + void + SetThreadPtr (Thread *thread); + + void + SetFramePtr (StackFrame *frame); + + lldb::TargetSP + GetTargetSP () const + { + return m_target_wp.lock(); + } + + lldb::ProcessSP + GetProcessSP () const + { + return m_process_wp.lock(); + } + + lldb::ThreadSP + GetThreadSP () const; + + lldb::StackFrameSP + GetFrameSP () const; + + ExecutionContext + Lock () const; + + bool + HasThreadRef () const + { + return m_tid != LLDB_INVALID_THREAD_ID; + } + + bool + HasFrameRef () const + { + return m_stack_id.IsValid(); + } + +protected: + //------------------------------------------------------------------ + // Member variables + //------------------------------------------------------------------ + lldb::TargetWP m_target_wp; ///< The target that owns the process/thread/frame + lldb::ProcessWP m_process_wp; ///< The process that owns the thread/frame + mutable lldb::ThreadWP m_thread_wp; ///< The thread that owns the frame + mutable lldb::StackFrameWP m_frame_wp; ///< The stack frame in thread. + lldb::tid_t m_tid; + StackID m_stack_id; +}; + //---------------------------------------------------------------------- /// @class ExecutionContext ExecutionContext.h "lldb/Target/ExecutionContext.h" /// @brief A class that contains an execution context. @@ -41,10 +154,27 @@ public: ExecutionContext (const ExecutionContext &rhs); + ExecutionContext (Target* t, bool fill_current_process_thread_frame = true); + + ExecutionContext (const lldb::TargetSP &target_sp, bool get_process); + ExecutionContext (const lldb::ProcessSP &process_sp); + ExecutionContext (const lldb::ThreadSP &thread_sp); + ExecutionContext (const lldb::StackFrameSP &frame_sp); + ExecutionContext (const ExecutionContextRef &exe_ctx_ref); + ExecutionContext (const ExecutionContextRef *exe_ctx_ref); + ExecutionContext (ExecutionContextScope *exe_scope); + ExecutionContext (ExecutionContextScope &exe_scope); + + ExecutionContext & operator =(const ExecutionContext &rhs); - ExecutionContext (Target* t, bool fill_current_process_thread_frame = true); + bool + operator ==(const ExecutionContext &rhs) const; + + bool + operator !=(const ExecutionContext &rhs) const; + //------------------------------------------------------------------ /// Construct with process, thread, and frame index. /// @@ -64,10 +194,6 @@ public: StackFrame * frame = NULL); - ExecutionContext (ExecutionContextScope *exe_scope); - - ExecutionContext (ExecutionContextScope &exe_scope); - ~ExecutionContext(); //------------------------------------------------------------------ /// Clear the object's state. @@ -84,6 +210,9 @@ public: ExecutionContextScope * GetBestExecutionContextScope () const; + uint32_t + GetAddressByteSize() const; + Target * GetTargetPtr () const; @@ -115,25 +244,25 @@ public: GetFrameRef () const; const lldb::TargetSP & - GetTargetSP () + GetTargetSP () const { return m_target_sp; } const lldb::ProcessSP & - GetProcessSP () + GetProcessSP () const { return m_process_sp; } const lldb::ThreadSP & - GetThreadSP () + GetThreadSP () const { return m_thread_sp; } const lldb::StackFrameSP & - GetFrameSP () + GetFrameSP () const { return m_frame_sp; } @@ -162,6 +291,47 @@ public: void SetFramePtr (StackFrame *frame); + //------------------------------------------------------------------ + // Set the execution context using a target shared pointer. + // + // If "target_sp" is valid, sets the target context to match and + // if "get_process" is true, sets the process shared pointer if + // the target currently has a process. + //------------------------------------------------------------------ + void + SetContext (const lldb::TargetSP &target_sp, bool get_process); + + //------------------------------------------------------------------ + // Set the execution context using a process shared pointer. + // + // If "process_sp" is valid, then set the process and target in this + // context. Thread and frame contexts will be cleared. + // If "process_sp" is not valid, all shared pointers are reset. + //------------------------------------------------------------------ + void + SetContext (const lldb::ProcessSP &process_sp); + + //------------------------------------------------------------------ + // Set the execution context using a thread shared pointer. + // + // If "thread_sp" is valid, then set the thread, process and target + // in this context. The frame context will be cleared. + // If "thread_sp" is not valid, all shared pointers are reset. + //------------------------------------------------------------------ + void + SetContext (const lldb::ThreadSP &thread_sp); + + //------------------------------------------------------------------ + // Set the execution context using a thread shared pointer. + // + // If "frame_sp" is valid, then set the frame, thread, process and + // target in this context + // If "frame_sp" is not valid, all shared pointers are reset. + //------------------------------------------------------------------ + void + SetContext (const lldb::StackFrameSP &frame_sp); + + protected: //------------------------------------------------------------------ // Member variables @@ -171,7 +341,6 @@ protected: lldb::ThreadSP m_thread_sp; ///< The thread that owns the frame lldb::StackFrameSP m_frame_sp; ///< The stack frame in thread. }; - } // namespace lldb_private #endif // liblldb_ExecutionContext_h_ diff --git a/lldb/include/lldb/Target/StackFrameList.h b/lldb/include/lldb/Target/StackFrameList.h index d37f9257f95f..db22a405ed14 100644 --- a/lldb/include/lldb/Target/StackFrameList.h +++ b/lldb/include/lldb/Target/StackFrameList.h @@ -43,7 +43,7 @@ public: GetFrameWithConcreteFrameIndex (uint32_t unwind_idx); lldb::StackFrameSP - GetFrameWithStackID (StackID &stack_id); + GetFrameWithStackID (const StackID &stack_id); // Mark a stack frame as the current frame uint32_t diff --git a/lldb/include/lldb/Target/StackID.h b/lldb/include/lldb/Target/StackID.h index cac57da0114c..15f24dd4725b 100644 --- a/lldb/include/lldb/Target/StackID.h +++ b/lldb/include/lldb/Target/StackID.h @@ -84,12 +84,9 @@ public: } bool - IsValid () + IsValid () const { - if (m_pc == LLDB_INVALID_ADDRESS && m_cfa == LLDB_INVALID_ADDRESS) - return false; - else - return true; + return m_pc != LLDB_INVALID_ADDRESS || m_cfa != LLDB_INVALID_ADDRESS; } void diff --git a/lldb/include/lldb/Target/Thread.h b/lldb/include/lldb/Target/Thread.h index a704dfd90d8b..1ec196bb4c48 100644 --- a/lldb/include/lldb/Target/Thread.h +++ b/lldb/include/lldb/Target/Thread.h @@ -339,7 +339,7 @@ public: GetFrameWithConcreteFrameIndex (uint32_t unwind_idx); virtual lldb::StackFrameSP - GetFrameWithStackID(StackID &stack_id) + GetFrameWithStackID (const StackID &stack_id) { return GetStackFrameList().GetFrameWithStackID (stack_id); } diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h index 3c2d2a1e26a9..97ca12fb574d 100644 --- a/lldb/include/lldb/lldb-forward.h +++ b/lldb/include/lldb/lldb-forward.h @@ -84,6 +84,8 @@ class Error; class Event; class EventData; class ExecutionContext; +class ExecutionContextRef; +class ExecutionContextRefLocker; class ExecutionContextScope; class FileSpec; class FileSpecList; diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index 7eb56a806a34..d4d2c06a4480 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -175,10 +175,10 @@ SBValue::IsInScope () lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); result = value_sp->IsInScope (); } } @@ -197,10 +197,10 @@ SBValue::GetValue () lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); cstr = value_sp->GetValueAsCString (); } } @@ -249,10 +249,10 @@ SBValue::GetObjectDescription () lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); cstr = value_sp->GetObjectDescription (); } } @@ -296,10 +296,10 @@ SBValue::GetValueDidChange () lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); result = value_sp->GetValueDidChange (); } } @@ -317,10 +317,10 @@ SBValue::GetSummary () lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); cstr = value_sp->GetSummaryAsCString(); } } @@ -342,10 +342,10 @@ SBValue::GetLocation () lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); cstr = value_sp->GetLocationAsCString(); } } @@ -367,10 +367,10 @@ SBValue::SetValueFromCString (const char *value_str) lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); success = value_sp->SetValueFromCString (value_str); } } @@ -384,12 +384,16 @@ SBValue::GetTypeFormat () lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - if (value_sp->UpdateValueIfNeeded(true)) + TargetSP target_sp(value_sp->GetTargetSP()); + if (target_sp) { - lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat(); - if (format_sp) - format.SetSP(format_sp); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + if (value_sp->UpdateValueIfNeeded(true)) + { + lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat(); + if (format_sp) + format.SetSP(format_sp); + } } } return format; @@ -402,12 +406,16 @@ SBValue::GetTypeSummary () lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - if (value_sp->UpdateValueIfNeeded(true)) + TargetSP target_sp(value_sp->GetTargetSP()); + if (target_sp) { - lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat(); - if (summary_sp) - summary.SetSP(summary_sp); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + if (value_sp->UpdateValueIfNeeded(true)) + { + lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat(); + if (summary_sp) + summary.SetSP(summary_sp); + } } } return summary; @@ -420,15 +428,19 @@ SBValue::GetTypeFilter () lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - if (value_sp->UpdateValueIfNeeded(true)) + TargetSP target_sp(value_sp->GetTargetSP()); + if (target_sp) { - lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren(); - - if (synthetic_sp && !synthetic_sp->IsScripted()) + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + if (value_sp->UpdateValueIfNeeded(true)) { - TypeFilterImplSP filter_sp = std::tr1::static_pointer_cast(synthetic_sp); - filter.SetSP(filter_sp); + lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren(); + + if (synthetic_sp && !synthetic_sp->IsScripted()) + { + TypeFilterImplSP filter_sp = std::tr1::static_pointer_cast(synthetic_sp); + filter.SetSP(filter_sp); + } } } } @@ -442,15 +454,19 @@ SBValue::GetTypeSynthetic () lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - if (value_sp->UpdateValueIfNeeded(true)) + TargetSP target_sp(value_sp->GetTargetSP()); + if (target_sp) { - lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren(); - - if (children_sp && children_sp->IsScripted()) + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + if (value_sp->UpdateValueIfNeeded(true)) { - TypeSyntheticImplSP synth_sp = std::tr1::static_pointer_cast(children_sp); - synthetic.SetSP(synth_sp); + lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren(); + + if (children_sp && children_sp->IsScripted()) + { + TypeSyntheticImplSP synth_sp = std::tr1::static_pointer_cast(children_sp); + synthetic.SetSP(synth_sp); + } } } } @@ -504,18 +520,23 @@ SBValue::CreateValueFromExpression (const char *name, const char* expression) lldb::ValueObjectSP new_value_sp; if (value_sp) { - value_sp->GetUpdatePoint().GetTargetSP()->EvaluateExpression (expression, - value_sp->GetExecutionContextScope()->CalculateStackFrame(), - eExecutionPolicyOnlyWhenNeeded, - false, // coerce to id - true, // unwind on error - true, // keep in memory - eNoDynamicValues, - new_value_sp); - if (new_value_sp) + ExecutionContext exe_ctx (value_sp->GetExecutionContextRef()); + Target* target = exe_ctx.GetTargetPtr(); + if (target) { - new_value_sp->SetName(ConstString(name)); - sb_value.SetSP(new_value_sp); + target->EvaluateExpression (expression, + exe_ctx.GetFramePtr(), + eExecutionPolicyOnlyWhenNeeded, + false, // coerce to id + true, // unwind on error + true, // keep in memory + eNoDynamicValues, + new_value_sp); + if (new_value_sp) + { + new_value_sp->SetName(ConstString(name)); + sb_value.SetSP(new_value_sp); + } } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); @@ -545,13 +566,14 @@ SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType s lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t))); - ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (value_sp->GetExecutionContextScope(), + ExecutionContext exe_ctx (value_sp->GetExecutionContextRef()); + ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), pointee_type_impl_sp->GetASTContext(), pointee_type_impl_sp->GetOpaqueQualType(), ConstString(name), buffer, lldb::endian::InlHostByteOrder(), - GetTarget().GetProcess().GetAddressByteSize())); + exe_ctx.GetAddressByteSize())); if (ptr_result_valobj_sp) { @@ -583,7 +605,9 @@ SBValue::CreateValueFromData (const char* name, SBData data, SBType type) lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - new_value_sp = ValueObjectConstResult::Create (value_sp->GetExecutionContextScope(), + ExecutionContext exe_ctx (value_sp->GetExecutionContextRef()); + + new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), type.m_opaque_sp->GetASTContext() , type.m_opaque_sp->GetOpaqueQualType(), ConstString(name), @@ -610,7 +634,11 @@ SBValue::GetChildAtIndex (uint32_t idx) lldb::DynamicValueType use_dynamic = eNoDynamicValues; lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) - use_dynamic = value_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue(); + { + TargetSP target_sp(value_sp->GetTargetSP()); + if (target_sp) + use_dynamic = target_sp->GetPreferDynamicValue(); + } return GetChildAtIndex (idx, use_dynamic, can_create_synthetic); } @@ -622,10 +650,10 @@ SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); const bool can_create = true; child_sp = value_sp->GetChildAtIndex (idx, can_create); if (can_create_synthetic && !child_sp) @@ -667,10 +695,10 @@ SBValue::GetIndexOfChildWithName (const char *name) lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); idx = value_sp->GetIndexOfChildWithName (ConstString(name)); } @@ -693,7 +721,7 @@ SBValue::GetChildMemberWithName (const char *name) if (value_sp) { lldb::DynamicValueType use_dynamic_value = eNoDynamicValues; - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { Mutex::Locker api_locker (target_sp->GetAPIMutex()); @@ -714,7 +742,7 @@ SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dy lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { Mutex::Locker api_locker (target_sp->GetAPIMutex()); @@ -746,10 +774,10 @@ SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic) lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); return SBValue (value_sp->GetDynamicValue(use_dynamic)); } } @@ -763,10 +791,10 @@ SBValue::GetStaticValue () lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); return SBValue(value_sp->GetStaticValue()); } } @@ -780,10 +808,10 @@ SBValue::IsDynamic() lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); return value_sp->IsDynamic(); } } @@ -797,10 +825,10 @@ SBValue::GetValueForExpressionPath(const char* expr_path) lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); // using default values for all the fancy options, just do it if you can child_sp = value_sp->GetValueForExpressionPath(expr_path); } @@ -822,10 +850,10 @@ SBValue::GetValueAsSigned(SBError& error, int64_t fail_value) lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); Scalar scalar; if (value_sp->ResolveValue (scalar)) return scalar.GetRawBits64(fail_value); @@ -846,10 +874,10 @@ SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value) lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); Scalar scalar; if (value_sp->ResolveValue (scalar)) return scalar.GetRawBits64(fail_value); @@ -869,10 +897,10 @@ SBValue::GetValueAsSigned(int64_t fail_value) lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); Scalar scalar; if (value_sp->ResolveValue (scalar)) return scalar.GetRawBits64(fail_value); @@ -887,10 +915,10 @@ SBValue::GetValueAsUnsigned(uint64_t fail_value) lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); Scalar scalar; if (value_sp->ResolveValue (scalar)) return scalar.GetRawBits64(fail_value); @@ -907,10 +935,10 @@ SBValue::GetNumChildren () lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); num_children = value_sp->GetNumChildren(); } @@ -931,10 +959,10 @@ SBValue::Dereference () lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); Error error; sb_value = value_sp->Dereference (error); @@ -955,10 +983,10 @@ SBValue::TypeIsPointerType () lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); is_ptr_type = value_sp->IsPointerType(); } @@ -978,10 +1006,10 @@ SBValue::GetOpaqueType() lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp(value_sp->GetTargetSP()); if (target_sp) { - Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); return value_sp->GetClangType(); } @@ -997,7 +1025,7 @@ SBValue::GetTarget() lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - target_sp = value_sp->GetUpdatePoint().GetTargetSP(); + target_sp = value_sp->GetTargetSP(); sb_target.SetSP (target_sp); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); @@ -1019,7 +1047,7 @@ SBValue::GetProcess() lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - process_sp = value_sp->GetUpdatePoint().GetProcessSP(); + process_sp = value_sp->GetProcessSP(); if (process_sp) sb_process.SetSP (process_sp); } @@ -1042,11 +1070,8 @@ SBValue::GetThread() lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - if (value_sp->GetExecutionContextScope()) - { - thread_sp = value_sp->GetExecutionContextScope()->CalculateThread()->shared_from_this(); - sb_thread.SetThread(thread_sp); - } + thread_sp = value_sp->GetThreadSP(); + sb_thread.SetThread(thread_sp); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -1067,11 +1092,8 @@ SBValue::GetFrame() lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - if (value_sp->GetExecutionContextScope()) - { - frame_sp = value_sp->GetExecutionContextScope()->CalculateStackFrame()->shared_from_this(); - sb_frame.SetFrameSP (frame_sp); - } + frame_sp = value_sp->GetFrameSP(); + sb_frame.SetFrameSP (frame_sp); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -1162,10 +1184,10 @@ SBValue::AddressOf() lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - Target* target = value_sp->GetUpdatePoint().GetTargetSP().get(); - if (target) + TargetSP target_sp (value_sp->GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (target->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); Error error; sb_value = value_sp->AddressOf (error); } @@ -1184,10 +1206,10 @@ SBValue::GetLoadAddress() lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - Target* target = value_sp->GetUpdatePoint().GetTargetSP().get(); - if (target) + TargetSP target_sp (value_sp->GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (target->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); const bool scalar_is_load_address = true; AddressType addr_type; value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type); @@ -1200,7 +1222,7 @@ SBValue::GetLoadAddress() { Address addr; module->ResolveFileAddress(value, addr); - value = addr.GetLoadAddress(value_sp->GetUpdatePoint().GetTargetSP().get()); + value = addr.GetLoadAddress(target_sp.get()); } } else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid) @@ -1221,11 +1243,11 @@ SBValue::GetAddress() lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - Target* target = value_sp->GetUpdatePoint().GetTargetSP().get(); - if (target) + TargetSP target_sp (value_sp->GetTargetSP()); + if (target_sp) { lldb::addr_t value = LLDB_INVALID_ADDRESS; - Mutex::Locker api_locker (target->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); const bool scalar_is_load_address = true; AddressType addr_type; value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type); @@ -1240,7 +1262,7 @@ SBValue::GetAddress() // no need to check the return value on this.. if it can actually do the resolve // addr will be in the form (section,offset), otherwise it will simply be returned // as (NULL, value) - addr.SetLoadAddress(value, target); + addr.SetLoadAddress(value, target_sp.get()); } } } @@ -1258,11 +1280,11 @@ SBValue::GetPointeeData (uint32_t item_idx, lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - Target* target = value_sp->GetUpdatePoint().GetTargetSP().get(); - if (target) + TargetSP target_sp (value_sp->GetTargetSP()); + if (target_sp) { DataExtractorSP data_sp(new DataExtractor()); - Mutex::Locker api_locker (target->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); value_sp->GetPointeeData(*data_sp, item_idx, item_count); if (data_sp->GetByteSize() > 0) *sb_data = data_sp; @@ -1286,7 +1308,7 @@ SBValue::GetData () lldb::ValueObjectSP value_sp(GetSP()); if (value_sp) { - TargetSP target_sp (value_sp->GetUpdatePoint().GetTargetSP()); + TargetSP target_sp (value_sp->GetTargetSP()); if (target_sp) { Mutex::Locker api_locker (target_sp->GetAPIMutex()); diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 7f768e9ec41e..0c17ca9735b6 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -1394,7 +1394,7 @@ Debugger::FormatPrompt if (index_higher < 0) index_higher = valobj->GetNumChildren() - 1; - uint32_t max_num_children = target->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay(); + uint32_t max_num_children = target->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay(); for (;index_lower<=index_higher;index_lower++) { diff --git a/lldb/source/Core/FormatClasses.cpp b/lldb/source/Core/FormatClasses.cpp index ded4938568be..d59da37c4874 100644 --- a/lldb/source/Core/FormatClasses.cpp +++ b/lldb/source/Core/FormatClasses.cpp @@ -85,8 +85,7 @@ StringSummaryFormat::FormatObject(lldb::ValueObjectSP object) return "NULL"; StreamString s; - ExecutionContext exe_ctx; - object->GetExecutionContextScope()->CalculateExecutionContext(exe_ctx); + ExecutionContext exe_ctx (object->GetExecutionContextRef()); SymbolContext sc; StackFrame *frame = exe_ctx.GetFramePtr(); if (frame) @@ -237,8 +236,7 @@ SyntheticArrayView::GetDescription() #ifndef LLDB_DISABLE_PYTHON -TypeSyntheticImpl::FrontEnd::FrontEnd(std::string pclass, - lldb::ValueObjectSP be) : +TypeSyntheticImpl::FrontEnd::FrontEnd(std::string pclass, lldb::ValueObjectSP be) : SyntheticChildrenFrontEnd(be), m_python_class(pclass) { @@ -249,7 +247,7 @@ TypeSyntheticImpl::FrontEnd::FrontEnd(std::string pclass, return; } - m_interpreter = m_backend->GetUpdatePoint().GetTargetSP()->GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); + m_interpreter = m_backend->GetTargetSP()->GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); if (m_interpreter == NULL) m_wrapper = NULL; diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index 9182979fd40b..0c75affd1bdd 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -353,10 +353,7 @@ ValueObject::ResolveValue (Scalar &scalar) { if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything { - ExecutionContext exe_ctx; - ExecutionContextScope *exe_scope = GetExecutionContextScope(); - if (exe_scope) - exe_scope->CalculateExecutionContext(exe_ctx); + ExecutionContext exe_ctx (GetExecutionContextRef()); Value tmp_value(m_value); scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ()); if (scalar.IsValid()) @@ -516,8 +513,7 @@ ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int3 clang_type_t clang_type = GetClangType(); clang_type_t child_clang_type; - ExecutionContext exe_ctx; - GetExecutionContextScope()->CalculateExecutionContext (exe_ctx); + ExecutionContext exe_ctx (GetExecutionContextRef()); child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx, clang_ast, @@ -594,48 +590,46 @@ ValueObject::GetSummaryAsCString () GetClangAST(), &elem_or_pointee_clang_type)); - ExecutionContextScope *exe_scope = GetExecutionContextScope(); - if (exe_scope) + if (ClangASTContext::IsFunctionPointerType (clang_type)) { - if (ClangASTContext::IsFunctionPointerType (clang_type)) + AddressType func_ptr_address_type = eAddressTypeInvalid; + addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type); + if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS) { - AddressType func_ptr_address_type = eAddressTypeInvalid; - addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type); - if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS) + switch (func_ptr_address_type) { - switch (func_ptr_address_type) - { - case eAddressTypeInvalid: - case eAddressTypeFile: - break; + case eAddressTypeInvalid: + case eAddressTypeFile: + break; - case eAddressTypeLoad: + case eAddressTypeLoad: + { + ExecutionContext exe_ctx (GetExecutionContextRef()); + + Address so_addr; + Target *target = exe_ctx.GetTargetPtr(); + if (target && target->GetSectionLoadList().IsEmpty() == false) { - Address so_addr; - Target *target = exe_scope->CalculateTarget(); - if (target && target->GetSectionLoadList().IsEmpty() == false) + if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr)) { - if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr)) - { - so_addr.Dump (&sstr, - exe_scope, - Address::DumpStyleResolvedDescription, - Address::DumpStyleSectionNameOffset); - } + so_addr.Dump (&sstr, + exe_ctx.GetBestExecutionContextScope(), + Address::DumpStyleResolvedDescription, + Address::DumpStyleSectionNameOffset); } } - break; - - case eAddressTypeHost: - break; } + break; + + case eAddressTypeHost: + break; } - if (sstr.GetSize() > 0) - { - m_summary_str.assign (1, '('); - m_summary_str.append (sstr.GetData(), sstr.GetSize()); - m_summary_str.append (1, ')'); - } + } + if (sstr.GetSize() > 0) + { + m_summary_str.assign (1, '('); + m_summary_str.append (sstr.GetData(), sstr.GetSize()); + m_summary_str.append (1, ')'); } } } @@ -720,9 +714,6 @@ ValueObject::GetPointeeData (DataExtractor& data, AddressType addr_type; lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type); - ExecutionContextScope *exe_scope = GetExecutionContextScope(); - - switch (addr_type) { case eAddressTypeFile: @@ -732,27 +723,25 @@ ValueObject::GetPointeeData (DataExtractor& data, { Address so_addr; module->ResolveFileAddress(addr, so_addr); - if (exe_scope) + ExecutionContext exe_ctx (GetExecutionContextRef()); + Target* target = exe_ctx.GetTargetPtr(); + if (target) { - Target* target = exe_scope->CalculateTarget(); - if (target) + heap_buf_ptr->SetByteSize(bytes); + size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error); + if (error.Success()) { - heap_buf_ptr->SetByteSize(bytes); - size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error); - if (error.Success()) - { - data.SetData(data_sp); - return bytes_read; - } + data.SetData(data_sp); + return bytes_read; } } } } break; case eAddressTypeLoad: - if (exe_scope) { - Process *process = exe_scope->CalculateProcess(); + ExecutionContext exe_ctx (GetExecutionContextRef()); + Process *process = exe_ctx.GetProcessPtr(); if (process) { heap_buf_ptr->SetByteSize(bytes); @@ -784,8 +773,7 @@ size_t ValueObject::GetData (DataExtractor& data) { UpdateValueIfNeeded(false); - ExecutionContext exe_ctx; - GetExecutionContextScope()->CalculateExecutionContext(exe_ctx); + ExecutionContext exe_ctx (GetExecutionContextRef()); Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule()); if (error.Fail()) return 0; @@ -820,15 +808,17 @@ strlen_or_inf (const char* str, } void -ValueObject::ReadPointedString(Stream& s, - Error& error, - uint32_t max_length, - bool honor_array, - Format item_format) +ValueObject::ReadPointedString (Stream& s, + Error& error, + uint32_t max_length, + bool honor_array, + Format item_format) { - - if (max_length == 0) - max_length = GetUpdatePoint().GetTargetSP()->GetMaximumSizeOfStringSummary(); + ExecutionContext exe_ctx (GetExecutionContextRef()); + Target* target = exe_ctx.GetTargetPtr(); + + if (target && max_length == 0) + max_length = target->GetMaximumSizeOfStringSummary(); clang_type_t clang_type = GetClangType(); clang_type_t elem_or_pointee_clang_type; @@ -838,129 +828,124 @@ ValueObject::ReadPointedString(Stream& s, if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) && ClangASTContext::IsCharType (elem_or_pointee_clang_type)) { - ExecutionContextScope *exe_scope = GetExecutionContextScope(); - if (exe_scope) + if (target == NULL) + { + s << ""; + } + else + { + addr_t cstr_address = LLDB_INVALID_ADDRESS; + AddressType cstr_address_type = eAddressTypeInvalid; + + size_t cstr_len = 0; + bool capped_data = false; + if (type_flags.Test (ClangASTContext::eTypeIsArray)) { - Target *target = exe_scope->CalculateTarget(); - if (target == NULL) + // We have an array + cstr_len = ClangASTContext::GetArraySize (clang_type); + if (cstr_len > max_length) { - s << ""; + capped_data = true; + cstr_len = max_length; + } + cstr_address = GetAddressOf (true, &cstr_address_type); + } + else + { + // We have a pointer + cstr_address = GetPointerValue (&cstr_address_type); + } + if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS) + { + Address cstr_so_addr (NULL, cstr_address); + DataExtractor data; + size_t bytes_read = 0; + if (cstr_len > 0 && honor_array) + { + // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host + // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this + GetPointeeData(data, 0, cstr_len); + + if ((bytes_read = data.GetByteSize()) > 0) + { + s << '"'; + data.Dump (&s, + 0, // Start offset in "data" + item_format, + 1, // Size of item (1 byte for a char!) + bytes_read, // How many bytes to print? + UINT32_MAX, // num per line + LLDB_INVALID_ADDRESS,// base address + 0, // bitfield bit size + 0); // bitfield bit offset + if (capped_data) + s << "..."; + s << '"'; + } } else { - addr_t cstr_address = LLDB_INVALID_ADDRESS; - AddressType cstr_address_type = eAddressTypeInvalid; + cstr_len = max_length; + const size_t k_max_buf_size = 64; + + size_t offset = 0; - size_t cstr_len = 0; - bool capped_data = false; - if (type_flags.Test (ClangASTContext::eTypeIsArray)) + int cstr_len_displayed = -1; + bool capped_cstr = false; + // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host + // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this + while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0) { - // We have an array - cstr_len = ClangASTContext::GetArraySize (clang_type); - if (cstr_len > max_length) + const char *cstr = data.PeekCStr(0); + size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1); + if (len > k_max_buf_size) + len = k_max_buf_size; + if (cstr && cstr_len_displayed < 0) + s << '"'; + + if (cstr_len_displayed < 0) + cstr_len_displayed = len; + + if (len == 0) + break; + cstr_len_displayed += len; + if (len > bytes_read) + len = bytes_read; + if (len > cstr_len) + len = cstr_len; + + data.Dump (&s, + 0, // Start offset in "data" + item_format, + 1, // Size of item (1 byte for a char!) + len, // How many bytes to print? + UINT32_MAX, // num per line + LLDB_INVALID_ADDRESS,// base address + 0, // bitfield bit size + 0); // bitfield bit offset + + if (len < k_max_buf_size) + break; + + if (len >= cstr_len) { - capped_data = true; - cstr_len = max_length; + capped_cstr = true; + break; } - cstr_address = GetAddressOf (true, &cstr_address_type); + + cstr_len -= len; + offset += len; } - else + + if (cstr_len_displayed >= 0) { - // We have a pointer - cstr_address = GetPointerValue (&cstr_address_type); - } - if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS) - { - Address cstr_so_addr (NULL, cstr_address); - DataExtractor data; - size_t bytes_read = 0; - if (cstr_len > 0 && honor_array) - { - // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host - // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this - GetPointeeData(data, 0, cstr_len); - - if ((bytes_read = data.GetByteSize()) > 0) - { - s << '"'; - data.Dump (&s, - 0, // Start offset in "data" - item_format, - 1, // Size of item (1 byte for a char!) - bytes_read, // How many bytes to print? - UINT32_MAX, // num per line - LLDB_INVALID_ADDRESS,// base address - 0, // bitfield bit size - 0); // bitfield bit offset - if (capped_data) - s << "..."; - s << '"'; - } - } - else - { - cstr_len = max_length; - const size_t k_max_buf_size = 64; - - size_t offset = 0; - - int cstr_len_displayed = -1; - bool capped_cstr = false; - // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host - // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this - while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0) - { - const char *cstr = data.PeekCStr(0); - size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1); - if (len > k_max_buf_size) - len = k_max_buf_size; - if (cstr && cstr_len_displayed < 0) - s << '"'; - - if (cstr_len_displayed < 0) - cstr_len_displayed = len; - - if (len == 0) - break; - cstr_len_displayed += len; - if (len > bytes_read) - len = bytes_read; - if (len > cstr_len) - len = cstr_len; - - data.Dump (&s, - 0, // Start offset in "data" - item_format, - 1, // Size of item (1 byte for a char!) - len, // How many bytes to print? - UINT32_MAX, // num per line - LLDB_INVALID_ADDRESS,// base address - 0, // bitfield bit size - 0); // bitfield bit offset - - if (len < k_max_buf_size) - break; - - if (len >= cstr_len) - { - capped_cstr = true; - break; - } - - cstr_len -= len; - offset += len; - } - - if (cstr_len_displayed >= 0) - { - s << '"'; - if (capped_cstr) - s << "..."; - } - } + s << '"'; + if (capped_cstr) + s << "..."; } } } + } } else { @@ -979,11 +964,8 @@ ValueObject::GetObjectDescription () if (!m_object_desc_str.empty()) return m_object_desc_str.c_str(); - ExecutionContextScope *exe_scope = GetExecutionContextScope(); - if (exe_scope == NULL) - return NULL; - - Process *process = exe_scope->CalculateProcess(); + ExecutionContext exe_ctx (GetExecutionContextRef()); + Process *process = exe_ctx.GetProcessPtr(); if (process == NULL) return NULL; @@ -1053,6 +1035,7 @@ ValueObject::GetValueAsCString () } } StreamString sstr; + ExecutionContext exe_ctx (GetExecutionContextRef()); if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST clang_type, // The clang type to display &sstr, @@ -1062,7 +1045,7 @@ ValueObject::GetValueAsCString () GetByteSize(), // Byte size of item in "m_data" GetBitfieldBitSize(), // Bitfield bit size GetBitfieldBitOffset(), - GetExecutionContextScope())) // Bitfield bit offset + exe_ctx.GetBestExecutionContextScope())) // Bitfield bit offset m_value_str.swap(sstr.GetString()); else { @@ -1089,8 +1072,19 @@ ValueObject::GetValueAsCString () my_format = reg_info->format; } + ExecutionContext exe_ctx (GetExecutionContextRef()); + StreamString reg_sstr; - m_data.Dump(®_sstr, 0, my_format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0, GetExecutionContextScope()); + m_data.Dump (®_sstr, + 0, + my_format, + reg_info->byte_size, + 1, + UINT32_MAX, + LLDB_INVALID_ADDRESS, + 0, + 0, + exe_ctx.GetBestExecutionContextScope()); m_value_str.swap(reg_sstr.GetString()); } } @@ -1492,24 +1486,25 @@ ValueObject::SetValueFromCString (const char *value_str) { switch (value_type) { - case Value::eValueTypeLoadAddress: + case Value::eValueTypeLoadAddress: { // If it is a load address, then the scalar value is the storage location // of the data, and we have to shove this value down to that load location. - ProcessSP process_sp = GetUpdatePoint().GetProcessSP(); - if (process_sp) + ExecutionContext exe_ctx (GetExecutionContextRef()); + Process *process = exe_ctx.GetProcessPtr(); + if (process) { addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS); - size_t bytes_written = process_sp->WriteScalarToMemory (target_addr, - new_scalar, - byte_size, - error); + size_t bytes_written = process->WriteScalarToMemory (target_addr, + new_scalar, + byte_size, + error); if (!error.Success() || bytes_written != byte_size) return false; } } break; - case Value::eValueTypeHostAddress: + case Value::eValueTypeHostAddress: { // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data. DataExtractor new_data; @@ -1520,18 +1515,18 @@ ValueObject::SetValueFromCString (const char *value_str) bool success = new_scalar.GetData(new_data); if (success) { - new_data.CopyByteOrderedData(0, - byte_size, - const_cast(m_data.GetDataStart()), - byte_size, - m_data.GetByteOrder()); + new_data.CopyByteOrderedData (0, + byte_size, + const_cast(m_data.GetDataStart()), + byte_size, + m_data.GetByteOrder()); } m_value.GetScalar() = (uintptr_t)m_data.GetDataStart(); } break; - case Value::eValueTypeFileAddress: - case Value::eValueTypeScalar: + case Value::eValueTypeFileAddress: + case Value::eValueTypeScalar: break; } } @@ -1896,39 +1891,39 @@ ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic) if (!m_dynamic_value && !IsDynamic()) { - Process *process = m_update_point.GetProcessSP().get(); - bool worth_having_dynamic_value = false; - - - // FIXME: Process should have some kind of "map over Runtimes" so we don't have to - // hard code this everywhere. - LanguageType known_type = GetObjectRuntimeLanguage(); - if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC) + ExecutionContext exe_ctx (GetExecutionContextRef()); + Process *process = exe_ctx.GetProcessPtr(); + if (process) { - LanguageRuntime *runtime = process->GetLanguageRuntime (known_type); - if (runtime) - worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this); - } - else - { - LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus); - if (cpp_runtime) - worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this); + bool worth_having_dynamic_value = false; - if (!worth_having_dynamic_value) + + // FIXME: Process should have some kind of "map over Runtimes" so we don't have to + // hard code this everywhere. + LanguageType known_type = GetObjectRuntimeLanguage(); + if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC) { - LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC); - if (objc_runtime) - worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this); + LanguageRuntime *runtime = process->GetLanguageRuntime (known_type); + if (runtime) + worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this); + } + else + { + LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus); + if (cpp_runtime) + worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this); + + if (!worth_having_dynamic_value) + { + LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC); + if (objc_runtime) + worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this); + } } - } - - if (worth_having_dynamic_value) - m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic); -// if (worth_having_dynamic_value) -// printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager); - + if (worth_having_dynamic_value) + m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic); + } } } @@ -3029,7 +3024,8 @@ ValueObject::DumpValueObject (/*strstr(typeName, "id") == typeName ||*/ ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC)) { - Process* process = valobj->GetUpdatePoint().GetProcessSP().get(); + ExecutionContext exe_ctx (valobj->GetExecutionContextRef()); + Process *process = exe_ctx.GetProcessPtr(); if (process == NULL) s.Printf(", dynamic type: unknown) "); else @@ -3179,9 +3175,9 @@ ValueObject::DumpValueObject if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr)) { - ValueObjectSP synth_valobj = valobj->GetSyntheticValue(use_synth ? - eUseSyntheticFilter : - eNoSyntheticFilter); + ValueObjectSP synth_valobj = valobj->GetSyntheticValue (use_synth ? + eUseSyntheticFilter : + eNoSyntheticFilter); uint32_t num_children = synth_valobj->GetNumChildren(); bool print_dotdotdot = false; if (num_children) @@ -3198,7 +3194,7 @@ ValueObject::DumpValueObject s.IndentMore(); } - uint32_t max_num_children = valobj->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay(); + uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay(); if (num_children > max_num_children && !ignore_cap) { @@ -3234,7 +3230,10 @@ ValueObject::DumpValueObject { if (print_dotdotdot) { - valobj->GetUpdatePoint().GetTargetSP()->GetDebugger().GetCommandInterpreter().ChildrenTruncated(); + ExecutionContext exe_ctx (valobj->GetExecutionContextRef()); + Target *target = exe_ctx.GetTargetPtr(); + if (target) + target->GetDebugger().GetCommandInterpreter().ChildrenTruncated(); s.Indent("...\n"); } s.IndentLess(); @@ -3278,27 +3277,21 @@ ValueObject::CreateConstantValue (const ConstString &name) if (UpdateValueIfNeeded(false) && m_error.Success()) { - ExecutionContextScope *exe_scope = GetExecutionContextScope(); - if (exe_scope) - { - ExecutionContext exe_ctx; - exe_scope->CalculateExecutionContext(exe_ctx); - - clang::ASTContext *ast = GetClangAST (); - - DataExtractor data; - data.SetByteOrder (m_data.GetByteOrder()); - data.SetAddressByteSize(m_data.GetAddressByteSize()); - - m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule()); - - valobj_sp = ValueObjectConstResult::Create (exe_scope, - ast, - GetClangType(), - name, - data, - GetAddressOf()); - } + ExecutionContext exe_ctx (GetExecutionContextRef()); + clang::ASTContext *ast = GetClangAST (); + + DataExtractor data; + data.SetByteOrder (m_data.GetByteOrder()); + data.SetAddressByteSize(m_data.GetAddressByteSize()); + + m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule()); + + valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), + ast, + GetClangType(), + name, + data, + GetAddressOf()); } if (!valobj_sp) @@ -3332,8 +3325,7 @@ ValueObject::Dereference (Error &error) clang_type_t clang_type = GetClangType(); clang_type_t child_clang_type; - ExecutionContext exe_ctx; - GetExecutionContextScope()->CalculateExecutionContext (exe_ctx); + ExecutionContext exe_ctx (GetExecutionContextRef()); child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx, clang_ast, @@ -3421,7 +3413,8 @@ ValueObject::AddressOf (Error &error) { std::string name (1, '&'); name.append (m_name.AsCString("")); - m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(), + ExecutionContext exe_ctx (GetExecutionContextRef()); + m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), ast, ClangASTContext::CreatePointerType (ast, clang_type), ConstString (name.c_str()), @@ -3452,8 +3445,8 @@ ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type) if (ptr_value != LLDB_INVALID_ADDRESS) { Address ptr_addr (NULL, ptr_value); - - valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(), + ExecutionContext exe_ctx (GetExecutionContextRef()); + valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, clang_ast_type); @@ -3471,8 +3464,8 @@ ValueObject::CastPointerType (const char *name, TypeSP &type_sp) if (ptr_value != LLDB_INVALID_ADDRESS) { Address ptr_addr (NULL, ptr_value); - - valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(), + ExecutionContext exe_ctx (GetExecutionContextRef()); + valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, type_sp); @@ -3481,73 +3474,63 @@ ValueObject::CastPointerType (const char *name, TypeSP &type_sp) } ValueObject::EvaluationPoint::EvaluationPoint () : - ExecutionContextScope(), - m_thread_id (LLDB_INVALID_UID), - m_mod_id () + m_mod_id(), + m_exe_ctx_ref(), + m_needs_update (true), + m_first_update (true) { } ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected): - ExecutionContextScope (), + m_mod_id(), + m_exe_ctx_ref(), m_needs_update (true), - m_first_update (true), - m_thread_id (LLDB_INVALID_THREAD_ID), - m_mod_id () - + m_first_update (true) { - ExecutionContext exe_ctx; - - if (exe_scope) - exe_scope->CalculateExecutionContext(exe_ctx); - Target *target = exe_ctx.GetTargetPtr(); - if (target != NULL) + ExecutionContext exe_ctx(exe_scope); + TargetSP target_sp (exe_ctx.GetTargetSP()); + if (target_sp) { - m_target_sp = target->shared_from_this(); - m_process_sp = exe_ctx.GetProcessSP(); - if (!m_process_sp) - m_process_sp = target->GetProcessSP(); + m_exe_ctx_ref.SetTargetSP (target_sp); + ProcessSP process_sp (exe_ctx.GetProcessSP()); + if (!process_sp) + process_sp = target_sp->GetProcessSP(); - if (m_process_sp) + if (process_sp) { - m_mod_id = m_process_sp->GetModID(); + m_mod_id = process_sp->GetModID(); + m_exe_ctx_ref.SetProcessSP (process_sp); - Thread *thread = exe_ctx.GetThreadPtr(); + ThreadSP thread_sp (exe_ctx.GetThreadSP()); - if (thread == NULL) + if (!thread_sp) { if (use_selected) - thread = m_process_sp->GetThreadList().GetSelectedThread().get(); + thread_sp = process_sp->GetThreadList().GetSelectedThread(); } - if (thread != NULL) + if (thread_sp) { - m_thread_id = thread->GetIndexID(); + m_exe_ctx_ref.SetThreadSP(thread_sp); - StackFrame *frame = exe_ctx.GetFramePtr(); - if (frame == NULL) + StackFrameSP frame_sp (exe_ctx.GetFrameSP()); + if (!frame_sp) { if (use_selected) - { - frame = thread->GetSelectedFrame().get(); - if (frame) - m_stack_id = frame->GetStackID(); - } + frame_sp = thread_sp->GetSelectedFrame(); } - else - m_stack_id = frame->GetStackID(); + if (frame_sp) + m_exe_ctx_ref.SetFrameSP(frame_sp); } } } } ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) : - m_needs_update(true), - m_first_update(true), - m_target_sp (rhs.m_target_sp), - m_process_sp (rhs.m_process_sp), - m_thread_id (rhs.m_thread_id), - m_stack_id (rhs.m_stack_id), - m_mod_id () + m_mod_id(), + m_exe_ctx_ref(rhs.m_exe_ctx_ref), + m_needs_update (true), + m_first_update (true) { } @@ -3555,49 +3538,6 @@ ValueObject::EvaluationPoint::~EvaluationPoint () { } -Target * -ValueObject::EvaluationPoint::CalculateTarget () -{ - return m_target_sp.get(); -} - -Process * -ValueObject::EvaluationPoint::CalculateProcess () -{ - return m_process_sp.get(); -} - -Thread * -ValueObject::EvaluationPoint::CalculateThread () -{ - ExecutionContextScope *exe_scope; - SyncWithProcessState(exe_scope); - if (exe_scope) - return exe_scope->CalculateThread(); - else - return NULL; -} - -StackFrame * -ValueObject::EvaluationPoint::CalculateStackFrame () -{ - ExecutionContextScope *exe_scope; - SyncWithProcessState(exe_scope); - if (exe_scope) - return exe_scope->CalculateStackFrame(); - else - return NULL; -} - -void -ValueObject::EvaluationPoint::CalculateExecutionContext (ExecutionContext &exe_ctx) -{ - ExecutionContextScope *exe_scope; - SyncWithProcessState(exe_scope); - if (exe_scope) - return exe_scope->CalculateExecutionContext (exe_ctx); -} - // This function checks the EvaluationPoint against the current process state. If the current // state matches the evaluation point, or the evaluation point is already invalid, then we return // false, meaning "no change". If the current state is different, we update our state, and return @@ -3606,23 +3546,22 @@ ValueObject::EvaluationPoint::CalculateExecutionContext (ExecutionContext &exe_c // exe_scope will be set to the current execution context scope. bool -ValueObject::EvaluationPoint::SyncWithProcessState(ExecutionContextScope *&exe_scope) +ValueObject::EvaluationPoint::SyncWithProcessState() { // Start with the target, if it is NULL, then we're obviously not going to get any further: - exe_scope = m_target_sp.get(); + ExecutionContext exe_ctx(m_exe_ctx_ref.Lock()); - if (exe_scope == NULL) + if (exe_ctx.GetTargetPtr() == NULL) return false; // If we don't have a process nothing can change. - if (!m_process_sp) + Process *process = exe_ctx.GetProcessPtr(); + if (process == NULL) return false; - exe_scope = m_process_sp.get(); - // If our stop id is the current stop ID, nothing has changed: - ProcessModID current_mod_id = m_process_sp->GetModID(); + ProcessModID current_mod_id = process->GetModID(); // If the current stop id is 0, either we haven't run yet, or the process state has been cleared. // In either case, we aren't going to be able to sync with the process state. @@ -3651,26 +3590,27 @@ ValueObject::EvaluationPoint::SyncWithProcessState(ExecutionContextScope *&exe_s // That way we'll be sure to return a valid exe_scope. // If we used to have a thread or a frame but can't find it anymore, then mark ourselves as invalid. - if (m_thread_id != LLDB_INVALID_THREAD_ID) + if (m_exe_ctx_ref.HasThreadRef()) { - Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get(); - if (our_thread == NULL) + ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP()); + if (thread_sp) { - SetInvalid(); + if (m_exe_ctx_ref.HasFrameRef()) + { + StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP()); + if (!frame_sp) + { + // We used to have a frame, but now it is gone + SetInvalid(); + } + } } else { - exe_scope = our_thread; - - if (m_stack_id.IsValid()) - { - StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get(); - if (our_frame == NULL) - SetInvalid(); - else - exe_scope = our_frame; - } + // We used to have a thread, but now it is gone + SetInvalid(); } + } return changed; } @@ -3678,110 +3618,111 @@ ValueObject::EvaluationPoint::SyncWithProcessState(ExecutionContextScope *&exe_s void ValueObject::EvaluationPoint::SetUpdated () { - if (m_process_sp) - m_mod_id = m_process_sp->GetModID(); + ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP()); + if (process_sp) + m_mod_id = process_sp->GetModID(); m_first_update = false; m_needs_update = false; } -bool -ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope) -{ - if (!IsValid()) - return false; - - bool needs_update = false; - - // The target has to be non-null, and the - Target *target = exe_scope->CalculateTarget(); - if (target != NULL) - { - Target *old_target = m_target_sp.get(); - assert (target == old_target); - Process *process = exe_scope->CalculateProcess(); - if (process != NULL) - { - // FOR NOW - assume you can't update variable objects across process boundaries. - Process *old_process = m_process_sp.get(); - assert (process == old_process); - ProcessModID current_mod_id = process->GetModID(); - if (m_mod_id != current_mod_id) - { - needs_update = true; - m_mod_id = current_mod_id; - } - // See if we're switching the thread or stack context. If no thread is given, this is - // being evaluated in a global context. - Thread *thread = exe_scope->CalculateThread(); - if (thread != NULL) - { - user_id_t new_thread_index = thread->GetIndexID(); - if (new_thread_index != m_thread_id) - { - needs_update = true; - m_thread_id = new_thread_index; - m_stack_id.Clear(); - } - - StackFrame *new_frame = exe_scope->CalculateStackFrame(); - if (new_frame != NULL) - { - if (new_frame->GetStackID() != m_stack_id) - { - needs_update = true; - m_stack_id = new_frame->GetStackID(); - } - } - else - { - m_stack_id.Clear(); - needs_update = true; - } - } - else - { - // If this had been given a thread, and now there is none, we should update. - // Otherwise we don't have to do anything. - if (m_thread_id != LLDB_INVALID_UID) - { - m_thread_id = LLDB_INVALID_UID; - m_stack_id.Clear(); - needs_update = true; - } - } - } - else - { - // If there is no process, then we don't need to update anything. - // But if we're switching from having a process to not, we should try to update. - if (m_process_sp.get() != NULL) - { - needs_update = true; - m_process_sp.reset(); - m_thread_id = LLDB_INVALID_UID; - m_stack_id.Clear(); - } - } - } - else - { - // If there's no target, nothing can change so we don't need to update anything. - // But if we're switching from having a target to not, we should try to update. - if (m_target_sp.get() != NULL) - { - needs_update = true; - m_target_sp.reset(); - m_process_sp.reset(); - m_thread_id = LLDB_INVALID_UID; - m_stack_id.Clear(); - } - } - if (!m_needs_update) - m_needs_update = needs_update; - - return needs_update; -} +//bool +//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope) +//{ +// if (!IsValid()) +// return false; +// +// bool needs_update = false; +// +// // The target has to be non-null, and the +// Target *target = exe_scope->CalculateTarget(); +// if (target != NULL) +// { +// Target *old_target = m_target_sp.get(); +// assert (target == old_target); +// Process *process = exe_scope->CalculateProcess(); +// if (process != NULL) +// { +// // FOR NOW - assume you can't update variable objects across process boundaries. +// Process *old_process = m_process_sp.get(); +// assert (process == old_process); +// ProcessModID current_mod_id = process->GetModID(); +// if (m_mod_id != current_mod_id) +// { +// needs_update = true; +// m_mod_id = current_mod_id; +// } +// // See if we're switching the thread or stack context. If no thread is given, this is +// // being evaluated in a global context. +// Thread *thread = exe_scope->CalculateThread(); +// if (thread != NULL) +// { +// user_id_t new_thread_index = thread->GetIndexID(); +// if (new_thread_index != m_thread_id) +// { +// needs_update = true; +// m_thread_id = new_thread_index; +// m_stack_id.Clear(); +// } +// +// StackFrame *new_frame = exe_scope->CalculateStackFrame(); +// if (new_frame != NULL) +// { +// if (new_frame->GetStackID() != m_stack_id) +// { +// needs_update = true; +// m_stack_id = new_frame->GetStackID(); +// } +// } +// else +// { +// m_stack_id.Clear(); +// needs_update = true; +// } +// } +// else +// { +// // If this had been given a thread, and now there is none, we should update. +// // Otherwise we don't have to do anything. +// if (m_thread_id != LLDB_INVALID_UID) +// { +// m_thread_id = LLDB_INVALID_UID; +// m_stack_id.Clear(); +// needs_update = true; +// } +// } +// } +// else +// { +// // If there is no process, then we don't need to update anything. +// // But if we're switching from having a process to not, we should try to update. +// if (m_process_sp.get() != NULL) +// { +// needs_update = true; +// m_process_sp.reset(); +// m_thread_id = LLDB_INVALID_UID; +// m_stack_id.Clear(); +// } +// } +// } +// else +// { +// // If there's no target, nothing can change so we don't need to update anything. +// // But if we're switching from having a target to not, we should try to update. +// if (m_target_sp.get() != NULL) +// { +// needs_update = true; +// m_target_sp.reset(); +// m_process_sp.reset(); +// m_thread_id = LLDB_INVALID_UID; +// m_stack_id.Clear(); +// } +// } +// if (!m_needs_update) +// m_needs_update = needs_update; +// +// return needs_update; +//} void ValueObject::ClearUserVisibleData() diff --git a/lldb/source/Core/ValueObjectChild.cpp b/lldb/source/Core/ValueObjectChild.cpp index 92532a3e52c9..eb2479047420 100644 --- a/lldb/source/Core/ValueObjectChild.cpp +++ b/lldb/source/Core/ValueObjectChild.cpp @@ -129,10 +129,13 @@ ValueObjectChild::UpdateValue () switch (addr_type) { case eAddressTypeFile: - if (m_update_point.GetProcessSP().get() != NULL && m_update_point.GetProcessSP()->IsAlive() == true) - m_value.SetValueType (Value::eValueTypeLoadAddress); - else - m_value.SetValueType(Value::eValueTypeFileAddress); + { + lldb::ProcessSP process_sp (GetProcessSP()); + if (process_sp && process_sp->IsAlive() == true) + m_value.SetValueType (Value::eValueTypeLoadAddress); + else + m_value.SetValueType(Value::eValueTypeFileAddress); + } break; case eAddressTypeLoad: m_value.SetValueType (Value::eValueTypeLoadAddress); @@ -186,7 +189,7 @@ ValueObjectChild::UpdateValue () if (m_error.Success()) { - ExecutionContext exe_ctx (GetExecutionContextScope()); + ExecutionContext exe_ctx (GetExecutionContextRef().Lock()); m_error = m_value.GetValueAsData (&exe_ctx, GetClangAST (), m_data, 0, GetModule()); } } diff --git a/lldb/source/Core/ValueObjectConstResultImpl.cpp b/lldb/source/Core/ValueObjectConstResultImpl.cpp index 31646b4ca0be..731f3938e283 100644 --- a/lldb/source/Core/ValueObjectConstResultImpl.cpp +++ b/lldb/source/Core/ValueObjectConstResultImpl.cpp @@ -53,13 +53,14 @@ ValueObjectConstResultImpl::DerefOnTarget() if (m_load_addr_backend.get() == NULL) { lldb::addr_t tgt_address = m_impl_backend->GetPointerValue(); - m_load_addr_backend = ValueObjectConstResult::Create (m_impl_backend->GetExecutionContextScope(), + ExecutionContext exe_ctx (m_impl_backend->GetExecutionContextRef()); + m_load_addr_backend = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_impl_backend->GetClangAST(), m_impl_backend->GetClangType(), m_impl_backend->GetName(), tgt_address, eAddressTypeLoad, - m_impl_backend->GetUpdatePoint().GetProcessSP()->GetAddressByteSize()); + exe_ctx.GetAddressByteSize()); } return m_load_addr_backend; } @@ -107,8 +108,7 @@ ValueObjectConstResultImpl::CreateChildAtIndex (uint32_t idx, bool synthetic_arr lldb::clang_type_t clang_type = m_impl_backend->GetClangType(); lldb::clang_type_t child_clang_type; - ExecutionContext exe_ctx; - m_impl_backend->GetExecutionContextScope()->CalculateExecutionContext (exe_ctx); + ExecutionContext exe_ctx (m_impl_backend->GetExecutionContextRef()); child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx, clang_ast, @@ -184,14 +184,14 @@ ValueObjectConstResultImpl::AddressOf (Error &error) std::string new_name("&"); new_name.append(m_impl_backend->GetName().AsCString("")); - - m_address_of_backend = ValueObjectConstResult::Create(m_impl_backend->GetExecutionContextScope(), - type.GetASTContext(), - type.GetPointerType(), - ConstString(new_name.c_str()), - buffer, - lldb::endian::InlHostByteOrder(), - m_impl_backend->GetExecutionContextScope()->CalculateProcess()->GetAddressByteSize()); + ExecutionContext exe_ctx (m_impl_backend->GetExecutionContextRef()); + m_address_of_backend = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), + type.GetASTContext(), + type.GetPointerType(), + ConstString(new_name.c_str()), + buffer, + lldb::endian::InlHostByteOrder(), + exe_ctx.GetAddressByteSize()); m_address_of_backend->GetValue().SetValueType(Value::eValueTypeScalar); m_address_of_backend->GetValue().GetScalar() = m_live_address; diff --git a/lldb/source/Core/ValueObjectDynamicValue.cpp b/lldb/source/Core/ValueObjectDynamicValue.cpp index 5ea7993411b9..e608ce9bb708 100644 --- a/lldb/source/Core/ValueObjectDynamicValue.cpp +++ b/lldb/source/Core/ValueObjectDynamicValue.cpp @@ -117,7 +117,7 @@ ValueObjectCast::UpdateValue () // say we are changed if our location has changed. SetValueDidChange (m_value.GetValueType() != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar()); } - ExecutionContext exe_ctx (GetExecutionContextScope()); + ExecutionContext exe_ctx (GetExecutionContextRef()); m_error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), m_data, 0, GetModule()); SetValueDidChange (m_parent->GetValueDidChange()); return true; @@ -235,7 +235,7 @@ ValueObjectDynamicValue::UpdateValue () return true; } - ExecutionContext exe_ctx (GetExecutionContextScope()); + ExecutionContext exe_ctx (GetExecutionContextRef()); Target *target = exe_ctx.GetTargetPtr(); if (target) { @@ -244,7 +244,7 @@ ValueObjectDynamicValue::UpdateValue () } // First make sure our Type and/or Address haven't changed: - Process *process = m_update_point.GetProcessSP().get(); + Process *process = exe_ctx.GetProcessPtr(); if (!process) return false; @@ -311,7 +311,8 @@ ValueObjectDynamicValue::UpdateValue () // We've moved, so we should be fine... m_address = dynamic_address; - lldb::addr_t load_address = m_address.GetLoadAddress(m_update_point.GetTargetSP().get()); + lldb::TargetSP target_sp (GetTargetSP()); + lldb::addr_t load_address = m_address.GetLoadAddress(target_sp.get()); m_value.GetScalar() = load_address; } diff --git a/lldb/source/Core/ValueObjectMemory.cpp b/lldb/source/Core/ValueObjectMemory.cpp index 5d9406e02f2a..9f26a4608648 100644 --- a/lldb/source/Core/ValueObjectMemory.cpp +++ b/lldb/source/Core/ValueObjectMemory.cpp @@ -64,7 +64,8 @@ ValueObjectMemory::ValueObjectMemory (ExecutionContextScope *exe_scope, assert (m_type_sp.get() != NULL); SetName (ConstString(name)); m_value.SetContext(Value::eContextTypeLLDBType, m_type_sp.get()); - lldb::addr_t load_address = m_address.GetLoadAddress(m_update_point.GetTargetSP().get()); + TargetSP target_sp (GetTargetSP()); + lldb::addr_t load_address = m_address.GetLoadAddress(target_sp.get()); if (load_address != LLDB_INVALID_ADDRESS) { m_value.SetValueType(Value::eValueTypeLoadAddress); @@ -99,9 +100,11 @@ ValueObjectMemory::ValueObjectMemory (ExecutionContextScope *exe_scope, assert (m_clang_type.GetASTContext()); assert (m_clang_type.GetOpaqueQualType()); + TargetSP target_sp (GetTargetSP()); + SetName (ConstString(name)); m_value.SetContext(Value::eContextTypeClangType, m_clang_type.GetOpaqueQualType()); - lldb::addr_t load_address = m_address.GetLoadAddress(m_update_point.GetTargetSP().get()); + lldb::addr_t load_address = m_address.GetLoadAddress (target_sp.get()); if (load_address != LLDB_INVALID_ADDRESS) { m_value.SetValueType(Value::eValueTypeLoadAddress); @@ -183,7 +186,7 @@ ValueObjectMemory::UpdateValue () SetValueIsValid (false); m_error.Clear(); - ExecutionContext exe_ctx (GetExecutionContextScope()); + ExecutionContext exe_ctx (GetExecutionContextRef()); Target *target = exe_ctx.GetTargetPtr(); if (target) diff --git a/lldb/source/Core/ValueObjectRegister.cpp b/lldb/source/Core/ValueObjectRegister.cpp index 40e4d89a0705..f0896094eafa 100644 --- a/lldb/source/Core/ValueObjectRegister.cpp +++ b/lldb/source/Core/ValueObjectRegister.cpp @@ -77,8 +77,8 @@ bool ValueObjectRegisterContext::UpdateValue () { m_error.Clear(); - ExecutionContextScope *exe_scope = GetExecutionContextScope(); - StackFrame *frame = exe_scope->CalculateStackFrame(); + ExecutionContext exe_ctx(GetExecutionContextRef()); + StackFrame *frame = exe_ctx.GetFramePtr(); if (frame) m_reg_ctx_sp = frame->GetRegisterContext(); else @@ -102,7 +102,10 @@ ValueObjectRegisterContext::CreateChildAtIndex (uint32_t idx, bool synthetic_arr const uint32_t num_children = GetNumChildren(); if (idx < num_children) - new_valobj = new ValueObjectRegisterSet(GetExecutionContextScope(), m_reg_ctx_sp, idx); + { + ExecutionContext exe_ctx(GetExecutionContextRef()); + new_valobj = new ValueObjectRegisterSet(exe_ctx.GetBestExecutionContextScope(), m_reg_ctx_sp, idx); + } return new_valobj; } @@ -174,8 +177,8 @@ ValueObjectRegisterSet::UpdateValue () { m_error.Clear(); SetValueDidChange (false); - ExecutionContextScope *exe_scope = GetExecutionContextScope(); - StackFrame *frame = exe_scope->CalculateStackFrame(); + ExecutionContext exe_ctx(GetExecutionContextRef()); + StackFrame *frame = exe_ctx.GetFramePtr(); if (frame == NULL) m_reg_ctx_sp.reset(); else @@ -355,8 +358,8 @@ bool ValueObjectRegister::UpdateValue () { m_error.Clear(); - ExecutionContextScope *exe_scope = GetExecutionContextScope(); - StackFrame *frame = exe_scope->CalculateStackFrame(); + ExecutionContext exe_ctx(GetExecutionContextRef()); + StackFrame *frame = exe_ctx.GetFramePtr(); if (frame == NULL) { m_reg_ctx_sp.reset(); diff --git a/lldb/source/Core/ValueObjectVariable.cpp b/lldb/source/Core/ValueObjectVariable.cpp index 181324db251c..24f189d9f953 100644 --- a/lldb/source/Core/ValueObjectVariable.cpp +++ b/lldb/source/Core/ValueObjectVariable.cpp @@ -127,7 +127,7 @@ ValueObjectVariable::UpdateValue () else { lldb::addr_t loclist_base_load_addr = LLDB_INVALID_ADDRESS; - ExecutionContext exe_ctx (GetExecutionContextScope()); + ExecutionContext exe_ctx (GetExecutionContextRef()); Target *target = exe_ctx.GetTargetPtr(); if (target) @@ -242,15 +242,27 @@ ValueObjectVariable::UpdateValue () bool ValueObjectVariable::IsInScope () { - ExecutionContextScope *exe_scope = GetExecutionContextScope(); - if (!exe_scope) - return true; - - StackFrame *frame = exe_scope->CalculateStackFrame(); - if (!frame) - return true; + const ExecutionContextRef &exe_ctx_ref = GetExecutionContextRef(); + if (exe_ctx_ref.HasFrameRef()) + { + ExecutionContext exe_ctx (exe_ctx_ref); + StackFrame *frame = exe_ctx.GetFramePtr(); + if (frame) + { + return m_variable_sp->IsInScope (frame); + } + else + { + // This ValueObject had a frame at one time, but now we + // can't locate it, so return false since we probably aren't + // in scope. + return false; + } + } + // We have a variable that wasn't tied to a frame, which + // means it is a global and is always in scope. + return true; - return m_variable_sp->IsInScope (frame); } Module * diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp index 71b7162102aa..0aefdaa3fa21 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -1330,7 +1330,8 @@ ScriptInterpreterPython::CreateSyntheticScriptedProvider (std::string class_name if (!valobj.get()) return NULL; - Target *target = valobj->GetUpdatePoint().GetTargetSP().get(); + ExecutionContext exe_ctx (valobj->GetExecutionContextRef()); + Target *target = exe_ctx.GetTargetPtr(); if (!target) return NULL; @@ -1448,7 +1449,8 @@ ScriptInterpreterPython::CallPythonScriptFunction (const char *python_function_n if (!valobj.get()) return ""; - Target *target = valobj->GetUpdatePoint().GetTargetSP().get(); + ExecutionContext exe_ctx (valobj->GetExecutionContextRef()); + Target *target = exe_ctx.GetTargetPtr(); if (!target) return ""; diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp index 27f80cb3cb55..b8cf0d501200 100644 --- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp @@ -65,9 +65,11 @@ ItaniumABILanguageRuntime::GetDynamicTypeAndAddress (ValueObject &in_value, lldb::addr_t original_ptr = in_value.GetPointerValue(&address_type); if (original_ptr == LLDB_INVALID_ADDRESS) return false; - - Target *target = in_value.GetUpdatePoint().GetTargetSP().get(); - Process *process = in_value.GetUpdatePoint().GetProcessSP().get(); + + ExecutionContext exe_ctx (in_value.GetExecutionContextRef()); + + Target *target = exe_ctx.GetTargetPtr(); + Process *process = exe_ctx.GetProcessPtr(); char memory_buffer[16]; DataExtractor data(memory_buffer, sizeof(memory_buffer), diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp index 43c9aa604425..eaae268eb595 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp @@ -39,22 +39,23 @@ using namespace lldb; using namespace lldb_private; bool -AppleObjCRuntime::GetObjectDescription (Stream &str, ValueObject &object) +AppleObjCRuntime::GetObjectDescription (Stream &str, ValueObject &valobj) { bool is_signed; // ObjC objects can only be pointers, but we extend this to integer types because an expression might just // result in an address, and we should try that to see if the address is an ObjC object. - if (!(object.IsPointerType() || object.IsIntegerType(is_signed))) + if (!(valobj.IsPointerType() || valobj.IsIntegerType(is_signed))) return NULL; // Make the argument list: we pass one arg, the address of our pointer, to the print function. Value val; - if (!object.ResolveValue(val.GetScalar())) + if (!valobj.ResolveValue(val.GetScalar())) return NULL; - - return GetObjectDescription(str, val, object.GetExecutionContextScope()); + + ExecutionContext exe_ctx (valobj.GetExecutionContextRef()); + return GetObjectDescription(str, val, exe_ctx.GetBestExecutionContextScope()); } bool diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index e3341c95a278..618ccf295fa8 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -237,8 +237,9 @@ AppleObjCRuntimeV2::GetDynamicTypeAndAddress (ValueObject &in_value, Address &address) { // The Runtime is attached to a particular process, you shouldn't pass in a value from another process. - assert (in_value.GetUpdatePoint().GetProcessSP().get() == m_process); - + assert (in_value.GetProcessSP().get() == m_process); + assert (m_process != NULL); + // Make sure we can have a dynamic value before starting... if (CouldHaveDynamicValue (in_value)) { @@ -309,10 +310,10 @@ AppleObjCRuntimeV2::GetDynamicTypeAndAddress (ValueObject &in_value, // If the class address didn't point into the binary, or // it points into the right section but there wasn't a symbol // there, try to look it up by calling the class method in the target. - ExecutionContextScope *exe_scope = in_value.GetExecutionContextScope(); - Thread *thread_to_use; - if (exe_scope) - thread_to_use = exe_scope->CalculateThread(); + + ExecutionContext exe_ctx (in_value.GetExecutionContextRef()); + + Thread *thread_to_use = exe_ctx.GetThreadPtr(); if (thread_to_use == NULL) thread_to_use = m_process->GetThreadList().GetSelectedThread().get(); @@ -592,15 +593,20 @@ AppleObjCRuntimeV2::GetISA(ValueObject& valobj) if (IsTaggedPointer(isa_pointer)) return g_objc_Tagged_ISA; - uint8_t pointer_size = valobj.GetUpdatePoint().GetProcessSP()->GetAddressByteSize(); + ExecutionContext exe_ctx (valobj.GetExecutionContextRef()); + + Process *process = exe_ctx.GetProcessPtr(); + if (process) + { + uint8_t pointer_size = process->GetAddressByteSize(); - Error error; - ObjCLanguageRuntime::ObjCISA isa = - valobj.GetUpdatePoint().GetProcessSP()->ReadUnsignedIntegerFromMemory(isa_pointer, - pointer_size, - 0, - error); - return isa; + Error error; + return process->ReadUnsignedIntegerFromMemory (isa_pointer, + pointer_size, + 0, + error); + } + return 0; } // TODO: should we have a transparent_kvo parameter here to say if we diff --git a/lldb/source/Target/ExecutionContext.cpp b/lldb/source/Target/ExecutionContext.cpp index 8360d1addcfa..6cce08a093b6 100644 --- a/lldb/source/Target/ExecutionContext.cpp +++ b/lldb/source/Target/ExecutionContext.cpp @@ -25,24 +25,51 @@ ExecutionContext::ExecutionContext() : } ExecutionContext::ExecutionContext (const ExecutionContext &rhs) : - m_target_sp (rhs.m_target_sp), + m_target_sp(rhs.m_target_sp), m_process_sp(rhs.m_process_sp), - m_thread_sp (rhs.m_thread_sp), - m_frame_sp (rhs.m_frame_sp) + m_thread_sp(rhs.m_thread_sp), + m_frame_sp(rhs.m_frame_sp) { } -ExecutionContext & -ExecutionContext::operator =(const ExecutionContext &rhs) +ExecutionContext::ExecutionContext (const lldb::TargetSP &target_sp, bool get_process) : + m_target_sp (), + m_process_sp (), + m_thread_sp (), + m_frame_sp () { - if (this != &rhs) - { - m_target_sp = rhs.m_target_sp; - m_process_sp = rhs.m_process_sp; - m_thread_sp = rhs.m_thread_sp; - m_frame_sp = rhs.m_frame_sp; - } - return *this; + if (target_sp) + SetContext (target_sp, get_process); +} + +ExecutionContext::ExecutionContext (const lldb::ProcessSP &process_sp) : + m_target_sp (), + m_process_sp (), + m_thread_sp (), + m_frame_sp () +{ + if (process_sp) + SetContext (process_sp); +} + +ExecutionContext::ExecutionContext (const lldb::ThreadSP &thread_sp) : + m_target_sp (), + m_process_sp (), + m_thread_sp (), + m_frame_sp () +{ + if (thread_sp) + SetContext (thread_sp); +} + +ExecutionContext::ExecutionContext (const lldb::StackFrameSP &frame_sp) : + m_target_sp (), + m_process_sp (), + m_thread_sp (), + m_frame_sp () +{ + if (frame_sp) + SetContext (frame_sp); } ExecutionContext::ExecutionContext (Target* t, bool fill_current_process_thread_frame) : @@ -73,17 +100,37 @@ ExecutionContext::ExecutionContext(Process* process, Thread *thread, StackFrame m_target_sp = process->GetTarget().shared_from_this(); } -ExecutionContext::ExecutionContext (ExecutionContextScope *exe_scope_ptr) +ExecutionContext::ExecutionContext (const ExecutionContextRef &exe_ctx_ref) : + m_target_sp (exe_ctx_ref.GetTargetSP()), + m_process_sp (exe_ctx_ref.GetProcessSP()), + m_thread_sp (exe_ctx_ref.GetThreadSP()), + m_frame_sp (exe_ctx_ref.GetFrameSP()) +{ +} + +ExecutionContext::ExecutionContext (const ExecutionContextRef *exe_ctx_ref_ptr) : + m_target_sp (), + m_process_sp (), + m_thread_sp (), + m_frame_sp () +{ + if (exe_ctx_ref_ptr) + { + m_target_sp = exe_ctx_ref_ptr->GetTargetSP(); + m_process_sp = exe_ctx_ref_ptr->GetProcessSP(); + m_thread_sp = exe_ctx_ref_ptr->GetThreadSP(); + m_frame_sp = exe_ctx_ref_ptr->GetFrameSP(); + } +} + +ExecutionContext::ExecutionContext (ExecutionContextScope *exe_scope_ptr) : + m_target_sp (), + m_process_sp (), + m_thread_sp (), + m_frame_sp () { if (exe_scope_ptr) exe_scope_ptr->CalculateExecutionContext (*this); - else - { - m_target_sp.reset(); - m_process_sp.reset(); - m_thread_sp.reset(); - m_frame_sp.reset(); - } } ExecutionContext::ExecutionContext (ExecutionContextScope &exe_scope_ref) @@ -104,6 +151,17 @@ ExecutionContext::~ExecutionContext() { } +uint32_t +ExecutionContext::GetAddressByteSize() const +{ + if (m_target_sp && m_target_sp->GetArchitecture().IsValid()) + m_target_sp->GetArchitecture().GetAddressByteSize(); + if (m_process_sp) + m_process_sp->GetAddressByteSize(); + return sizeof(void *); +} + + RegisterContext * ExecutionContext::GetRegisterContext () const @@ -235,3 +293,351 @@ ExecutionContext::SetFramePtr (StackFrame *frame) m_frame_sp.reset(); } +void +ExecutionContext::SetContext (const lldb::TargetSP &target_sp, bool get_process) +{ + m_target_sp = target_sp; + if (get_process && target_sp) + m_process_sp = target_sp->GetProcessSP(); + else + m_process_sp.reset(); + m_thread_sp.reset(); + m_frame_sp.reset(); +} + +void +ExecutionContext::SetContext (const lldb::ProcessSP &process_sp) +{ + m_process_sp = process_sp; + if (process_sp) + m_target_sp = process_sp->GetTarget().shared_from_this(); + else + m_target_sp.reset(); + m_thread_sp.reset(); + m_frame_sp.reset(); +} + +void +ExecutionContext::SetContext (const lldb::ThreadSP &thread_sp) +{ + m_frame_sp.reset(); + m_thread_sp = thread_sp; + if (thread_sp) + { + m_process_sp = thread_sp->GetProcess().shared_from_this(); + if (m_process_sp) + m_target_sp = m_process_sp->GetTarget().shared_from_this(); + else + m_target_sp.reset(); + } + else + { + m_target_sp.reset(); + m_process_sp.reset(); + } +} + +void +ExecutionContext::SetContext (const lldb::StackFrameSP &frame_sp) +{ + m_frame_sp = frame_sp; + if (frame_sp) + { + m_thread_sp = frame_sp->GetThread().shared_from_this(); + if (m_thread_sp) + { + m_process_sp = m_thread_sp->GetProcess().shared_from_this(); + if (m_process_sp) + m_target_sp = m_process_sp->GetTarget().shared_from_this(); + else + m_target_sp.reset(); + } + else + { + m_target_sp.reset(); + m_process_sp.reset(); + } + } + else + { + m_target_sp.reset(); + m_process_sp.reset(); + m_thread_sp.reset(); + } +} + +ExecutionContext & +ExecutionContext::operator =(const ExecutionContext &rhs) +{ + if (this != &rhs) + { + m_target_sp = rhs.m_target_sp; + m_process_sp = rhs.m_process_sp; + m_thread_sp = rhs.m_thread_sp; + m_frame_sp = rhs.m_frame_sp; + } + return *this; +} + +bool +ExecutionContext::operator ==(const ExecutionContext &rhs) const +{ + // Check that the frame shared pointers match, or both are valid and their stack + // IDs match since sometimes we get new objects that represent the same + // frame within a thread. + if ((m_frame_sp == rhs.m_frame_sp) || (m_frame_sp && rhs.m_frame_sp && m_frame_sp->GetStackID() == rhs.m_frame_sp->GetStackID())) + { + // Check that the thread shared pointers match, or both are valid and + // their thread IDs match since sometimes we get new objects that + // represent the same thread within a process. + if ((m_thread_sp == rhs.m_thread_sp) || (m_thread_sp && rhs.m_thread_sp && m_thread_sp->GetID() == rhs.m_thread_sp->GetID())) + { + // Processes and targets don't change much + return m_process_sp == rhs.m_process_sp && m_target_sp == rhs.m_target_sp; + } + } + return false; +} + +bool +ExecutionContext::operator !=(const ExecutionContext &rhs) const +{ + return !(*this == rhs); +} + + +ExecutionContextRef::ExecutionContextRef() : + m_target_wp (), + m_process_wp (), + m_thread_wp (), + m_frame_wp (), + m_tid(LLDB_INVALID_THREAD_ID), + m_stack_id () +{ +} + +ExecutionContextRef::ExecutionContextRef (const ExecutionContext *exe_ctx) : + m_target_wp (), + m_process_wp (), + m_thread_wp (), + m_frame_wp (), + m_tid(LLDB_INVALID_THREAD_ID), + m_stack_id () +{ + if (exe_ctx) + *this = *exe_ctx; +} + +ExecutionContextRef::ExecutionContextRef (const ExecutionContext &exe_ctx) : + m_target_wp (), + m_process_wp (), + m_thread_wp (), + m_frame_wp (), + m_tid(LLDB_INVALID_THREAD_ID), + m_stack_id () +{ + *this = exe_ctx; +} + + +ExecutionContextRef::ExecutionContextRef (Target *target, bool adopt_selected) : + m_target_wp(), + m_process_wp(), + m_thread_wp(), + m_frame_wp(), + m_tid(LLDB_INVALID_THREAD_ID), + m_stack_id () +{ + SetTargetPtr (target, adopt_selected); +} + + + + +ExecutionContextRef::ExecutionContextRef (const ExecutionContextRef &rhs) : + m_target_wp (rhs.m_target_wp), + m_process_wp(rhs.m_process_wp), + m_thread_wp (rhs.m_thread_wp), + m_frame_wp (rhs.m_frame_wp), + m_tid (rhs.m_tid), + m_stack_id (rhs.m_stack_id) +{ +} + +ExecutionContextRef & +ExecutionContextRef::operator =(const ExecutionContextRef &rhs) +{ + if (this != &rhs) + { + m_target_wp = rhs.m_target_wp; + m_process_wp = rhs.m_process_wp; + m_thread_wp = rhs.m_thread_wp; + m_frame_wp = rhs.m_frame_wp; + m_tid = rhs.m_tid; + m_stack_id = rhs.m_stack_id; + } + return *this; +} + +ExecutionContextRef & +ExecutionContextRef::operator =(const ExecutionContext &exe_ctx) +{ + m_target_wp = exe_ctx.GetTargetSP(); + m_process_wp = exe_ctx.GetProcessSP(); + SetThreadSP (exe_ctx.GetThreadSP()); + SetFrameSP (exe_ctx.GetFrameSP()); + return *this; +} + +void +ExecutionContextRef::Clear() +{ + m_target_wp.reset(); + m_process_wp.reset(); + m_thread_wp.reset(); + m_frame_wp.reset(); + m_tid = LLDB_INVALID_THREAD_ID; + m_stack_id.Clear(); +} + +ExecutionContextRef::~ExecutionContextRef() +{ +} + +void +ExecutionContextRef::SetTargetSP (const lldb::TargetSP &target_sp) +{ + m_target_wp = target_sp; +} + +void +ExecutionContextRef::SetProcessSP (const lldb::ProcessSP &process_sp) +{ + m_process_wp = process_sp; +} + +void +ExecutionContextRef::SetThreadSP (const lldb::ThreadSP &thread_sp) +{ + m_thread_wp = thread_sp; + if (thread_sp) + m_tid = thread_sp->GetID(); + else + m_tid = LLDB_INVALID_THREAD_ID; +} + +void +ExecutionContextRef::SetFrameSP (const lldb::StackFrameSP &frame_sp) +{ + m_frame_wp = frame_sp; + if (frame_sp) + m_stack_id = frame_sp->GetStackID(); + else + m_stack_id.Clear(); +} + +void +ExecutionContextRef::SetTargetPtr (Target* target, bool adopt_selected) +{ + Clear(); + if (target) + { + lldb::TargetSP target_sp (target->shared_from_this()); + if (target_sp) + { + m_target_wp = target_sp; + if (adopt_selected) + { + lldb::ProcessSP process_sp (target_sp->GetProcessSP()); + if (process_sp) + { + m_process_wp = process_sp; + if (process_sp) + { + lldb::ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread()); + if (!thread_sp) + thread_sp = process_sp->GetThreadList().GetThreadAtIndex(0); + + if (thread_sp) + { + SetThreadSP (thread_sp); + lldb::StackFrameSP frame_sp (thread_sp->GetSelectedFrame()); + if (!frame_sp) + frame_sp = thread_sp->GetStackFrameAtIndex(0); + if (frame_sp) + SetFrameSP (frame_sp); + } + } + } + } + } + } +} + +void +ExecutionContextRef::SetProcessPtr (Process *process) +{ + if (process) + m_process_wp = process->shared_from_this(); + else + m_process_wp.reset(); +} + +void +ExecutionContextRef::SetThreadPtr (Thread *thread) +{ + if (thread) + m_thread_wp = thread->shared_from_this(); + else + m_thread_wp.reset(); +} + +void +ExecutionContextRef::SetFramePtr (StackFrame *frame) +{ + if (frame) + m_frame_wp = frame->shared_from_this(); + else + m_frame_wp.reset(); +} + + +lldb::ThreadSP +ExecutionContextRef::GetThreadSP () const +{ + lldb::ThreadSP thread_sp (m_thread_wp.lock()); + if (!thread_sp && m_tid != LLDB_INVALID_THREAD_ID) + { + lldb::ProcessSP process_sp(GetProcessSP()); + if (process_sp) + { + thread_sp = process_sp->GetThreadList().FindThreadByID(m_tid); + m_thread_wp = thread_sp; + } + } + return thread_sp; +} + +lldb::StackFrameSP +ExecutionContextRef::GetFrameSP () const +{ + lldb::StackFrameSP frame_sp (m_frame_wp.lock()); + if (!frame_sp && m_stack_id.IsValid()) + { + lldb::ThreadSP thread_sp (GetThreadSP()); + if (thread_sp) + { + frame_sp = thread_sp->GetFrameWithStackID (m_stack_id); + m_frame_wp = frame_sp; + } + } + return frame_sp; +} + +ExecutionContext +ExecutionContextRef::Lock () const +{ + return ExecutionContext(this); +} + + diff --git a/lldb/source/Target/StackFrameList.cpp b/lldb/source/Target/StackFrameList.cpp index 76f74f1533cc..b69cad2f9c5a 100644 --- a/lldb/source/Target/StackFrameList.cpp +++ b/lldb/source/Target/StackFrameList.cpp @@ -332,7 +332,7 @@ StackFrameList::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx) } StackFrameSP -StackFrameList::GetFrameWithStackID (StackID &stack_id) +StackFrameList::GetFrameWithStackID (const StackID &stack_id) { uint32_t frame_idx = 0; StackFrameSP frame_sp;