Big change in the way ObjectFile file contents are managed. We now
mmap() the entire object file contents into memory with MAP_PRIVATE.
We do this because object file contents can change on us and currently
this helps alleviate this situation. It also make the code for accessing
object file data much easier to manage and we don't end up opening the
file, reading some data and closing the file over and over.

llvm-svn: 148017
diff --git a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
index 8c4359f..bd257dc 100644
--- a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
+++ b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
@@ -51,15 +51,17 @@
 ObjectContainerUniversalMachO::CreateInstance
 (
     Module* module,
-    DataBufferSP& dataSP,
+    DataBufferSP& data_sp,
     const FileSpec *file,
     addr_t offset,
     addr_t length
 )
 {
-    if (ObjectContainerUniversalMachO::MagicBytesMatch(dataSP))
+    DataExtractor data;
+    data.SetData (data_sp, offset, length);
+    if (ObjectContainerUniversalMachO::MagicBytesMatch(data))
     {
-        std::auto_ptr<ObjectContainerUniversalMachO> container_ap(new ObjectContainerUniversalMachO (module, dataSP, file, offset, length));
+        std::auto_ptr<ObjectContainerUniversalMachO> container_ap(new ObjectContainerUniversalMachO (module, data_sp, file, offset, length));
         if (container_ap->ParseHeader())
         {
             return container_ap.release();
@@ -71,9 +73,8 @@
 
 
 bool
-ObjectContainerUniversalMachO::MagicBytesMatch (DataBufferSP& dataSP)
+ObjectContainerUniversalMachO::MagicBytesMatch (const DataExtractor &data)
 {
-    DataExtractor data(dataSP, lldb::endian::InlHostByteOrder(), 4);
     uint32_t offset = 0;
     uint32_t magic = data.GetU32(&offset);
     return magic == UniversalMagic || magic == UniversalMagicSwapped;
@@ -115,17 +116,6 @@
 
         m_header.nfat_arch = m_data.GetU32(&offset);
 
-        const size_t nfat_arch_size = sizeof(fat_arch) * m_header.nfat_arch;
-        // See if the current data we have is enough for all of the fat headers?
-        if (!m_data.ValidOffsetForDataOfSize(offset, nfat_arch_size))
-        {
-            // The fat headers are larger than the number of bytes we have been
-            // given when this class was constructed. We will read the exact number
-            // of bytes that we need.
-            DataBufferSP data_sp(m_file.ReadFileContents(m_offset, nfat_arch_size + sizeof(fat_header)));
-            m_data.SetData (data_sp);
-        }
-
         // Now we should have enough data for all of the fat headers, so lets index
         // them so we know how many architectures that this universal binary contains.
         uint32_t arch_idx = 0;
@@ -140,9 +130,6 @@
                 }
             }
         }
-        // Now that we have indexed the universal headers, we no longer need any cached data.
-        m_data.Clear();
-
         return true;
     }
     else
@@ -222,7 +209,8 @@
                 return ObjectFile::FindPlugin (m_module, 
                                                file, 
                                                m_offset + m_fat_archs[arch_idx].offset, 
-                                               m_fat_archs[arch_idx].size);
+                                               m_fat_archs[arch_idx].size,
+                                               m_data.GetSharedDataBuffer());
             }
         }
     }