Fixed a problem where expressions would attempt to
allocate memory in a process that did not support
expression execution. Also improved detection of
whether or not a process can execute expressions.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@140202 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/lldb/Target/Process.h b/include/lldb/Target/Process.h
index 3bf87f9..fbf85a3 100644
--- a/include/lldb/Target/Process.h
+++ b/include/lldb/Target/Process.h
@@ -2301,6 +2301,24 @@
AllocateMemory (size_t size, uint32_t permissions, Error &error);
//------------------------------------------------------------------
+ /// Determines whether executing JIT-compiled code in this process
+ /// is possible.
+ ///
+ /// @return
+ /// True if execution of JIT code is possible; false otherwise.
+ //------------------------------------------------------------------
+ bool CanJIT ();
+
+ //------------------------------------------------------------------
+ /// Sets whether executing JIT-compiled code in this process
+ /// is possible.
+ ///
+ /// @param[in] can_jit
+ /// True if execution of JIT code is possible; false otherwise.
+ //------------------------------------------------------------------
+ void SetCanJIT (bool can_jit);
+
+ //------------------------------------------------------------------
/// Actually deallocate memory in the process.
///
/// This function will deallocate memory in the process's address
@@ -2771,6 +2789,12 @@
LanguageRuntimeCollection m_language_runtimes;
std::auto_ptr<NextEventAction> m_next_event_action_ap;
+ enum {
+ eCanJITDontKnow= 0,
+ eCanJITYes,
+ eCanJITNo
+ } m_can_jit;
+
size_t
RemoveBreakpointOpcodesFromBuffer (lldb::addr_t addr, size_t size, uint8_t *buf) const;
diff --git a/source/Expression/ClangExpressionParser.cpp b/source/Expression/ClangExpressionParser.cpp
index 921dc00..3549196 100644
--- a/source/Expression/ClangExpressionParser.cpp
+++ b/source/Expression/ClangExpressionParser.cpp
@@ -496,8 +496,32 @@
return err;
}
- if (m_expr.NeedsValidation() && exe_ctx.process && exe_ctx.process->GetDynamicCheckers())
+ if (execution_policy != eExecutionPolicyNever &&
+ m_expr.NeedsValidation() &&
+ exe_ctx.process)
{
+ if (!exe_ctx.process->GetDynamicCheckers())
+ {
+ DynamicCheckerFunctions *dynamic_checkers = new DynamicCheckerFunctions();
+
+ StreamString install_errors;
+
+ if (!dynamic_checkers->Install(install_errors, exe_ctx))
+ {
+ if (install_errors.GetString().empty())
+ err.SetErrorString ("couldn't install checkers, unknown error");
+ else
+ err.SetErrorString (install_errors.GetString().c_str());
+
+ return err;
+ }
+
+ exe_ctx.process->SetDynamicCheckers(dynamic_checkers);
+
+ if (log)
+ log->Printf("== [ClangUserExpression::Evaluate] Finished installing dynamic checkers ==");
+ }
+
IRDynamicChecks ir_dynamic_checks(*exe_ctx.process->GetDynamicCheckers(), function_name.c_str());
if (!ir_dynamic_checks.runOnModule(*module))
diff --git a/source/Expression/ClangUserExpression.cpp b/source/Expression/ClangUserExpression.cpp
index 742367f..194ad95 100644
--- a/source/Expression/ClangUserExpression.cpp
+++ b/source/Expression/ClangUserExpression.cpp
@@ -615,34 +615,8 @@
}
}
- if (exe_ctx.process == NULL)
+ if (exe_ctx.process == NULL || !exe_ctx.process->CanJIT())
execution_policy = eExecutionPolicyNever;
-
- if (execution_policy != eExecutionPolicyNever && !exe_ctx.process->GetDynamicCheckers())
- {
- if (log)
- log->Printf("== [ClangUserExpression::Evaluate] Installing dynamic checkers ==");
-
- DynamicCheckerFunctions *dynamic_checkers = new DynamicCheckerFunctions();
-
- StreamString install_errors;
-
- if (!dynamic_checkers->Install(install_errors, exe_ctx))
- {
- if (install_errors.GetString().empty())
- error.SetErrorString ("couldn't install checkers, unknown error");
- else
- error.SetErrorString (install_errors.GetString().c_str());
-
- result_valobj_sp = ValueObjectConstResult::Create (NULL, error);
- return eExecutionSetupError;
- }
-
- exe_ctx.process->SetDynamicCheckers(dynamic_checkers);
-
- if (log)
- log->Printf("== [ClangUserExpression::Evaluate] Finished installing dynamic checkers ==");
- }
ClangUserExpressionSP user_expression_sp (new ClangUserExpression (expr_cstr, expr_prefix));
diff --git a/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index e5f6155..6628f92 100644
--- a/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ b/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -78,7 +78,10 @@
}
if (create)
+ {
+ process->SetCanJIT(false);
return new DynamicLoaderDarwinKernel (process);
+ }
return NULL;
}
diff --git a/source/Target/Process.cpp b/source/Target/Process.cpp
index 14f26d2..bab1eda 100644
--- a/source/Target/Process.cpp
+++ b/source/Target/Process.cpp
@@ -601,7 +601,8 @@
m_memory_cache (*this),
m_allocated_memory_cache (*this),
m_attached_to_process (false),
- m_next_event_action_ap()
+ m_next_event_action_ap(),
+ m_can_jit(eCanJITYes)
{
UpdateInstanceName();
@@ -1956,6 +1957,18 @@
#endif
}
+bool
+Process::CanJIT ()
+{
+ return m_can_jit == eCanJITYes;
+}
+
+void
+Process::SetCanJIT (bool can_jit)
+{
+ m_can_jit = (can_jit ? eCanJITYes : eCanJITNo);
+}
+
Error
Process::DeallocateMemory (addr_t ptr)
{