49 llvm::StringRef expr, llvm::StringRef prefix,
53 :
Expression(exe_scope), m_expr_text(std::string(expr)),
54 m_expr_prefix(std::string(prefix)), m_language(language),
55 m_desired_type(desired_type), m_options(options) {}
62 lldb::StackFrameSP frame_sp = exe_ctx.
GetFrameSP();
65 m_address = frame_sp->GetFrameCodeAddress();
69 lldb::TargetSP &target_sp,
70 lldb::ProcessSP &process_sp,
71 lldb::StackFrameSP &frame_sp) {
75 if (process_sp != expected_process_sp)
86 frame_sp->GetFrameCodeAddress(),
87 target_sp.get()) == 0);
94 lldb::TargetSP target_sp;
95 lldb::ProcessSP process_sp;
96 lldb::StackFrameSP frame_sp;
107 "Couldn't load '%s' because the context is incomplete",
112 lldb::VariableSP var_sp;
113 lldb::ValueObjectSP valobj_sp;
115 return frame_sp->GetValueForVariableExpressionPath(
130 if (!err.
Success() || !valobj_sp.get())
137 "Couldn't load '%s' because its value couldn't be evaluated",
148 llvm::StringRef expr, llvm::StringRef prefix,
149 lldb::ValueObjectSP &result_valobj_sp,
Status &
error,
150 std::string *fixed_expression,
ValueObject *ctx_obj) {
154 static unsigned const ctx_type_mask = lldb::TypeFlags::eTypeIsClass |
155 lldb::TypeFlags::eTypeIsStructUnion |
156 lldb::TypeFlags::eTypeIsReference;
158 LLDB_LOG(log,
"== [UserExpression::Evaluate] Passed a context object of "
159 "an invalid type, can't run expressions.");
160 error.SetErrorString(
"a context object of an invalid type passed");
165 if (ctx_obj && ctx_obj->
GetTypeInfo() & lldb::TypeFlags::eTypeIsReference) {
168 if (!
error.Success()) {
169 LLDB_LOG(log,
"== [UserExpression::Evaluate] Passed a context object of "
170 "a reference type that can't be dereferenced, can't run "
172 error.SetErrorString(
173 "passed context object of an reference type cannot be deferenced");
177 ctx_obj = deref_ctx_sp.get();
189 LLDB_LOG(log,
"== [UserExpression::Evaluate] Passed a NULL target, can't "
191 error.SetErrorString(
"expression passed a null target");
198 LLDB_LOG(log,
"== [UserExpression::Evaluate] No process, but the policy is "
199 "eExecutionPolicyAlways");
201 error.SetErrorString(
"expression needed to run but couldn't: no process");
203 return execution_results;
208 error.SetErrorString(
"Can't make a function caller while the process is "
210 return execution_results;
219 (process ==
nullptr || !process->
CanJIT()))
229 llvm::StringRef full_prefix;
230 llvm::StringRef option_prefix(options.
GetPrefix());
231 std::string full_prefix_storage;
232 if (!prefix.empty() && !option_prefix.empty()) {
233 full_prefix_storage = std::string(prefix);
234 full_prefix_storage.append(std::string(option_prefix));
235 full_prefix = full_prefix_storage;
236 }
else if (!prefix.empty())
237 full_prefix = prefix;
239 full_prefix = option_prefix;
248 language = frame->GetLanguage();
251 lldb::UserExpressionSP user_expression_sp(
253 desired_type, options, ctx_obj,
256 LLDB_LOG(log,
"== [UserExpression::Evaluate] Getting expression: {0} ==",
261 LLDB_LOG(log,
"== [UserExpression::Evaluate] Parsing expression {0} ==",
264 const bool keep_expression_in_memory =
true;
268 error.SetErrorString(
"expression interrupted by callback before parse");
277 user_expression_sp->Parse(diagnostic_manager, exe_ctx, execution_policy,
278 keep_expression_in_memory, generate_debug_info);
281 std::string tmp_fixed_expression;
282 if (fixed_expression ==
nullptr)
283 fixed_expression = &tmp_fixed_expression;
285 *fixed_expression = user_expression_sp->GetFixedText().str();
288 if (!parse_success) {
291 user_expression_sp.reset();
296 for (uint64_t i = 0; i < max_fix_retries; ++i) {
298 lldb::UserExpressionSP fixed_expression_sp(
300 fixed_expression->c_str(), full_prefix, language, desired_type,
301 options, ctx_obj,
error));
303 parse_success = fixed_expression_sp->Parse(
304 fixed_diagnostic_manager, exe_ctx, execution_policy,
305 keep_expression_in_memory, generate_debug_info);
307 diagnostic_manager.
Clear();
308 user_expression_sp = fixed_expression_sp;
313 if (!fixed_expression_sp->GetFixedText().empty()) {
314 *fixed_expression = fixed_expression_sp->GetFixedText().str();
318 fixed_expression->clear();
325 if (!parse_success) {
328 llvm::raw_string_ostream os(msg);
329 os <<
"expression failed to parse:\n";
333 os <<
"unknown error";
335 !fixed_expression->empty())
336 os <<
"\nfixed expression suggested:\n " << *fixed_expression;
338 error.SetExpressionError(execution_results, msg.c_str());
343 lldb::ExpressionVariableSP expr_result;
346 !user_expression_sp->CanInterpret()) {
347 LLDB_LOG(log,
"== [UserExpression::Evaluate] Expression may not run, but "
348 "is not constant ==");
352 "expression needed to run but couldn't");
358 error.SetExpressionError(
360 "expression interrupted by callback before execution");
366 diagnostic_manager.
Clear();
368 LLDB_LOG(log,
"== [UserExpression::Evaluate] Executing expression ==");
371 user_expression_sp->Execute(diagnostic_manager, exe_ctx, options,
372 user_expression_sp, expr_result);
375 LLDB_LOG(log,
"== [UserExpression::Evaluate] Execution completed "
379 error.SetExpressionError(
380 execution_results,
"expression failed to execute, unknown error");
382 error.SetExpressionError(execution_results,
386 result_valobj_sp = expr_result->GetValueObject();
387 result_valobj_sp->SetPreferredDisplayLanguage(language);
390 "== [UserExpression::Evaluate] Execution completed "
391 "normally with result {0} ==",
392 result_valobj_sp->GetValueAsCString());
394 LLDB_LOG(log,
"== [UserExpression::Evaluate] Execution completed "
395 "normally with no result ==");
404 error.SetExpressionError(
406 "expression interrupted by callback after complete");
410 if (result_valobj_sp.get() ==
nullptr) {
415 return execution_results;
422 lldb::UserExpressionSP &shared_ptr_to_me,
423 lldb::ExpressionVariableSP &result_var) {
425 diagnostic_manager, exe_ctx, options, shared_ptr_to_me, result_var);
428 if (
auto *persistent_state =
430 persistent_state->RemovePersistentVariable(result_var);
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
static int CompareLoadAddress(const Address &lhs, const Address &rhs, Target *target)
bool IsValid() const
Check if the object state is valid.
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
std::string GetString(char separator='\n')
const DiagnosticList & Diagnostics()
const char * GetPrefix() const
uint64_t GetRetriesWithFixIts() const
bool GetAutoApplyFixIts() const
bool InvokeCancelCallback(lldb::ExpressionEvaluationPhase phase) const
ExecutionPolicy GetExecutionPolicy() const
bool GetSuppressPersistentResult() const
lldb::LanguageType GetLanguage() const
bool GetGenerateDebugInfo() const
bool DoesCoerceToId() 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.
ExecutionContextScope * GetBestExecutionContextScope() const
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
const lldb::ProcessSP & GetProcessSP() const
Get accessor to get the process shared pointer.
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
const lldb::StackFrameSP & GetFrameSP() const
Get accessor to get the frame shared pointer.
Target * GetTargetPtr() const
Returns a pointer to the target object.
const lldb::ThreadSP & GetThreadSP() const
Get accessor to get the thread shared pointer.
Process * GetProcessPtr() const
Returns a pointer to the process object.
Encapsulates a single expression for use in lldb.
lldb::ProcessWP m_jit_process_wp
Expression's always have to have a target...
A plug-in interface definition class for debugging a process.
lldb::StateType GetState()
Get accessor for the current process state.
bool CanJIT()
Determines whether executing JIT-compiled code in this process is possible.
This base class provides an interface to stack frames.
@ eExpressionPathOptionsNoFragileObjcIvar
@ eExpressionPathOptionCheckPtrVsMember
@ eExpressionPathOptionsNoSyntheticArrayRange
@ eExpressionPathOptionsNoSyntheticChildren
void Clear()
Clear the object state.
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
bool Success() const
Test for success condition.
bool GetEnableNotifyAboutFixIts() const
lldb::LanguageType GetLanguage() const
PersistentExpressionState * GetPersistentExpressionStateForLanguage(lldb::LanguageType language)
UserExpression * GetUserExpressionForLanguage(llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language, Expression::ResultType desired_type, const EvaluateExpressionOptions &options, ValueObject *ctx_obj, Status &error)
Address m_address
The address the process is stopped in.
~UserExpression() override
Destructor.
virtual lldb::ExpressionResults DoExecute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options, lldb::UserExpressionSP &shared_ptr_to_me, lldb::ExpressionVariableSP &result)=0
void InstallContext(ExecutionContext &exe_ctx)
Populate m_in_cplusplus_method and m_in_objectivec_method based on the environment.
UserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language, ResultType desired_type, const EvaluateExpressionOptions &options)
Constructor.
static const Status::ValueType kNoResult
ValueObject::GetError() returns this if there is no result from the expression.
static lldb::ExpressionResults Evaluate(ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options, llvm::StringRef expr_cstr, llvm::StringRef expr_prefix, lldb::ValueObjectSP &result_valobj_sp, Status &error, std::string *fixed_expression=nullptr, ValueObject *ctx_obj=nullptr)
Evaluate one expression in the scratch context of the target passed in the exe_ctx and return its res...
bool LockAndCheckContext(ExecutionContext &exe_ctx, lldb::TargetSP &target_sp, lldb::ProcessSP &process_sp, lldb::StackFrameSP &frame_sp)
bool MatchesContext(ExecutionContext &exe_ctx)
static lldb::addr_t GetObjectPointer(lldb::StackFrameSP frame_sp, ConstString &object_name, Status &err)
lldb::LanguageType m_language
The language to use when parsing (eLanguageTypeUnknown means use defaults)
lldb::ExpressionResults Execute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options, lldb::UserExpressionSP &shared_ptr_to_me, lldb::ExpressionVariableSP &result)
Execute the parsed expression by callinng the derived class's DoExecute method.
static lldb::ValueObjectSP GetObjectPointerValueObject(lldb::StackFrameSP frame, ConstString const &object_name, Status &err)
Return ValueObject for a given variable name in the current stack frame.
static char ID
LLVM RTTI support.
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address=LLDB_INVALID_ADDRESS)
virtual lldb::ValueObjectSP Dereference(Status &error)
virtual uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr)
#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.
ExecutionPolicy
Expression execution policies.
@ eExecutionPolicyTopLevel
@ eExpressionEvaluationComplete
@ eExpressionEvaluationParse
@ eExpressionEvaluationExecution
@ eStateStopped
Process or thread is stopped and can be examined.
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ eErrorTypeGeneric
Generic errors that can be any value.
ExpressionResults
The results of expression evaluation.