<rdar://problem/10103468>
I started work on being able to add symbol files after a debug session
had started with a new "target symfile add" command and quickly ran into
problems with stale Address objects in breakpoint locations that had
lldb_private::Section pointers into modules that had been removed or
replaced. This also let to grabbing stale modules from those sections.
So I needed to thread harded the Address, Section and related objects.
To do this I modified the ModuleChild class to now require a ModuleSP
on initialization so that a weak reference can created. I also changed
all places that were handing out "Section *" to have them hand out SectionSP.
All ObjectFile, SymbolFile and SymbolVendors were inheriting from ModuleChild
so all of the find plug-in, static creation function and constructors now
require ModuleSP references instead of Module *.
Address objects now have weak references to their sections which can
safely go stale when a module gets destructed.
This checkin doesn't complete the "target symfile add" command, but it
does get us a lot clioser to being able to do such things without a high
risk of crashing or memory corruption.
llvm-svn: 151336
diff --git a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
index 8456ecd..1d9158a 100644
--- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
+++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
@@ -263,7 +263,7 @@
ObjectContainer *
ObjectContainerBSDArchive::CreateInstance
(
- Module* module,
+ const lldb::ModuleSP &module_sp,
DataBufferSP& data_sp,
const FileSpec *file,
addr_t offset,
@@ -275,13 +275,13 @@
{
Timer scoped_timer (__PRETTY_FUNCTION__,
"ObjectContainerBSDArchive::CreateInstance (module = %s/%s, file = %p, file_offset = 0x%z8.8x, file_size = 0x%z8.8x)",
- module->GetFileSpec().GetDirectory().AsCString(),
- module->GetFileSpec().GetFilename().AsCString(),
+ module_sp->GetFileSpec().GetDirectory().AsCString(),
+ module_sp->GetFileSpec().GetFilename().AsCString(),
file, offset, length);
- Archive::shared_ptr archive_sp (Archive::FindCachedArchive (*file, module->GetArchitecture(), module->GetModificationTime()));
+ Archive::shared_ptr archive_sp (Archive::FindCachedArchive (*file, module_sp->GetArchitecture(), module_sp->GetModificationTime()));
- std::auto_ptr<ObjectContainerBSDArchive> container_ap(new ObjectContainerBSDArchive (module, data_sp, file, offset, length));
+ std::auto_ptr<ObjectContainerBSDArchive> container_ap(new ObjectContainerBSDArchive (module_sp, data_sp, file, offset, length));
if (container_ap.get())
{
@@ -316,13 +316,13 @@
ObjectContainerBSDArchive::ObjectContainerBSDArchive
(
- Module* module,
+ const lldb::ModuleSP &module_sp,
DataBufferSP& dataSP,
const lldb_private::FileSpec *file,
lldb::addr_t offset,
lldb::addr_t size
) :
- ObjectContainer (module, file, offset, size, dataSP),
+ ObjectContainer (module_sp, file, offset, size, dataSP),
m_archive_sp ()
{
}
@@ -345,10 +345,14 @@
{
if (m_data.GetByteSize() > 0)
{
- m_archive_sp = Archive::ParseAndCacheArchiveForFile (m_file,
- m_module->GetArchitecture(),
- m_module->GetModificationTime(),
- m_data);
+ ModuleSP module_sp (GetModule());
+ if (module_sp)
+ {
+ m_archive_sp = Archive::ParseAndCacheArchiveForFile (m_file,
+ module_sp->GetArchitecture(),
+ module_sp->GetModificationTime(),
+ m_data);
+ }
}
}
return m_archive_sp.get() != NULL;
@@ -383,15 +387,19 @@
ObjectFileSP
ObjectContainerBSDArchive::GetObjectFile (const FileSpec *file)
{
- if (m_module->GetObjectName() && m_archive_sp)
+ ModuleSP module_sp (GetModule());
+ if (module_sp)
{
- Object *object = m_archive_sp->FindObject (m_module->GetObjectName());
- if (object)
- return ObjectFile::FindPlugin (m_module,
- file,
- object->ar_file_offset,
- object->ar_file_size,
- m_data.GetSharedDataBuffer());
+ if (module_sp->GetObjectName() && m_archive_sp)
+ {
+ Object *object = m_archive_sp->FindObject (module_sp->GetObjectName());
+ if (object)
+ return ObjectFile::FindPlugin (module_sp,
+ file,
+ object->ar_file_offset,
+ object->ar_file_size,
+ m_data.GetSharedDataBuffer());
+ }
}
return ObjectFileSP();
}