Added the ability to extract a ModuleSpecList (a new class) from an ObjectFile. This is designed to be used when you have an object file that contains one or more architectures (MacOSX universal (fat) files) and/or one or more objects (BSD archive (.a files)).

There is a new static ObjectFile function you can call:

size_t
ObjectFile::GetModuleSpecifications (const FileSpec &file,
                                     lldb::offset_t file_offset,
                                     ModuleSpecList &specs)

This will fill in "specs" which the details of all the module specs (file + arch + UUID (if there is one) + object name (for BSD archive objects eventually) + file offset to the object in question).

This helps us when a user specifies a file that contains a single architecture, and also helps us when we are given a debug symbol file (like a dSYM file on MacOSX) that contains one or more architectures and we need to be able to match it up to an existing Module that has no debug info.

llvm-svn: 180224
diff --git a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
index 19d17f0..2ca17e5 100644
--- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
+++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
@@ -239,7 +239,8 @@
 {
     PluginManager::RegisterPlugin (GetPluginNameStatic(),
                                    GetPluginDescriptionStatic(),
-                                   CreateInstance);
+                                   CreateInstance,
+                                   GetModuleSpecifications);
 }
 
 void
@@ -472,3 +473,14 @@
     return 1;
 }
 
+
+size_t
+ObjectContainerBSDArchive::GetModuleSpecifications (const lldb_private::FileSpec& file,
+                                                    lldb::DataBufferSP& data_sp,
+                                                    lldb::offset_t data_offset,
+                                                    lldb::offset_t file_offset,
+                                                    lldb::offset_t length,
+                                                    lldb_private::ModuleSpecList &specs)
+{
+    return 0;
+}
diff --git a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h
index f4bd5d2..7802eb1 100644
--- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h
+++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h
@@ -46,6 +46,14 @@
                     lldb::offset_t offset,
                     lldb::offset_t length);
 
+    static size_t
+    GetModuleSpecifications (const lldb_private::FileSpec& file,
+                             lldb::DataBufferSP& data_sp,
+                             lldb::offset_t data_offset,
+                             lldb::offset_t file_offset,
+                             lldb::offset_t length,
+                             lldb_private::ModuleSpecList &specs);
+
     static bool
     MagicBytesMatch (const lldb_private::DataExtractor &data);
 
diff --git a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
index 9a28736..d1f4434 100644
--- a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
+++ b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
@@ -11,6 +11,7 @@
 #include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/DataBuffer.h"
 #include "lldb/Core/Module.h"
+#include "lldb/Core/ModuleSpec.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Core/Stream.h"
 #include "lldb/Symbol/ObjectFile.h"
@@ -25,7 +26,8 @@
 {
     PluginManager::RegisterPlugin (GetPluginNameStatic(),
                                    GetPluginDescriptionStatic(),
-                                   CreateInstance);
+                                   CreateInstance,
+                                   GetModuleSpecifications);
 }
 
 void
