diff options
| author | Greg Clayton <gclayton@apple.com> | 2012-02-18 05:35:26 +0000 |
|---|---|---|
| committer | Greg Clayton <gclayton@apple.com> | 2012-02-18 05:35:26 +0000 |
| commit | d9e416c0ea61c13440e99fdab86e44c6e71a8eff (patch) | |
| tree | 7cdcdc10fb941cb0658a5a651a5f6ceb2cd40e63 | |
| parent | 0dea49e324ecb836ddad859495bde8ffc48a8ae0 (diff) | |
| download | bcm5719-llvm-d9e416c0ea61c13440e99fdab86e44c6e71a8eff.tar.gz bcm5719-llvm-d9e416c0ea61c13440e99fdab86e44c6e71a8eff.zip | |
The second part in thread hardening the internals of LLDB where we make
the lldb_private::StackFrame objects hold onto a weak pointer to the thread
object. The lldb_private::StackFrame objects the the most volatile objects
we have as when we are doing single stepping, frames can often get lost or
thrown away, only to be re-created as another object that still refers to the
same frame. We have another bug tracking that. But we need to be able to
have frames no longer be able to get the thread when they are not part of
a thread anymore, and this is the first step (this fix makes that possible
but doesn't implement it yet).
Also changed lldb_private::ExecutionContextScope to return shared pointers to
all objects in the execution context to further thread harden the internals.
llvm-svn: 150871
30 files changed, 560 insertions, 454 deletions
diff --git a/lldb/include/lldb/Target/ExecutionContextScope.h b/lldb/include/lldb/Target/ExecutionContextScope.h index 6e5815ff84c..7ba40971af2 100644 --- a/lldb/include/lldb/Target/ExecutionContextScope.h +++ b/lldb/include/lldb/Target/ExecutionContextScope.h @@ -42,16 +42,16 @@ public: virtual ~ExecutionContextScope () {} - virtual Target * + virtual lldb::TargetSP CalculateTarget () = 0; - virtual Process * + virtual lldb::ProcessSP CalculateProcess () = 0; - virtual Thread * + virtual lldb::ThreadSP CalculateThread () = 0; - virtual StackFrame * + virtual lldb::StackFrameSP CalculateStackFrame () = 0; //------------------------------------------------------------------ diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index d3fa8457f0b..ce0e145f64a 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -3064,28 +3064,25 @@ public: //------------------------------------------------------------------ // lldb::ExecutionContextScope pure virtual functions //------------------------------------------------------------------ - virtual Target * - CalculateTarget () - { - return &m_target; - } - - virtual Process * + virtual lldb::TargetSP + CalculateTarget (); + + virtual lldb::ProcessSP CalculateProcess () { - return this; + return shared_from_this(); } - - virtual Thread * + + virtual lldb::ThreadSP CalculateThread () { - return NULL; + return lldb::ThreadSP(); } - - virtual StackFrame * + + virtual lldb::StackFrameSP CalculateStackFrame () { - return NULL; + return lldb::StackFrameSP(); } virtual void diff --git a/lldb/include/lldb/Target/RegisterContext.h b/lldb/include/lldb/Target/RegisterContext.h index af6a20e54ea..f08abe6ecc4 100644 --- a/lldb/include/lldb/Target/RegisterContext.h +++ b/lldb/include/lldb/Target/RegisterContext.h @@ -157,16 +157,16 @@ public: //------------------------------------------------------------------ // lldb::ExecutionContextScope pure virtual functions //------------------------------------------------------------------ - virtual Target * + virtual lldb::TargetSP CalculateTarget (); - - virtual Process * + + virtual lldb::ProcessSP CalculateProcess (); - - virtual Thread * + + virtual lldb::ThreadSP CalculateThread (); - - virtual StackFrame * + + virtual lldb::StackFrameSP CalculateStackFrame (); virtual void diff --git a/lldb/include/lldb/Target/StackFrame.h b/lldb/include/lldb/Target/StackFrame.h index 0995a04f8cf..9487ffedcb9 100644 --- a/lldb/include/lldb/Target/StackFrame.h +++ b/lldb/include/lldb/Target/StackFrame.h @@ -41,24 +41,24 @@ public: //------------------------------------------------------------------ // Constructors and Destructors //------------------------------------------------------------------ - StackFrame (lldb::user_id_t frame_idx, + StackFrame (const lldb::ThreadSP &thread_sp, + lldb::user_id_t frame_idx, lldb::user_id_t concrete_frame_idx, - Thread &thread, lldb::addr_t cfa, lldb::addr_t pc, const SymbolContext *sc_ptr); - StackFrame (lldb::user_id_t frame_idx, + StackFrame (const lldb::ThreadSP &thread_sp, + lldb::user_id_t frame_idx, lldb::user_id_t concrete_frame_idx, - Thread &thread, const lldb::RegisterContextSP ®_context_sp, lldb::addr_t cfa, lldb::addr_t pc, const SymbolContext *sc_ptr); - StackFrame (lldb::user_id_t frame_idx, + StackFrame (const lldb::ThreadSP &thread_sp, + lldb::user_id_t frame_idx, lldb::user_id_t concrete_frame_idx, - Thread &thread, const lldb::RegisterContextSP ®_context_sp, lldb::addr_t cfa, const Address& pc, @@ -66,13 +66,11 @@ public: virtual ~StackFrame (); - Thread & - GetThread() - { return m_thread; } - - const Thread & - GetThread() const - { return m_thread; } + lldb::ThreadSP + GetThread () const + { + return m_thread_wp.lock(); + } StackID& GetStackID(); @@ -151,16 +149,16 @@ public: //------------------------------------------------------------------ // lldb::ExecutionContextScope pure virtual functions //------------------------------------------------------------------ - virtual Target * + virtual lldb::TargetSP CalculateTarget (); - - virtual Process * + + virtual lldb::ProcessSP CalculateProcess (); - - virtual Thread * + + virtual lldb::ThreadSP CalculateThread (); - - virtual StackFrame * + + virtual lldb::StackFrameSP CalculateStackFrame (); virtual void @@ -187,11 +185,12 @@ protected: bool HasCachedData () const; + private: //------------------------------------------------------------------ // For StackFrame only //------------------------------------------------------------------ - Thread &m_thread; + lldb::ThreadWP m_thread_wp; uint32_t m_frame_index; uint32_t m_concrete_frame_index; lldb::RegisterContextSP m_reg_context_sp; diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 712eb0e1b69..3979565f9ec 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -842,16 +842,16 @@ public: //------------------------------------------------------------------ // lldb::ExecutionContextScope pure virtual functions //------------------------------------------------------------------ - virtual Target * + virtual lldb::TargetSP CalculateTarget (); - - virtual Process * + + virtual lldb::ProcessSP CalculateProcess (); - - virtual Thread * + + virtual lldb::ThreadSP CalculateThread (); - - virtual StackFrame * + + virtual lldb::StackFrameSP CalculateStackFrame (); virtual void diff --git a/lldb/include/lldb/Target/Thread.h b/lldb/include/lldb/Target/Thread.h index 1ec196bb4c4..87acae4dcbd 100644 --- a/lldb/include/lldb/Target/Thread.h +++ b/lldb/include/lldb/Target/Thread.h @@ -730,16 +730,16 @@ public: //------------------------------------------------------------------ // lldb::ExecutionContextScope pure virtual functions //------------------------------------------------------------------ - virtual Target * + virtual lldb::TargetSP CalculateTarget (); - - virtual Process * + + virtual lldb::ProcessSP CalculateProcess (); - - virtual Thread * + + virtual lldb::ThreadSP CalculateThread (); - - virtual StackFrame * + + virtual lldb::StackFrameSP CalculateStackFrame (); virtual void diff --git a/lldb/lldb.xcodeproj/xcshareddata/xcschemes/LLDB.xcscheme b/lldb/lldb.xcodeproj/xcshareddata/xcschemes/LLDB.xcscheme index a6c35bdfd6d..fb3e48f3c43 100644 --- a/lldb/lldb.xcodeproj/xcshareddata/xcschemes/LLDB.xcscheme +++ b/lldb/lldb.xcodeproj/xcshareddata/xcschemes/LLDB.xcscheme @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <Scheme - version = "1.3"> + LastUpgradeVersion = "0430" + version = "1.8"> <BuildAction parallelizeBuildables = "NO" buildImplicitDependencies = "YES"> @@ -28,6 +29,15 @@ buildConfiguration = "Debug"> <Testables> </Testables> + <MacroExpansion> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "26F5C26910F3D9A4009D5894" + BuildableName = "lldb" + BlueprintName = "lldb-tool" + ReferencedContainer = "container:lldb.xcodeproj"> + </BuildableReference> + </MacroExpansion> <EnvironmentVariables> <EnvironmentVariable key = "BLUBBY" @@ -43,7 +53,10 @@ displayScale = "1.00" launchStyle = "0" useCustomWorkingDirectory = "NO" - buildConfiguration = "Debug"> + buildConfiguration = "Debug" + ignoresPersistentStateOnLaunch = "NO" + debugDocumentVersioning = "YES" + allowLocationSimulation = "YES"> <BuildableProductRunnable> <BuildableReference BuildableIdentifier = "primary" @@ -69,7 +82,8 @@ shouldUseLaunchSchemeArgsEnv = "YES" savedToolIdentifier = "" useCustomWorkingDirectory = "NO" - buildConfiguration = "Release"> + buildConfiguration = "Release" + debugDocumentVersioning = "YES"> <EnvironmentVariables> <EnvironmentVariable key = "BLUBBY" diff --git a/lldb/lldb.xcodeproj/xcshareddata/xcschemes/darwin-debug.xcscheme b/lldb/lldb.xcodeproj/xcshareddata/xcschemes/darwin-debug.xcscheme index 199c1d140a9..e30dce04323 100644 --- a/lldb/lldb.xcodeproj/xcshareddata/xcschemes/darwin-debug.xcscheme +++ b/lldb/lldb.xcodeproj/xcshareddata/xcschemes/darwin-debug.xcscheme @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <Scheme - version = "1.3"> + LastUpgradeVersion = "0430" + version = "1.8"> <BuildAction parallelizeBuildables = "NO" buildImplicitDependencies = "YES"> @@ -37,13 +38,16 @@ </EnvironmentVariables> </TestAction> <LaunchAction - selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB" + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB" displayScaleIsEnabled = "NO" displayScale = "1.00" launchStyle = "0" useCustomWorkingDirectory = "NO" - buildConfiguration = "Debug"> + buildConfiguration = "Debug" + ignoresPersistentStateOnLaunch = "NO" + debugDocumentVersioning = "YES" + allowLocationSimulation = "YES"> <BuildableProductRunnable> <BuildableReference BuildableIdentifier = "primary" @@ -69,7 +73,8 @@ shouldUseLaunchSchemeArgsEnv = "YES" savedToolIdentifier = "" useCustomWorkingDirectory = "NO" - buildConfiguration = "Release"> + buildConfiguration = "Release" + debugDocumentVersioning = "YES"> <BuildableProductRunnable> <BuildableReference BuildableIdentifier = "primary" diff --git a/lldb/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme b/lldb/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme index af9b125593e..3a6ee591b31 100644 --- a/lldb/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme +++ b/lldb/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <Scheme + LastUpgradeVersion = "0430" version = "1.3"> <BuildAction parallelizeBuildables = "NO" diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp index fb9957106a1..eaf4f8a01ca 100644 --- a/lldb/source/API/SBFrame.cpp +++ b/lldb/source/API/SBFrame.cpp @@ -54,7 +54,7 @@ namespace lldb_private { { if (frame_sp) { - m_thread_wp = frame_sp->GetThread().shared_from_this(); + m_thread_wp = frame_sp->GetThread(); m_stack_id = frame_sp->GetStackID(); } } @@ -81,11 +81,11 @@ namespace lldb_private { // Our frame is still alive, make sure that our thread // still has this exact frame... lldb::StackFrameSP tmp_frame_sp (thread_sp->GetStackFrameAtIndex (frame_sp->GetFrameIndex())); - if (tmp_frame_sp.get() == frame_sp.get()) + if (tmp_frame_sp == frame_sp) return frame_sp; } // The original stack frame might have gone away, - // we need to check for the stac + // we need to check for the frame by stack ID frame_sp = thread_sp->GetFrameWithStackID (m_stack_id); m_frame_wp = frame_sp; } @@ -98,7 +98,7 @@ namespace lldb_private { if (frame_sp) { m_frame_wp = frame_sp; - m_thread_wp = frame_sp->GetThread().shared_from_this(); + m_thread_wp = frame_sp->GetThread(); m_stack_id = frame_sp->GetStackID(); } else @@ -203,17 +203,19 @@ SBFrame::GetSymbolContext (uint32_t resolve_scope) const { SBSymbolContext sb_sym_ctx; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_sym_ctx.SetSymbolContext(&frame_sp->GetSymbolContext (resolve_scope)); + Mutex::Locker api_locker (target->GetAPIMutex()); + sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope)); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)", - frame_sp.get(), resolve_scope, sb_sym_ctx.get()); + frame, resolve_scope, sb_sym_ctx.get()); return sb_sym_ctx; } @@ -223,18 +225,20 @@ SBFrame::GetModule () const { SBModule sb_module; ModuleSP module_sp; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - module_sp = frame_sp->GetSymbolContext (eSymbolContextModule).module_sp; + Mutex::Locker api_locker (target->GetAPIMutex()); + module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp; sb_module.SetSP (module_sp); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)", - frame_sp.get(), module_sp.get()); + frame, module_sp.get()); return sb_module; } @@ -243,16 +247,18 @@ SBCompileUnit SBFrame::GetCompileUnit () const { SBCompileUnit sb_comp_unit; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_comp_unit.reset (frame_sp->GetSymbolContext (eSymbolContextCompUnit).comp_unit); + Mutex::Locker api_locker (target->GetAPIMutex()); + sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetModule () => SBCompileUnit(%p)", - frame_sp.get(), sb_comp_unit.get()); + frame, sb_comp_unit.get()); return sb_comp_unit; } @@ -261,16 +267,18 @@ SBFunction SBFrame::GetFunction () const { SBFunction sb_function; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_function.reset(frame_sp->GetSymbolContext (eSymbolContextFunction).function); + Mutex::Locker api_locker (target->GetAPIMutex()); + sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)", - frame_sp.get(), sb_function.get()); + frame, sb_function.get()); return sb_function; } @@ -279,16 +287,18 @@ SBSymbol SBFrame::GetSymbol () const { SBSymbol sb_symbol; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_symbol.reset(frame_sp->GetSymbolContext (eSymbolContextSymbol).symbol); + Mutex::Locker api_locker (target->GetAPIMutex()); + sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)", - frame_sp.get(), sb_symbol.get()); + frame, sb_symbol.get()); return sb_symbol; } @@ -296,16 +306,18 @@ SBBlock SBFrame::GetBlock () const { SBBlock sb_block; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_block.SetPtr (frame_sp->GetSymbolContext (eSymbolContextBlock).block); + Mutex::Locker api_locker (target->GetAPIMutex()); + sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)", - frame_sp.get(), sb_block.GetPtr()); + frame, sb_block.GetPtr()); return sb_block; } @@ -313,16 +325,18 @@ SBBlock SBFrame::GetFrameBlock () const { SBBlock sb_block; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_block.SetPtr(frame_sp->GetFrameBlock ()); + Mutex::Locker api_locker (target->GetAPIMutex()); + sb_block.SetPtr(frame->GetFrameBlock ()); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)", - frame_sp.get(), sb_block.GetPtr()); + frame, sb_block.GetPtr()); return sb_block; } @@ -330,16 +344,18 @@ SBLineEntry SBFrame::GetLineEntry () const { SBLineEntry sb_line_entry; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_line_entry.SetLineEntry (frame_sp->GetSymbolContext (eSymbolContextLineEntry).line_entry); + Mutex::Locker api_locker (target->GetAPIMutex()); + sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)", - frame_sp.get(), sb_line_entry.get()); + frame, sb_line_entry.get()); return sb_line_entry; } @@ -349,14 +365,16 @@ SBFrame::GetFrameID () const uint32_t frame_idx = UINT32_MAX; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) - frame_idx = frame_sp->GetFrameIndex (); + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) + frame_idx = frame->GetFrameIndex (); LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetFrameID () => %u", - frame_sp.get(), frame_idx); + frame, frame_idx); return frame_idx; } @@ -364,16 +382,18 @@ addr_t SBFrame::GetPC () const { addr_t addr = LLDB_INVALID_ADDRESS; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - addr = frame_sp->GetFrameCodeAddress().GetOpcodeLoadAddress (&frame_sp->GetThread().GetProcess().GetTarget()); + Mutex::Locker api_locker (target->GetAPIMutex()); + addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", frame_sp.get(), addr); + log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", frame, addr); return addr; } @@ -382,17 +402,19 @@ bool SBFrame::SetPC (addr_t new_pc) { bool ret_val = false; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - ret_val = frame_sp->GetRegisterContext()->SetPC (new_pc); + Mutex::Locker api_locker (target->GetAPIMutex()); + ret_val = frame->GetRegisterContext()->SetPC (new_pc); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%llx) => %i", - frame_sp.get(), new_pc, ret_val); + frame, new_pc, ret_val); return ret_val; } @@ -401,15 +423,17 @@ addr_t SBFrame::GetSP () const { addr_t addr = LLDB_INVALID_ADDRESS; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - addr = frame_sp->GetRegisterContext()->GetSP(); + Mutex::Locker api_locker (target->GetAPIMutex()); + addr = frame->GetRegisterContext()->GetSP(); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", frame_sp.get(), addr); + log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", frame, addr); return addr; } @@ -419,16 +443,18 @@ addr_t SBFrame::GetFP () const { addr_t addr = LLDB_INVALID_ADDRESS; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - addr = frame_sp->GetRegisterContext()->GetFP(); + Mutex::Locker api_locker (target->GetAPIMutex()); + addr = frame->GetRegisterContext()->GetFP(); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", frame_sp.get(), addr); + log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", frame, addr); return addr; } @@ -437,15 +463,17 @@ SBAddress SBFrame::GetPCAddress () const { SBAddress sb_addr; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_addr.SetAddress (&frame_sp->GetFrameCodeAddress()); + Mutex::Locker api_locker (target->GetAPIMutex()); + sb_addr.SetAddress (&frame->GetFrameCodeAddress()); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame_sp.get(), sb_addr.get()); + log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame, sb_addr.get()); return sb_addr; } @@ -459,10 +487,12 @@ lldb::SBValue SBFrame::GetValueForVariablePath (const char *var_path) { SBValue sb_value; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue(); + lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); sb_value = GetValueForVariablePath (var_path, use_dynamic); } return sb_value; @@ -472,17 +502,19 @@ lldb::SBValue SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic) { SBValue sb_value; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp && var_path && var_path[0]) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target && var_path && var_path[0]) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + Mutex::Locker api_locker (target->GetAPIMutex()); VariableSP var_sp; Error error; - ValueObjectSP value_sp (frame_sp->GetValueForVariableExpressionPath (var_path, - use_dynamic, - StackFrame::eExpressionPathOptionCheckPtrVsMember, - var_sp, - error)); + ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path, + use_dynamic, + StackFrame::eExpressionPathOptionCheckPtrVsMember, + var_sp, + error)); sb_value.SetSP(value_sp); } return sb_value; @@ -492,10 +524,12 @@ SBValue SBFrame::FindVariable (const char *name) { SBValue value; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue(); + lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); value = FindVariable (name, use_dynamic); } return value; @@ -508,12 +542,14 @@ SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic) VariableSP var_sp; SBValue sb_value; ValueObjectSP value_sp; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp && name && name[0]) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target && name && name[0]) { VariableList variable_list; - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock)); + Mutex::Locker api_locker (target->GetAPIMutex()); + SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock)); if (sc.block) { @@ -532,7 +568,7 @@ SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic) if (var_sp) { - value_sp = frame_sp->GetValueObjectForFrameVariable(var_sp, use_dynamic); + value_sp = frame->GetValueObjectForFrameVariable(var_sp, use_dynamic); sb_value.SetSP(value_sp); } @@ -541,7 +577,7 @@ SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic) LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)", - frame_sp.get(), name, value_sp.get()); + frame, name, value_sp.get()); return sb_value; } @@ -550,10 +586,12 @@ SBValue SBFrame::FindValue (const char *name, ValueType value_type) { SBValue value; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue(); + lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); value = FindValue (name, value_type, use_dynamic); } return value; @@ -564,10 +602,12 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy { SBValue sb_value; ValueObjectSP value_sp; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp && name && name[0]) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target && name && name[0]) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + Mutex::Locker api_locker (target->GetAPIMutex()); switch (value_type) { @@ -576,9 +616,9 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy case eValueTypeVariableArgument: // function argument variables case eValueTypeVariableLocal: // function local variables { - VariableList *variable_list = frame_sp->GetVariableList(true); + VariableList *variable_list = frame->GetVariableList(true); - SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock)); + SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock)); const bool can_create = true; const bool get_parent_variables = true; @@ -598,7 +638,7 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy variable_sp->GetScope() == value_type && variable_sp->GetName() == const_name) { - value_sp = frame_sp->GetValueObjectForFrameVariable (variable_sp, use_dynamic); + value_sp = frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic); sb_value.SetSP (value_sp); break; } @@ -609,7 +649,7 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy case eValueTypeRegister: // stack frame register value { - RegisterContextSP reg_ctx (frame_sp->GetRegisterContext()); + RegisterContextSP reg_ctx (frame->GetRegisterContext()); if (reg_ctx) { const uint32_t num_regs = reg_ctx->GetRegisterCount(); @@ -620,7 +660,7 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy ((reg_info->name && strcasecmp (reg_info->name, name) == 0) || (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0))) { - value_sp = ValueObjectRegister::Create (frame_sp.get(), reg_ctx, reg_idx); + value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx); sb_value.SetSP (value_sp); break; } @@ -631,7 +671,7 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy case eValueTypeRegisterSet: // A collection of stack frame register values { - RegisterContextSP reg_ctx (frame_sp->GetRegisterContext()); + RegisterContextSP reg_ctx (frame->GetRegisterContext()); if (reg_ctx) { const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); @@ -642,7 +682,7 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy ((reg_set->name && strcasecmp (reg_set->name, name) == 0) || (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0))) { - value_sp = ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx); + value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx); sb_value.SetSP (value_sp); break; } @@ -654,7 +694,7 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy case eValueTypeConstResult: // constant result variables { ConstString const_name(name); - ClangExpressionVariableSP expr_var_sp (frame_sp->GetThread().GetProcess().GetTarget().GetPersistentVariables().GetVariable (const_name)); + ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name)); if (expr_var_sp) { value_sp = expr_var_sp->GetValueObject(); @@ -671,7 +711,7 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)", - frame_sp.get(), name, value_type, value_sp.get()); + frame, name, value_type, value_sp.get()); return sb_value; @@ -694,22 +734,18 @@ SBFrame::GetThread () const { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - SBThread sb_thread; - ThreadSP thread_sp; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) - { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - thread_sp = frame_sp->GetThread().shared_from_this(); - sb_thread.SetThread (thread_sp); - } + ExecutionContext exe_ctx(GetFrameSP()); + ThreadSP thread_sp (exe_ctx.GetThreadSP()); + SBThread sb_thread (thread_sp); if (log) { SBStream sstr; sb_thread.GetDescription (sstr); - log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", frame_sp.get(), - thread_sp.get(), sstr.GetData()); + log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", + exe_ctx.GetFramePtr(), + thread_sp.get(), + sstr.GetData()); } return sb_thread; @@ -719,16 +755,18 @@ const char * SBFrame::Disassemble () const { const char *disassembly = NULL; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - disassembly = frame_sp->Disassemble(); + Mutex::Locker api_locker (target->GetAPIMutex()); + disassembly = frame->Disassemble(); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBFrame(%p)::Disassemble () => %s", frame_sp.get(), disassembly); + log->Printf ("SBFrame(%p)::Disassemble () => %s", frame, disassembly); return disassembly; } @@ -741,10 +779,12 @@ SBFrame::GetVariables (bool arguments, bool in_scope_only) { SBValueList value_list; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue(); + lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic); } return value_list; @@ -760,25 +800,27 @@ SBFrame::GetVariables (bool arguments, LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBValueList value_list; - StackFrameSP frame_sp(GetFrameSP()); + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); if (log) log->Printf ("SBFrame(%p)::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)", - frame_sp.get(), + frame, arguments, locals, statics, in_scope_only); - if (frame_sp) + if (frame && target) { size_t i; VariableList *variable_list = NULL; // Scope for locker { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - variable_list = frame_sp->GetVariableList(true); + Mutex::Locker api_locker (target->GetAPIMutex()); + variable_list = frame->GetVariableList(true); } if (variable_list) { @@ -811,10 +853,10 @@ SBFrame::GetVariables (bool arguments, } if (add_variable) { - if (in_scope_only && !variable_sp->IsInScope(frame_sp.get())) + if (in_scope_only && !variable_sp->IsInScope(frame)) continue; - value_list.Append(frame_sp->GetValueObjectForFrameVariable (variable_sp, use_dynamic)); + value_list.Append(frame->GetValueObjectForFrameVariable (variable_sp, use_dynamic)); } } } @@ -824,7 +866,7 @@ SBFrame::GetVariables (bool arguments, if (log) { - log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame_sp.get(), + log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame, value_list.get()); } @@ -837,23 +879,25 @@ SBFrame::GetRegisters () LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBValueList value_list; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - RegisterContextSP reg_ctx (frame_sp->GetRegisterContext()); + Mutex::Locker api_locker (target->GetAPIMutex()); + RegisterContextSP reg_ctx (frame->GetRegisterContext()); if (reg_ctx) { const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) { - value_list.Append(ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx)); + value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx)); } } } if (log) - log->Printf ("SBFrame(%p)::Registers () => SBValueList(%p)", frame_sp.get(), value_list.get()); + log->Printf ("SBFrame(%p)::Registers () => SBValueList(%p)", frame, value_list.get()); return value_list; } @@ -863,11 +907,13 @@ SBFrame::GetDescription (SBStream &description) { Stream &strm = description.ref(); - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - frame_sp->DumpUsingSettingsFormat (&strm); + Mutex::Locker api_locker (target->GetAPIMutex()); + frame->DumpUsingSettingsFormat (&strm); } else strm.PutCString ("No value"); @@ -879,10 +925,12 @@ SBValue SBFrame::EvaluateExpression (const char *expr) { SBValue result; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue(); + lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); result = EvaluateExpression (expr, use_dynamic); } return result; @@ -899,17 +947,19 @@ SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dyna SBValue expr_result; ValueObjectSP expr_value_sp; - StackFrameSP frame_sp(GetFrameSP()); + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); if (log) - log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", frame_sp.get(), expr); + log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", frame, expr); - if (frame_sp) + if (frame && target) { - Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + Mutex::Locker api_locker (target->GetAPIMutex()); StreamString frame_description; - frame_sp->DumpUsingSettingsFormat (&frame_description); + frame->DumpUsingSettingsFormat (&frame_description); Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s", expr, fetch_dynamic_value, frame_description.GetString().c_str()); @@ -918,14 +968,14 @@ SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dyna const bool unwind_on_error = true; const bool keep_in_memory = false; - exe_results = frame_sp->GetThread().GetProcess().GetTarget().EvaluateExpression(expr, - frame_sp.get(), - eExecutionPolicyOnlyWhenNeeded, - coerce_to_id, - unwind_on_error, - keep_in_memory, - fetch_dynamic_value, - expr_value_sp); + exe_results = target->EvaluateExpression (expr, + frame, + eExecutionPolicyOnlyWhenNeeded, + coerce_to_id, + unwind_on_error, + keep_in_memory, + fetch_dynamic_value, + expr_value_sp); expr_result.SetSP(expr_value_sp); Host::SetCrashDescription (NULL); } @@ -936,7 +986,8 @@ SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dyna expr_result.GetSummary()); if (log) - log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", frame_sp.get(), + log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", + frame, expr, expr_value_sp.get(), exe_results); @@ -947,10 +998,12 @@ SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dyna bool SBFrame::IsInlined() { - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - Block *block = frame_sp->GetSymbolContext(eSymbolContextBlock).block; + Block *block = frame->GetSymbolContext(eSymbolContextBlock).block; if (block) return block->GetContainingInlinedBlock () != NULL; } @@ -961,10 +1014,12 @@ const char * SBFrame::GetFunctionName() { const char *name = NULL; - StackFrameSP frame_sp(GetFrameSP()); - if (frame_sp) + ExecutionContext exe_ctx(GetFrameSP()); + StackFrame *frame = exe_ctx.GetFramePtr(); + Target *target = exe_ctx.GetTargetPtr(); + if (frame && target) { - SymbolContext sc (frame_sp->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol)); + SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol)); if (sc.block) { Block *inlined_block = sc.block->GetContainingInlinedBlock (); diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp index c8a9bcc217f..c44a45b8930 100644 --- a/lldb/source/Commands/CommandObjectFrame.cpp +++ b/lldb/source/Commands/CommandObjectFrame.cpp @@ -278,8 +278,9 @@ public: bool show_frame_info = true; bool show_source = !already_shown; - uint32_t source_lines_before = 3; - uint32_t source_lines_after = 3; + Debugger &debugger = m_interpreter.GetDebugger(); + const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true); + const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false); if (frame->GetStatus (result.GetOutputStream(), show_frame_info, show_source, diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp index 120ae5e4aa7..5ce845f88ae 100644 --- a/lldb/source/Core/Address.cpp +++ b/lldb/source/Core/Address.cpp @@ -28,12 +28,12 @@ ReadBytes (ExecutionContextScope *exe_scope, const Address &address, void *dst, if (exe_scope == NULL) return 0; - Target *target = exe_scope->CalculateTarget(); - if (target) + TargetSP target_sp (exe_scope->CalculateTarget()); + if (target_sp) { Error error; bool prefer_file_cache = false; - return target->ReadMemory (address, prefer_file_cache, dst, dst_len, error); + return target_sp->ReadMemory (address, prefer_file_cache, dst, dst_len, error); } return 0; } @@ -46,11 +46,11 @@ GetByteOrderAndAddressSize (ExecutionContextScope *exe_scope, const Address &add if (exe_scope == NULL) return false; - Target *target = exe_scope->CalculateTarget(); - if (target) + TargetSP target_sp (exe_scope->CalculateTarget()); + if (target_sp) { - byte_order = target->GetArchitecture().GetByteOrder(); - addr_size = target->GetArchitecture().GetAddressByteSize(); + byte_order = target_sp->GetArchitecture().GetByteOrder(); + addr_size = target_sp->GetArchitecture().GetAddressByteSize(); } if (byte_order == eByteOrderInvalid || addr_size == 0) @@ -362,18 +362,13 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum if (m_section == NULL) style = DumpStyleLoadAddress; - Target *target = NULL; - Process *process = NULL; - if (exe_scope) - { - target = exe_scope->CalculateTarget(); - process = exe_scope->CalculateProcess(); - } + ExecutionContext exe_ctx (exe_scope); + Target *target = exe_ctx.GetTargetPtr(); // If addr_byte_size is UINT32_MAX, then determine the correct address // byte size for the process or default to the size of addr_t if (addr_size == UINT32_MAX) { - if (process) + if (target) addr_size = target->GetArchitecture().GetAddressByteSize (); else addr_size = sizeof(addr_t); @@ -517,8 +512,8 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum { SymbolContext func_sc; target->GetImages().ResolveSymbolContextForAddress (so_addr, - eSymbolContextEverything, - func_sc); + eSymbolContextEverything, + func_sc); if (func_sc.function || func_sc.symbol) { showed_info = true; @@ -608,8 +603,8 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum if (target) { target->GetImages().ResolveSymbolContextForAddress (so_addr, - eSymbolContextEverything, - pointer_sc); + eSymbolContextEverything, + pointer_sc); if (pointer_sc.function || pointer_sc.symbol) { s->PutCString(": "); diff --git a/lldb/source/Core/DataExtractor.cpp b/lldb/source/Core/DataExtractor.cpp index 28303ab2e66..b88b5384deb 100644 --- a/lldb/source/Core/DataExtractor.cpp +++ b/lldb/source/Core/DataExtractor.cpp @@ -1354,17 +1354,17 @@ DataExtractor::Dump (Stream *s, if (item_format == eFormatInstruction) { - Target *target = NULL; + TargetSP target_sp; if (exe_scope) - target = exe_scope->CalculateTarget(); - if (target) + target_sp = exe_scope->CalculateTarget(); + if (target_sp) { - DisassemblerSP disassembler_sp (Disassembler::FindPlugin(target->GetArchitecture(), NULL)); + DisassemblerSP disassembler_sp (Disassembler::FindPlugin(target_sp->GetArchitecture(), NULL)); if (disassembler_sp) { lldb::addr_t addr = base_addr + start_offset; lldb_private::Address so_addr; - if (!target->GetSectionLoadList().ResolveLoadAddress(addr, so_addr)) + if (!target_sp->GetSectionLoadList().ResolveLoadAddress(addr, so_addr)) { so_addr.SetOffset(addr); so_addr.SetSection(NULL); @@ -1724,9 +1724,9 @@ DataExtractor::Dump (Stream *s, s->Printf("0x%*.*llx", 2 * item_byte_size, 2 * item_byte_size, addr); if (exe_scope) { - Target *target = exe_scope->CalculateTarget(); + TargetSP target_sp (exe_scope->CalculateTarget()); lldb_private::Address so_addr; - if (target && target->GetSectionLoadList().ResolveLoadAddress(addr, so_addr)) + if (target_sp && target_sp->GetSectionLoadList().ResolveLoadAddress(addr, so_addr)) { s->PutChar(' '); so_addr.Dump (s, diff --git a/lldb/source/Core/EmulateInstruction.cpp b/lldb/source/Core/EmulateInstruction.cpp index a3990fc5de7..f17924747d8 100644 --- a/lldb/source/Core/EmulateInstruction.cpp +++ b/lldb/source/Core/EmulateInstruction.cpp @@ -10,7 +10,6 @@ #include "lldb/Core/EmulateInstruction.h" #include "lldb/Core/Address.h" -#include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/DataExtractor.h" #include "lldb/Core/Error.h" #include "lldb/Core/PluginManager.h" @@ -287,24 +286,20 @@ EmulateInstruction::ReadMemoryFrame (EmulateInstruction *instruction, const Context &context, lldb::addr_t addr, void *dst, - size_t length) + size_t dst_len) { - if (!baton) + if (!baton || dst == NULL || dst_len == 0) return 0; - - + StackFrame *frame = (StackFrame *) baton; - DataBufferSP data_sp (new DataBufferHeap (length, '\0')); - Error error; - - size_t bytes_read = frame->GetThread().GetProcess().ReadMemory (addr, data_sp->GetBytes(), data_sp->GetByteSize(), - error); - - if (bytes_read > 0) - ((DataBufferHeap *) data_sp.get())->CopyData (dst, length); - - return bytes_read; + ProcessSP process_sp (frame->CalculateProcess()); + if (process_sp) + { + Error error; + return process_sp->ReadMemory (addr, dst, dst_len, error); + } + return 0; } size_t @@ -312,26 +307,19 @@ EmulateInstruction::WriteMemoryFrame (EmulateInstruction *instruction, void *baton, const Context &context, lldb::addr_t addr, - const void *dst, - size_t length) + const void *src, + size_t src_len) { - if (!baton) + if (!baton || src == NULL || src_len == 0) return 0; StackFrame *frame = (StackFrame *) baton; - lldb::DataBufferSP data_sp (new DataBufferHeap (dst, length)); - if (data_sp) + ProcessSP process_sp (frame->CalculateProcess()); + if (process_sp) { - length = data_sp->GetByteSize(); - if (length > 0) - { - Error error; - size_t bytes_written = frame->GetThread().GetProcess().WriteMemory (addr, data_sp->GetBytes(), length, - error); - - return bytes_written; - } + Error error; + return process_sp->WriteMemory (addr, src, src_len, error); } return 0; diff --git a/lldb/source/Core/ValueObjectRegister.cpp b/lldb/source/Core/ValueObjectRegister.cpp index f0896094eaf..e257165ae11 100644 --- a/lldb/source/Core/ValueObjectRegister.cpp +++ b/lldb/source/Core/ValueObjectRegister.cpp @@ -307,10 +307,11 @@ ValueObjectRegister::GetClangType () { if (m_clang_type == NULL) { - Process *process = m_reg_ctx_sp->CalculateProcess (); - if (process) + ExecutionContext exe_ctx (GetExecutionContextRef()); + Target *target = exe_ctx.GetTargetPtr(); + if (target) { - Module *exe_module = process->GetTarget().GetExecutableModulePointer(); + Module *exe_module = target->GetExecutableModulePointer(); if (exe_module) { m_clang_type = exe_module->GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize (m_reg_info.encoding, @@ -338,10 +339,11 @@ ValueObjectRegister::CalculateNumChildren() clang::ASTContext * ValueObjectRegister::GetClangAST () { - Process *process = m_reg_ctx_sp->CalculateProcess (); - if (process) + ExecutionContext exe_ctx (GetExecutionContextRef()); + Target *target = exe_ctx.GetTargetPtr(); + if (target) { - Module *exe_module = process->GetTarget().GetExecutableModulePointer(); + Module *exe_module = target->GetExecutableModulePointer(); if (exe_module) return exe_module->GetClangASTContext().getASTContext(); } diff --git a/lldb/source/Expression/ClangExpressionParser.cpp b/lldb/source/Expression/ClangExpressionParser.cpp index 958d18b5a40..3a8c697d47c 100644 --- a/lldb/source/Expression/ClangExpressionParser.cpp +++ b/lldb/source/Expression/ClangExpressionParser.cpp @@ -224,15 +224,15 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope, break; } - Process *process = NULL; + lldb::ProcessSP process_sp; if (exe_scope) - process = exe_scope->CalculateProcess(); + process_sp = exe_scope->CalculateProcess(); - if (process && m_compiler->getLangOpts().ObjC1) + if (process_sp && m_compiler->getLangOpts().ObjC1) { - if (process->GetObjCLanguageRuntime()) + if (process_sp->GetObjCLanguageRuntime()) { - if (process->GetObjCLanguageRuntime()->GetRuntimeVersion() == eAppleObjC_V2) + if (process_sp->GetObjCLanguageRuntime()->GetRuntimeVersion() == eAppleObjC_V2) { m_compiler->getLangOpts().ObjCNonFragileABI = true; // NOT i386 m_compiler->getLangOpts().ObjCNonFragileABI2 = true; // NOT i386 @@ -256,18 +256,18 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope, m_compiler->getDiagnosticOpts().Warnings.push_back("no-unused-value"); // Set the target triple. - Target *target = NULL; + lldb::TargetSP target_sp; if (exe_scope) - target = exe_scope->CalculateTarget(); + target_sp = exe_scope->CalculateTarget(); // TODO: figure out what to really do when we don't have a valid target. // Sometimes this will be ok to just use the host target triple (when we // evaluate say "2+3", but other expressions like breakpoint conditions // and other things that _are_ target specific really shouldn't just be // using the host triple. This needs to be fixed in a better way. - if (target && target->GetArchitecture().IsValid()) + if (target_sp && target_sp->GetArchitecture().IsValid()) { - std::string triple = target->GetArchitecture().GetTriple().str(); + std::string triple = target_sp->GetArchitecture().GetTriple().str(); int dash_count = 0; for (size_t i = 0; i < triple.size(); ++i) diff --git a/lldb/source/Expression/ClangFunction.cpp b/lldb/source/Expression/ClangFunction.cpp index 22447692749..62a07d5a571 100644 --- a/lldb/source/Expression/ClangFunction.cpp +++ b/lldb/source/Expression/ClangFunction.cpp @@ -66,11 +66,9 @@ ClangFunction::ClangFunction m_compiled (false), m_JITted (false) { - Process *process = exe_scope.CalculateProcess(); + m_jit_process_sp = exe_scope.CalculateProcess(); // Can't make a ClangFunction without a process. - assert (process != NULL); - - m_jit_process_sp = process->shared_from_this(); + assert (m_jit_process_sp); } ClangFunction::ClangFunction @@ -91,11 +89,9 @@ ClangFunction::ClangFunction m_compiled (false), m_JITted (false) { - Process *process = exe_scope.CalculateProcess(); + m_jit_process_sp = exe_scope.CalculateProcess(); // Can't make a ClangFunction without a process. - assert (process != NULL); - - m_jit_process_sp = process->shared_from_this(); + assert (m_jit_process_sp); m_function_addr = m_function_ptr->GetAddressRange().GetBaseAddress(); m_function_return_qual_type = m_function_ptr->GetReturnClangType(); diff --git a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp index 0d1e74b2513..182294d65b5 100644 --- a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp +++ b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp @@ -106,19 +106,22 @@ PadString(Stream *s, const std::string &str, size_t width) s->Printf("%s ", str.c_str()); } static void -AddSymbolicInfo (ExecutionContextScope *exe_scope, +AddSymbolicInfo (const ExecutionContext *exe_ctx, StreamString &comment, uint64_t operand_value, const Address &inst_addr) { Address so_addr; Target *target = NULL; - if (exe_scope) - target = exe_scope->CalculateTarget(); + if (exe_ctx) + target = exe_ctx->GetTargetPtr(); if (target && !target->GetSectionLoadList().IsEmpty()) { if (target->GetSectionLoadList().ResolveLoadAddress(operand_value, so_addr)) - so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset); + so_addr.Dump (&comment, + exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL, + Address::DumpStyleResolvedDescriptionNoModule, + Address::DumpStyleSectionNameOffset); } else { @@ -126,7 +129,10 @@ AddSymbolicInfo (ExecutionContextScope *exe_scope, if (module) { if (module->ResolveFileAddress(operand_value, so_addr)) - so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset); + so_addr.Dump (&comment, + exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL, + Address::DumpStyleResolvedDescriptionNoModule, + Address::DumpStyleSectionNameOffset); } } } @@ -166,7 +172,7 @@ InstructionLLVM::Dump uint32_t max_opcode_byte_size, bool show_address, bool show_bytes, - const lldb_private::ExecutionContext* exe_ctx, + const ExecutionContext* exe_ctx, bool raw ) { @@ -336,7 +342,7 @@ InstructionLLVM::Dump comment.Printf("0x%*.*llx ", addr_nibble_size, addr_nibble_size, operand_value); } - AddSymbolicInfo(exe_scope, comment, operand_value, GetAddress()); + AddSymbolicInfo(exe_ctx, comment, operand_value, GetAddress()); } // EDEvaluateOperand } // EDOperandIsMemory } // EDGetOperand @@ -365,7 +371,7 @@ InstructionLLVM::Dump uint64_t operand_value = PC + atoi(++pos); // Put the address value into the operands. operands.Printf("0x%8.8llx ", operand_value); - AddSymbolicInfo(exe_scope, comment, operand_value, GetAddress()); + AddSymbolicInfo(exe_ctx, comment, operand_value, GetAddress()); } } // Yet more workaround for "bl #..." and "blx #...". @@ -387,7 +393,7 @@ InstructionLLVM::Dump llvm::StringRef Str(pos - 1); RStrip(Str, '\n'); operands.PutCString(Str.str().c_str()); - AddSymbolicInfo(exe_scope, comment, operand_value, GetAddress()); + AddSymbolicInfo(exe_ctx, comment, operand_value, GetAddress()); } } // END of workaround. @@ -446,10 +452,9 @@ InstructionLLVM::CalculateMnemonicOperandsAndComment (ExecutionContextScope *exe int currentOpIndex = -1; StreamString comment; uint32_t addr_nibble_size = 8; - addr_t base_addr = LLDB_INVALID_ADDRESS; - Target *target = NULL; - if (exe_scope) - target = exe_scope->CalculateTarget(); + addr_t base_addr = LLDB_INVALID_ADDRESS; + ExecutionContext exe_ctx (exe_scope); + Target *target = exe_ctx.GetTargetPtr(); if (target && !target->GetSectionLoadList().IsEmpty()) base_addr = GetAddress().GetLoadAddress (target); if (base_addr == LLDB_INVALID_ADDRESS) @@ -501,7 +506,7 @@ InstructionLLVM::CalculateMnemonicOperandsAndComment (ExecutionContextScope *exe if (!EDEvaluateOperand(&operand_value, operand, IPRegisterReader, &rra)) { comment.Printf("0x%*.*llx ", addr_nibble_size, addr_nibble_size, operand_value); - AddSymbolicInfo (exe_scope, comment, operand_value, GetAddress()); + AddSymbolicInfo (&exe_ctx, comment, operand_value, GetAddress()); } } } @@ -526,7 +531,7 @@ InstructionLLVM::CalculateMnemonicOperandsAndComment (ExecutionContextScope *exe uint64_t operand_value = PC + atoi(++pos); // Put the address value into the operands. comment.Printf("0x%*.*llx ", addr_nibble_size, addr_nibble_size, operand_value); - AddSymbolicInfo (exe_scope, comment, operand_value, GetAddress()); + AddSymbolicInfo (&exe_ctx, comment, operand_value, GetAddress()); } } // Yet more workaround for "bl #..." and "blx #...". @@ -551,7 +556,7 @@ InstructionLLVM::CalculateMnemonicOperandsAndComment (ExecutionContextScope *exe // llvm::StringRef Str(pos - 1); // RStrip(Str, '\n'); // operands.PutCString(Str.str().c_str()); - AddSymbolicInfo (exe_scope, comment, operand_value, GetAddress()); + AddSymbolicInfo (&exe_ctx, comment, operand_value, GetAddress()); } } // END of workaround. diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp index 983f1671bc6..396a285aed6 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp @@ -630,14 +630,16 @@ AppleObjCTrampolineHandler::GetStepThroughDispatchPlan (Thread &thread, bool sto lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0); - Process *process = thread.CalculateProcess(); - const ABI *abi = process->GetABI().get(); + const ABI *abi = NULL; + ProcessSP process_sp (thread.CalculateProcess()); + if (process_sp) + abi = process_sp->GetABI().get(); if (abi == NULL) return ret_plan_sp; - Target *target = thread.CalculateTarget(); + TargetSP target_sp (thread.CalculateTarget()); - ClangASTContext *clang_ast_context = target->GetScratchClangASTContext(); + ClangASTContext *clang_ast_context = target_sp->GetScratchClangASTContext(); ValueList argument_values; Value void_ptr_value; lldb::clang_type_t clang_void_ptr_type = clang_ast_context->GetVoidPtrType(false); @@ -671,9 +673,8 @@ AppleObjCTrampolineHandler::GetStepThroughDispatchPlan (Thread &thread, bool sto if (!success) return ret_plan_sp; - ExecutionContext exe_ctx; - thread.CalculateExecutionContext (exe_ctx); - + ExecutionContext exe_ctx (thread.shared_from_this()); + Process *process = exe_ctx.GetProcessPtr(); // isa_addr will store the class pointer that the method is being dispatched to - so either the class // directly or the super class if this is one of the objc_msgSendSuper flavors. That's mostly used to // look up the class/selector pair in our cache. diff --git a/lldb/source/Symbol/FuncUnwinders.cpp b/lldb/source/Symbol/FuncUnwinders.cpp index e01f0b7b6c3..92d613490cf 100644 --- a/lldb/source/Symbol/FuncUnwinders.cpp +++ b/lldb/source/Symbol/FuncUnwinders.cpp @@ -166,10 +166,10 @@ FuncUnwinders::GetUnwindPlanArchitectureDefault (Thread& thread) { m_tried_unwind_arch_default = true; Address current_pc; - Target *target = thread.CalculateTarget(); - if (target) + ProcessSP process_sp (thread.CalculateProcess()); + if (process_sp) { - ABI *abi = thread.GetProcess().GetABI().get(); + ABI *abi = process_sp->GetABI().get(); if (abi) { m_unwind_plan_arch_default_sp.reset (new UnwindPlan (lldb::eRegisterKindGeneric)); @@ -202,10 +202,10 @@ FuncUnwinders::GetUnwindPlanArchitectureDefaultAtFunctionEntry (Thread& thread) { m_tried_unwind_arch_default_at_func_entry = true; Address current_pc; - Target *target = thread.CalculateTarget(); - if (target) + ProcessSP process_sp (thread.CalculateProcess()); + if (process_sp) { - ABI *abi = thread.GetProcess().GetABI().get(); + ABI *abi = process_sp->GetABI().get(); if (abi) { m_unwind_plan_arch_default_at_func_entry_sp.reset (new UnwindPlan (lldb::eRegisterKindGeneric)); diff --git a/lldb/source/Symbol/Variable.cpp b/lldb/source/Symbol/Variable.cpp index a868e5f5cbb..161d4826bad 100644 --- a/lldb/source/Symbol/Variable.cpp +++ b/lldb/source/Symbol/Variable.cpp @@ -216,19 +216,19 @@ Variable::LocationIsValidForFrame (StackFrame *frame) if (frame) { - Target *target = &frame->GetThread().GetProcess().GetTarget(); - Function *function = frame->GetSymbolContext(eSymbolContextFunction).function; if (function) { - addr_t loclist_base_load_addr = function->GetAddressRange().GetBaseAddress().GetLoadAddress (target); + TargetSP target_sp (frame->CalculateTarget()); + + addr_t loclist_base_load_addr = function->GetAddressRange().GetBaseAddress().GetLoadAddress (target_sp.get()); if (loclist_base_load_addr == LLDB_INVALID_ADDRESS) return false; // It is a location list. We just need to tell if the location // list contains the current address when converted to a load // address return m_location.LocationListContainsAddress (loclist_base_load_addr, - frame->GetFrameCodeAddress().GetLoadAddress (target)); + frame->GetFrameCodeAddress().GetLoadAddress (target_sp.get())); } } return false; diff --git a/lldb/source/Target/ExecutionContext.cpp b/lldb/source/Target/ExecutionContext.cpp index 6cce08a093b..e284438eee8 100644 --- a/lldb/source/Target/ExecutionContext.cpp +++ b/lldb/source/Target/ExecutionContext.cpp @@ -343,7 +343,7 @@ ExecutionContext::SetContext (const lldb::StackFrameSP &frame_sp) m_frame_sp = frame_sp; if (frame_sp) { - m_thread_sp = frame_sp->GetThread().shared_from_this(); + m_thread_sp = frame_sp->CalculateThread(); if (m_thread_sp) { m_process_sp = m_thread_sp->GetProcess().shared_from_this(); diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 6f5589bb189..e959e407001 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -3490,6 +3490,12 @@ Process::ProcessEventData::SetUpdateStateOnRemoval (Event *event_ptr) return false; } +lldb::TargetSP +Process::CalculateTarget () +{ + return m_target.shared_from_this(); +} + void Process::CalculateExecutionContext (ExecutionContext &exe_ctx) { diff --git a/lldb/source/Target/RegisterContext.cpp b/lldb/source/Target/RegisterContext.cpp index a7856c6332c..ba1f641a046 100644 --- a/lldb/source/Target/RegisterContext.cpp +++ b/lldb/source/Target/RegisterContext.cpp @@ -356,32 +356,32 @@ RegisterContext::WriteRegisterValueToMemory (const RegisterInfo *reg_info, } -Target * +TargetSP RegisterContext::CalculateTarget () { return m_thread.CalculateTarget(); } -Process * +ProcessSP RegisterContext::CalculateProcess () { return m_thread.CalculateProcess (); } -Thread * +ThreadSP RegisterContext::CalculateThread () { - return &m_thread; + return m_thread.shared_from_this(); } -StackFrame * +StackFrameSP RegisterContext::CalculateStackFrame () { // Register contexts might belong to many frames if we have inlined // functions inside a frame since all inlined functions share the // same registers, so we can't definitively say which frame we come from... - return NULL; + return StackFrameSP(); } void diff --git a/lldb/source/Target/StackFrame.cpp b/lldb/source/Target/StackFrame.cpp index 2ce69f8c04e..c1802b497e0 100644 --- a/lldb/source/Target/StackFrame.cpp +++ b/lldb/source/Target/StackFrame.cpp @@ -39,13 +39,13 @@ using namespace lldb_private; #define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1) #define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1) -StackFrame::StackFrame (user_id_t frame_idx, +StackFrame::StackFrame (const ThreadSP &thread_sp, + user_id_t frame_idx, user_id_t unwind_frame_index, - Thread &thread, addr_t cfa, addr_t pc, const SymbolContext *sc_ptr) : - m_thread (thread), + m_thread_wp (thread_sp), m_frame_index (frame_idx), m_concrete_frame_index (unwind_frame_index), m_reg_context_sp (), @@ -66,14 +66,14 @@ StackFrame::StackFrame (user_id_t frame_idx, } } -StackFrame::StackFrame (user_id_t frame_idx, +StackFrame::StackFrame (const ThreadSP &thread_sp, + user_id_t frame_idx, user_id_t unwind_frame_index, - Thread &thread, const RegisterContextSP ®_context_sp, addr_t cfa, addr_t pc, const SymbolContext *sc_ptr) : - m_thread (thread), + m_thread_wp (thread_sp), m_frame_index (frame_idx), m_concrete_frame_index (unwind_frame_index), m_reg_context_sp (reg_context_sp), @@ -95,23 +95,24 @@ StackFrame::StackFrame (user_id_t frame_idx, if (reg_context_sp && !m_sc.target_sp) { - m_sc.target_sp = reg_context_sp->GetThread().GetProcess().GetTarget().shared_from_this(); - m_flags.Set (eSymbolContextTarget); + m_sc.target_sp = reg_context_sp->CalculateTarget(); + if (m_sc.target_sp) + m_flags.Set (eSymbolContextTarget); } } -StackFrame::StackFrame (user_id_t frame_idx, +StackFrame::StackFrame (const ThreadSP &thread_sp, + user_id_t frame_idx, user_id_t unwind_frame_index, - Thread &thread, const RegisterContextSP ®_context_sp, addr_t cfa, const Address& pc_addr, const SymbolContext *sc_ptr) : - m_thread (thread), + m_thread_wp (thread_sp), m_frame_index (frame_idx), m_concrete_frame_index (unwind_frame_index), m_reg_context_sp (reg_context_sp), - m_id (pc_addr.GetLoadAddress (&thread.GetProcess().GetTarget()), cfa, NULL), + m_id (pc_addr.GetLoadAddress (&thread_sp->GetProcess().GetTarget()), cfa, NULL), m_frame_code_addr (pc_addr), m_sc (), m_flags (), @@ -129,8 +130,9 @@ StackFrame::StackFrame (user_id_t frame_idx, if (m_sc.target_sp.get() == NULL && reg_context_sp) { - m_sc.target_sp = reg_context_sp->GetThread().GetProcess().GetTarget().shared_from_this(); - m_flags.Set (eSymbolContextTarget); + m_sc.target_sp = reg_context_sp->CalculateTarget(); + if (m_sc.target_sp) + m_flags.Set (eSymbolContextTarget); } Module *pc_module = pc_addr.GetModulePtr(); @@ -209,18 +211,25 @@ StackFrame::GetFrameCodeAddress() // Resolve the PC into a temporary address because if ResolveLoadAddress // fails to resolve the address, it will clear the address object... - - if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), &m_thread.GetProcess().GetTarget())) + ThreadSP thread_sp (GetThread()); + if (thread_sp) { - const Section *section = m_frame_code_addr.GetSection(); - if (section) + TargetSP target_sp (thread_sp->CalculateTarget()); + if (target_sp) { - Module *module = section->GetModule(); - if (module) + if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get())) { - m_sc.module_sp = module->shared_from_this(); - if (m_sc.module_sp) - m_flags.Set(eSymbolContextModule); + const Section *section = m_frame_code_addr.GetSection(); + if (section) + { + Module *module = section->GetModule(); + if (module) + { + m_sc.module_sp = module->shared_from_this(); + if (m_sc.module_sp) + m_flags.Set(eSymbolContextModule); + } + } } } } @@ -235,7 +244,9 @@ StackFrame::ChangePC (addr_t pc) m_frame_code_addr.SetSection(NULL); m_sc.Clear(); m_flags.Reset(0); - m_thread.ClearStackFrames (); + ThreadSP thread_sp (GetThread()); + if (thread_sp) + thread_sp->ClearStackFrames (); } const char * @@ -243,17 +254,19 @@ StackFrame::Disassemble () { if (m_disassembly.GetSize() == 0) { - ExecutionContext exe_ctx; - CalculateExecutionContext(exe_ctx); - Target &target = m_thread.GetProcess().GetTarget(); - Disassembler::Disassemble (target.GetDebugger(), - target.GetArchitecture(), - NULL, - exe_ctx, - 0, - 0, - 0, - m_disassembly); + ExecutionContext exe_ctx (shared_from_this()); + Target *target = exe_ctx.GetTargetPtr(); + if (target) + { + Disassembler::Disassemble (target->GetDebugger(), + target->GetArchitecture(), + NULL, + exe_ctx, + 0, + 0, + 0, + m_disassembly); + } if (m_disassembly.GetSize() == 0) return NULL; } @@ -411,13 +424,15 @@ StackFrame::GetSymbolContext (uint32_t resolve_scope) // If we don't have a module, then we can't have the compile unit, // function, block, line entry or symbol, so we can safely call // ResolveSymbolContextForAddress with our symbol context member m_sc. - resolved |= m_thread.GetProcess().GetTarget().GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc); + TargetSP target_sp (CalculateTarget()); + if (target_sp) + resolved |= target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc); } // If the target was requested add that: - if (m_sc.target_sp.get() == NULL) + if (!m_sc.target_sp) { - m_sc.target_sp = CalculateProcess()->GetTarget().shared_from_this(); + m_sc.target_sp = CalculateTarget(); if (m_sc.target_sp) resolved |= eSymbolContextTarget; } @@ -1019,11 +1034,11 @@ StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr) m_frame_base_error.Clear(); m_flags.Set(GOT_FRAME_BASE); - ExecutionContext exe_ctx (&m_thread.GetProcess(), &m_thread, this); + ExecutionContext exe_ctx (shared_from_this()); Value expr_value; addr_t loclist_base_addr = LLDB_INVALID_ADDRESS; if (m_sc.function->GetFrameBaseExpression().IsLocationList()) - loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (&m_thread.GetProcess().GetTarget()); + loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr()); if (m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, NULL, NULL, NULL, NULL, loclist_base_addr, NULL, expr_value, &m_frame_base_error) == false) { @@ -1055,7 +1070,11 @@ RegisterContextSP StackFrame::GetRegisterContext () { if (!m_reg_context_sp) - m_reg_context_sp = m_thread.CreateRegisterContextForFrame (this); + { + ThreadSP thread_sp (GetThread()); + if (thread_sp) + m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this); + } return m_reg_context_sp; } @@ -1130,36 +1149,47 @@ StackFrame::IsInlined () return false; } -Target * +TargetSP StackFrame::CalculateTarget () { - return m_thread.CalculateTarget(); + TargetSP target_sp; + ThreadSP thread_sp(GetThread()); + if (thread_sp) + { + ProcessSP process_sp (thread_sp->CalculateProcess()); + if (process_sp) + target_sp = process_sp->CalculateTarget(); + } + return target_sp; } -Process * +ProcessSP StackFrame::CalculateProcess () { - return m_thread.CalculateProcess(); + ProcessSP process_sp; + ThreadSP thread_sp(GetThread()); + if (thread_sp) + process_sp = thread_sp->CalculateProcess(); + return process_sp; } -Thread * +ThreadSP StackFrame::CalculateThread () { - return &m_thread; + return GetThread(); } -StackFrame * +StackFrameSP StackFrame::CalculateStackFrame () { - return this; + return shared_from_this(); } void StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx) { - m_thread.CalculateExecutionContext (exe_ctx); - exe_ctx.SetFramePtr(this); + exe_ctx.SetContext (shared_from_this()); } void @@ -1169,11 +1199,13 @@ StackFrame::DumpUsingSettingsFormat (Stream *strm) return; GetSymbolContext(eSymbolContextEverything); - ExecutionContext exe_ctx; - CalculateExecutionContext(exe_ctx); + ExecutionContext exe_ctx (shared_from_this()); const char *end = NULL; StreamString s; - const char *frame_format = m_thread.GetProcess().GetTarget().GetDebugger().GetFrameFormat(); + const char *frame_format = NULL; + Target *target = exe_ctx.GetTargetPtr(); + if (target) + frame_format = target->GetDebugger().GetFrameFormat(); if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end)) { strm->Write(s.GetData(), s.GetSize()); @@ -1193,11 +1225,20 @@ StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths) if (show_frame_index) strm->Printf("frame #%u: ", m_frame_index); - strm->Printf("0x%0*llx ", m_thread.GetProcess().GetTarget().GetArchitecture().GetAddressByteSize() * 2, GetFrameCodeAddress().GetLoadAddress(&m_thread.GetProcess().GetTarget())); + ExecutionContext exe_ctx (shared_from_this()); + Target *target = exe_ctx.GetTargetPtr(); + strm->Printf("0x%0*llx ", + target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16, + GetFrameCodeAddress().GetLoadAddress(target)); GetSymbolContext(eSymbolContextEverything); const bool show_module = true; const bool show_inline = true; - m_sc.DumpStopContext(strm, &m_thread.GetProcess(), GetFrameCodeAddress(), show_fullpaths, show_module, show_inline); + m_sc.DumpStopContext (strm, + exe_ctx.GetBestExecutionContextScope(), + GetFrameCodeAddress(), + show_fullpaths, + show_module, + show_inline); } void @@ -1216,7 +1257,7 @@ StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame) { assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value - assert (&m_thread == &curr_frame.m_thread); + assert (GetThread() == curr_frame.GetThread()); m_frame_index = curr_frame.m_frame_index; m_concrete_frame_index = curr_frame.m_concrete_frame_index; m_reg_context_sp = curr_frame.m_reg_context_sp; @@ -1260,29 +1301,28 @@ StackFrame::GetStatus (Stream& strm, if (show_source) { - Target &target = GetThread().GetProcess().GetTarget(); - Debugger &debugger = target.GetDebugger(); - const uint32_t source_before = debugger.GetStopSourceLineCount(true); - const uint32_t source_after = debugger.GetStopSourceLineCount(false); + ExecutionContext exe_ctx (shared_from_this()); bool have_source = false; - if (source_before || source_after) + DebuggerInstanceSettings::StopDisassemblyType disasm_display = DebuggerInstanceSettings::eStopDisassemblyTypeNever; + Target *target = exe_ctx.GetTargetPtr(); + if (target && (source_lines_before || source_lines_after)) { GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry); if (m_sc.comp_unit && m_sc.line_entry.IsValid()) { - if (target.GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file, - m_sc.line_entry.line, - source_before, - source_after, - "->", - &strm)) + if (target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file, + m_sc.line_entry.line, + source_lines_before, + source_lines_after, + "->", + &strm)) { have_source = true; } } + disasm_display = target->GetDebugger().GetStopDisassemblyDisplay (); } - DebuggerInstanceSettings::StopDisassemblyType disasm_display = debugger.GetStopDisassemblyDisplay (); switch (disasm_display) { @@ -1294,17 +1334,16 @@ StackFrame::GetStatus (Stream& strm, break; // Fall through to next case case DebuggerInstanceSettings::eStopDisassemblyTypeAlways: + if (target) { - const uint32_t disasm_lines = debugger.GetDisassemblyLineCount(); + const uint32_t disasm_lines = target->GetDebugger().GetDisassemblyLineCount(); if (disasm_lines > 0) { - const ArchSpec &target_arch = target.GetArchitecture(); + const ArchSpec &target_arch = target->GetArchitecture(); AddressRange pc_range; pc_range.GetBaseAddress() = GetFrameCodeAddress(); pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize()); - ExecutionContext exe_ctx; - CalculateExecutionContext(exe_ctx); - Disassembler::Disassemble (debugger, + Disassembler::Disassemble (target->GetDebugger(), target_arch, NULL, exe_ctx, diff --git a/lldb/source/Target/StackFrameList.cpp b/lldb/source/Target/StackFrameList.cpp index b69cad2f9c5..27383d87ef7 100644 --- a/lldb/source/Target/StackFrameList.cpp +++ b/lldb/source/Target/StackFrameList.cpp @@ -89,9 +89,9 @@ StackFrameList::GetNumFrames (bool can_create) { cfa = m_thread.m_reg_context_sp->GetSP(); m_thread.GetRegisterContext(); - unwind_frame_sp.reset (new StackFrame (m_frames.size(), + unwind_frame_sp.reset (new StackFrame (m_thread.shared_from_this(), + m_frames.size(), idx, - m_thread, m_thread.m_reg_context_sp, cfa, m_thread.m_reg_context_sp->GetPC(), @@ -108,7 +108,7 @@ StackFrameList::GetNumFrames (bool can_create) { const bool success = unwinder->GetFrameInfoAtIndex(idx, cfa, pc); assert (success); - unwind_frame_sp.reset (new StackFrame (m_frames.size(), idx, m_thread, cfa, pc, NULL)); + unwind_frame_sp.reset (new StackFrame (m_thread.shared_from_this(), m_frames.size(), idx, cfa, pc, NULL)); m_frames.push_back (unwind_frame_sp); } @@ -130,9 +130,9 @@ StackFrameList::GetNumFrames (bool can_create) while (unwind_sc.GetParentOfInlinedScope(curr_frame_address, next_frame_sc, next_frame_address)) { - StackFrameSP frame_sp(new StackFrame (m_frames.size(), + StackFrameSP frame_sp(new StackFrame (m_thread.shared_from_this(), + m_frames.size(), idx, - m_thread, unwind_frame_sp->GetRegisterContextSP (), cfa, next_frame_address, @@ -264,9 +264,9 @@ StackFrameList::GetFrameAtIndex (uint32_t idx) // context with the stack frame at index zero. m_thread.GetRegisterContext(); assert (m_thread.m_reg_context_sp.get()); - frame_sp.reset (new StackFrame (0, + frame_sp.reset (new StackFrame (m_thread.shared_from_this(), 0, - m_thread, + 0, m_thread.m_reg_context_sp, m_thread.m_reg_context_sp->GetSP(), m_thread.m_reg_context_sp->GetPC(), @@ -289,7 +289,7 @@ StackFrameList::GetFrameAtIndex (uint32_t idx) addr_t pc, cfa; if (unwinder->GetFrameInfoAtIndex(idx, cfa, pc)) { - frame_sp.reset (new StackFrame (idx, idx, m_thread, cfa, pc, NULL)); + frame_sp.reset (new StackFrame (m_thread.shared_from_this(), idx, idx, cfa, pc, NULL)); Function *function = frame_sp->GetSymbolContext (eSymbolContextFunction).function; if (function) diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index c0aa7a51977..ce4777fea53 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1286,28 +1286,28 @@ Target::GetSharedModule } -Target * +TargetSP Target::CalculateTarget () { - return this; + return shared_from_this(); } -Process * +ProcessSP Target::CalculateProcess () { - return NULL; + return ProcessSP(); } -Thread * +ThreadSP Target::CalculateThread () { - return NULL; + return ThreadSP(); } -StackFrame * +StackFrameSP Target::CalculateStackFrame () { - return NULL; + return StackFrameSP(); } void diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp index 1c13b3df631..7423249f36b 100644 --- a/lldb/source/Target/Thread.cpp +++ b/lldb/source/Target/Thread.cpp @@ -1015,28 +1015,28 @@ Thread::DumpThreadPlans (lldb_private::Stream *s) const } -Target * +TargetSP Thread::CalculateTarget () { return m_process.CalculateTarget(); } -Process * +ProcessSP Thread::CalculateProcess () { - return &m_process; + return m_process.shared_from_this(); } -Thread * +ThreadSP Thread::CalculateThread () { - return this; + return shared_from_this(); } -StackFrame * +StackFrameSP Thread::CalculateStackFrame () { - return NULL; + return StackFrameSP(); } void diff --git a/lldb/source/Target/ThreadPlanStepInRange.cpp b/lldb/source/Target/ThreadPlanStepInRange.cpp index b1c1bbc1d61..3455e908d0f 100644 --- a/lldb/source/Target/ThreadPlanStepInRange.cpp +++ b/lldb/source/Target/ThreadPlanStepInRange.cpp @@ -194,13 +194,13 @@ ThreadPlanStepInRange::ShouldStop (Event *event_ptr) if (sc.function) { func_start_address = sc.function->GetAddressRange().GetBaseAddress(); - if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget())) + if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get())) bytes_to_skip = sc.function->GetPrologueByteSize(); } else if (sc.symbol) { func_start_address = sc.symbol->GetValue(); - if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget())) + if (curr_addr == func_start_address.GetLoadAddress(m_thread.CalculateTarget().get())) bytes_to_skip = sc.symbol->GetPrologueByteSize(); } diff --git a/lldb/tools/debugserver/debugserver.xcodeproj/xcshareddata/xcschemes/debugserver.xcscheme b/lldb/tools/debugserver/debugserver.xcodeproj/xcshareddata/xcschemes/debugserver.xcscheme index 9cfaa138c67..e09e13611ca 100644 --- a/lldb/tools/debugserver/debugserver.xcodeproj/xcshareddata/xcschemes/debugserver.xcscheme +++ b/lldb/tools/debugserver/debugserver.xcodeproj/xcshareddata/xcschemes/debugserver.xcscheme @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <Scheme + LastUpgradeVersion = "0430" version = "1.8"> <BuildAction parallelizeBuildables = "NO" @@ -53,6 +54,7 @@ launchStyle = "0" useCustomWorkingDirectory = "NO" buildConfiguration = "Debug" + ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" allowLocationSimulation = "YES"> <BuildableProductRunnable> |

