diff options
-rw-r--r-- | lldb/include/lldb/Core/Module.h | 19 | ||||
-rw-r--r-- | lldb/source/Core/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lldb/source/Core/Module.cpp | 21 | ||||
-rw-r--r-- | lldb/source/Expression/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lldb/source/Expression/IRExecutionUnit.cpp | 26 |
5 files changed, 33 insertions, 35 deletions
diff --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h index 9bc642835cd..82c6bf8696c 100644 --- a/lldb/include/lldb/Core/Module.h +++ b/lldb/include/lldb/Core/Module.h @@ -155,8 +155,23 @@ public: Module(const ModuleSpec &module_spec); - static lldb::ModuleSP - CreateJITModule(const lldb::ObjectFileJITDelegateSP &delegate_sp); + template <typename ObjFilePlugin, typename... Args> + static lldb::ModuleSP CreateModuleFromObjectFile(Args &&... args) { + // Must create a module and place it into a shared pointer before we can + // create an object file since it has a std::weak_ptr back to the module, + // so we need to control the creation carefully in this static function + lldb::ModuleSP module_sp(new Module()); + module_sp->m_objfile_sp = + std::make_shared<ObjFilePlugin>(module_sp, std::forward<Args>(args)...); + + // Once we get the object file, update our module with the object file's + // architecture since it might differ in vendor/os if some parts were + // unknown. + if (!module_sp->m_objfile_sp->GetArchitecture(module_sp->m_arch)) + return nullptr; + + return module_sp; + } //------------------------------------------------------------------ /// Destructor. diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt index cac56e29fc1..64c56611ced 100644 --- a/lldb/source/Core/CMakeLists.txt +++ b/lldb/source/Core/CMakeLists.txt @@ -69,7 +69,6 @@ add_lldb_library(lldbCore lldbPluginProcessUtility lldbPluginCPlusPlusLanguage lldbPluginObjCLanguage - lldbPluginObjectFileJIT ${LLDB_CURSES_LIBS} LINK_COMPONENTS diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 88e5b582d3d..b6b89078491 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -53,7 +53,6 @@ #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" #include "Plugins/Language/ObjC/ObjCLanguage.h" -#include "Plugins/ObjectFile/JIT/ObjectFileJIT.h" #include "llvm/ADT/STLExtras.h" // for make_unique #include "llvm/Support/Compiler.h" // for LLVM_PRETT... @@ -1652,26 +1651,6 @@ uint32_t Module::GetVersion(uint32_t *versions, uint32_t num_versions) { return 0; } -ModuleSP -Module::CreateJITModule(const lldb::ObjectFileJITDelegateSP &delegate_sp) { - if (delegate_sp) { - // Must create a module and place it into a shared pointer before we can - // create an object file since it has a std::weak_ptr back to the module, - // so we need to control the creation carefully in this static function - ModuleSP module_sp(new Module()); - module_sp->m_objfile_sp = - std::make_shared<ObjectFileJIT>(module_sp, delegate_sp); - if (module_sp->m_objfile_sp) { - // Once we get the object file, update our module with the object file's - // architecture since it might differ in vendor/os if some parts were - // unknown. - module_sp->m_objfile_sp->GetArchitecture(module_sp->m_arch); - } - return module_sp; - } - return ModuleSP(); -} - bool Module::GetIsDynamicLinkEditor() { ObjectFile *obj_file = GetObjectFile(); diff --git a/lldb/source/Expression/CMakeLists.txt b/lldb/source/Expression/CMakeLists.txt index 7d9643a45dd..020d470ed12 100644 --- a/lldb/source/Expression/CMakeLists.txt +++ b/lldb/source/Expression/CMakeLists.txt @@ -30,6 +30,7 @@ add_lldb_library(lldbExpression lldbTarget lldbUtility lldbPluginExpressionParserClang + lldbPluginObjectFileJIT LINK_COMPONENTS Core diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp index 298ad10e9dd..e34a4c7fac5 100644 --- a/lldb/source/Expression/IRExecutionUnit.cpp +++ b/lldb/source/Expression/IRExecutionUnit.cpp @@ -33,6 +33,7 @@ #include "lldb/Utility/Log.h" #include "lldb/../../source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" +#include "lldb/../../source/Plugins/ObjectFile/JIT/ObjectFileJIT.h" using namespace lldb_private; @@ -1225,15 +1226,18 @@ bool IRExecutionUnit::GetArchitecture(lldb_private::ArchSpec &arch) { lldb::ModuleSP IRExecutionUnit::GetJITModule() { ExecutionContext exe_ctx(GetBestExecutionContextScope()); Target *target = exe_ctx.GetTargetPtr(); - if (target) { - lldb::ModuleSP jit_module_sp = lldb_private::Module::CreateJITModule( - std::static_pointer_cast<lldb_private::ObjectFileJITDelegate>( - shared_from_this())); - if (jit_module_sp) { - bool changed = false; - jit_module_sp->SetLoadAddress(*target, 0, true, changed); - } - return jit_module_sp; - } - return lldb::ModuleSP(); + if (!target) + return nullptr; + + auto Delegate = std::static_pointer_cast<lldb_private::ObjectFileJITDelegate>( + shared_from_this()); + + lldb::ModuleSP jit_module_sp = + lldb_private::Module::CreateModuleFromObjectFile<ObjectFileJIT>(Delegate); + if (!jit_module_sp) + return nullptr; + + bool changed = false; + jit_module_sp->SetLoadAddress(*target, 0, true, changed); + return jit_module_sp; } |