[Lldb-commits] [lldb] r333143 - Break dependency from Core to ObjectFileJIT.
Zachary Turner via lldb-commits
lldb-commits at lists.llvm.org
Wed May 23 16:56:09 PDT 2018
Author: zturner
Date: Wed May 23 16:56:09 2018
New Revision: 333143
URL: http://llvm.org/viewvc/llvm-project?rev=333143&view=rev
Log:
Break dependency from Core to ObjectFileJIT.
The only reason this was here was so that Module could have a
function called CreateJITModule which created things in a special
order. Instead of making this specific to creating JIT modules,
I converted this into a template function that can create a module
for any type of object file plugin and just forwards arguments
through. Since the template is not instantiated in Core, the linker
(and header file) dependency moves to the point where it is
instantiated, which only happens in Expression. Conceptually, this
location also makes more sense for a dependency on ObjectFileJIT.
After all, we JIT expressions so it's no surprise that Expression
needs to make use of ObjectFileJIT.
Differential Revision: https://reviews.llvm.org/D47228
Modified:
lldb/trunk/include/lldb/Core/Module.h
lldb/trunk/source/Core/CMakeLists.txt
lldb/trunk/source/Core/Module.cpp
lldb/trunk/source/Expression/CMakeLists.txt
lldb/trunk/source/Expression/IRExecutionUnit.cpp
Modified: lldb/trunk/include/lldb/Core/Module.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=333143&r1=333142&r2=333143&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Module.h (original)
+++ lldb/trunk/include/lldb/Core/Module.h Wed May 23 16:56:09 2018
@@ -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.
Modified: lldb/trunk/source/Core/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/CMakeLists.txt?rev=333143&r1=333142&r2=333143&view=diff
==============================================================================
--- lldb/trunk/source/Core/CMakeLists.txt (original)
+++ lldb/trunk/source/Core/CMakeLists.txt Wed May 23 16:56:09 2018
@@ -69,7 +69,6 @@ add_lldb_library(lldbCore
lldbPluginProcessUtility
lldbPluginCPlusPlusLanguage
lldbPluginObjCLanguage
- lldbPluginObjectFileJIT
${LLDB_CURSES_LIBS}
LINK_COMPONENTS
Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=333143&r1=333142&r2=333143&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Wed May 23 16:56:09 2018
@@ -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 *ve
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();
Modified: lldb/trunk/source/Expression/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/CMakeLists.txt?rev=333143&r1=333142&r2=333143&view=diff
==============================================================================
--- lldb/trunk/source/Expression/CMakeLists.txt (original)
+++ lldb/trunk/source/Expression/CMakeLists.txt Wed May 23 16:56:09 2018
@@ -30,6 +30,7 @@ add_lldb_library(lldbExpression
lldbTarget
lldbUtility
lldbPluginExpressionParserClang
+ lldbPluginObjectFileJIT
LINK_COMPONENTS
Core
Modified: lldb/trunk/source/Expression/IRExecutionUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRExecutionUnit.cpp?rev=333143&r1=333142&r2=333143&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRExecutionUnit.cpp (original)
+++ lldb/trunk/source/Expression/IRExecutionUnit.cpp Wed May 23 16:56:09 2018
@@ -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(ll
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;
}
More information about the lldb-commits
mailing list