Switching back to using std::tr1::shared_ptr. We originally switched away

due to RTTI worries since llvm and clang don't use RTTI, but I was able to 
switch back with no issues as far as I can tell. Once the RTTI issue wasn't
an issue, we were looking for a way to properly track weak pointers to objects
to solve some of the threading issues we have been running into which naturally
led us back to std::tr1::weak_ptr. We also wanted the ability to make a shared 
pointer from just a pointer, which is also easily solved using the 
std::tr1::enable_shared_from_this class. 

The main reason for this move back is so we can start properly having weak
references to objects. Currently a lldb_private::Thread class has a refrence
to its parent lldb_private::Process. This doesn't work well when we now hand
out a SBThread object that contains a shared pointer to a lldb_private::Thread
as this SBThread can be held onto by external clients and if they end up
using one of these objects we can easily crash.

So the next task is to start adopting std::tr1::weak_ptr where ever it makes
sense which we can do with lldb_private::Debugger, lldb_private::Target,
lldb_private::Process, lldb_private::Thread, lldb_private::StackFrame, and
many more objects now that they are no longer using intrusive ref counted
pointer objects (you can't do std::tr1::weak_ptr functionality with intrusive
pointers).

llvm-svn: 149207
This commit is contained in:
Greg Clayton
2012-01-29 20:56:30 +00:00
parent 3f09de6442
commit e1cd1be6d6
94 changed files with 409 additions and 416 deletions

View File

@@ -149,14 +149,6 @@ Target::GetProcessSP () const
return m_process_sp;
}
lldb::TargetSP
Target::GetSP()
{
// This object contains an instrusive ref count base class so we can
// easily make a shared pointer to this object
return TargetSP(this);
}
void
Target::Destroy()
{
@@ -256,8 +248,7 @@ Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
BreakpointSP
Target::CreateBreakpoint (Address &addr, bool internal)
{
TargetSP target_sp = this->GetSP();
SearchFilterSP filter_sp(new SearchFilterForNonModuleSpecificSearches (target_sp));
SearchFilterSP filter_sp(new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
return CreateBreakpoint (filter_sp, resolver_sp, internal);
}
@@ -290,17 +281,16 @@ SearchFilterSP
Target::GetSearchFilterForModule (const FileSpec *containingModule)
{
SearchFilterSP filter_sp;
lldb::TargetSP target_sp = this->GetSP();
if (containingModule != NULL)
{
// TODO: We should look into sharing module based search filters
// across many breakpoints like we do for the simple target based one
filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule));
filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule));
}
else
{
if (m_search_filter_sp.get() == NULL)
m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (target_sp));
m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
filter_sp = m_search_filter_sp;
}
return filter_sp;
@@ -310,17 +300,16 @@ SearchFilterSP
Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
{
SearchFilterSP filter_sp;
lldb::TargetSP target_sp = this->GetSP();
if (containingModules && containingModules->GetSize() != 0)
{
// TODO: We should look into sharing module based search filters
// across many breakpoints like we do for the simple target based one
filter_sp.reset (new SearchFilterByModuleList (target_sp, *containingModules));
filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules));
}
else
{
if (m_search_filter_sp.get() == NULL)
m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (target_sp));
m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this()));
filter_sp = m_search_filter_sp;
}
return filter_sp;
@@ -333,17 +322,16 @@ Target::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules
return GetSearchFilterForModuleList(containingModules);
SearchFilterSP filter_sp;
lldb::TargetSP target_sp = this->GetSP();
if (containingModules == NULL)
{
// We could make a special "CU List only SearchFilter". Better yet was if these could be composable,
// but that will take a little reworking.
filter_sp.reset (new SearchFilterByModuleListAndCU (target_sp, FileSpecList(), *containingSourceFiles));
filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles));
}
else
{
filter_sp.reset (new SearchFilterByModuleListAndCU (target_sp, *containingModules, *containingSourceFiles));
filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles));
}
return filter_sp;
}
@@ -1073,11 +1061,12 @@ Target::ReadMemory (const Address& addr,
if (load_addr == LLDB_INVALID_ADDRESS)
{
if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec())
Module *addr_module = resolved_addr.GetModulePtr();
if (addr_module && addr_module->GetFileSpec())
error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded",
resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(),
addr_module->GetFileSpec().GetFilename().AsCString(),
resolved_addr.GetFileAddress(),
resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString());
addr_module->GetFileSpec().GetFilename().AsCString());
else
error.SetErrorStringWithFormat("0x%llx can't be resolved", resolved_addr.GetFileAddress());
}
@@ -1339,7 +1328,7 @@ Target::GetScratchClangASTContext(bool create_on_demand)
if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand)
{
m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
m_scratch_ast_source_ap.reset (new ClangASTSource(GetSP()));
m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this()));
m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext());
llvm::OwningPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy());
m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source);
@@ -1678,7 +1667,7 @@ lldb::user_id_t
Target::AddStopHook (Target::StopHookSP &new_hook_sp)
{
lldb::user_id_t new_uid = ++m_stop_hook_next_id;
new_hook_sp.reset (new StopHook(GetSP(), new_uid));
new_hook_sp.reset (new StopHook(shared_from_this(), new_uid));
m_stop_hooks[new_uid] = new_hook_sp;
return new_uid;
}