45 llvm::StringRef prefix,
49 :
UserExpression(exe_scope, expr, prefix, language, desired_type, options),
60 m_target->GetImages().Remove(jit_module_sp);
78 "Expression can't be run, because there is no JIT compiled function");
88 "errored out in %s, couldn't PrepareToExecuteJITExpression",
100 if (!module || !function) {
108 std::vector<lldb::addr_t> args;
110 if (!
AddArguments(exe_ctx, args, struct_address, diagnostic_manager)) {
112 "errored out in %s, couldn't AddArguments",
121 interpreter_error, function_stack_bottom,
122 function_stack_top, exe_ctx, options.
GetTimeout());
124 if (!interpreter_error.
Success()) {
126 "supposed to interpret, but failed: %s",
133 "%s called with no thread selected",
144 std::vector<lldb::addr_t> args;
146 if (!
AddArguments(exe_ctx, args, struct_address, diagnostic_manager)) {
148 "errored out in %s, couldn't AddArguments",
158 if (!call_plan_sp || !call_plan_sp->ValidatePlan(&ss)) {
169 function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize();
170 function_stack_top = function_stack_pointer;
173 "-- [UserExpression::Execute] Execution of expression begins --");
188 LLDB_LOGF(log,
"-- [UserExpression::Execute] Execution of expression "
193 const char *error_desc =
nullptr;
196 :
"hit a breakpoint";
198 if (user_expression_plan) {
200 error_desc = real_stop_info_sp->GetDescription();
205 "Expression execution %s: %s.", explanation,
209 "Expression execution %s.", explanation);
216 "The process has been returned to the state before expression "
222 "The process has been left at the point where it was "
223 "interrupted, use \"thread return -x\" to return to the state "
224 "before expression evaluation.");
227 return execution_result;
233 "Expression execution was halted at the first instruction of the "
234 "expression function because \"debug\" was requested.\n"
235 "Use \"thread return -x\" to return to the state before expression "
237 return execution_result;
242 "Couldn't execute expression: the thread on "
243 "which the expression was being run (0x%" PRIx64
244 ") exited during its execution.",
246 return execution_result;
251 "Couldn't execute expression: result was %s",
252 toString(execution_result).c_str());
253 return execution_result;
258 function_stack_bottom, function_stack_top))
270 LLDB_LOGF(log,
"-- [UserExpression::FinalizeJITExecution] Dematerializing "
271 "after execution --");
275 "Couldn't apply expression side effects : no "
276 "dematerializer is present");
280 Status dematerialize_error;
285 if (!dematerialize_error.
Success()) {
287 "Couldn't apply expression side effects : %s",
288 dematerialize_error.
AsCString(
"unknown error"));
299 result->PreserveDynamicOption(options->GetUseDynamic());
300 result->TransferAddress();
318 "The context has changed before we could JIT the expression!");
328 const bool zero_memory =
false;
332 lldb::ePermissionsReadable | lldb::ePermissionsWritable, policy,
336 diagnostic_manager.
Printf(
338 "Couldn't allocate space for materialized struct: %s",
339 toString(address_or_error.takeError()).c_str());
347 size_t stack_frame_size = target->GetExprAllocSize();
348 if (stack_frame_size == 0) {
350 if (process && (abi_sp = process->GetABI()))
351 stack_frame_size = abi_sp->GetStackFrameSize();
353 stack_frame_size = 512 * 1024;
356 const bool zero_memory =
false;
359 lldb::ePermissionsReadable | lldb::ePermissionsWritable,
364 diagnostic_manager.
Printf(
366 "Couldn't allocate space for the stack frame: %s",
367 toString(address_or_error.takeError()).c_str());
377 if (!materialize_error.
Success()) {
379 "Couldn't materialize: %s",
#define LLDB_LOGF(log,...)
static bool Interpret(llvm::Module &module, llvm::Function &function, llvm::ArrayRef< lldb::addr_t > args, lldb_private::IRExecutionUnit &execution_unit, lldb_private::Status &error, lldb::addr_t stack_frame_bottom, lldb::addr_t stack_frame_top, lldb_private::ExecutionContext &exe_ctx, lldb_private::Timeout< std::micro > timeout)
A section + offset based address class.
size_t void PutString(lldb::Severity severity, llvm::StringRef str)
void AppendMessageToDiagnostic(llvm::StringRef str)
size_t Printf(lldb::Severity severity, const char *format,...) __attribute__((format(printf
bool DoesIgnoreBreakpoints() const
bool DoesUnwindOnError() const
const Timeout< std::micro > & GetTimeout() const
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool HasThreadScope() const
Returns true the ExecutionContext object contains a valid target, process, and thread.
ExecutionContextScope * GetBestExecutionContextScope() const
Process & GetProcessRef() const
Returns a reference to the process object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
Thread & GetThreadRef() const
Returns a reference to the thread object.
lldb::addr_t m_jit_start_addr
An expression might have a process, but it doesn't need to (e.g.
@ eAllocationPolicyHostOnly
This allocation was created in the host and will never make it into the process.
@ eAllocationPolicyMirror
The intent is that this allocation exist both in the host and the process and have the same content i...
lldb::ExpressionResults DoExecute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options, lldb::UserExpressionSP &shared_ptr_to_me, lldb::ExpressionVariableSP &result) override
std::string m_transformed_text
The text of the expression, as send to the parser.
bool m_can_interpret
True if the expression could be evaluated statically; false otherwise.
std::unique_ptr< Materializer > m_materializer_up
The materializer to use when running the expression.
bool m_allow_cxx
True if the language allows C++.
Target * m_target
The target for storing persistent data like types and variables.
bool FinalizeJITExecution(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, lldb::ExpressionVariableSP &result, lldb::addr_t function_stack_bottom=LLDB_INVALID_ADDRESS, lldb::addr_t function_stack_top=LLDB_INVALID_ADDRESS) override
Apply the side effects of the function to program state.
bool PrepareToExecuteJITExpression(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, lldb::addr_t &struct_address)
~LLVMUserExpression() override
lldb::ModuleWP m_jit_module_wp
lldb::addr_t m_stack_frame_bottom
The bottom of the allocated stack frame.
LLVMUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr, llvm::StringRef prefix, SourceLanguage language, ResultType desired_type, const EvaluateExpressionOptions &options)
std::shared_ptr< IRExecutionUnit > m_execution_unit_sp
The execution unit the expression is stored in.
bool m_allow_objc
True if the language allows Objective-C.
Materializer::DematerializerSP m_dematerializer_sp
The dematerializer.
lldb::addr_t m_stack_frame_top
The top of the allocated stack frame.
virtual bool AddArguments(ExecutionContext &exe_ctx, std::vector< lldb::addr_t > &args, lldb::addr_t struct_address, DiagnosticManager &diagnostic_manager)=0
lldb::addr_t m_materialized_address
The address at which the arguments to the expression have been materialized.
RAII guard that pops a policy on destruction.
Guard PushPublicStateRunningExpression()
static PolicyStack & Get()
lldb::ExpressionResults RunThreadPlan(ExecutionContext &exe_ctx, lldb::ThreadPlanSP &thread_plan_sp, const EvaluateExpressionOptions &options, DiagnosticManager &diagnostic_manager)
void SetRunningUserExpression(bool on)
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
bool Success() const
Test for success condition.
llvm::StringRef GetString() const
lldb::addr_t GetFunctionStackPointer()
lldb::StopInfoSP GetRealStopInfo() override
void TransferExpressionOwnership()
virtual lldb::ExpressionVariableSP GetResultAfterDematerialization(ExecutionContextScope *exe_scope)
bool LockAndCheckContext(ExecutionContext &exe_ctx, lldb::TargetSP &target_sp, lldb::ProcessSP &process_sp, lldb::StackFrameSP &frame_sp)
UserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr, llvm::StringRef prefix, SourceLanguage language, ResultType desired_type, const EvaluateExpressionOptions &options)
Constructor.
EvaluateExpressionOptions * GetOptions() override
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::string toString(FormatterBytecode::OpCodes op)
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
std::shared_ptr< lldb_private::ABI > ABISP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::ExpressionVariable > ExpressionVariableSP
std::shared_ptr< lldb_private::UserExpression > UserExpressionSP
ExpressionResults
The results of expression evaluation.
@ eExpressionHitBreakpoint
@ eExpressionStoppedForDebug
@ eExpressionResultUnavailable
@ eExpressionThreadVanished
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP
A type-erased pair of llvm::dwarf::SourceLanguageName and version.
lldb::user_id_t GetID() const
Get accessor for the user ID.