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/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;
+}
+