Don't put modules for .o files into the global shared module list. We
used to do this because we needed to find the shared pointer for a .o
file when the .o file's module was needed in a SymbolContext since the
module in a symbol context was a shared pointer. Now that we are using
intrusive pointers we don't have this limitation anymore since any
instrusive shared pointer can be made from a pointer to an object
all on its own.
Also switched over to having the Module and SymbolVendor use shared
pointers to their object files as had a leak on MacOSX when the
SymbolVendor's object file wasn't the same as the Module's (debug info
in a stand along file (dSYM file)). Now everything will correctly clean
itself up when the module goes away after an executable gets rebuilt.
Now we correctly get rid of .o files that are used with the DWARF with
debug map executables on subsequent runs since the only shared pointer
to the object files in from the DWARF symbol file debug map parser, and
when the module gets replaced, it destroys to old one along with all .o
files.
Also added a small optimization when using BSD archives where we will
remove old BSD containers from the shared list when they are outdated.
llvm-svn: 140002
diff --git a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
index 26cd036..771b00d 100644
--- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
+++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
@@ -160,14 +160,33 @@
Mutex::Locker locker(Archive::GetArchiveCacheMutex ());
shared_ptr archive_sp;
Archive::Map &archive_map = Archive::GetArchiveCache ();
- Archive::Map::iterator pos;
- for (pos = archive_map.find (file); pos != archive_map.end() && pos->first == file; ++pos)
+ Archive::Map::iterator pos = archive_map.find (file);
+ // Don't cache a value for "archive_map.end()" below since we might
+ // delete an archive entry...
+ while (pos != archive_map.end() && pos->first == file)
{
- if (pos->second->GetArchitecture() == arch &&
- pos->second->GetModificationTime() == time)
+ if (pos->second->GetArchitecture() == arch)
{
- archive_sp = pos->second;
+ if (pos->second->GetModificationTime() == time)
+ {
+ return pos->second;
+ }
+ else
+ {
+ // We have a file at the same path with the same architecture
+ // whose modification time doesn't match. It doesn't make sense
+ // for us to continue to use this BSD archive since we cache only
+ // the object info which consists of file time info and also the
+ // file offset and file size of any contianed objects. Since
+ // this information is now out of date, we won't get the correct
+ // information if we go and extract the file data, so we should
+ // remove the old and outdated entry.
+ archive_map.erase (pos);
+ pos = archive_map.find (file);
+ continue;
+ }
}
+ ++pos;
}
return archive_sp;
}
@@ -266,7 +285,7 @@
// Read everything since we need that in order to index all the
// objects in the archive
- data_sp = file->ReadFileContents(offset, length);
+ data_sp = file->MemoryMapFileContents (offset, length);
std::auto_ptr<ObjectContainerBSDArchive> container_ap(new ObjectContainerBSDArchive (module, data_sp, file, offset, length));
if (container_ap->ParseHeader())
@@ -363,7 +382,7 @@
s->EOL();
}
-ObjectFile *
+ObjectFileSP
ObjectContainerBSDArchive::GetObjectFile (const FileSpec *file)
{
if (m_module->GetObjectName() && m_archive_sp)
@@ -372,7 +391,7 @@
if (object)
return ObjectFile::FindPlugin (m_module, file, m_offset + object->ar_file_offset, object->ar_file_size);
}
- return NULL;
+ return ObjectFileSP();
}
diff --git a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h
index 2b45a13..9343831 100644
--- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h
+++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h
@@ -63,10 +63,17 @@
virtual bool
ParseHeader ();
+ virtual size_t
+ GetNumObjects () const
+ {
+ if (m_archive_sp)
+ return m_archive_sp->GetNumObjects();
+ return 0;
+ }
virtual void
Dump (lldb_private::Stream *s) const;
- virtual lldb_private::ObjectFile *
+ virtual lldb::ObjectFileSP
GetObjectFile (const lldb_private::FileSpec *file);
//------------------------------------------------------------------
@@ -101,6 +108,7 @@
uint32_t ar_size; // size in bytes
uint32_t ar_file_offset; // file offset in bytes from the beginning of the file of the object data
uint32_t ar_file_size; // length of the object data
+ lldb::ObjectFileSP object_file_sp;
typedef std::vector<Object> collection;
typedef collection::iterator iterator;
@@ -136,6 +144,12 @@
~Archive ();
size_t
+ GetNumObjects () const
+ {
+ return m_objects.size();
+ }
+
+ size_t
ParseObjects (lldb_private::DataExtractor &data);
Object *
@@ -152,6 +166,9 @@
{
return m_arch;
}
+
+ bool
+ HasNoExternalReferences() const;
protected:
diff --git a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
index 83c5825..218e97e 100644
--- a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
+++ b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
@@ -196,7 +196,7 @@
return false;
}
-ObjectFile *
+ObjectFileSP
ObjectContainerUniversalMachO::GetObjectFile (const FileSpec *file)
{
uint32_t arch_idx = 0;
@@ -219,11 +219,14 @@
{
if (arch == curr_arch)
{
- return ObjectFile::FindPlugin (m_module, file, m_offset + m_fat_archs[arch_idx].offset, m_fat_archs[arch_idx].size);
+ return ObjectFile::FindPlugin (m_module,
+ file,
+ m_offset + m_fat_archs[arch_idx].offset,
+ m_fat_archs[arch_idx].size);
}
}
}
- return NULL;
+ return ObjectFileSP();
}
diff --git a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h
index 8cc0fbd..989fd6d 100644
--- a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h
+++ b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h
@@ -68,7 +68,7 @@
virtual bool
GetArchitectureAtIndex (uint32_t cpu_idx, lldb_private::ArchSpec& arch) const;
- virtual lldb_private::ObjectFile *
+ virtual lldb::ObjectFileSP
GetObjectFile (const lldb_private::FileSpec *file);
//------------------------------------------------------------------