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