summaryrefslogtreecommitdiffstats
path: root/lldb/source/API/SBSourceManager.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2013-03-19 00:20:55 +0000
committerGreg Clayton <gclayton@apple.com>2013-03-19 00:20:55 +0000
commit9585fbfc67a8de61a87e98e6a1b989a1ed98e48d (patch)
treec343bd265584d82e6e354722d328758e14f541f9 /lldb/source/API/SBSourceManager.cpp
parent8dfb68e0398ef48d41dc8ea058e9aa750b5fc85f (diff)
downloadbcm5719-llvm-9585fbfc67a8de61a87e98e6a1b989a1ed98e48d.tar.gz
bcm5719-llvm-9585fbfc67a8de61a87e98e6a1b989a1ed98e48d.zip
<rdar://problem/13443931>
Fixed a crasher in the SourceManager where it wasn't checking the m_target member variable for NULL. In doing this fix, I hardened this class to have weak pointers to the debugger and target in case they do go away. I also changed SBSourceManager to hold onto weak pointers to the debugger and target so they don't keep objects alive by holding a strong reference to them. llvm-svn: 177365
Diffstat (limited to 'lldb/source/API/SBSourceManager.cpp')
-rw-r--r--lldb/source/API/SBSourceManager.cpp56
1 files changed, 33 insertions, 23 deletions
diff --git a/lldb/source/API/SBSourceManager.cpp b/lldb/source/API/SBSourceManager.cpp
index caa1b0c1b52..0b8cbfceda0 100644
--- a/lldb/source/API/SBSourceManager.cpp
+++ b/lldb/source/API/SBSourceManager.cpp
@@ -27,22 +27,24 @@ namespace lldb_private
class SourceManagerImpl
{
public:
- SourceManagerImpl (const lldb::DebuggerSP &debugger_sp)
+ SourceManagerImpl (const lldb::DebuggerSP &debugger_sp) :
+ m_debugger_wp (debugger_sp),
+ m_target_wp ()
{
- m_debugger_sp = debugger_sp;
}
- SourceManagerImpl (const lldb::TargetSP &target_sp)
+ SourceManagerImpl (const lldb::TargetSP &target_sp) :
+ m_debugger_wp (),
+ m_target_wp (target_sp)
{
- m_target_sp = target_sp;
}
SourceManagerImpl (const SourceManagerImpl &rhs)
{
if (&rhs == this)
return;
- m_debugger_sp = rhs.m_debugger_sp;
- m_target_sp = rhs.m_target_sp;
+ m_debugger_wp = rhs.m_debugger_wp;
+ m_target_wp = rhs.m_target_wp;
}
size_t
@@ -56,27 +58,35 @@ namespace lldb_private
if (!file)
return 0;
- if (m_debugger_sp)
- return m_debugger_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (file,
- line,
- context_before,
- context_after,
- current_line_cstr,
- s);
- else if (m_target_sp)
- return m_target_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (file,
- line,
- context_before,
- context_after,
- current_line_cstr,
- s);
+ lldb::TargetSP target_sp (m_target_wp.lock());
+ if (target_sp)
+ {
+ return target_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (file,
+ line,
+ context_before,
+ context_after,
+ current_line_cstr,
+ s);
+ }
else
- return 0;
+ {
+ lldb::DebuggerSP debugger_sp (m_debugger_wp.lock());
+ if (debugger_sp)
+ {
+ return debugger_sp->GetSourceManager().DisplaySourceLinesWithLineNumbers (file,
+ line,
+ context_before,
+ context_after,
+ current_line_cstr,
+ s);
+ }
+ }
+ return 0;
}
private:
- lldb::DebuggerSP m_debugger_sp;
- lldb::TargetSP m_target_sp;
+ lldb::DebuggerWP m_debugger_wp;
+ lldb::TargetWP m_target_wp;
};
}
OpenPOWER on IntegriCloud