@@ -109,44 +111,52 @@
 bool
 ObjectContainerUniversalMachO::ParseHeader ()
 {
+    bool success = ParseHeader (m_data, m_header, m_fat_archs);
+    // We no longer need any data, we parsed all we needed to parse
+    // and cached it in m_header and m_fat_archs
+    m_data.Clear();
+    return success;
+}
+
+bool
+ObjectContainerUniversalMachO::ParseHeader (lldb_private::DataExtractor &data,
+                                            llvm::MachO::fat_header &header,
+                                            std::vector<llvm::MachO::fat_arch> &fat_archs)
+{
     bool success = false;
     // Store the file offset for this universal file as we could have a universal .o file
     // in a BSD archive, or be contained in another kind of object.
-    lldb::offset_t offset = 0;
     // Universal mach-o files always have their headers in big endian.
-    m_data.SetByteOrder (eByteOrderBig);
-    m_header.magic = m_data.GetU32(&offset);
+    lldb::offset_t offset = 0;
+    data.SetByteOrder (eByteOrderBig);
+    header.magic = data.GetU32(&offset);
+    fat_archs.clear();
 
-    if (m_header.magic == UniversalMagic)
+    if (header.magic == UniversalMagic)
     {
-        m_data.SetAddressByteSize(4);
 
-        m_header.nfat_arch = m_data.GetU32(&offset);
-
+        data.SetAddressByteSize(4);
+        
+        header.nfat_arch = data.GetU32(&offset);
+        
         // 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;
-        for (arch_idx = 0; arch_idx < m_header.nfat_arch; ++arch_idx)
+        for (arch_idx = 0; arch_idx < header.nfat_arch; ++arch_idx)
         {
-            if (m_data.ValidOffsetForDataOfSize(offset, sizeof(fat_arch)))
+            if (data.ValidOffsetForDataOfSize(offset, sizeof(fat_arch)))
             {
                 fat_arch arch;
-                if (m_data.GetU32(&offset, &arch, sizeof(fat_arch)/sizeof(uint32_t)))
-                {
-                    m_fat_archs.push_back(arch);
-                }
+                if (data.GetU32(&offset, &arch, sizeof(fat_arch)/sizeof(uint32_t)))
+                    fat_archs.push_back(arch);
             }
         }
         success = true;
     }
     else
     {
-        memset(&m_header, 0, sizeof(m_header));
+        memset(&header, 0, sizeof(header));
     }
-
-    // We no longer need any data, we parsed all we needed to parse
-    // and cached it in m_header and m_fat_archs
-    m_data.Clear();
     return success;
 }
 
@@ -268,3 +278,33 @@
 }
 
 
+size_t
+ObjectContainerUniversalMachO::GetModuleSpecifications (const lldb_private::FileSpec& file,
+                                                        lldb::DataBufferSP& data_sp,
+                                                        lldb::offset_t data_offset,
+                                                        lldb::offset_t file_offset,
+                                                        lldb::offset_t length,
+                                                        lldb_private::ModuleSpecList &specs)
+{
+    const size_t initial_count = specs.GetSize();
+    
+    DataExtractor data;
+    data.SetData (data_sp, data_offset, length);
+
+    if (ObjectContainerUniversalMachO::MagicBytesMatch(data))
+    {
+        llvm::MachO::fat_header header;
+        std::vector<llvm::MachO::fat_arch> fat_archs;
+        if (ParseHeader (data, header, fat_archs))
+        {
+            for (const llvm::MachO::fat_arch &fat_arch : fat_archs)
+            {
+                ObjectFile::GetModuleSpecifications (file,
+                                                     fat_arch.offset + file_offset,
+                                                     specs);
+            }
+        }
+    }
+    return specs.GetSize() - initial_count;
+}
+
diff --git a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h
index 78945b0..1fe1a2d 100644
--- a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h
+++ b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h
@@ -42,6 +42,14 @@
                     lldb::offset_t offset,
                     lldb::offset_t length);
 
+    static size_t
+    GetModuleSpecifications (const lldb_private::FileSpec& file,
+                             lldb::DataBufferSP& data_sp,
+                             lldb::offset_t data_offset,
+                             lldb::offset_t file_offset,
+                             lldb::offset_t length,
+                             lldb_private::ModuleSpecList &specs);
+
     static bool
     MagicBytesMatch (const lldb_private::DataExtractor &data);
 
@@ -88,6 +96,12 @@
 protected:
     llvm::MachO::fat_header m_header;
     std::vector<llvm::MachO::fat_arch> m_fat_archs;
+    
+    static bool
+    ParseHeader (lldb_private::DataExtractor &data,
+                 llvm::MachO::fat_header &header,
+                 std::vector<llvm::MachO::fat_arch> &fat_archs);
+
 };
 
 #endif  // liblldb_ObjectContainerUniversalMachO_h_