summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2019-07-31 11:57:34 +0000
committerPavel Labath <pavel@labath.sk>2019-07-31 11:57:34 +0000
commite84f78412bb6cf06e7ff35cb49da60596f582aa7 (patch)
tree1bbeff32b511cb6b91a5c210e0f188517db0c5bb
parent24e4e8087f3af2f3df1d5447006d0bb87c0ebd8b (diff)
downloadbcm5719-llvm-e84f78412bb6cf06e7ff35cb49da60596f582aa7.tar.gz
bcm5719-llvm-e84f78412bb6cf06e7ff35cb49da60596f582aa7.zip
Add llvm-style RTTI to ObjectFile hierarchy
Summary: On the heels of D62934, this patch uses the same approach to introduce llvm RTTI support to the ObjectFile hierarchy. It also replaces the existing uses of GetPluginName doing run-time type checks with llvm::dyn_cast and friends. This formally introduces new dependencies from some other plugins to ObjectFile plugins. However, I believe this is fine because: - these dependencies were already kind of there, and the only reason we could get away with not modeling them explicitly was because the code was relying on magically knowing what will GetPluginName() return for a particular kind of object files. - the dependencies themselves are logical (it makes sense for SymbolVendorELF to depend on ObjectFileELF), or at least don't actively get in the way (the JitLoaderGDB->MachO thing). - they don't introduce any new dependency loops as ObjectFile plugins don't depend on any other plugins Reviewers: xiaobai, JDevlieghere, espindola Subscribers: emaste, mgorny, arichardson, MaskRay, lldb-commits Differential Revision: https://reviews.llvm.org/D65450 llvm-svn: 367413
-rw-r--r--lldb/include/lldb/Symbol/ObjectFile.h4
-rw-r--r--lldb/source/Plugins/JITLoader/GDB/CMakeLists.txt1
-rw-r--r--lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp32
-rw-r--r--lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp2
-rw-r--r--lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h7
-rw-r--r--lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp2
-rw-r--r--lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h7
-rw-r--r--lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp2
-rw-r--r--lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h7
-rw-r--r--lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp2
-rw-r--r--lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h7
-rw-r--r--lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp2
-rw-r--r--lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h7
-rw-r--r--lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp5
-rw-r--r--lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp2
-rw-r--r--lldb/source/Plugins/SymbolVendor/ELF/CMakeLists.txt1
-rw-r--r--lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp9
-rw-r--r--lldb/source/Plugins/SymbolVendor/MacOSX/CMakeLists.txt1
-rw-r--r--lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp9
-rw-r--r--lldb/source/Symbol/ObjectFile.cpp2
20 files changed, 76 insertions, 35 deletions
diff --git a/lldb/include/lldb/Symbol/ObjectFile.h b/lldb/include/lldb/Symbol/ObjectFile.h
index 84683e3f2a3..76cc05523e4 100644
--- a/lldb/include/lldb/Symbol/ObjectFile.h
+++ b/lldb/include/lldb/Symbol/ObjectFile.h
@@ -204,6 +204,10 @@ public:
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
diff --git a/lldb/source/Plugins/JITLoader/GDB/CMakeLists.txt b/lldb/source/Plugins/JITLoader/GDB/CMakeLists.txt
index 774d85b16a2..ecdff2823d4 100644
--- a/lldb/source/Plugins/JITLoader/GDB/CMakeLists.txt
+++ b/lldb/source/Plugins/JITLoader/GDB/CMakeLists.txt
@@ -16,6 +16,7 @@ add_lldb_library(lldbPluginJITLoaderGDB PLUGIN
lldbSymbol
lldbTarget
lldbUtility
+ lldbPluginObjectFileMachO
LINK_COMPONENTS
Support
)
diff --git a/lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp b/lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
index 0593af4caad..2aa284f2a5c 100644
--- a/lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
+++ b/lldb/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 <memory>
@@ -326,20 +324,16 @@ bool JITLoaderGDB::ReadJITDescriptorImpl(bool all_entries) {
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<ObjectFileMachO>(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;
diff --git a/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp b/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
index 60dd9f9cecf..f895e9cbc2e 100644
--- a/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
+++ b/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
@@ -42,6 +42,8 @@ llvm::Optional<Header> Header::parse(llvm::StringRef text) {
return Header{ArchSpec(triple), std::move(uuid)};
}
+char ObjectFileBreakpad::ID;
+
void ObjectFileBreakpad::Initialize() {
PluginManager::RegisterPlugin(GetPluginNameStatic(),
GetPluginDescriptionStatic(), CreateInstance,
diff --git a/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h b/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
index e8885e0cc89..2ce6a343cf0 100644
--- a/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
+++ b/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
@@ -48,6 +48,13 @@ public:
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;
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 37f61456a7e..b107afc1d81 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -333,6 +333,8 @@ static uint32_t subTypeFromElfHeader(const elf::ELFHeader &header) {
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);
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index 8abe9951d4e..2a213771aad 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -89,6 +89,13 @@ public:
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;
diff --git a/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp b/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
index eaf973da383..c55b96d9110 100644
--- a/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
+++ b/lldb/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,
diff --git a/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h b/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
index 99241126cd1..c992683cfc3 100644
--- a/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
+++ b/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
@@ -46,6 +46,13 @@ public:
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;
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 1007dbbe12e..bfb732b836f 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -830,6 +830,8 @@ static uint32_t MachHeaderSizeFromMagic(uint32_t magic) {
#define MACHO_NLIST_ARM_SYMBOL_IS_THUMB 0x0008
+char ObjectFileMachO::ID;
+
void ObjectFileMachO::Initialize() {
PluginManager::RegisterPlugin(
GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
index 2326873ed41..1185e1ec899 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
@@ -63,6 +63,13 @@ public:
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;
diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
index 1ab9ce848f9..d2dd934c357 100644
--- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
@@ -88,6 +88,8 @@ static UUID GetCoffUUID(llvm::object::COFFObjectFile *coff_obj) {
return UUID();
}
+char ObjectFilePECOFF::ID;
+
void ObjectFilePECOFF::Initialize() {
PluginManager::RegisterPlugin(
GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
index 6aa9eba4ec1..68ea7a7270c 100644
--- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
+++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
@@ -85,6 +85,13 @@ public:
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,
diff --git a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
index ef034292839..551ef901f52 100644
--- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
+++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
@@ -179,10 +179,7 @@ ConstString SymbolFileBreakpad::GetPluginNameStatic() {
}
uint32_t SymbolFileBreakpad::CalculateAbilities() {
- if (!m_objfile_sp)
- return 0;
- if (m_objfile_sp->GetPluginName() !=
- ObjectFileBreakpad::GetPluginNameStatic())
+ if (!m_objfile_sp || !llvm::isa<ObjectFileBreakpad>(*m_objfile_sp))
return 0;
return CompileUnits | Functions | LineTables;
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
index cd0ffd753ff..b12b51ba5a1 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -120,6 +120,8 @@ loadMatchingPDBFile(std::string exe_path, llvm::BumpPtrAllocator &allocator) {
}
OwningBinary<Binary> 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<llvm::object::COFFObjectFile>(binary.getBinary());
if (!obj)
return nullptr;
diff --git a/lldb/source/Plugins/SymbolVendor/ELF/CMakeLists.txt b/lldb/source/Plugins/SymbolVendor/ELF/CMakeLists.txt
index e742fac9312..86562c47518 100644
--- a/lldb/source/Plugins/SymbolVendor/ELF/CMakeLists.txt
+++ b/lldb/source/Plugins/SymbolVendor/ELF/CMakeLists.txt
@@ -5,4 +5,5 @@ add_lldb_library(lldbPluginSymbolVendorELF PLUGIN
lldbCore
lldbHost
lldbSymbol
+ lldbPluginObjectFileELF
)
diff --git a/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp b/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
index f279af61a13..92953f0a72f 100644
--- a/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
+++ b/lldb/source/Plugins/SymbolVendor/ELF/SymbolVendorELF.cpp
@@ -10,6 +10,7 @@
#include <string.h>
+#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 @@ SymbolVendorELF::CreateInstance(const lldb::ModuleSP &module_sp,
if (!module_sp)
return nullptr;
- ObjectFile *obj_file = module_sp->GetObjectFile();
+ ObjectFileELF *obj_file =
+ llvm::dyn_cast_or_null<ObjectFileELF>(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;
diff --git a/lldb/source/Plugins/SymbolVendor/MacOSX/CMakeLists.txt b/lldb/source/Plugins/SymbolVendor/MacOSX/CMakeLists.txt
index bbcdff9705a..8e82eae1513 100644
--- a/lldb/source/Plugins/SymbolVendor/MacOSX/CMakeLists.txt
+++ b/lldb/source/Plugins/SymbolVendor/MacOSX/CMakeLists.txt
@@ -7,4 +7,5 @@ add_lldb_library(lldbPluginSymbolVendorMacOSX PLUGIN
lldbCore
lldbHost
lldbSymbol
+ lldbPluginObjectFileMachO
)
diff --git a/lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp b/lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
index af9ea0af7ad..857f4f05b83 100644
--- a/lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
+++ b/lldb/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
@@ -10,6 +10,7 @@
#include <string.h>
+#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 @@ SymbolVendorMacOSX::CreateInstance(const lldb::ModuleSP &module_sp,
if (!module_sp)
return NULL;
- ObjectFile *obj_file = module_sp->GetObjectFile();
+ ObjectFile *obj_file =
+ llvm::dyn_cast_or_null<ObjectFileMachO>(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)",
diff --git a/lldb/source/Symbol/ObjectFile.cpp b/lldb/source/Symbol/ObjectFile.cpp
index 35510a25495..f0981a8cd12 100644
--- a/lldb/source/Symbol/ObjectFile.cpp
+++ b/lldb/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,
OpenPOWER on IntegriCloud