42#include "llvm/BinaryFormat/Dwarf.h"
49 llvm::StringRef expr, llvm::StringRef prefix,
52 :
Expression(exe_scope), m_expr_text(std::string(expr)),
53 m_expr_prefix(std::string(prefix)), m_language(language),
54 m_desired_type(desired_type), m_options(options) {}
64 m_address = frame_sp->GetFrameCodeAddress();
74 if (process_sp != expected_process_sp)
85 frame_sp->GetFrameCodeAddress(),
86 target_sp.get()) == 0);
106 "Couldn't load '{0}' because the context is incomplete", object_name);
113 return frame_sp->GetValueForVariableExpressionPath(
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) {
152 static unsigned const ctx_type_mask = lldb::TypeFlags::eTypeIsClass |
153 lldb::TypeFlags::eTypeIsStructUnion |
154 lldb::TypeFlags::eTypeIsReference;
156 LLDB_LOG(log,
"== [UserExpression::Evaluate] Passed a context object of "
157 "an invalid type, can't run expressions.");
158 error.SetErrorString(
"a context object of an invalid type passed");
163 if (ctx_obj && ctx_obj->
GetTypeInfo() & lldb::TypeFlags::eTypeIsReference) {
166 if (!
error.Success()) {
167 LLDB_LOG(log,
"== [UserExpression::Evaluate] Passed a context object of "
168 "a reference type that can't be dereferenced, can't run "
170 error.SetErrorString(
171 "passed context object of an reference type cannot be deferenced");
175 ctx_obj = deref_ctx_sp.get();
187 LLDB_LOG(log,
"== [UserExpression::Evaluate] Passed a NULL target, can't "
189 error.SetErrorString(
"expression passed a null target");
196 LLDB_LOG(log,
"== [UserExpression::Evaluate] No process, but the policy is "
197 "eExecutionPolicyAlways");
199 error.SetErrorString(
"expression needed to run but couldn't: no process");
201 return execution_results;
207 error.SetErrorStringWithFormatv(
208 "unable to evaluate expression while the process is {0}: the process "
209 "must be stopped because the expression might require allocating "
212 return execution_results;
220 (process ==
nullptr || !process->
CanJIT()))
230 llvm::StringRef full_prefix;
231 llvm::StringRef option_prefix(options.
GetPrefix());
232 std::string full_prefix_storage;
233 if (!prefix.empty() && !option_prefix.empty()) {
234 full_prefix_storage = std::string(prefix);
235 full_prefix_storage.append(std::string(option_prefix));
236 full_prefix = full_prefix_storage;
237 }
else if (!prefix.empty())
238 full_prefix = prefix;
240 full_prefix = option_prefix;
249 language = frame->GetLanguage();
254 desired_type, options, ctx_obj,
256 if (
error.Fail() || !user_expression_sp) {
257 LLDB_LOG(log,
"== [UserExpression::Evaluate] Getting expression: {0} ==",
262 LLDB_LOG(log,
"== [UserExpression::Evaluate] Parsing expression {0} ==",
265 const bool keep_expression_in_memory =
true;
269 error.SetErrorString(
"expression interrupted by callback before parse");
278 user_expression_sp->Parse(diagnostic_manager, exe_ctx, execution_policy,
279 keep_expression_in_memory, generate_debug_info);
282 std::string tmp_fixed_expression;
283 if (fixed_expression ==
nullptr)
284 fixed_expression = &tmp_fixed_expression;
286 *fixed_expression = user_expression_sp->GetFixedText().str();
289 if (!parse_success) {
292 user_expression_sp.reset();
297 for (uint64_t i = 0; i < max_fix_retries; ++i) {
301 fixed_expression->c_str(), full_prefix, language, desired_type,
302 options, ctx_obj,
error));
303 if (!fixed_expression_sp)
306 parse_success = fixed_expression_sp->Parse(
307 fixed_diagnostic_manager, exe_ctx, execution_policy,
308 keep_expression_in_memory, generate_debug_info);
310 diagnostic_manager.
Clear();
311 user_expression_sp = fixed_expression_sp;
316 if (!fixed_expression_sp->GetFixedText().empty()) {
317 *fixed_expression = fixed_expression_sp->GetFixedText().str();
321 fixed_expression->clear();
327 if (!parse_success) {
330 llvm::raw_string_ostream os(msg);
334 os <<
"expression failed to parse (no further compiler diagnostics)";
336 !fixed_expression->empty())
337 os <<
"\nfixed expression suggested:\n " << *fixed_expression;
339 error.SetExpressionError(execution_results, msg.c_str());
347 !user_expression_sp->CanInterpret()) {
348 LLDB_LOG(log,
"== [UserExpression::Evaluate] Expression may not run, but "
349 "is not constant ==");
353 "expression needed to run but couldn't");
359 error.SetExpressionError(
361 "expression interrupted by callback before execution");
367 diagnostic_manager.
Clear();
369 LLDB_LOG(log,
"== [UserExpression::Evaluate] Executing expression ==");
372 user_expression_sp->Execute(diagnostic_manager, exe_ctx, options,
373 user_expression_sp, expr_result);
376 LLDB_LOG(log,
"== [UserExpression::Evaluate] Execution completed "
380 error.SetExpressionError(
381 execution_results,
"expression failed to execute, unknown error");
383 error.SetExpressionError(execution_results,
387 result_valobj_sp = expr_result->GetValueObject();
388 result_valobj_sp->SetPreferredDisplayLanguage(
392 "== [UserExpression::Evaluate] Execution completed "
393 "normally with result {0} ==",
394 result_valobj_sp->GetValueAsCString());
396 LLDB_LOG(log,
"== [UserExpression::Evaluate] Execution completed "
397 "normally with no result ==");
406 error.SetExpressionError(
408 "expression interrupted by callback after complete");
412 if (result_valobj_sp.get() ==
nullptr) {
417 return execution_results;
427 diagnostic_manager, exe_ctx, options, shared_ptr_to_me, result_var);
430 if (
auto *persistent_state =
433 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.
std::string GetString(char separator='\n')
const DiagnosticList & Diagnostics()
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.
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 SetErrorStringWithFormatv(const char *format, Args &&... args)
void Clear()
Clear the object state.
bool Success() const
Test for success condition.
bool GetEnableNotifyAboutFixIts() const
SourceLanguage GetLanguage() 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
void InstallContext(ExecutionContext &exe_ctx)
Populate m_in_cplusplus_method and m_in_objectivec_method based on the environment.
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, 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.
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ 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::Variable > VariableSP
std::shared_ptr< lldb_private::Target > TargetSP
A type-erased pair of llvm::dwarf::SourceLanguageName and version.
lldb::LanguageType AsLanguageType() const