44 llvm::StringRef prefix,
48 :
UserExpression(exe_scope, expr, prefix, language, desired_type, options),
51 m_allow_objc(false), m_transformed_text(), m_execution_unit_sp(),
52 m_materializer_up(), m_jit_module_wp(), m_target(nullptr),
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;
191 if (user_expression_plan) {
193 error_desc = real_stop_info_sp->GetDescription();
197 "Execution was interrupted, reason: %s.",
201 "Execution was interrupted.");
208 "The process has been returned to the state before expression "
214 "The process has been left at the point where it was "
216 "use \"thread return -x\" to return to the state before "
217 "expression evaluation.");
220 return execution_result;
224 "Execution was halted at the first instruction of the expression "
225 "function because \"debug\" was requested.\n"
226 "Use \"thread return -x\" to return to the state before expression "
228 return execution_result;
230 diagnostic_manager.
Printf(
232 "Couldn't complete execution; the thread "
233 "on which the expression was being run: 0x%" PRIx64
234 " exited during its execution.",
236 return execution_result;
238 diagnostic_manager.
Printf(
241 return execution_result;
246 function_stack_bottom, function_stack_top)) {
259 LLDB_LOGF(log,
"-- [UserExpression::FinalizeJITExecution] Dematerializing "
260 "after execution --");
264 "Couldn't apply expression side effects : no "
265 "dematerializer is present");
269 Status dematerialize_error;
274 if (!dematerialize_error.
Success()) {
276 "Couldn't apply expression side effects : %s",
277 dematerialize_error.
AsCString(
"unknown error"));
285 result->TransferAddress();
302 "The context has changed before we could JIT the expression!");
314 const bool zero_memory =
false;
319 lldb::ePermissionsReadable | lldb::ePermissionsWritable, policy,
320 zero_memory, alloc_error);
323 diagnostic_manager.
Printf(
325 "Couldn't allocate space for materialized struct: %s",
336 size_t stack_frame_size = target->GetExprAllocSize();
337 if (stack_frame_size == 0) {
339 if (process && (abi_sp = process->GetABI()))
340 stack_frame_size = abi_sp->GetStackFrameSize();
342 stack_frame_size = 512 * 1024;
345 const bool zero_memory =
false;
349 lldb::ePermissionsReadable | lldb::ePermissionsWritable,
355 diagnostic_manager.
Printf(
357 "Couldn't allocate space for the stack frame: %s",
368 if (!materialize_error.
Success()) {
370 "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
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.
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.
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.
bool Remove(const lldb::ModuleSP &module_sp, bool notify=true)
Remove a module from the module list.
lldb::ExpressionResults RunThreadPlan(ExecutionContext &exe_ctx, lldb::ThreadPlanSP &thread_plan_sp, const EvaluateExpressionOptions &options, DiagnosticManager &diagnostic_manager)
void SetRunningUserExpression(bool on)
static const char * ExecutionResultAsCString(lldb::ExpressionResults result)
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
const ModuleList & GetImages() const
Get accessor for the images for this process.
lldb::addr_t GetFunctionStackPointer()
lldb::StopInfoSP GetRealStopInfo() override
void TransferExpressionOwnership()
Encapsulates a one-time expression for use in lldb.
virtual lldb::ExpressionVariableSP GetResultAfterDematerialization(ExecutionContextScope *exe_scope)
bool LockAndCheckContext(ExecutionContext &exe_ctx, lldb::TargetSP &target_sp, lldb::ProcessSP &process_sp, lldb::StackFrameSP &frame_sp)
#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::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.