diff options
author | Greg Clayton <gclayton@apple.com> | 2012-01-30 07:41:31 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2012-01-30 07:41:31 +0000 |
commit | b9556acc9e1e48cd86bb8b60de7168c1e5f8710d (patch) | |
tree | e56d2433b931257625667effbba2a20200c2b81a /lldb/source/API | |
parent | 5d917075fd86131abecbb27e9ddb8703d4eb2ae3 (diff) | |
download | bcm5719-llvm-b9556acc9e1e48cd86bb8b60de7168c1e5f8710d.tar.gz bcm5719-llvm-b9556acc9e1e48cd86bb8b60de7168c1e5f8710d.zip |
SBFrame is now threadsafe using some extra tricks. One issue is that stack
frames might go away (the object itself, not the actual logical frame) when
we are single stepping due to the way we currently sometimes end up flushing
frames when stepping in/out/over. They later will come back to life
represented by another object yet they have the same StackID. Now when you get
a lldb::SBFrame object, it will track the frame it is initialized with until
the thread goes away or the StackID no longer exists in the stack for the
thread it was created on. It uses a weak_ptr to both the frame and thread and
also stores the StackID. These three items allow us to determine when the
stack frame object has gone away (the weak_ptr will be NULL) and allows us to
find the correct frame again. In our test suite we had such cases where we
were just getting lucky when something like this happened:
1 - stop at breakpoint
2 - get first frame in thread where we stopped
3 - run an expression that causes the program to JIT and run code
4 - run more expressions on the frame from step 2 which was very very luckily
still around inside a shared pointer, yet, not part of the current
thread (a new stack frame object had appeared with the same stack ID and
depth).
We now avoid all such issues and properly keep up to date, or we start
returning errors when the frame doesn't exist and always responds with
invalid answers.
Also fixed the UserSettingsController (not going to rewrite this just yet)
so that it doesn't crash on shutdown. Using weak_ptr's came in real handy to
track when the master controller has already gone away and this allowed me to
pull out the previous NotifyOwnerIsShuttingDown() patch as it is no longer
needed.
llvm-svn: 149231
Diffstat (limited to 'lldb/source/API')
-rw-r--r-- | lldb/source/API/SBAddress.cpp | 9 | ||||
-rw-r--r-- | lldb/source/API/SBCommandInterpreter.cpp | 10 | ||||
-rw-r--r-- | lldb/source/API/SBDebugger.cpp | 81 | ||||
-rw-r--r-- | lldb/source/API/SBFrame.cpp | 417 | ||||
-rw-r--r-- | lldb/source/API/SBFunction.cpp | 9 | ||||
-rw-r--r-- | lldb/source/API/SBInstruction.cpp | 65 | ||||
-rw-r--r-- | lldb/source/API/SBModule.cpp | 6 | ||||
-rw-r--r-- | lldb/source/API/SBProcess.cpp | 29 | ||||
-rw-r--r-- | lldb/source/API/SBSourceManager.cpp | 2 | ||||
-rw-r--r-- | lldb/source/API/SBSymbol.cpp | 7 | ||||
-rw-r--r-- | lldb/source/API/SBTarget.cpp | 110 | ||||
-rw-r--r-- | lldb/source/API/SBThread.cpp | 47 | ||||
-rw-r--r-- | lldb/source/API/SBValue.cpp | 63 |
13 files changed, 496 insertions, 359 deletions
diff --git a/lldb/source/API/SBAddress.cpp b/lldb/source/API/SBAddress.cpp index 6e6a806de48..7cb0d902dfb 100644 --- a/lldb/source/API/SBAddress.cpp +++ b/lldb/source/API/SBAddress.cpp @@ -170,18 +170,19 @@ SBAddress::GetLoadAddress (const SBTarget &target) const LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); lldb::addr_t addr = LLDB_INVALID_ADDRESS; + TargetSP target_sp (target.GetSP()); if (m_opaque_ap.get()) { - Mutex::Locker api_locker (target->GetAPIMutex()); - addr = m_opaque_ap->GetAddress().GetLoadAddress (target.get()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + addr = m_opaque_ap->GetAddress().GetLoadAddress (target_sp.get()); } if (log) { if (addr == LLDB_INVALID_ADDRESS) - log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => LLDB_INVALID_ADDRESS", target.get()); + log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => LLDB_INVALID_ADDRESS", target_sp.get()); else - log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => 0x%llx", target.get(), addr); + log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => 0x%llx", target_sp.get(), addr); } return addr; diff --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp index 7fbf5c2c73d..e6054789090 100644 --- a/lldb/source/API/SBCommandInterpreter.cpp +++ b/lldb/source/API/SBCommandInterpreter.cpp @@ -188,24 +188,26 @@ SBCommandInterpreter::HasAliasOptions () SBProcess SBCommandInterpreter::GetProcess () { - SBProcess process; + SBProcess sb_process; + ProcessSP process_sp; if (m_opaque_ptr) { TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); if (target_sp) { Mutex::Locker api_locker(target_sp->GetAPIMutex()); - process.SetProcess(target_sp->GetProcessSP()); + process_sp = target_sp->GetProcessSP(); + sb_process.SetSP(process_sp); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBCommandInterpreter(%p)::GetProcess () => SBProcess(%p)", - m_opaque_ptr, process.get()); + m_opaque_ptr, process_sp.get()); - return process; + return sb_process; } CommandInterpreter * diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index ce72631ce65..9c2eea065ce 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -302,11 +302,12 @@ SBDebugger::HandleCommand (const char *command) if (m_opaque_sp->GetAsyncExecution() == false) { SBProcess process(GetCommandInterpreter().GetProcess ()); - if (process.IsValid()) + ProcessSP process_sp (process.GetSP()); + if (process_sp) { EventSP event_sp; Listener &lldb_listener = m_opaque_sp->GetListener(); - while (lldb_listener.GetNextEventForBroadcaster (process.get(), event_sp)) + while (lldb_listener.GetNextEventForBroadcaster (process_sp.get(), event_sp)) { SBEvent event(event_sp); HandleProcessEvent (process, event, GetOutputFileHandle(), GetErrorFileHandle()); @@ -338,11 +339,15 @@ SBDebugger::HandleProcessEvent (const SBProcess &process, const SBEvent &event, if (!process.IsValid()) return; + TargetSP target_sp (process.GetTarget().GetSP()); + if (!target_sp) + return; + const uint32_t event_type = event.GetType(); char stdio_buffer[1024]; size_t len; - Mutex::Locker api_locker (process.GetTarget()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); if (event_type & (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged)) { @@ -474,6 +479,7 @@ SBDebugger::CreateTarget (const char *filename, lldb::SBError& sb_error) { SBTarget sb_target; + TargetSP target_sp; if (m_opaque_sp) { sb_error.Clear(); @@ -481,7 +487,6 @@ SBDebugger::CreateTarget (const char *filename, OptionGroupPlatform platform_options (false); platform_options.SetPlatformName (platform_name); - TargetSP target_sp; sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, filename_spec, target_triple, @@ -490,7 +495,7 @@ SBDebugger::CreateTarget (const char *filename, target_sp); if (sb_error.Success()) - sb_target.reset (target_sp); + sb_target.SetSP (target_sp); } else { @@ -507,7 +512,7 @@ SBDebugger::CreateTarget (const char *filename, platform_name, add_dependent_modules, sb_error.GetCString(), - sb_target.get()); + target_sp.get()); } return sb_target; @@ -517,7 +522,8 @@ SBTarget SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename, const char *target_triple) { - SBTarget target; + SBTarget sb_target; + TargetSP target_sp; if (m_opaque_sp) { FileSpec file_spec (filename, true); @@ -529,17 +535,17 @@ SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename, add_dependent_modules, NULL, target_sp)); - target.reset (target_sp); + sb_target.SetSP (target_sp); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndTargetTriple (filename=\"%s\", triple=%s) => SBTarget(%p)", - m_opaque_sp.get(), filename, target_triple, target.get()); + m_opaque_sp.get(), filename, target_triple, target_sp.get()); } - return target; + return sb_target; } SBTarget @@ -547,11 +553,11 @@ SBDebugger::CreateTargetWithFileAndArch (const char *filename, const char *arch_ { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - SBTarget target; + SBTarget sb_target; + TargetSP target_sp; if (m_opaque_sp) { FileSpec file (filename, true); - TargetSP target_sp; Error error; const bool add_dependent_modules = true; @@ -565,28 +571,28 @@ SBDebugger::CreateTargetWithFileAndArch (const char *filename, const char *arch_ if (error.Success()) { m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get()); - target.reset(target_sp); + sb_target.SetSP (target_sp); } } if (log) { log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", arch=%s) => SBTarget(%p)", - m_opaque_sp.get(), filename, arch_cstr, target.get()); + m_opaque_sp.get(), filename, arch_cstr, target_sp.get()); } - return target; + return sb_target; } SBTarget SBDebugger::CreateTarget (const char *filename) { - SBTarget target; + SBTarget sb_target; + TargetSP target_sp; if (m_opaque_sp) { FileSpec file (filename, true); ArchSpec arch = Target::GetDefaultArchitecture (); - TargetSP target_sp; Error error; const bool add_dependent_modules = true; @@ -600,29 +606,33 @@ SBDebugger::CreateTarget (const char *filename) if (error.Success()) { m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get()); - target.reset (target_sp); + sb_target.SetSP (target_sp); } } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)", - m_opaque_sp.get(), filename, target.get()); + m_opaque_sp.get(), filename, target_sp.get()); } - return target; + return sb_target; } bool SBDebugger::DeleteTarget (lldb::SBTarget &target) { bool result = false; - if (m_opaque_sp && target.IsValid()) + if (m_opaque_sp) { - // No need to lock, the target list is thread safe - result = m_opaque_sp->GetTargetList().DeleteTarget (target.m_opaque_sp); - target->Destroy(); - target.Clear(); - ModuleList::RemoveOrphanSharedModules(); + TargetSP target_sp(target.GetSP()); + if (target_sp) + { + // No need to lock, the target list is thread safe + result = m_opaque_sp->GetTargetList().DeleteTarget (target_sp); + target_sp->Destroy(); + target.Clear(); + ModuleList::RemoveOrphanSharedModules(); + } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); @@ -640,7 +650,7 @@ SBDebugger::GetTargetAtIndex (uint32_t idx) if (m_opaque_sp) { // No need to lock, the target list is thread safe - sb_target.reset(m_opaque_sp->GetTargetList().GetTargetAtIndex (idx)); + sb_target.SetSP (m_opaque_sp->GetTargetList().GetTargetAtIndex (idx)); } return sb_target; } @@ -652,7 +662,7 @@ SBDebugger::FindTargetWithProcessID (pid_t pid) if (m_opaque_sp) { // No need to lock, the target list is thread safe - sb_target.reset(m_opaque_sp->GetTargetList().FindTargetWithProcessID (pid)); + sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcessID (pid)); } return sb_target; } @@ -666,7 +676,7 @@ SBDebugger::FindTargetWithFileAndArch (const char *filename, const char *arch_na // No need to lock, the target list is thread safe ArchSpec arch (arch_name, m_opaque_sp->GetPlatformList().GetSelectedPlatform().get()); TargetSP target_sp (m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture (FileSpec(filename, false), arch_name ? &arch : NULL)); - sb_target.reset(target_sp); + sb_target.SetSP (target_sp); } return sb_target; } @@ -678,7 +688,7 @@ SBDebugger::FindTargetWithLLDBProcess (const ProcessSP &process_sp) if (m_opaque_sp) { // No need to lock, the target list is thread safe - sb_target.reset(m_opaque_sp->GetTargetList().FindTargetWithProcess (process_sp.get())); + sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcess (process_sp.get())); } return sb_target; } @@ -701,10 +711,12 @@ SBDebugger::GetSelectedTarget () LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBTarget sb_target; + TargetSP target_sp; if (m_opaque_sp) { // No need to lock, the target list is thread safe - sb_target.reset(m_opaque_sp->GetTargetList().GetSelectedTarget ()); + target_sp = m_opaque_sp->GetTargetList().GetSelectedTarget (); + sb_target.SetSP (target_sp); } if (log) @@ -712,7 +724,7 @@ SBDebugger::GetSelectedTarget () SBStream sstr; sb_target.GetDescription (sstr, eDescriptionLevelBrief); log->Printf ("SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s", m_opaque_sp.get(), - sb_target.get(), sstr.GetData()); + target_sp.get(), sstr.GetData()); } return sb_target; @@ -723,16 +735,17 @@ SBDebugger::SetSelectedTarget (SBTarget &sb_target) { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + TargetSP target_sp (sb_target.GetSP()); if (m_opaque_sp) { - m_opaque_sp->GetTargetList().SetSelectedTarget (sb_target.get()); + m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get()); } if (log) { SBStream sstr; sb_target.GetDescription (sstr, eDescriptionLevelBrief); log->Printf ("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s", m_opaque_sp.get(), - sb_target.get(), sstr.GetData()); + target_sp.get(), sstr.GetData()); } } diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp index 38fcc4eb88a..564cf7736f2 100644 --- a/lldb/source/API/SBFrame.cpp +++ b/lldb/source/API/SBFrame.cpp @@ -32,6 +32,7 @@ #include "lldb/Target/Process.h" #include "lldb/Target/RegisterContext.h" #include "lldb/Target/StackFrame.h" +#include "lldb/Target/StackID.h" #include "lldb/Target/Thread.h" #include "lldb/API/SBDebugger.h" @@ -41,16 +42,91 @@ #include "lldb/API/SBSymbolContext.h" #include "lldb/API/SBThread.h" +namespace lldb_private { + + class StackFrameImpl + { + public: + StackFrameImpl (const lldb::StackFrameSP &frame_sp) : + m_frame_wp (frame_sp), + m_thread_wp (), + m_stack_id () + { + if (frame_sp) + { + m_thread_wp = frame_sp->GetThread().shared_from_this(); + m_stack_id = frame_sp->GetStackID(); + } + } + + ~StackFrameImpl() + { + } + + lldb::StackFrameSP + GetFrameSP () + { + lldb::StackFrameSP frame_sp; + // We have a weak pointer to our thread, which might + // be NULL'ed out if the thread went away, so first + // make sure our thread is still alive. + lldb::ThreadSP thread_sp (m_thread_wp.lock()); + if (thread_sp) + { + // Our thread is still here, check if our frame + // is still alive as well. + frame_sp = m_frame_wp.lock(); + if (frame_sp) + { + // Our frame is still alive, make sure that our thread + // still has this exact frame... + lldb::StackFrameSP tmp_frame_sp (thread_sp->GetStackFrameAtIndex (frame_sp->GetFrameIndex())); + if (tmp_frame_sp.get() == frame_sp.get()) + return frame_sp; + } + // The original stack frame might have gone away, + // we need to check for the stac + frame_sp = thread_sp->GetFrameWithStackID (m_stack_id); + m_frame_wp = frame_sp; + } + return frame_sp; + } + + void + SetFrameSP (const lldb::StackFrameSP &frame_sp) + { + if (frame_sp) + { + m_frame_wp = frame_sp; + m_thread_wp = frame_sp->GetThread().shared_from_this(); + m_stack_id = frame_sp->GetStackID(); + } + else + { + m_frame_wp.reset(); + m_thread_wp.reset(); + m_stack_id.Clear(); + } + } + + protected: + lldb::StackFrameWP m_frame_wp; + lldb::ThreadWP m_thread_wp; + StackID m_stack_id; + }; +} // namespace lldb_private + using namespace lldb; using namespace lldb_private; + SBFrame::SBFrame () : m_opaque_sp () { } SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) : - m_opaque_sp (lldb_object_sp) + m_opaque_sp (new StackFrameImpl (lldb_object_sp)) { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); @@ -59,7 +135,7 @@ SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) : SBStream sstr; GetDescription (sstr); log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s", - lldb_object_sp.get(), m_opaque_sp.get(), sstr.GetData()); + lldb_object_sp.get(), lldb_object_sp.get(), sstr.GetData()); } } @@ -81,27 +157,45 @@ SBFrame::~SBFrame() { } +StackFrameSP +SBFrame::GetFrameSP() const +{ + StackFrameImplSP impl_sp (m_opaque_sp); + StackFrameSP frame_sp; + if (impl_sp) + frame_sp = impl_sp->GetFrameSP(); + return frame_sp; +} void -SBFrame::SetFrame (const StackFrameSP &lldb_object_sp) +SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp) { - void *old_ptr = m_opaque_sp.get(); - m_opaque_sp = lldb_object_sp; - LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - if (log) + if (lldb_object_sp) { - log->Printf ("SBFrame(%p)::SetFrame(sp=%p) := SBFrame(%p)", - old_ptr, lldb_object_sp.get(), m_opaque_sp.get()); + if (m_opaque_sp) + { + StackFrameImplSP impl_sp (m_opaque_sp); + if (impl_sp) + impl_sp->SetFrameSP (lldb_object_sp); + } + else + { + m_opaque_sp = StackFrameImplSP (new StackFrameImpl(lldb_object_sp)); + } + } + else + { + m_opaque_sp.reset(); } - } - bool SBFrame::IsValid() const { - return (m_opaque_sp.get() != NULL); + StackFrameImplSP impl_sp (m_opaque_sp); + if (impl_sp) + return (impl_sp->GetFrameSP().get() != NULL); + return false; } SBSymbolContext @@ -109,16 +203,17 @@ SBFrame::GetSymbolContext (uint32_t resolve_scope) const { SBSymbolContext sb_sym_ctx; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_sym_ctx.SetSymbolContext(&m_opaque_sp->GetSymbolContext (resolve_scope)); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_sym_ctx.SetSymbolContext(&frame_sp->GetSymbolContext (resolve_scope)); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)", - m_opaque_sp.get(), resolve_scope, sb_sym_ctx.get()); + frame_sp.get(), resolve_scope, sb_sym_ctx.get()); return sb_sym_ctx; } @@ -127,16 +222,17 @@ SBModule SBFrame::GetModule () const { SBModule sb_module; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - *sb_module = m_opaque_sp->GetSymbolContext (eSymbolContextModule).module_sp; + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + *sb_module = frame_sp->GetSymbolContext (eSymbolContextModule).module_sp; } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)", - m_opaque_sp.get(), sb_module.get()); + frame_sp.get(), sb_module.get()); return sb_module; } @@ -145,15 +241,16 @@ SBCompileUnit SBFrame::GetCompileUnit () const { SBCompileUnit sb_comp_unit; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_comp_unit.reset (m_opaque_sp->GetSymbolContext (eSymbolContextCompUnit).comp_unit); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_comp_unit.reset (frame_sp->GetSymbolContext (eSymbolContextCompUnit).comp_unit); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetModule () => SBCompileUnit(%p)", - m_opaque_sp.get(), sb_comp_unit.get()); + frame_sp.get(), sb_comp_unit.get()); return sb_comp_unit; } @@ -162,15 +259,16 @@ SBFunction SBFrame::GetFunction () const { SBFunction sb_function; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_function.reset(m_opaque_sp->GetSymbolContext (eSymbolContextFunction).function); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_function.reset(frame_sp->GetSymbolContext (eSymbolContextFunction).function); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)", - m_opaque_sp.get(), sb_function.get()); + frame_sp.get(), sb_function.get()); return sb_function; } @@ -179,15 +277,16 @@ SBSymbol SBFrame::GetSymbol () const { SBSymbol sb_symbol; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_symbol.reset(m_opaque_sp->GetSymbolContext (eSymbolContextSymbol).symbol); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_symbol.reset(frame_sp->GetSymbolContext (eSymbolContextSymbol).symbol); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)", - m_opaque_sp.get(), sb_symbol.get()); + frame_sp.get(), sb_symbol.get()); return sb_symbol; } @@ -195,15 +294,16 @@ SBBlock SBFrame::GetBlock () const { SBBlock sb_block; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_block.reset (m_opaque_sp->GetSymbolContext (eSymbolContextBlock).block); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_block.reset (frame_sp->GetSymbolContext (eSymbolContextBlock).block); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)", - m_opaque_sp.get(), sb_block.get()); + frame_sp.get(), sb_block.get()); return sb_block; } @@ -211,15 +311,16 @@ SBBlock SBFrame::GetFrameBlock () const { SBBlock sb_block; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_block.reset(m_opaque_sp->GetFrameBlock ()); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_block.reset(frame_sp->GetFrameBlock ()); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)", - m_opaque_sp.get(), sb_block.get()); + frame_sp.get(), sb_block.get()); return sb_block; } @@ -227,27 +328,33 @@ SBLineEntry SBFrame::GetLineEntry () const { SBLineEntry sb_line_entry; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_line_entry.SetLineEntry (m_opaque_sp->GetSymbolContext (eSymbolContextLineEntry).line_entry); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_line_entry.SetLineEntry (frame_sp->GetSymbolContext (eSymbolContextLineEntry).line_entry); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)", - m_opaque_sp.get(), sb_line_entry.get()); + frame_sp.get(), sb_line_entry.get()); return sb_line_entry; } uint32_t SBFrame::GetFrameID () const { - uint32_t frame_idx = m_opaque_sp ? m_opaque_sp->GetFrameIndex () : UINT32_MAX; + uint32_t frame_idx = UINT32_MAX; + + + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) + frame_idx = frame_sp->GetFrameIndex (); LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetFrameID () => %u", - m_opaque_sp.get(), frame_idx); + frame_sp.get(), frame_idx); return frame_idx; } @@ -255,15 +362,16 @@ addr_t SBFrame::GetPC () const { addr_t addr = LLDB_INVALID_ADDRESS; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - addr = m_opaque_sp->GetFrameCodeAddress().GetOpcodeLoadAddress (&m_opaque_sp->GetThread().GetProcess().GetTarget()); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + addr = frame_sp->GetFrameCodeAddress().GetOpcodeLoadAddress (&frame_sp->GetThread().GetProcess().GetTarget()); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", m_opaque_sp.get(), addr); + log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", frame_sp.get(), addr); return addr; } @@ -272,16 +380,17 @@ bool SBFrame::SetPC (addr_t new_pc) { bool ret_val = false; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - ret_val = m_opaque_sp->GetRegisterContext()->SetPC (new_pc); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + ret_val = frame_sp->GetRegisterContext()->SetPC (new_pc); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%llx) => %i", - m_opaque_sp.get(), new_pc, ret_val); + frame_sp.get(), new_pc, ret_val); return ret_val; } @@ -290,14 +399,15 @@ addr_t SBFrame::GetSP () const { addr_t addr = LLDB_INVALID_ADDRESS; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - addr = m_opaque_sp->GetRegisterContext()->GetSP(); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + addr = frame_sp->GetRegisterContext()->GetSP(); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", m_opaque_sp.get(), addr); + log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", frame_sp.get(), addr); return addr; } @@ -307,15 +417,16 @@ addr_t SBFrame::GetFP () const { addr_t addr = LLDB_INVALID_ADDRESS; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - addr = m_opaque_sp->GetRegisterContext()->GetFP(); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + addr = frame_sp->GetRegisterContext()->GetFP(); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", m_opaque_sp.get(), addr); + log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", frame_sp.get(), addr); return addr; } @@ -324,14 +435,15 @@ SBAddress SBFrame::GetPCAddress () const { SBAddress sb_addr; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_addr.SetAddress (&m_opaque_sp->GetFrameCodeAddress()); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_addr.SetAddress (&frame_sp->GetFrameCodeAddress()); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", m_opaque_sp.get(), sb_addr.get()); + log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame_sp.get(), sb_addr.get()); return sb_addr; } @@ -345,9 +457,10 @@ SBValue SBFrame::FindVariable (const char *name) { SBValue value; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - lldb::DynamicValueType use_dynamic = m_opaque_sp->CalculateTarget()->GetPreferDynamicValue(); + lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue(); value = FindVariable (name, use_dynamic); } return value; @@ -358,12 +471,12 @@ SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic) { VariableSP var_sp; SBValue sb_value; - - if (m_opaque_sp && name && name[0]) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp && name && name[0]) { VariableList variable_list; - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - SymbolContext sc (m_opaque_sp->GetSymbolContext (eSymbolContextBlock)); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock)); if (sc.block) { @@ -381,14 +494,14 @@ SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic) } if (var_sp) - *sb_value = ValueObjectSP (m_opaque_sp->GetValueObjectForFrameVariable(var_sp, use_dynamic)); + *sb_value = ValueObjectSP (frame_sp->GetValueObjectForFrameVariable(var_sp, use_dynamic)); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)", - m_opaque_sp.get(), name, sb_value.get()); + frame_sp.get(), name, sb_value.get()); return sb_value; } @@ -397,9 +510,10 @@ SBValue SBFrame::FindValue (const char *name, ValueType value_type) { SBValue value; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - lldb::DynamicValueType use_dynamic = m_opaque_sp->CalculateTarget()->GetPreferDynamicValue(); + lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue(); value = FindValue (name, value_type, use_dynamic); } return value; @@ -409,9 +523,10 @@ SBValue SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic) { SBValue sb_value; - if (m_opaque_sp && name && name[0]) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp && name && name[0]) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); switch (value_type) { @@ -420,9 +535,9 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy case eValueTypeVariableArgument: // function argument variables case eValueTypeVariableLocal: // function local variables { - VariableList *variable_list = m_opaque_sp->GetVariableList(true); + VariableList *variable_list = frame_sp->GetVariableList(true); - SymbolContext sc (m_opaque_sp->GetSymbolContext (eSymbolContextBlock)); + SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock)); const bool can_create = true; const bool get_parent_variables = true; @@ -442,7 +557,7 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy variable_sp->GetScope() == value_type && variable_sp->GetName() == const_name) { - *sb_value = ValueObjectSP (m_opaque_sp->GetValueObjectForFrameVariable(variable_sp, + *sb_value = ValueObjectSP (frame_sp->GetValueObjectForFrameVariable(variable_sp, use_dynamic)); break; } @@ -453,7 +568,7 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy case eValueTypeRegister: // stack frame register value { - RegisterContextSP reg_ctx (m_opaque_sp->GetRegisterContext()); + RegisterContextSP reg_ctx (frame_sp->GetRegisterContext()); if (reg_ctx) { const uint32_t num_regs = reg_ctx->GetRegisterCount(); @@ -464,7 +579,7 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy ((reg_info->name && strcasecmp (reg_info->name, name) == 0) || (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0))) { - *sb_value = ValueObjectRegister::Create (m_opaque_sp.get(), reg_ctx, reg_idx); + *sb_value = ValueObjectRegister::Create (frame_sp.get(), reg_ctx, reg_idx); } } } @@ -473,7 +588,7 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy case eValueTypeRegisterSet: // A collection of stack frame register values { - RegisterContextSP reg_ctx (m_opaque_sp->GetRegisterContext()); + RegisterContextSP reg_ctx (frame_sp->GetRegisterContext()); if (reg_ctx) { const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); @@ -484,7 +599,7 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy ((reg_set->name && strcasecmp (reg_set->name, name) == 0) || (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0))) { - *sb_value = ValueObjectRegisterSet::Create (m_opaque_sp.get(), reg_ctx, set_idx); + *sb_value = ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx); } } } @@ -494,7 +609,7 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy case eValueTypeConstResult: // constant result variables { ConstString const_name(name); - ClangExpressionVariableSP expr_var_sp (m_opaque_sp->GetThread().GetProcess().GetTarget().GetPersistentVariables().GetVariable (const_name)); + ClangExpressionVariableSP expr_var_sp (frame_sp->GetThread().GetProcess().GetTarget().GetPersistentVariables().GetVariable (const_name)); if (expr_var_sp) *sb_value = expr_var_sp->GetValueObject(); } @@ -508,7 +623,7 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)", - m_opaque_sp.get(), name, value_type, sb_value.get()); + frame_sp.get(), name, value_type, sb_value.get()); return sb_value; @@ -517,31 +632,13 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueTy bool SBFrame::operator == (const SBFrame &rhs) const { - return m_opaque_sp.get() == rhs.m_opaque_sp.get(); + return GetFrameSP().get() == rhs.GetFrameSP().get(); } bool SBFrame::operator != (const SBFrame &rhs) const { - return m_opaque_sp.get() != rhs.m_opaque_sp.get(); -} - -lldb_private::StackFrame * -SBFrame::operator->() const -{ - return m_opaque_sp.get(); -} - -lldb_private::StackFrame * -SBFrame::get() const -{ - return m_opaque_sp.get(); -} - -lldb::StackFrameSP & -SBFrame::get_sp() -{ - return m_opaque_sp; + return GetFrameSP().get() != rhs.GetFrameSP().get(); } SBThread @@ -551,10 +648,11 @@ SBFrame::GetThread () const SBThread sb_thread; ThreadSP thread_sp; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - thread_sp = m_opaque_sp->GetThread().shared_from_this(); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + thread_sp = frame_sp->GetThread().shared_from_this(); sb_thread.SetThread (thread_sp); } @@ -562,7 +660,7 @@ SBFrame::GetThread () const { SBStream sstr; sb_thread.GetDescription (sstr); - log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", m_opaque_sp.get(), + log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", frame_sp.get(), thread_sp.get(), sstr.GetData()); } @@ -573,15 +671,16 @@ const char * SBFrame::Disassemble () const { const char *disassembly = NULL; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - disassembly = m_opaque_sp->Disassemble(); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + disassembly = frame_sp->Disassemble(); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBFrame(%p)::Disassemble () => %s", m_opaque_sp.get(), disassembly); + log->Printf ("SBFrame(%p)::Disassemble () => %s", frame_sp.get(), disassembly); return disassembly; } @@ -594,9 +693,10 @@ SBFrame::GetVariables (bool arguments, bool in_scope_only) { SBValueList value_list; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - lldb::DynamicValueType use_dynamic = m_opaque_sp->CalculateTarget()->GetPreferDynamicValue(); + lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue(); value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic); } return value_list; @@ -611,24 +711,26 @@ SBFrame::GetVariables (bool arguments, { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + SBValueList value_list; + StackFrameSP frame_sp(GetFrameSP()); + if (log) log->Printf ("SBFrame(%p)::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)", - m_opaque_sp.get(), + frame_sp.get(), arguments, locals, statics, in_scope_only); - - SBValueList value_list; - if (m_opaque_sp) + + if (frame_sp) { size_t i; VariableList *variable_list = NULL; // Scope for locker { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - variable_list = m_opaque_sp->GetVariableList(true); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + variable_list = frame_sp->GetVariableList(true); } if (variable_list) { @@ -661,10 +763,10 @@ SBFrame::GetVariables (bool arguments, } if (add_variable) { - if (in_scope_only && !variable_sp->IsInScope(m_opaque_sp.get())) + if (in_scope_only && !variable_sp->IsInScope(frame_sp.get())) continue; - value_list.Append(m_opaque_sp->GetValueObjectForFrameVariable (variable_sp, use_dynamic)); + value_list.Append(frame_sp->GetValueObjectForFrameVariable (variable_sp, use_dynamic)); } } } @@ -674,7 +776,7 @@ SBFrame::GetVariables (bool arguments, if (log) { - log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", m_opaque_sp.get(), + log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame_sp.get(), value_list.get()); } @@ -687,22 +789,23 @@ SBFrame::GetRegisters () LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBValueList value_list; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - RegisterContextSP reg_ctx (m_opaque_sp->GetRegisterContext()); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + RegisterContextSP reg_ctx (frame_sp->GetRegisterContext()); if (reg_ctx) { const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) { - value_list.Append(ValueObjectRegisterSet::Create (m_opaque_sp.get(), reg_ctx, set_idx)); + value_list.Append(ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx)); } } } if (log) - log->Printf ("SBFrame(%p)::Registers () => SBValueList(%p)", m_opaque_sp.get(), value_list.get()); + log->Printf ("SBFrame(%p)::Registers () => SBValueList(%p)", frame_sp.get(), value_list.get()); return value_list; } @@ -712,10 +815,11 @@ SBFrame::GetDescription (SBStream &description) { Stream &strm = description.ref(); - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - m_opaque_sp->DumpUsingSettingsFormat (&strm); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + frame_sp->DumpUsingSettingsFormat (&strm); } else strm.PutCString ("No value"); @@ -727,9 +831,10 @@ SBValue SBFrame::EvaluateExpression (const char *expr) { SBValue result; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - lldb::DynamicValueType use_dynamic = m_opaque_sp->CalculateTarget()->GetPreferDynamicValue(); + lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue(); result = EvaluateExpression (expr, use_dynamic); } return result; @@ -744,16 +849,18 @@ SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dyna ExecutionResults exe_results; SBValue expr_result; + + StackFrameSP frame_sp(GetFrameSP()); if (log) - log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", m_opaque_sp.get(), expr); + log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", frame_sp.get(), expr); - if (m_opaque_sp) + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); StreamString frame_description; - m_opaque_sp->DumpUsingSettingsFormat (&frame_description); + frame_sp->DumpUsingSettingsFormat (&frame_description); Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s", expr, fetch_dynamic_value, frame_description.GetString().c_str()); @@ -762,14 +869,14 @@ SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dyna const bool unwind_on_error = true; const bool keep_in_memory = false; - exe_results = m_opaque_sp->GetThread().GetProcess().GetTarget().EvaluateExpression(expr, - m_opaque_sp.get(), - eExecutionPolicyOnlyWhenNeeded, - coerce_to_id, - unwind_on_error, - keep_in_memory, - fetch_dynamic_value, - *expr_result); + exe_results = frame_sp->GetThread().GetProcess().GetTarget().EvaluateExpression(expr, + frame_sp.get(), + eExecutionPolicyOnlyWhenNeeded, + coerce_to_id, + unwind_on_error, + keep_in_memory, + fetch_dynamic_value, + *expr_result); Host::SetCrashDescription (NULL); } @@ -780,7 +887,7 @@ SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dyna expr_result.GetSummary()); if (log) - log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", m_opaque_sp.get(), + log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", frame_sp.get(), expr, expr_result.get(), exe_results); @@ -791,9 +898,10 @@ SBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dyna bool SBFrame::IsInlined() { - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Block *block = m_opaque_sp->GetSymbolContext(eSymbolContextBlock).block; + Block *block = frame_sp->GetSymbolContext(eSymbolContextBlock).block; if (block) return block->GetContainingInlinedBlock () != NULL; } @@ -804,9 +912,10 @@ const char * SBFrame::GetFunctionName() { const char *name = NULL; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - SymbolContext sc (m_opaque_sp->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol)); + SymbolContext sc (frame_sp->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol)); if (sc.block) { Block *inlined_block = sc.block->GetContainingInlinedBlock (); diff --git a/lldb/source/API/SBFunction.cpp b/lldb/source/API/SBFunction.cpp index f55b2147741..e3e56a53011 100644 --- a/lldb/source/API/SBFunction.cpp +++ b/lldb/source/API/SBFunction.cpp @@ -127,11 +127,12 @@ SBFunction::GetInstructions (SBTarget target) { Mutex::Locker api_locker; ExecutionContext exe_ctx; - if (target.IsValid()) + TargetSP target_sp (target.GetSP()); + if (target_sp) { - api_locker.Reset (target->GetAPIMutex().GetMutex()); - target->CalculateExecutionContext (exe_ctx); - exe_ctx.SetProcessSP(target->GetProcessSP()); + api_locker.Reset (target_sp->GetAPIMutex().GetMutex()); + target_sp->CalculateExecutionContext (exe_ctx); + exe_ctx.SetProcessSP(target_sp->GetProcessSP()); } ModuleSP module_sp = m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModuleSP(); if (module_sp) diff --git a/lldb/source/API/SBInstruction.cpp b/lldb/source/API/SBInstruction.cpp index 26f8d1aa005..f384b5b97b4 100644 --- a/lldb/source/API/SBInstruction.cpp +++ b/lldb/source/API/SBInstruction.cpp @@ -75,11 +75,12 @@ SBInstruction::GetMnemonic(SBTarget target) { Mutex::Locker api_locker; ExecutionContext exe_ctx; - if (target.IsValid()) + TargetSP target_sp (target.GetSP()); + if (target_sp) { - api_locker.Reset (target->GetAPIMutex().GetMutex()); - target->CalculateExecutionContext (exe_ctx); - exe_ctx.SetProcessSP(target->GetProcessSP()); + api_locker.Reset (target_sp->GetAPIMutex().GetMutex()); + target_sp->CalculateExecutionContext (exe_ctx); + exe_ctx.SetProcessSP(target_sp->GetProcessSP()); } return m_opaque_sp->GetMnemonic(exe_ctx.GetBestExecutionContextScope()); } @@ -93,11 +94,12 @@ SBInstruction::GetOperands(SBTarget target) { Mutex::Locker api_locker; ExecutionContext exe_ctx; - if (target.IsValid()) + TargetSP target_sp (target.GetSP()); + if (target_sp) { - api_locker.Reset (target->GetAPIMutex().GetMutex()); - target->CalculateExecutionContext (exe_ctx); - exe_ctx.SetProcessSP(target->GetProcessSP()); + api_locker.Reset (target_sp->GetAPIMutex().GetMutex()); + target_sp->CalculateExecutionContext (exe_ctx); + exe_ctx.SetProcessSP(target_sp->GetProcessSP()); } return m_opaque_sp->GetOperands(exe_ctx.GetBestExecutionContextScope()); } @@ -111,11 +113,12 @@ SBInstruction::GetComment(SBTarget target) { Mutex::Locker api_locker; ExecutionContext exe_ctx; - if (target.IsValid()) + TargetSP target_sp (target.GetSP()); + if (target_sp) { - api_locker.Reset (target->GetAPIMutex().GetMutex()); - target->CalculateExecutionContext (exe_ctx); - exe_ctx.SetProcessSP(target->GetProcessSP()); + api_locker.Reset (target_sp->GetAPIMutex().GetMutex()); + target_sp->CalculateExecutionContext (exe_ctx); + exe_ctx.SetProcessSP(target_sp->GetProcessSP()); } return m_opaque_sp->GetComment(exe_ctx.GetBestExecutionContextScope()); } @@ -142,12 +145,13 @@ SBInstruction::GetData (SBTarget target) if (opcode_data && opcode_data_size > 0) { ByteOrder data_byte_order = opcode.GetDataByteOrder(); - if (data_byte_order == eByteOrderInvalid) - data_byte_order = target->GetArchitecture().GetByteOrder(); + TargetSP target_sp (target.GetSP()); + if (data_byte_order == eByteOrderInvalid && target_sp) + data_byte_order = target_sp->GetArchitecture().GetByteOrder(); DataBufferSP data_buffer_sp (new DataBufferHeap (opcode_data, opcode_data_size)); DataExtractorSP data_extractor_sp (new DataExtractor (data_buffer_sp, data_byte_order, - target.IsValid() ? target->GetArchitecture().GetAddressByteSize() : sizeof(void*))); + target_sp ? target_sp->GetArchitecture().GetAddressByteSize() : sizeof(void*))); sb_data.SetOpaque (data_extractor_sp); } } @@ -199,20 +203,25 @@ SBInstruction::Print (FILE *out) bool SBInstruction::EmulateWithFrame (lldb::SBFrame &frame, uint32_t evaluate_options) { - if (m_opaque_sp && frame.get()) + if (m_opaque_sp) { - lldb_private::ExecutionContext exe_ctx; - frame->CalculateExecutionContext (exe_ctx); - lldb_private::Target *target = exe_ctx.GetTargetPtr(); - lldb_private::ArchSpec arch = target->GetArchitecture(); - - return m_opaque_sp->Emulate (arch, - evaluate_options, - (void *) frame.get(), - &lldb_private::EmulateInstruction::ReadMemoryFrame, - &lldb_private::EmulateInstruction::WriteMemoryFrame, - &lldb_private::EmulateInstruction::ReadRegisterFrame, - &lldb_private::EmulateInstruction::WriteRegisterFrame); + lldb::StackFrameSP frame_sp (frame.GetFrameSP()); + + if (frame_sp) + { + lldb_private::ExecutionContext exe_ctx; + frame_sp->CalculateExecutionContext (exe_ctx); + lldb_private::Target *target = exe_ctx.GetTargetPtr(); + lldb_private::ArchSpec arch = target->GetArchitecture(); + + return m_opaque_sp->Emulate (arch, + evaluate_options, + (void *) frame_sp.get(), + &lldb_private::EmulateInstruction::ReadMemoryFrame, + &lldb_private::EmulateInstruction::WriteMemoryFrame, + &lldb_private::EmulateInstruction::ReadRegisterFrame, + &lldb_private::EmulateInstruction::WriteRegisterFrame); + } } return false; } diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp index 0c1307ccc76..28180fce63a 100644 --- a/lldb/source/API/SBModule.cpp +++ b/lldb/source/API/SBModule.cpp @@ -381,10 +381,8 @@ SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_ for (uint32_t i=0; i<match_count; ++i) { lldb::ValueObjectSP valobj_sp; - if (target.IsValid()) - valobj_sp = ValueObjectVariable::Create (target.get(), variable_list.GetVariableAtIndex(i)); - else - valobj_sp = ValueObjectVariable::Create (NULL, variable_list.GetVariableAtIndex(i)); + TargetSP target_sp (target.GetSP()); + valobj_sp = ValueObjectVariable::Create (target_sp.get(), variable_list.GetVariableAtIndex(i)); if (valobj_sp) value_object_list.Append(valobj_sp); } diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp index 91731bcd3b7..3422efbdb94 100644 --- a/lldb/source/API/SBProcess.cpp +++ b/lldb/source/API/SBProcess.cpp @@ -74,8 +74,14 @@ SBProcess::~SBProcess() { } +lldb::ProcessSP +SBProcess::GetSP() const +{ + return m_opaque_sp; +} + void -SBProcess::SetProcess (const ProcessSP &process_sp) +SBProcess::SetSP (const ProcessSP &process_sp) { m_opaque_sp = process_sp; } @@ -239,11 +245,15 @@ SBProcess::GetTarget() const LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBTarget sb_target; + TargetSP target_sp; if (m_opaque_sp) - sb_target = m_opaque_sp->GetTarget().shared_from_this(); + { + target_sp = m_opaque_sp->GetTarget().shared_from_this(); + sb_target.SetSP (target_sp); + } if (log) - log->Printf ("SBProcess(%p)::GetTarget () => SBTarget(%p)", m_opaque_sp.get(), sb_target.get()); + log->Printf ("SBProcess(%p)::GetTarget () => SBTarget(%p)", m_opaque_sp.get(), target_sp.get()); return sb_target; } @@ -717,12 +727,6 @@ SBProcess::GetBroadcaster () const return broadcaster; } -lldb_private::Process * -SBProcess::operator->() const -{ - return m_opaque_sp.get(); -} - size_t SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error) { @@ -864,13 +868,6 @@ SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &s return bytes_written; } -// Mimic shared pointer... -lldb_private::Process * -SBProcess::get() const -{ - return m_opaque_sp.get(); -} - bool SBProcess::GetDescription (SBStream &description) { diff --git a/lldb/source/API/SBSourceManager.cpp b/lldb/source/API/SBSourceManager.cpp index f9926dc825b..743d5651bbb 100644 --- a/lldb/source/API/SBSourceManager.cpp +++ b/lldb/source/API/SBSourceManager.cpp @@ -89,7 +89,7 @@ SBSourceManager::SBSourceManager (const SBDebugger &debugger) SBSourceManager::SBSourceManager (const SBTarget &target) { - m_opaque_ap.reset(new SourceManagerImpl (target.get_sp())); + m_opaque_ap.reset(new SourceManagerImpl (target.GetSP())); } SBSourceManager::SBSourceManager (const SBSourceManager &rhs) diff --git a/lldb/source/API/SBSymbol.cpp b/lldb/source/API/SBSymbol.cpp index 51bb98c194a..697fff8e101 100644 --- a/lldb/source/API/SBSymbol.cpp +++ b/lldb/source/API/SBSymbol.cpp @@ -123,10 +123,11 @@ SBSymbol::GetInstructions (SBTarget target) { Mutex::Locker api_locker; ExecutionContext exe_ctx; - if (target.IsValid()) + TargetSP target_sp (target.GetSP()); + if (target_sp) { - api_locker.Reset (target->GetAPIMutex().GetMutex()); - target->CalculateExecutionContext (exe_ctx); + api_locker.Reset (target_sp->GetAPIMutex().GetMutex()); + target_sp->CalculateExecutionContext (exe_ctx); } const AddressRange *symbol_range = m_opaque_ptr->GetAddressRangePtr(); if (symbol_range) diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index f594827a1e2..dc06e7c9e5e 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -96,19 +96,19 @@ SBTarget::IsValid () const SBProcess SBTarget::GetProcess () { - SBProcess sb_process; + ProcessSP process_sp; if (m_opaque_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - sb_process.SetProcess (m_opaque_sp->GetProcessSP()); + process_sp = m_opaque_sp->GetProcessSP(); + sb_process.SetSP (process_sp); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)", - m_opaque_sp.get(), sb_process.get()); + m_opaque_sp.get(), process_sp.get()); } return sb_process; @@ -182,6 +182,7 @@ SBTarget::Launch error.get()); } SBProcess sb_process; + ProcessSP process_sp; if (m_opaque_sp) { Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); @@ -190,18 +191,17 @@ SBTarget::Launch launch_flags |= eLaunchFlagDisableASLR; StateType state = eStateInvalid; - sb_process.SetProcess (m_opaque_sp->GetProcessSP()); - if (sb_process.IsValid()) + process_sp = m_opaque_sp->GetProcessSP(); + if (process_sp) { - state = sb_process->GetState(); + state = process_sp->GetState(); - if (sb_process->IsAlive() && state != eStateConnected) + if (process_sp->IsAlive() && state != eStateConnected) { if (state == eStateAttaching) error.SetErrorString ("process attach is in progress"); else error.SetErrorString ("a process is already being debugged"); - sb_process.Clear(); return sb_process; } } @@ -214,20 +214,20 @@ SBTarget::Launch if (listener.IsValid()) { error.SetErrorString ("process is connected and already has a listener, pass empty listener"); - sb_process.Clear(); return sb_process; } } else { if (listener.IsValid()) - sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref())); + process_sp = m_opaque_sp->CreateProcess (listener.ref()); else - sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); + process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()); } - if (sb_process.IsValid()) + if (process_sp) { + sb_process.SetSP (process_sp); if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO")) launch_flags |= eLaunchFlagDisableSTDIO; @@ -241,7 +241,7 @@ SBTarget::Launch if (envp) launch_info.GetEnvironmentEntries ().SetArguments (envp); - error.SetError (sb_process->Launch (launch_info)); + error.SetError (process_sp->Launch (launch_info)); if (error.Success()) { // We we are stopping at the entry point, we can return now! @@ -249,17 +249,17 @@ SBTarget::Launch return sb_process; // Make sure we are stopped at the entry - StateType state = sb_process->WaitForProcessToStop (NULL); + StateType state = process_sp->WaitForProcessToStop (NULL); if (state == eStateStopped) { // resume the process to skip the entry point - error.SetError (sb_process->Resume()); + error.SetError (process_sp->Resume()); if (error.Success()) { // If we are doing synchronous mode, then wait for the // process to stop yet again! if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false) - sb_process->WaitForProcessToStop (NULL); + process_sp->WaitForProcessToStop (NULL); } } } @@ -278,7 +278,7 @@ SBTarget::Launch if (log) { log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)", - m_opaque_sp.get(), sb_process.get()); + m_opaque_sp.get(), process_sp.get()); } return sb_process; @@ -305,23 +305,23 @@ SBTarget::AttachToProcessWithID ) { SBProcess sb_process; + ProcessSP process_sp; if (m_opaque_sp) { Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); StateType state = eStateInvalid; - sb_process.SetProcess (m_opaque_sp->GetProcessSP()); - if (sb_process.IsValid()) + process_sp = m_opaque_sp->GetProcessSP(); + if (process_sp) { - state = sb_process->GetState(); + state = process_sp->GetState(); - if (sb_process->IsAlive() && state != eStateConnected) + if (process_sp->IsAlive() && state != eStateConnected) { if (state == eStateAttaching) error.SetErrorString ("process attach is in progress"); else error.SetErrorString ("a process is already being debugged"); - sb_process.Clear(); return sb_process; } } @@ -334,27 +334,27 @@ SBTarget::AttachToProcessWithID if (listener.IsValid()) { error.SetErrorString ("process is connected and already has a listener, pass empty listener"); - sb_process.Clear(); return sb_process; } } else { if (listener.IsValid()) - sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref())); + process_sp = m_opaque_sp->CreateProcess (listener.ref()); else - sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); + process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()); } - - if (sb_process.IsValid()) + if (process_sp) { + sb_process.SetSP (process_sp); + ProcessAttachInfo attach_info; attach_info.SetProcessID (pid); - error.SetError (sb_process->Attach (attach_info)); + error.SetError (process_sp->Attach (attach_info)); // If we are doing synchronous mode, then wait for the // process to stop! if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false) - sb_process->WaitForProcessToStop (NULL); + process_sp->WaitForProcessToStop (NULL); } else { @@ -379,23 +379,23 @@ SBTarget::AttachToProcessWithName ) { SBProcess sb_process; + ProcessSP process_sp; if (name && m_opaque_sp) { Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); StateType state = eStateInvalid; - sb_process.SetProcess (m_opaque_sp->GetProcessSP()); - if (sb_process.IsValid()) + process_sp = m_opaque_sp->GetProcessSP(); + if (process_sp) { - state = sb_process->GetState(); + state = process_sp->GetState(); - if (sb_process->IsAlive() && state != eStateConnected) + if (process_sp->IsAlive() && state != eStateConnected) { if (state == eStateAttaching) error.SetErrorString ("process attach is in progress"); else error.SetErrorString ("a process is already being debugged"); - sb_process.Clear(); return sb_process; } } @@ -408,28 +408,28 @@ SBTarget::AttachToProcessWithName if (listener.IsValid()) { error.SetErrorString ("process is connected and already has a listener, pass empty listener"); - sb_process.Clear(); return sb_process; } } else { if (listener.IsValid()) - sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref())); + process_sp = m_opaque_sp->CreateProcess (listener.ref()); else - sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); + process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()); } - if (sb_process.IsValid()) + if (process_sp) { + sb_process.SetSP (process_sp); ProcessAttachInfo attach_info; attach_info.GetExecutableFile().SetFile(name, false); attach_info.SetWaitForLaunch(wait_for); - error.SetError (sb_process->Attach (attach_info)); + error.SetError (process_sp->Attach (attach_info)); // If we are doing synchronous mode, then wait for the // process to stop! if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false) - sb_process->WaitForProcessToStop (NULL); + process_sp->WaitForProcessToStop (NULL); } else { @@ -454,18 +454,20 @@ SBTarget::ConnectRemote ) { SBProcess sb_process; + ProcessSP process_sp; if (m_opaque_sp) { Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); if (listener.IsValid()) - sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref(), plugin_name)); + process_sp = m_opaque_sp->CreateProcess (listener.ref(), plugin_name); else - sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name)); + process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name); - if (sb_process.IsValid()) + if (process_sp) { - error.SetError (sb_process->ConnectRemote (url)); + sb_process.SetSP (process_sp); + error.SetError (process_sp->ConnectRemote (url)); } else { @@ -513,26 +515,14 @@ SBTarget::operator != (const SBTarget &rhs) const return m_opaque_sp.get() != rhs.m_opaque_sp.get(); } -lldb_private::Target * -SBTarget::operator ->() const -{ - return m_opaque_sp.get(); -} - -lldb_private::Target * -SBTarget::get() const -{ - return m_opaque_sp.get(); -} - -const lldb::TargetSP & -SBTarget::get_sp () const +lldb::TargetSP +SBTarget::GetSP () const { return m_opaque_sp; } void -SBTarget::reset (const lldb::TargetSP& target_sp) +SBTarget::SetSP (const lldb::TargetSP& target_sp) { m_opaque_sp = target_sp; } diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp index 73f1d19b6b3..023e81fbcd8 100644 --- a/lldb/source/API/SBThread.cpp +++ b/lldb/source/API/SBThread.cpp @@ -557,11 +557,12 @@ SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame) ThreadSP thread_sp(m_opaque_wp.lock()); + StackFrameSP frame_sp (sb_frame.GetFrameSP()); if (log) { SBStream frame_desc_strm; sb_frame.GetDescription (frame_desc_strm); - log->Printf ("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)", thread_sp.get(), sb_frame.get(), frame_desc_strm.GetData()); + log->Printf ("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)", thread_sp.get(), frame_sp.get(), frame_desc_strm.GetData()); } if (thread_sp) @@ -576,7 +577,7 @@ SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame) stop_other_threads, eVoteYes, eVoteNoOpinion, - sb_frame->GetFrameIndex()); + frame_sp->GetFrameIndex()); Process &process = thread_sp->GetProcess(); process.GetThreadList().SetSelectedThreadByID (thread_sp->GetID()); @@ -658,8 +659,9 @@ SBThread::StepOverUntil (lldb::SBFrame &sb_frame, LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); char path[PATH_MAX]; - ThreadSP thread_sp(m_opaque_wp.lock()); - + ThreadSP thread_sp(m_opaque_wp.lock()); + StackFrameSP frame_sp (sb_frame.GetFrameSP()); + if (log) { SBStream frame_desc_strm; @@ -667,7 +669,7 @@ SBThread::StepOverUntil (lldb::SBFrame &sb_frame, sb_file_spec->GetPath (path, sizeof(path)); log->Printf ("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, file+line = %s:%u)", thread_sp.get(), - sb_frame.get(), + frame_sp.get(), frame_desc_strm.GetData(), path, line); } @@ -683,9 +685,7 @@ SBThread::StepOverUntil (lldb::SBFrame &sb_frame, } StackFrameSP frame_sp; - if (sb_frame.IsValid()) - frame_sp = sb_frame.get_sp(); - else + if (!frame_sp) { frame_sp = thread_sp->GetSelectedFrame (); if (!frame_sp) @@ -843,24 +843,26 @@ SBProcess SBThread::GetProcess () { - SBProcess process; + SBProcess sb_process; + ProcessSP process_sp; ThreadSP thread_sp(m_opaque_wp.lock()); if (thread_sp) { // Have to go up to the target so we can get a shared pointer to our process... - process.SetProcess(thread_sp->GetProcess().GetTarget().GetProcessSP()); + process_sp = thread_sp->GetProcess().GetTarget().GetProcessSP(); + sb_process.SetSP (process_sp); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { SBStream frame_desc_strm; - process.GetDescription (frame_desc_strm); + sb_process.GetDescription (frame_desc_strm); log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", thread_sp.get(), - process.get(), frame_desc_strm.GetData()); + process_sp.get(), frame_desc_strm.GetData()); } - return process; + return sb_process; } uint32_t @@ -888,11 +890,13 @@ SBThread::GetFrameAtIndex (uint32_t idx) LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBFrame sb_frame; + StackFrameSP frame_sp; ThreadSP thread_sp(m_opaque_wp.lock()); if (thread_sp) { Mutex::Locker api_locker (thread_sp->GetProcess().GetTarget().GetAPIMutex()); - sb_frame.SetFrame (thread_sp->GetStackFrameAtIndex (idx)); + frame_sp = thread_sp->GetStackFrameAtIndex (idx); + sb_frame.SetFrameSP (frame_sp); } if (log) @@ -900,7 +904,7 @@ SBThread::GetFrameAtIndex (uint32_t idx) SBStream frame_desc_strm; sb_frame.GetDescription (frame_desc_strm); log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s", - thread_sp.get(), idx, sb_frame.get(), frame_desc_strm.GetData()); + thread_sp.get(), idx, frame_sp.get(), frame_desc_strm.GetData()); } return sb_frame; @@ -912,11 +916,13 @@ SBThread::GetSelectedFrame () LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBFrame sb_frame; + StackFrameSP frame_sp; ThreadSP thread_sp(m_opaque_wp.lock()); if (thread_sp) { Mutex::Locker api_locker (thread_sp->GetProcess().GetTarget().GetAPIMutex()); - sb_frame.SetFrame (thread_sp->GetSelectedFrame ()); + frame_sp = thread_sp->GetSelectedFrame (); + sb_frame.SetFrameSP (frame_sp); } if (log) @@ -924,7 +930,7 @@ SBThread::GetSelectedFrame () SBStream frame_desc_strm; sb_frame.GetDescription (frame_desc_strm); log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s", - thread_sp.get(), sb_frame.get(), frame_desc_strm.GetData()); + thread_sp.get(), frame_sp.get(), frame_desc_strm.GetData()); } return sb_frame; @@ -936,15 +942,16 @@ SBThread::SetSelectedFrame (uint32_t idx) LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBFrame sb_frame; + StackFrameSP frame_sp; ThreadSP thread_sp(m_opaque_wp.lock()); if (thread_sp) { Mutex::Locker api_locker (thread_sp->GetProcess().GetTarget().GetAPIMutex()); - lldb::StackFrameSP frame_sp (thread_sp->GetStackFrameAtIndex (idx)); + frame_sp = thread_sp->GetStackFrameAtIndex (idx); if (frame_sp) { thread_sp->SetSelectedFrame (frame_sp.get()); - sb_frame.SetFrame (frame_sp); + sb_frame.SetFrameSP (frame_sp); } } @@ -953,7 +960,7 @@ SBThread::SetSelectedFrame (uint32_t idx) SBStream frame_desc_strm; sb_frame.GetDescription (frame_desc_strm); log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s", - thread_sp.get(), idx, sb_frame.get(), frame_desc_strm.GetData()); + thread_sp.get(), idx, frame_sp.get(), frame_desc_strm.GetData()); } return sb_frame; } diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index 858b8f1144d..b72c8f181b8 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -88,6 +88,8 @@ SBValue::GetError() if (m_opaque_sp.get()) sb_error.SetError(m_opaque_sp->GetError()); + else + sb_error.SetErrorString("error: invalid value"); return sb_error; } @@ -833,46 +835,44 @@ SBValue::GetOpaqueType() lldb::SBTarget SBValue::GetTarget() { - SBTarget result; + SBTarget sb_target; + TargetSP target_sp; if (m_opaque_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) - { - result = SBTarget(lldb::TargetSP(m_opaque_sp->GetUpdatePoint().GetTargetSP())); - } + target_sp = m_opaque_sp->GetUpdatePoint().GetTargetSP(); + sb_target.SetSP (target_sp); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { - if (result.get() == NULL) + if (target_sp.get() == NULL) log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get()); else - log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), result.get()); + log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), target_sp.get()); } - return result; + return sb_target; } lldb::SBProcess SBValue::GetProcess() { - SBProcess result; + SBProcess sb_process; + ProcessSP process_sp; if (m_opaque_sp) { - Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); - if (target) - { - result = SBProcess(lldb::ProcessSP(target->GetProcessSP())); - } + process_sp = m_opaque_sp->GetUpdatePoint().GetProcessSP(); + if (process_sp) + sb_process.SetSP (process_sp); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { - if (result.get() == NULL) + if (process_sp.get() == NULL) log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get()); else - log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), result.get()); + log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), process_sp.get()); } - return result; + return sb_process; } lldb::SBThread @@ -902,23 +902,25 @@ SBValue::GetThread() lldb::SBFrame SBValue::GetFrame() { - SBFrame result; + SBFrame sb_frame; + StackFrameSP frame_sp; if (m_opaque_sp) { if (m_opaque_sp->GetExecutionContextScope()) { - result.SetFrame (m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame()->shared_from_this()); + frame_sp = m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame()->shared_from_this(); + sb_frame.SetFrameSP (frame_sp); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { - if (result.get() == NULL) + if (frame_sp.get() == NULL) log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get()); else - log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), result.get()); + log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), frame_sp.get()); } - return result; + return sb_frame; } @@ -1191,17 +1193,25 @@ SBValue::WatchValue(bool read, bool write, bool watch_pointee) SBWatchpoint sb_wp_empty; // If the SBValue is not valid, there's no point in even trying to watch it. - if (!IsValid() || !GetFrame().IsValid()) + if (!IsValid()) return sb_wp_empty; // Read and Write cannot both be false. if (!read && !write) return sb_wp_empty; - + // If we are watching the pointee, check that the SBValue is a pointer type. if (watch_pointee && !GetType().IsPointerType()) return sb_wp_empty; + TargetSP target_sp (GetTarget().GetSP()); + if (!target_sp) + return sb_wp_empty; + + StackFrameSP frame_sp (GetFrame().GetFrameSP()); + if (!frame_sp) + return sb_wp_empty; + addr_t addr; size_t size; if (watch_pointee) { @@ -1218,12 +1228,11 @@ SBValue::WatchValue(bool read, bool write, bool watch_pointee) uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) | (write ? LLDB_WATCH_TYPE_WRITE : 0); - WatchpointSP wp_sp = GetFrame().m_opaque_sp->GetThread().GetProcess().GetTarget(). - CreateWatchpoint(addr, size, watch_type); + WatchpointSP wp_sp = target_sp->CreateWatchpoint(addr, size, watch_type); if (wp_sp) { // StackFrame::GetInScopeVariableList(true) to get file globals as well. - VariableListSP var_list_sp(GetFrame().m_opaque_sp->GetInScopeVariableList(true)); + VariableListSP var_list_sp(frame_sp->GetInScopeVariableList(true)); VariableSP var_sp = var_list_sp->FindVariable(ConstString(GetName())); if (var_sp && var_sp->GetDeclaration().GetFile()) { StreamString ss; |