45#include "llvm/BinaryFormat/Dwarf.h"
52 llvm::StringRef expr, llvm::StringRef prefix,
67 m_address = frame_sp->GetFrameCodeAddress();
77 if (process_sp != expected_process_sp)
88 frame_sp->GetFrameCodeAddress(),
89 target_sp.get()) == 0);
109 "Couldn't load '{0}' because the context is incomplete", object_name);
113 if (
auto var_list_sp = frame_sp->GetInScopeVariableList(
false))
115 var_list_sp->FindVariable(
ConstString(object_name),
false))
116 return frame_sp->GetValueObjectForFrameVariable(var_sp,
123 llvm::StringRef object_name,
128 if (!err.
Success() || !valobj_sp.get())
135 "Couldn't load '{0}' because its value couldn't be evaluated",
146 llvm::StringRef expr, llvm::StringRef prefix,
148 std::string *fixed_expression,
ValueObject *ctx_obj) {
156 static unsigned const ctx_type_mask = lldb::TypeFlags::eTypeIsClass |
157 lldb::TypeFlags::eTypeIsStructUnion |
158 lldb::TypeFlags::eTypeIsReference;
160 LLDB_LOG(log,
"== [UserExpression::Evaluate] Passed a context object of "
161 "an invalid type, can't run expressions.");
162 set_error(
Status(
"a context object of an invalid type passed"));
167 if (ctx_obj && ctx_obj->
GetTypeInfo() & lldb::TypeFlags::eTypeIsReference) {
170 if (!
error.Success()) {
171 LLDB_LOG(log,
"== [UserExpression::Evaluate] Passed a context object of "
172 "a reference type that can't be dereferenced, can't run "
175 "passed context object of an reference type cannot be deferenced"));
179 ctx_obj = deref_ctx_sp.get();
189 LLDB_LOG(log,
"== [UserExpression::Evaluate] Passed a NULL target, can't "
191 set_error(
Status(
"expression passed a null target"));
198 LLDB_LOG(log,
"== [UserExpression::Evaluate] No process, but the policy is "
199 "eExecutionPolicyAlways");
201 set_error(
Status(
"expression needed to run but couldn't: no process"));
210 "unable to evaluate expression while the process is {0}: the process "
211 "must be stopped because the expression might require allocating "
222 (process ==
nullptr || !process->
CanJIT()))
232 llvm::StringRef full_prefix;
233 llvm::StringRef option_prefix(options.
GetPrefix());
234 std::string full_prefix_storage;
235 if (!prefix.empty() && !option_prefix.empty()) {
236 full_prefix_storage = std::string(prefix);
237 full_prefix_storage.append(std::string(option_prefix));
238 full_prefix = full_prefix_storage;
239 }
else if (!prefix.empty())
240 full_prefix = prefix;
242 full_prefix = option_prefix;
251 language = frame->GetLanguage();
257 expr, full_prefix, language, desired_type, options, ctx_obj,
error));
258 if (
error.Fail() || !user_expression_sp) {
259 LLDB_LOG(log,
"== [UserExpression::Evaluate] Getting expression: {0} ==",
261 set_error(std::move(
error));
265 LLDB_LOG(log,
"== [UserExpression::Evaluate] Parsing expression {0} ==",
268 const bool keep_expression_in_memory =
true;
272 set_error(
Status(
"expression interrupted by callback before parse"));
279 user_expression_sp->Parse(diagnostic_manager, exe_ctx, execution_policy,
280 keep_expression_in_memory, generate_debug_info);
283 std::string tmp_fixed_expression;
284 if (fixed_expression ==
nullptr)
285 fixed_expression = &tmp_fixed_expression;
287 *fixed_expression = user_expression_sp->GetFixedText().str();
291 if (!parse_success) {
295 for (uint64_t i = 0; i < max_fix_retries; ++i) {
298 fixed_expression->c_str(), full_prefix, language, desired_type,
299 options, ctx_obj,
error));
300 if (!user_expression_sp)
304 parse_success = user_expression_sp->Parse(
305 fixed_diagnostic_manager, exe_ctx, execution_policy,
306 keep_expression_in_memory, generate_debug_info);
308 diagnostic_manager.
Clear();
313 if (!user_expression_sp->GetFixedText().empty()) {
314 *fixed_expression = user_expression_sp->GetFixedText().str();
318 fixed_expression->clear();
324 if (!parse_success) {
325 if (user_expression_sp)
326 user_expression_sp->FixupParseErrorDiagnostics(diagnostic_manager);
329 !fixed_expression->empty()) {
331 "fixed expression suggested:\n " + *fixed_expression;
338 "expression failed to parse (no further compiler diagnostics)"));
349 !user_expression_sp->CanInterpret()) {
350 LLDB_LOG(log,
"== [UserExpression::Evaluate] Expression may not run, but "
351 "is not constant ==");
356 "expression needed to run but couldn't"));
364 "expression interrupted by callback before execution")));
368 diagnostic_manager.
Clear();
370 LLDB_LOG(log,
"== [UserExpression::Evaluate] Executing expression ==");
373 user_expression_sp->Execute(diagnostic_manager, exe_ctx, options,
374 user_expression_sp, expr_result);
377 LLDB_LOG(log,
"== [UserExpression::Evaluate] Execution completed "
383 "expression failed to execute, unknown error"));
386 diagnostic_manager.
GetAsError(execution_results));
389 result_valobj_sp = expr_result->GetValueObject();
390 result_valobj_sp->SetPreferredDisplayLanguage(
394 "== [UserExpression::Evaluate] Execution completed "
395 "normally with result {0} ==",
396 result_valobj_sp->GetValueAsCString());
398 LLDB_LOG(log,
"== [UserExpression::Evaluate] Execution completed "
399 "normally with no result ==");
410 "expression interrupted by callback after complete")));
415 set_error(std::move(
error));
416 return execution_results;
428 Progress progress(
"Running expression",
433 diagnostic_manager, exe_ctx, options, shared_ptr_to_me, result_var);
436 if (
auto *persistent_state =
439 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)
A uniqued constant string class.
A class to manage flag bits.
const DiagnosticList & Diagnostics() const
llvm::Error GetAsError(lldb::ExpressionResults result, llvm::Twine message={}) const
Returns an ExpressionError with arg as error code.
void AddDiagnostic(llvm::StringRef message, lldb::Severity severity, DiagnosticOrigin origin, uint32_t compiler_id=LLDB_INVALID_COMPILER_ID)
const char * GetPrefix() const
uint64_t GetRetriesWithFixIts() const
SourceLanguage GetLanguage() const
bool GetAutoApplyFixIts() const
bool InvokeCancelCallback(lldb::ExpressionEvaluationPhase phase) const
ExecutionPolicy GetExecutionPolicy() const
bool GetSuppressPersistentResult() 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.
lldb::ProcessWP m_jit_process_wp
Expression's always have to have a target...
Expression(Target &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.
A Progress indicator helper class.
This base class provides an interface to stack frames.
void Clear()
Clear the object state.
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
bool Success() const
Test for success condition.
bool GetEnableNotifyAboutFixIts() const
SourceLanguage GetLanguage() const
Debugger & GetDebugger() const
PersistentExpressionState * GetPersistentExpressionStateForLanguage(lldb::LanguageType language)
UserExpression * GetUserExpressionForLanguage(llvm::StringRef expr, llvm::StringRef prefix, SourceLanguage 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.
static lldb::ValueObjectSP GetObjectPointerValueObject(lldb::StackFrameSP frame, llvm::StringRef object_name, Status &err)
Return ValueObject for a given variable name in the current stack frame.
SourceLanguage m_language
The language to use when parsing (unknown means use defaults).
virtual lldb::ExpressionResults DoExecute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options, lldb::UserExpressionSP &shared_ptr_to_me, lldb::ExpressionVariableSP &result)=0
ResultType m_desired_type
The type to coerce the expression's result to.
static lldb::ExpressionResults Evaluate(ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options, llvm::StringRef expr_cstr, llvm::StringRef expr_prefix, lldb::ValueObjectSP &result_valobj_sp, 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...
void InstallContext(ExecutionContext &exe_ctx)
Populate m_in_cplusplus_method and m_in_objectivec_method based on the environment.
std::string m_expr_prefix
The text of the translation-level definitions, as provided by the user.
static const Status::ValueType kNoResult
ValueObject::GetError() returns this if there is no result from the expression.
std::string m_expr_text
The text of the expression, as typed by the user.
EvaluateExpressionOptions m_options
Additional options provided by the user.
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, llvm::StringRef object_name, Status &err)
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.
UserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr, llvm::StringRef prefix, SourceLanguage language, ResultType desired_type, const EvaluateExpressionOptions &options)
Constructor.
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)
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr)
virtual lldb::ValueObjectSP Dereference(Status &error)
#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
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
@ eExpressionEvaluationComplete
@ eExpressionEvaluationParse
@ eExpressionEvaluationExecution
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::ExpressionVariable > ExpressionVariableSP
@ eStateStopped
Process or thread is stopped and can be examined.
@ eErrorTypeGeneric
Generic errors that can be any value.
std::shared_ptr< lldb_private::UserExpression > UserExpressionSP
ExpressionResults
The results of expression evaluation.
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Target > TargetSP
A type-erased pair of llvm::dwarf::SourceLanguageName and version.
lldb::LanguageType AsLanguageType() const