LLDB mainline
|
Encapsulates a one-time expression for use in lldb. More...
#include "lldb/Expression/UserExpression.h"
Public Types | |
enum | { kDefaultTimeout = 500000u } |
Public Types inherited from lldb_private::Expression | |
enum | ResultType { eResultTypeAny , eResultTypeId } |
Public Member Functions | |
bool | isA (const void *ClassID) const override |
UserExpression (ExecutionContextScope &exe_scope, llvm::StringRef expr, llvm::StringRef prefix, SourceLanguage language, ResultType desired_type, const EvaluateExpressionOptions &options) | |
Constructor. | |
~UserExpression () override | |
Destructor. | |
virtual bool | Parse (DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, lldb_private::ExecutionPolicy execution_policy, bool keep_result_in_memory, bool generate_debug_info)=0 |
Parse the expression. | |
virtual bool | Complete (ExecutionContext &exe_ctx, CompletionRequest &request, unsigned complete_pos) |
Attempts to find possible command line completions for the given (possible incomplete) user expression. | |
virtual bool | CanInterpret ()=0 |
bool | MatchesContext (ExecutionContext &exe_ctx) |
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. | |
virtual 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)=0 |
Apply the side effects of the function to program state. | |
const char * | Text () override |
Return the string that the parser should parse. | |
const char * | GetUserText () |
Return the string that the user typed. | |
const char * | FunctionName () override |
Return the function name that should be used for executing the expression. | |
virtual bool | IsParseCacheable () |
Returns whether the call to Parse on this user expression is cacheable. | |
SourceLanguage | Language () const override |
Return the language that should be used when parsing. | |
ResultType | DesiredResultType () const override |
Return the desired result type of the function, or eResultTypeAny if indifferent. | |
bool | NeedsValidation () override |
Return true if validation code should be inserted into the expression. | |
bool | NeedsVariableResolution () override |
Return true if external variables in the expression should be resolved. | |
EvaluateExpressionOptions * | GetOptions () override |
virtual lldb::ExpressionVariableSP | GetResultAfterDematerialization (ExecutionContextScope *exe_scope) |
llvm::StringRef | GetFixedText () |
Public Member Functions inherited from lldb_private::Expression | |
Expression (Target &target) | |
Expression (ExecutionContextScope &exe_scope) | |
virtual | ~Expression ()=default |
Destructor. | |
virtual const char * | Text ()=0 |
Return the string that the parser should parse. | |
virtual const char * | FunctionName ()=0 |
Return the function name that should be used for executing the expression. | |
virtual SourceLanguage | Language () const |
Return the language that should be used when parsing. | |
virtual Materializer * | GetMaterializer () |
Return the Materializer that the parser should use when registering external values. | |
virtual ResultType | DesiredResultType () const |
Return the desired result type of the function, or eResultTypeAny if indifferent. | |
virtual bool | NeedsValidation ()=0 |
Flags. | |
virtual bool | NeedsVariableResolution ()=0 |
Return true if external variables in the expression should be resolved. | |
virtual EvaluateExpressionOptions * | GetOptions () |
lldb::addr_t | StartAddress () |
Return the address of the function's JIT-compiled code, or LLDB_INVALID_ADDRESS if the function is not JIT compiled. | |
virtual void | WillStartExecuting () |
Called to notify the expression that it is about to be executed. | |
virtual void | DidFinishExecuting () |
Called to notify the expression that its execution has finished. | |
virtual ExpressionTypeSystemHelper * | GetTypeSystemHelper () |
virtual bool | isA (const void *ClassID) const =0 |
Static Public Member Functions | |
static bool | classof (const Expression *obj) |
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 result. | |
Static Public Attributes | |
static const Status::ValueType | kNoResult |
ValueObject::GetError() returns this if there is no result from the expression. | |
Protected Member Functions | |
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. | |
bool | LockAndCheckContext (ExecutionContext &exe_ctx, lldb::TargetSP &target_sp, lldb::ProcessSP &process_sp, lldb::StackFrameSP &frame_sp) |
Static Protected Member Functions | |
static lldb::addr_t | GetObjectPointer (lldb::StackFrameSP frame_sp, llvm::StringRef object_name, Status &err) |
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. | |
Protected Attributes | |
Address | m_address |
The address the process is stopped in. | |
std::string | m_expr_text |
The text of the expression, as typed by the user. | |
std::string | m_expr_prefix |
The text of the translation-level definitions, as provided by the user. | |
std::string | m_fixed_text |
The text of the expression with fix-its applied this won't be set if the fixed text doesn't parse. | |
SourceLanguage | m_language |
The language to use when parsing (unknown means use defaults). | |
ResultType | m_desired_type |
The type to coerce the expression's result to. | |
EvaluateExpressionOptions | m_options |
Additional options provided by the user. | |
Protected Attributes inherited from lldb_private::Expression | |
lldb::TargetWP | m_target_wp |
lldb::ProcessWP | m_jit_process_wp |
Expression's always have to have a target... | |
lldb::addr_t | m_jit_start_addr |
An expression might have a process, but it doesn't need to (e.g. | |
lldb::addr_t | m_jit_end_addr |
The address of the JITted function within the JIT allocation. | |
Static Private Attributes | |
static char | ID |
LLVM RTTI support. | |
Encapsulates a one-time expression for use in lldb.
LLDB uses expressions for various purposes, notably to call functions and as a backend for the expr command. UserExpression is a virtual base class that encapsulates the objects needed to parse and interpret or JIT an expression. The actual parsing part will be provided by the specific implementations of UserExpression - which will be vended through the appropriate TypeSystem.
Definition at line 35 of file UserExpression.h.
anonymous enum |
Enumerator | |
---|---|
kDefaultTimeout |
Definition at line 43 of file UserExpression.h.
UserExpression::UserExpression | ( | ExecutionContextScope & | exe_scope, |
llvm::StringRef | expr, | ||
llvm::StringRef | prefix, | ||
SourceLanguage | language, | ||
ResultType | desired_type, | ||
const EvaluateExpressionOptions & | options | ||
) |
Constructor.
[in] | expr | The expression to parse. |
[in] | language | If not eLanguageTypeUnknown, a language to use when parsing the expression. Currently restricted to those languages supported by Clang. |
[in] | desired_type | If not eResultTypeAny, the type to use for the expression result. |
Definition at line 48 of file UserExpression.cpp.
|
overridedefault |
Destructor.
|
pure virtual |
Implemented in lldb_private::LLVMUserExpression.
|
inlinestatic |
Definition at line 41 of file UserExpression.h.
References ID, and lldb_private::Expression::isA().
|
inlinevirtual |
Attempts to find possible command line completions for the given (possible incomplete) user expression.
[in] | exe_ctx | The execution context to use when looking up entities that are needed for parsing and completing (locations of functions, types of variables, persistent variables, etc.) |
[out] | request | The completion request to fill out. The completion should be a string that would complete the current token at the cursor position. Note that the string in the list replaces the current token in the command line. |
[in] | complete_pos | The position of the cursor inside the user expression string. The completion process starts on the token that the cursor is in. |
Reimplemented in lldb_private::ClangUserExpression.
Definition at line 111 of file UserExpression.h.
|
inlineoverridevirtual |
Return the desired result type of the function, or eResultTypeAny if indifferent.
Reimplemented from lldb_private::Expression.
Definition at line 209 of file UserExpression.h.
References m_desired_type.
|
protectedpure virtual |
Implemented in lldb_private::LLVMUserExpression.
Referenced by Execute().
|
static |
Evaluate one expression in the scratch context of the target passed in the exe_ctx and return its result.
[in] | exe_ctx | The execution context to use when evaluating the expression. |
[in] | options | Expression evaluation options. N.B. The language in the evaluation options will be used to determine the language used for expression evaluation. |
[in] | expr_cstr | A C string containing the expression to be evaluated. |
[in] | expr_prefix | If non-nullptr, a C string containing translation-unit level definitions to be included when the expression is parsed. |
[in,out] | result_valobj_sp | If execution is successful, the result valobj is placed here. |
[out] | error | Filled in with an error in case the expression evaluation fails to parse, run, or evaluated. |
[out] | fixed_expression | If non-nullptr, the fixed expression is copied into the provided string. |
[in] | ctx_obj | If specified, then the expression will be evaluated in the context of this object. It means that the context object's address will be treated as this for the expression (the expression will be evaluated as if it was inside of a method of the context object's class, and its this parameter were pointing to the context object). The parameter makes sense for class and union types only. Currently there is a limitation: the context object must be located in the debuggee process' memory (and have the load address). |
Definition at line 144 of file UserExpression.cpp.
References lldb_private::SourceLanguage::AsLanguageType(), lldb_private::Process::CanJIT(), lldb_private::DiagnosticManager::Clear(), lldb_private::ValueObjectConstResult::Create(), lldb_private::ValueObject::Dereference(), lldb_private::DiagnosticManager::Diagnostics(), lldb_private::EvaluateExpressionOptions::DoesCoerceToId(), lldb::eErrorTypeGeneric, lldb_private::eExecutionPolicyAlways, lldb_private::eExecutionPolicyNever, lldb_private::eExecutionPolicyTopLevel, lldb::eExpressionCompleted, lldb::eExpressionEvaluationComplete, lldb::eExpressionEvaluationExecution, lldb::eExpressionEvaluationParse, lldb::eExpressionInterrupted, lldb::eExpressionParseError, lldb::eExpressionSetupError, lldb::eLanguageTypeUnknown, lldb_private::Expression::eResultTypeAny, lldb_private::Expression::eResultTypeId, error(), lldb::eStateStopped, lldb_private::Expressions, lldb_private::EvaluateExpressionOptions::GetAutoApplyFixIts(), lldb_private::ExecutionContext::GetBestExecutionContextScope(), lldb_private::TargetProperties::GetEnableNotifyAboutFixIts(), lldb_private::EvaluateExpressionOptions::GetExecutionPolicy(), lldb_private::ExecutionContext::GetFramePtr(), lldb_private::EvaluateExpressionOptions::GetGenerateDebugInfo(), lldb_private::TargetProperties::GetLanguage(), lldb_private::EvaluateExpressionOptions::GetLanguage(), lldb_private::GetLog(), lldb_private::EvaluateExpressionOptions::GetPrefix(), lldb_private::ExecutionContext::GetProcessPtr(), lldb_private::EvaluateExpressionOptions::GetRetriesWithFixIts(), lldb_private::Process::GetState(), lldb_private::DiagnosticManager::GetString(), lldb_private::ExecutionContext::GetTargetPtr(), lldb_private::ExecutionContext::GetThreadSP(), lldb_private::ValueObject::GetTypeInfo(), lldb_private::Target::GetUserExpressionForLanguage(), lldb_private::EvaluateExpressionOptions::InvokeCancelCallback(), kNoResult, LLDB_LOG, lldb_private::StateAsCString(), and lldb_private::Step.
Referenced by lldb_private::Target::EvaluateExpression(), PlatformPOSIX::EvaluateLibdlExpression(), lldb_private::PlatformWindows::EvaluateLoaderExpression(), lldb_private::MemoryHistoryASan::GetHistoryThreads(), lldb_private::REPL::IOHandlerInputComplete(), lldb_private::StopInfoWatchpoint::PerformAction(), lldb_private::ReportRetriever::RetrieveReportData(), lldb_private::InstrumentationRuntimeTSan::RetrieveReportData(), and lldb_private::InstrumentationRuntimeUBSan::RetrieveReportData().
lldb::ExpressionResults UserExpression::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.
[in] | diagnostic_manager | A diagnostic manager to report errors to. |
[in] | exe_ctx | The execution context to use when looking up entities that are needed for parsing (locations of variables, etc.) |
[in] | options | Expression evaluation options. |
[in] | shared_ptr_to_me | This is a shared pointer to this UserExpression. This is needed because Execute can push a thread plan that will hold onto the UserExpression for an unbounded period of time. So you need to give the thread plan a reference to this object that can keep it alive. |
[in] | result | A pointer to direct at the persistent variable in which the expression's result is stored. |
Definition at line 421 of file UserExpression.cpp.
References lldb_private::SourceLanguage::AsLanguageType(), DoExecute(), lldb_private::Target::GetPersistentExpressionStateForLanguage(), lldb_private::EvaluateExpressionOptions::GetSuppressPersistentResult(), lldb_private::ExecutionContext::GetTargetPtr(), and m_language.
|
pure virtual |
Apply the side effects of the function to program state.
[in] | diagnostic_manager | A diagnostic manager to report errors to. |
[in] | exe_ctx | The execution context to use when looking up entities that are needed for parsing (locations of variables, etc.) |
[in] | result | A pointer to direct at the persistent variable in which the expression's result is stored. |
[in] | function_stack_bottom | A pointer to the bottom of the function's stack frame. This is used to determine whether the expression result resides in memory that will still be valid, or whether it needs to be treated as homeless for the purpose of future expressions. |
[in] | function_stack_top | A pointer to the top of the function's stack frame. This is used to determine whether the expression result resides in memory that will still be valid, or whether it needs to be treated as homeless for the purpose of future expressions. |
Implemented in lldb_private::LLVMUserExpression.
|
inlineoverridevirtual |
Return the function name that should be used for executing the expression.
Text() should contain the definition of this function.
Implements lldb_private::Expression.
Definition at line 193 of file UserExpression.h.
Referenced by lldb_private::ClangUserExpression::Parse().
|
inline |
Definition at line 277 of file UserExpression.h.
References m_fixed_text.
|
staticprotected |
Definition at line 122 of file UserExpression.cpp.
References GetObjectPointerValueObject(), LLDB_INVALID_ADDRESS, lldb_private::Status::SetErrorStringWithFormatv(), and lldb_private::Status::Success().
Referenced by lldb_private::ClangUserExpression::AddArguments().
|
staticprotected |
Return ValueObject for a given variable name in the current stack frame.
[in] | frame | Current stack frame. When passed a 'nullptr', this function returns an empty ValueObjectSP. |
[in] | object_name | Name of the variable in the current stack frame for which we want the ValueObjectSP. |
[out] | err | Status object which will get set on error. |
Definition at line 100 of file UserExpression.cpp.
References lldb_private::Status::Clear(), lldb_private::StackFrame::eExpressionPathOptionCheckPtrVsMember, lldb_private::StackFrame::eExpressionPathOptionsNoFragileObjcIvar, lldb_private::StackFrame::eExpressionPathOptionsNoSyntheticArrayRange, lldb_private::StackFrame::eExpressionPathOptionsNoSyntheticChildren, lldb::eNoDynamicValues, and lldb_private::Status::SetErrorStringWithFormatv().
Referenced by lldb_private::ClangUserExpression::GetCppObjectPointer(), and GetObjectPointer().
|
inlineoverridevirtual |
Reimplemented from lldb_private::Expression.
Definition at line 217 of file UserExpression.h.
References m_options.
|
inlinevirtual |
Reimplemented in lldb_private::ClangUserExpression.
Definition at line 220 of file UserExpression.h.
Referenced by lldb_private::LLVMUserExpression::FinalizeJITExecution().
|
inline |
Return the string that the user typed.
Definition at line 189 of file UserExpression.h.
References m_expr_text.
Referenced by lldb_private::ClangExpressionParser::Complete().
|
protected |
Populate m_in_cplusplus_method and m_in_objectivec_method based on the environment.
Definition at line 58 of file UserExpression.cpp.
References lldb_private::ExecutionContext::GetFrameSP(), lldb_private::ExecutionContext::GetProcessSP(), m_address, and lldb_private::Expression::m_jit_process_wp.
Referenced by lldb_private::ClangUserExpression::PrepareForParsing().
|
inlineoverridevirtual |
Implements lldb_private::Expression.
Reimplemented in lldb_private::ClangUserExpression.
Definition at line 40 of file UserExpression.h.
References ID.
Referenced by lldb_private::LLVMUserExpression::isA().
|
inlinevirtual |
Returns whether the call to Parse on this user expression is cacheable.
This function exists to provide an escape hatch for supporting languages where parsing an expression in the exact same context is unsafe. For example, languages where generic functions aren't monomorphized, but implement some other mechanism to represent generic values, may be unsafe to cache, as the concrete type substitution may be different in every expression evaluation.
Definition at line 202 of file UserExpression.h.
|
inlineoverridevirtual |
Return the language that should be used when parsing.
To use the default, return eLanguageTypeUnknown.
Reimplemented from lldb_private::Expression.
Definition at line 205 of file UserExpression.h.
References m_language.
|
protected |
Definition at line 67 of file UserExpression.cpp.
References lldb_private::Address::CompareLoadAddress(), lldb_private::ExecutionContext::GetFrameSP(), lldb_private::ExecutionContext::GetProcessSP(), lldb_private::ExecutionContext::GetTargetSP(), lldb_private::Address::IsValid(), m_address, and lldb_private::Expression::m_jit_process_wp.
Referenced by MatchesContext(), and lldb_private::LLVMUserExpression::PrepareToExecuteJITExpression().
bool UserExpression::MatchesContext | ( | ExecutionContext & | exe_ctx | ) |
Definition at line 92 of file UserExpression.cpp.
References LockAndCheckContext().
|
inlineoverridevirtual |
Return true if validation code should be inserted into the expression.
Implements lldb_private::Expression.
Definition at line 212 of file UserExpression.h.
|
inlineoverridevirtual |
Return true if external variables in the expression should be resolved.
Implements lldb_private::Expression.
Definition at line 215 of file UserExpression.h.
|
pure virtual |
Parse the expression.
[in] | diagnostic_manager | A diagnostic manager to report parse errors and warnings to. |
[in] | exe_ctx | The execution context to use when looking up entities that are needed for parsing (locations of functions, types of variables, persistent variables, etc.) |
[in] | execution_policy | Determines whether interpretation is possible or mandatory. |
[in] | keep_result_in_memory | True if the resulting persistent variable should reside in target memory, if applicable. |
Implemented in lldb_private::ClangUserExpression.
|
inlineoverridevirtual |
Return the string that the parser should parse.
Implements lldb_private::Expression.
Definition at line 186 of file UserExpression.h.
References m_expr_text.
|
staticprivate |
LLVM RTTI support.
Definition at line 37 of file UserExpression.h.
|
static |
ValueObject::GetError() returns this if there is no result from the expression.
Definition at line 273 of file UserExpression.h.
Referenced by lldb_private::CommandObjectDWIMPrint::DoExecute(), Evaluate(), and lldb_private::REPL::IOHandlerInputComplete().
|
protected |
The address the process is stopped in.
Definition at line 319 of file UserExpression.h.
Referenced by InstallContext(), and LockAndCheckContext().
|
protected |
The type to coerce the expression's result to.
If eResultTypeAny, inferred from the expression.
Definition at line 331 of file UserExpression.h.
Referenced by DesiredResultType().
|
protected |
The text of the translation-level definitions, as provided by the user.
Definition at line 323 of file UserExpression.h.
Referenced by lldb_private::ClangUserExpression::CreateSourceCode().
|
protected |
The text of the expression, as typed by the user.
Definition at line 321 of file UserExpression.h.
Referenced by lldb_private::ClangUserExpression::CreateSourceCode(), GetUserText(), lldb_private::ClangUserExpression::PrepareForParsing(), and Text().
|
protected |
The text of the expression with fix-its applied this won't be set if the fixed text doesn't parse.
Definition at line 326 of file UserExpression.h.
Referenced by GetFixedText(), and lldb_private::ClangUserExpression::TryParse().
|
protected |
The language to use when parsing (unknown means use defaults).
Definition at line 328 of file UserExpression.h.
Referenced by lldb_private::ClangUserExpression::ClangUserExpression(), Execute(), Language(), lldb_private::ClangUserExpression::Parse(), and lldb_private::ClangUserExpression::SetupCppModuleImports().
|
protected |
Additional options provided by the user.
Definition at line 333 of file UserExpression.h.
Referenced by lldb_private::ClangUserExpression::Complete(), lldb_private::ClangUserExpression::CreateSourceCode(), GetOptions(), lldb_private::ClangUserExpression::GetWrapKind(), lldb_private::ClangUserExpression::Parse(), and lldb_private::ClangUserExpression::TryParse().