Index: lldb/trunk/include/lldb/Symbol/ObjectFile.h =================================================================== --- lldb/trunk/include/lldb/Symbol/ObjectFile.h +++ lldb/trunk/include/lldb/Symbol/ObjectFile.h @@ -204,6 +204,10 @@ const char *path_with_object, lldb_private::FileSpec &archive_file, lldb_private::ConstString &archive_object, bool must_exist); + // LLVM RTTI support + static char ID; + virtual bool isA(const void *ClassID) const { return ClassID == &ID; } + /// Gets the address size in bytes for the current object file. /// /// \return Index: lldb/trunk/source/Plugins/JITLoader/GDB/CMakeLists.txt =================================================================== --- lldb/trunk/source/Plugins/JITLoader/GDB/CMakeLists.txt +++ lldb/trunk/source/Plugins/JITLoader/GDB/CMakeLists.txt @@ -16,6 +16,7 @@ lldbSymbol lldbTarget lldbUtility + lldbPluginObjectFileMachO LINK_COMPONENTS Support ) Index: lldb/trunk/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp =================================================================== --- lldb/trunk/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp +++ lldb/trunk/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp @@ -6,9 +6,8 @@ // //===----------------------------------------------------------------------===// - -#include "llvm/Support/MathExtras.h" - +#include "JITLoaderGDB.h" +#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" #include "lldb/Breakpoint/Breakpoint.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" @@ -26,8 +25,7 @@ #include "lldb/Utility/LLDBAssert.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/StreamString.h" - -#include "JITLoaderGDB.h" +#include "llvm/Support/MathExtras.h" #include @@ -326,20 +324,16 @@ module_sp->GetObjectFile()->GetSymtab(); m_jit_objects.insert(std::make_pair(symbolfile_addr, module_sp)); - if (module_sp->GetObjectFile()->GetPluginName() == - ConstString("mach-o")) { - ObjectFile *image_object_file = module_sp->GetObjectFile(); - if (image_object_file) { - const SectionList *section_list = - image_object_file->GetSectionList(); - if (section_list) { - uint64_t vmaddrheuristic = 0; - uint64_t lower = (uint64_t)-1; - uint64_t upper = 0; - updateSectionLoadAddress(*section_list, target, symbolfile_addr, - symbolfile_size, vmaddrheuristic, lower, - upper); - } + if (auto image_object_file = + llvm::dyn_cast(module_sp->GetObjectFile())) { + const SectionList *section_list = image_object_file->GetSectionList(); + if (section_list) { + uint64_t vmaddrheuristic = 0; + uint64_t lower = (uint64_t)-1; + uint64_t upper = 0; + updateSectionLoadAddress(*section_list, target, symbolfile_addr, + symbolfile_size, vmaddrheuristic, lower, + upper); } } else { bool changed = false; Index: lldb/trunk/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h =================================================================== --- lldb/trunk/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h +++ lldb/trunk/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h @@ -48,6 +48,13 @@ uint32_t GetPluginVersion() override { return 1; } + // LLVM RTTI support + static char ID; + bool isA(const void *ClassID) const override { + return ClassID == &ID || ObjectFile::isA(ClassID); + } + static bool classof(const ObjectFile *obj) { return obj->isA(&ID); } + // ObjectFile Protocol. bool ParseHeader() override; Index: lldb/trunk/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp =================================================================== --- lldb/trunk/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp +++ lldb/trunk/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp @@ -42,6 +42,8 @@ return Header{ArchSpec(triple), std::move(uuid)}; } +char ObjectFileBreakpad::ID; + void ObjectFileBreakpad::Initialize() { PluginManager::RegisterPlugin(GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance, Index: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h =================================================================== --- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h +++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h @@ -89,6 +89,13 @@ uint32_t GetPluginVersion() override; + // LLVM RTTI support + static char ID; + bool isA(const void *ClassID) const override { + return ClassID == &ID || ObjectFile::isA(ClassID); + } + static bool classof(const ObjectFile *obj) { return obj->isA(&ID); } + // ObjectFile Protocol. bool ParseHeader() override; Index: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp =================================================================== --- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -333,6 +333,8 @@ return LLDB_INVALID_CPUTYPE; } +char ObjectFileELF::ID; + // Arbitrary constant used as UUID prefix for core files. const uint32_t ObjectFileELF::g_core_uuid_magic(0xE210C); Index: lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h =================================================================== --- lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h +++ lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h @@ -46,6 +46,13 @@ lldb::offset_t length, lldb_private::ModuleSpecList &specs); + // LLVM RTTI support + static char ID; + bool isA(const void *ClassID) const override { + return ClassID == &ID || ObjectFile::isA(ClassID); + } + static bool classof(const ObjectFile *obj) { return obj->isA(&ID); } + // Member Functions bool ParseHeader() override; Index: lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp =================================================================== --- lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp +++ lldb/trunk/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp @@ -39,6 +39,8 @@ using namespace lldb; using namespace lldb_private; +char ObjectFileJIT::ID; + void ObjectFileJIT::Initialize() { PluginManager::RegisterPlugin(GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance, Index: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h =================================================================== --- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h +++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h @@ -63,6 +63,13 @@ static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset, lldb::addr_t length); + // LLVM RTTI support + static char ID; + bool isA(const void *ClassID) const override { + return ClassID == &ID || ObjectFile::isA(ClassID); + } + static bool classof(const ObjectFile *obj) { return obj->isA(&ID); } + // Member Functions bool ParseHeader() override; Index: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp =================================================================== --- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -830,6 +830,8 @@ #define MACHO_NLIST_ARM_SYMBOL_IS_THUMB 0x0008 +char ObjectFileMachO::ID; + void ObjectFileMachO::Initialize() { PluginManager::RegisterPlugin( GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance, Index: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h =================================================================== --- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h +++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h @@ -85,6 +85,13 @@ static lldb::SymbolType MapSymbolType(uint16_t coff_symbol_type); + // LLVM RTTI support + static char ID; + bool isA(const void *ClassID) const override { + return ClassID == &ID || ObjectFile::isA(ClassID); + } + static bool classof(const ObjectFile *obj) { return obj->isA(&ID); } + bool ParseHeader() override; bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, Index: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp =================================================================== --- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp +++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp @@ -88,6 +88,8 @@ return UUID(); } +char ObjectFilePECOFF::ID; + void ObjectFilePECOFF::Initialize() { PluginManager::RegisterPlugin( GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance, Index: lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp +++ lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp @@ -179,10 +179,7 @@ } uint32_t SymbolFileBreakpad::CalculateAbilities() { - if (!m_objfile_sp) - return 0; - if (m_objfile_sp->GetPluginName() != - ObjectFileBreakpad::GetPluginNameStatic()) + if (!m_objfile_sp || !llvm::isa(*m_objfile_sp)) return 0; return CompileUnits | Functions | LineTables; Index: lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -120,6 +120,8 @@ } OwningBinary binary = std::move(*expected_binary); + // TODO: Avoid opening the PE/COFF binary twice by reading this information + // directly from the lldb_private::ObjectFile. auto *obj = llvm::dyn_cast(binary.getBinary()); if (!obj) return nullptr; Index: lldb/trunk/source/Plugins/SymbolVendor/ELF/CMakeLists.txt =================================================================== --- lldb/trunk/source/Plugins/SymbolVendor/ELF/CMakeLists.txt +++ lldb/trunk/source/Plugins/SymbolVendor/ELF/CMakeLists.txt @@ -5,4 +5,5 @@ lldbCore lldbHost lldbSymbol + lldbPluginObjectFileELF ) Index: lldb/trunk/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp +++ lldb/trunk/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp @@ -10,6 +10,7 @@ #include +#include "Plugins/ObjectFile/ELF/ObjectFileELF.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" @@ -61,15 +62,11 @@ if (!module_sp) return nullptr; - ObjectFile *obj_file = module_sp->GetObjectFile(); + ObjectFileELF *obj_file = + llvm::dyn_cast_or_null(module_sp->GetObjectFile()); if (!obj_file) return nullptr; - static ConstString obj_file_elf("elf"); - ConstString obj_name = obj_file->GetPluginName(); - if (obj_name != obj_file_elf) - return nullptr; - lldb_private::UUID uuid = obj_file->GetUUID(); if (!uuid) return nullptr; Index: lldb/trunk/source/Plugins/SymbolVendor/MacOSX/CMakeLists.txt =================================================================== --- lldb/trunk/source/Plugins/SymbolVendor/MacOSX/CMakeLists.txt +++ lldb/trunk/source/Plugins/SymbolVendor/MacOSX/CMakeLists.txt @@ -7,4 +7,5 @@ lldbCore lldbHost lldbSymbol + lldbPluginObjectFileMachO ) Index: lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp +++ lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp @@ -10,6 +10,7 @@ #include +#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" @@ -97,15 +98,11 @@ if (!module_sp) return NULL; - ObjectFile *obj_file = module_sp->GetObjectFile(); + ObjectFile *obj_file = + llvm::dyn_cast_or_null(module_sp->GetObjectFile()); if (!obj_file) return NULL; - static ConstString obj_file_macho("mach-o"); - ConstString obj_name = obj_file->GetPluginName(); - if (obj_name != obj_file_macho) - return NULL; - static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); Timer scoped_timer(func_cat, "SymbolVendorMacOSX::CreateInstance (module = %s)", Index: lldb/trunk/source/Symbol/ObjectFile.cpp =================================================================== --- lldb/trunk/source/Symbol/ObjectFile.cpp +++ lldb/trunk/source/Symbol/ObjectFile.cpp @@ -26,6 +26,8 @@ using namespace lldb; using namespace lldb_private; +char ObjectFile::ID; + ObjectFileSP ObjectFile::FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file, lldb::offset_t file_offset, lldb::offset_t file_size,