summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/ObjectContainer/Universal-Mach-O
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2013-04-24 22:29:28 +0000
committerGreg Clayton <gclayton@apple.com>2013-04-24 22:29:28 +0000
commitf4d6de6a5385e18e0b7746d3037f2029069c6ef3 (patch)
treee9e6c4d2b765b926e5ec4dc75e006059730d8aef /lldb/source/Plugins/ObjectContainer/Universal-Mach-O
parent8d1d25222ec4b1c0d590cd888499d2061eaa67e3 (diff)
downloadbcm5719-llvm-f4d6de6a5385e18e0b7746d3037f2029069c6ef3.tar.gz
bcm5719-llvm-f4d6de6a5385e18e0b7746d3037f2029069c6ef3.zip
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
Diffstat (limited to 'lldb/source/Plugins/ObjectContainer/Universal-Mach-O')
-rw-r--r--lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp78
-rw-r--r--lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h14
2 files changed, 73 insertions, 19 deletions
diff --git a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
index 9a28736e3e6..d1f4434c987 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 @@ ObjectContainerUniversalMachO::Initialize()
{
PluginManager::RegisterPlugin (GetPluginNameStatic(),
GetPluginDescriptionStatic(),
- CreateInstance);
+ CreateInstance,
+ GetModuleSpecifications);
}
void
@@ -109,44 +111,52 @@ ObjectContainerUniversalMachO::~ObjectContainerUniversalMachO()
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 @@ ObjectContainerUniversalMachO::GetPluginVersion()
}
+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 78945b0ef98..1fe1a2d2165 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 @@ public:
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 @@ public:
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_
OpenPOWER on IntegriCloud