44 llvm::StringRef prefix,
48 :
UserExpression(exe_scope, expr, prefix, language, desired_type, options),
59 m_target->GetImages().Remove(jit_module_sp);
77 "Expression can't be run, because there is no JIT compiled function");
87 "errored out in %s, couldn't PrepareToExecuteJITExpression",
99 if (!module || !function) {
107 std::vector<lldb::addr_t> args;
109 if (!
AddArguments(exe_ctx, args, struct_address, diagnostic_manager)) {
111 "errored out in %s, couldn't AddArguments",
120 interpreter_error, function_stack_bottom,
121 function_stack_top, exe_ctx, options.
GetTimeout());
123 if (!interpreter_error.
Success()) {
125 "supposed to interpret, but failed: %s",
132 "%s called with no thread selected",
143 std::vector<lldb::addr_t> args;
145 if (!
AddArguments(exe_ctx, args, struct_address, diagnostic_manager)) {
147 "errored out in %s, couldn't AddArguments",
157 if (!call_plan_sp || !call_plan_sp->ValidatePlan(&ss)) {
168 function_stack_bottom = function_stack_pointer - HostInfo::GetPageSize();
169 function_stack_top = function_stack_pointer;
172 "-- [UserExpression::Execute] Execution of expression begins --");
184 LLDB_LOGF(log,
"-- [UserExpression::Execute] Execution of expression "
189 const char *error_desc =
nullptr;
192 :
"hit a breakpoint";
194 if (user_expression_plan) {
196 error_desc = real_stop_info_sp->GetDescription();
201 "Expression execution %s: %s.", explanation,
205 "Expression execution %s.", explanation);
212 "The process has been returned to the state before expression "
218 "The process has been left at the point where it was "
219 "interrupted, use \"thread return -x\" to return to the state "
220 "before expression evaluation.");
223 return execution_result;
229 "Expression execution was halted at the first instruction of the "
230 "expression function because \"debug\" was requested.\n"
231 "Use \"thread return -x\" to return to the state before expression "
233 return execution_result;
238 "Couldn't execute expression: the thread on "
239 "which the expression was being run (0x%" PRIx64
240 ") exited during its execution.",
242 return execution_result;
247 "Couldn't execute expression: result was %s",
248 toString(execution_result).c_str());
249 return execution_result;
254 function_stack_bottom, function_stack_top)) {
267 LLDB_LOGF(log,
"-- [UserExpression::FinalizeJITExecution] Dematerializing "
268 "after execution --");
272 "Couldn't apply expression side effects : no "
273 "dematerializer is present");
277 Status dematerialize_error;
282 if (!dematerialize_error.
Success()) {
284 "Couldn't apply expression side effects : %s",
285 dematerialize_error.
AsCString(
"unknown error"));
293 result->TransferAddress();
310 "The context has changed before we could JIT the expression!");
320 const bool zero_memory =
false;
324 lldb::ePermissionsReadable | lldb::ePermissionsWritable, policy,
328 diagnostic_manager.
Printf(
330 "Couldn't allocate space for materialized struct: %s",
331 toString(address_or_error.takeError()).c_str());
339 size_t stack_frame_size = target->GetExprAllocSize();
340 if (stack_frame_size == 0) {
342 if (process && (abi_sp = process->GetABI()))
343 stack_frame_size = abi_sp->GetStackFrameSize();
345 stack_frame_size = 512 * 1024;
348 const bool zero_memory =
false;
351 lldb::ePermissionsReadable | lldb::ePermissionsWritable,
356 diagnostic_manager.
Printf(
358 "Couldn't allocate space for the stack frame: %s",
359 toString(address_or_error.takeError()).c_str());
369 if (!materialize_error.
Success()) {
371 "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.
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.
#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.
const char * toString(AppleArm64ExceptionClass EC)
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.