Added and improved logging. This is helping us as we
diagnose a problem where we're not correctly emitting
PIC code.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@109568 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/ClangExpression.cpp b/source/Expression/ClangExpression.cpp
index c3bdd7a..d338a09 100644
--- a/source/Expression/ClangExpression.cpp
+++ b/source/Expression/ClangExpression.cpp
@@ -527,6 +527,7 @@
bool
ClangExpression::JITFunction (const ExecutionContext &exc_context, const char *name)
{
+ Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
llvm::Module *module = m_code_generator_ptr->GetModule();
@@ -538,11 +539,41 @@
m_jit_mm_ptr = new RecordingMemoryManager();
//llvm::InitializeNativeTarget();
+
if (m_execution_engine.get() == 0)
- m_execution_engine.reset(llvm::ExecutionEngine::createJIT (module, &error, m_jit_mm_ptr));
+ m_execution_engine.reset(llvm::ExecutionEngine::createJIT (module,
+ &error,
+ m_jit_mm_ptr,
+ CodeGenOpt::Default,
+ true,
+ CodeModel::Default));
+
m_execution_engine->DisableLazyCompilation();
llvm::Function *function = module->getFunction (llvm::StringRef (name));
-
+
+ if (log)
+ {
+ const char *relocation_model_string;
+
+ switch (llvm::TargetMachine::getRelocationModel())
+ {
+ case llvm::Reloc::Default:
+ relocation_model_string = "Default";
+ break;
+ case llvm::Reloc::Static:
+ relocation_model_string = "Static";
+ break;
+ case llvm::Reloc::PIC_:
+ relocation_model_string = "PIC_++";
+ break;
+ case llvm::Reloc::DynamicNoPIC:
+ relocation_model_string = "DynamicNoPIC";
+ break;
+ }
+
+ log->Printf("Target machine's relocation model: %s", relocation_model_string);
+ }
+
// We don't actually need the function pointer here, this just forces it to get resolved.
void *fun_ptr = m_execution_engine->getPointerToFunction(function);
// Note, you probably won't get here on error, since the LLVM JIT tends to just
@@ -558,6 +589,8 @@
bool
ClangExpression::WriteJITCode (const ExecutionContext &exc_context)
{
+ Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
+
if (m_jit_mm_ptr == NULL)
return false;
@@ -586,6 +619,9 @@
lldb::addr_t cursor = target_addr;
for (fun_pos = m_jit_mm_ptr->m_functions.begin(); fun_pos != fun_end; fun_pos++)
{
+ if (log)
+ log->Printf("Reading [%p-%p] from m_functions", fun_pos->first, fun_pos->second);
+
lldb::addr_t lstart = (lldb::addr_t) (*fun_pos).first;
lldb::addr_t lend = (lldb::addr_t) (*fun_pos).second;
size_t size = lend - lstart;