diff options
Diffstat (limited to 'lldb/source/Plugins')
10 files changed, 303 insertions, 57 deletions
diff --git a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp index 19d17f0033e..2ca17e506be 100644 --- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp +++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp @@ -239,7 +239,8 @@ ObjectContainerBSDArchive::Initialize() { PluginManager::RegisterPlugin (GetPluginNameStatic(), GetPluginDescriptionStatic(), - CreateInstance); + CreateInstance, + GetModuleSpecifications); } void @@ -472,3 +473,14 @@ ObjectContainerBSDArchive::GetPluginVersion() 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 f4bd5d20362..7802eb152d5 100644 --- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h +++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h @@ -46,6 +46,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); 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_ diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index 0ce96b972d8..4ba081a7b7c 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -17,6 +17,7 @@ #include "lldb/Core/Error.h" #include "lldb/Core/FileSpecList.h" #include "lldb/Core/Module.h" +#include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Section.h" #include "lldb/Core/Stream.h" @@ -149,7 +150,8 @@ ObjectFileELF::Initialize() PluginManager::RegisterPlugin(GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance, - CreateMemoryInstance); + CreateMemoryInstance, + GetModuleSpecifications); } void @@ -220,6 +222,17 @@ ObjectFileELF::CreateMemoryInstance (const lldb::ModuleSP &module_sp, } +size_t +ObjectFileELF::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; +} + //------------------------------------------------------------------ // PluginInterface protocol //------------------------------------------------------------------ diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h index 66b6f7110c2..78cfb3f5157 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h @@ -58,6 +58,13 @@ public: const lldb::ProcessSP &process_sp, lldb::addr_t header_addr); + 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); //------------------------------------------------------------------ // PluginInterface protocol //------------------------------------------------------------------ diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 90e56054a1f..7bd6020f1e6 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -19,6 +19,7 @@ #include "lldb/Core/FileSpecList.h" #include "lldb/Core/Log.h" #include "lldb/Core/Module.h" +#include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RangeMap.h" #include "lldb/Core/Section.h" @@ -367,7 +368,8 @@ ObjectFileMachO::Initialize() PluginManager::RegisterPlugin (GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance, - CreateMemoryInstance); + CreateMemoryInstance, + GetModuleSpecifications); } void @@ -433,6 +435,47 @@ ObjectFileMachO::CreateMemoryInstance (const lldb::ModuleSP &module_sp, return NULL; } +size_t +ObjectFileMachO::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(); + + if (ObjectFileMachO::MagicBytesMatch(data_sp, 0, data_sp->GetByteSize())) + { + DataExtractor data; + data.SetData(data_sp); + llvm::MachO::mach_header header; + if (ParseHeader (data, &data_offset, header)) + { + if (header.sizeofcmds >= data_sp->GetByteSize()) + { + data_sp = file.ReadFileContents(file_offset, header.sizeofcmds); + data_offset = 0; + } + if (data_sp) + { + ModuleSpec spec; + spec.GetFileSpec() = file; + spec.GetArchitecture().SetArchitecture(eArchTypeMachO, + header.cputype, + header.cpusubtype); + if (spec.GetArchitecture().IsValid()) + { + GetUUID (header, data, data_offset, spec.GetUUID()); + specs.Append(spec); + } + } + } + } + return specs.GetSize() - initial_count; +} + + const ConstString & ObjectFileMachO::GetSegmentNameTEXT() @@ -541,6 +584,61 @@ ObjectFileMachO::~ObjectFileMachO() { } +bool +ObjectFileMachO::ParseHeader (DataExtractor &data, + lldb::offset_t *data_offset_ptr, + llvm::MachO::mach_header &header) +{ + data.SetByteOrder (lldb::endian::InlHostByteOrder()); + // Leave magic in the original byte order + header.magic = data.GetU32(data_offset_ptr); + bool can_parse = false; + bool is_64_bit = false; + switch (header.magic) + { + case HeaderMagic32: + data.SetByteOrder (lldb::endian::InlHostByteOrder()); + data.SetAddressByteSize(4); + can_parse = true; + break; + + case HeaderMagic64: + data.SetByteOrder (lldb::endian::InlHostByteOrder()); + data.SetAddressByteSize(8); + can_parse = true; + is_64_bit = true; + break; + + case HeaderMagic32Swapped: + data.SetByteOrder(lldb::endian::InlHostByteOrder() == eByteOrderBig ? eByteOrderLittle : eByteOrderBig); + data.SetAddressByteSize(4); + can_parse = true; + break; + + case HeaderMagic64Swapped: + data.SetByteOrder(lldb::endian::InlHostByteOrder() == eByteOrderBig ? eByteOrderLittle : eByteOrderBig); + data.SetAddressByteSize(8); + is_64_bit = true; + can_parse = true; + break; + + default: + break; + } + + if (can_parse) + { + data.GetU32(data_offset_ptr, &header.cputype, 6); + if (is_64_bit) + *data_offset_ptr += 4; + return true; + } + else + { + memset(&header, 0, sizeof(header)); + } + return false; +} bool ObjectFileMachO::ParseHeader () @@ -3481,6 +3579,49 @@ ObjectFileMachO::Dump (Stream *s) } } +bool +ObjectFileMachO::GetUUID (const llvm::MachO::mach_header &header, + const lldb_private::DataExtractor &data, + lldb::offset_t lc_offset, + lldb_private::UUID& uuid) +{ + uint32_t i; + struct uuid_command load_cmd; + + lldb::offset_t offset = lc_offset; + for (i=0; i<header.ncmds; ++i) + { + const lldb::offset_t cmd_offset = offset; + if (data.GetU32(&offset, &load_cmd, 2) == NULL) + break; + + if (load_cmd.cmd == LoadCommandUUID) + { + const uint8_t *uuid_bytes = data.PeekData(offset, 16); + + if (uuid_bytes) + { + // OpenCL on Mac OS X uses the same UUID for each of its object files. + // We pretend these object files have no UUID to prevent crashing. + + const uint8_t opencl_uuid[] = { 0x8c, 0x8e, 0xb3, 0x9b, + 0x3b, 0xa8, + 0x4b, 0x16, + 0xb6, 0xa4, + 0x27, 0x63, 0xbb, 0x14, 0xf0, 0x0d }; + + if (!memcmp(uuid_bytes, opencl_uuid, 16)) + return false; + + uuid.SetBytes (uuid_bytes); + return true; + } + return false; + } + offset = cmd_offset + load_cmd.cmdsize; + } + return false; +} bool ObjectFileMachO::GetUUID (lldb_private::UUID* uuid) @@ -3489,40 +3630,8 @@ ObjectFileMachO::GetUUID (lldb_private::UUID* uuid) if (module_sp) { lldb_private::Mutex::Locker locker(module_sp->GetMutex()); - struct uuid_command load_cmd; lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic); - uint32_t i; - for (i=0; i<m_header.ncmds; ++i) - { - const lldb::offset_t cmd_offset = offset; - if (m_data.GetU32(&offset, &load_cmd, 2) == NULL) - break; - - if (load_cmd.cmd == LoadCommandUUID) - { - const uint8_t *uuid_bytes = m_data.PeekData(offset, 16); - - if (uuid_bytes) - { - // OpenCL on Mac OS X uses the same UUID for each of its object files. - // We pretend these object files have no UUID to prevent crashing. - - const uint8_t opencl_uuid[] = { 0x8c, 0x8e, 0xb3, 0x9b, - 0x3b, 0xa8, - 0x4b, 0x16, - 0xb6, 0xa4, - 0x27, 0x63, 0xbb, 0x14, 0xf0, 0x0d }; - - if (!memcmp(uuid_bytes, opencl_uuid, 16)) - return false; - - uuid->SetBytes (uuid_bytes); - return true; - } - return false; - } - offset = cmd_offset + load_cmd.cmdsize; - } + return GetUUID (m_header, m_data, offset, *uuid); } return false; } diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h index dcba2c5a6d6..2226e3dd695 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h @@ -55,6 +55,14 @@ public: const lldb::ProcessSP &process_sp, lldb::addr_t header_addr); + 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 (lldb::DataBufferSP& data_sp, lldb::addr_t offset, @@ -146,7 +154,19 @@ public: protected: - // Intended for same-host arm device debugging where lldb needs to + static bool + ParseHeader (lldb_private::DataExtractor &data, + lldb::offset_t *data_offset_ptr, + llvm::MachO::mach_header &header); + + + static bool + GetUUID (const llvm::MachO::mach_header &header, + const lldb_private::DataExtractor &data, + lldb::offset_t lc_offset, // Offset to the first load command + lldb_private::UUID& uuid); + + // Intended for same-host arm device debugging where lldb needs to // detect libraries in the shared cache and augment the nlist entries // with an on-disk dyld_shared_cache file. The process will record // the shared cache UUID so the on-disk cache can be matched or rejected diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp index 4ce198b7ee2..157b148ee5c 100644 --- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp @@ -16,6 +16,7 @@ #include "lldb/Host/FileSpec.h" #include "lldb/Core/FileSpecList.h" #include "lldb/Core/Module.h" +#include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Section.h" #include "lldb/Core/StreamFile.h" @@ -121,7 +122,8 @@ ObjectFilePECOFF::Initialize() PluginManager::RegisterPlugin (GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance, - CreateMemoryInstance); + CreateMemoryInstance, + GetModuleSpecifications); } void @@ -179,6 +181,18 @@ ObjectFilePECOFF::CreateMemoryInstance (const lldb::ModuleSP &module_sp, return NULL; } +size_t +ObjectFilePECOFF::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; +} + + bool ObjectFilePECOFF::MagicBytesMatch (DataBufferSP& data_sp) { diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h index 814559f5638..33973abad02 100644 --- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h +++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h @@ -47,6 +47,15 @@ public: lldb::DataBufferSP& data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr); + + 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 (lldb::DataBufferSP& data_sp); |