LLDB mainline
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
lldb_private::ClangExpressionParser Class Reference

"lldb/Expression/ClangExpressionParser.h" Encapsulates an instance of Clang that can parse expressions. More...

#include <ClangExpressionParser.h>

Inheritance diagram for lldb_private::ClangExpressionParser:
Inheritance graph
[legend]

Classes

class  LLDBPreprocessorCallbacks
 

Public Member Functions

 ClangExpressionParser (ExecutionContextScope *exe_scope, Expression &expr, bool generate_debug_info, std::vector< std::string > include_directories={}, std::string filename="<clang expression>")
 Constructor.
 
 ~ClangExpressionParser () override
 Destructor.
 
bool Complete (CompletionRequest &request, unsigned line, unsigned pos, unsigned typed_pos) override
 Attempts to find possible command line completions for the given expression.
 
unsigned Parse (DiagnosticManager &diagnostic_manager)
 Parse a single expression and convert it to IR using Clang.
 
bool RewriteExpression (DiagnosticManager &diagnostic_manager) override
 Try to use the FixIts in the diagnostic_manager to rewrite the expression.
 
Status PrepareForExecution (lldb::addr_t &func_addr, lldb::addr_t &func_end, lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx, bool &can_interpret, lldb_private::ExecutionPolicy execution_policy) override
 Ready an already-parsed expression for execution, possibly evaluating it statically.
 
Status RunStaticInitializers (lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx)
 Run all static initializers for an execution unit.
 
std::string GetClangTargetABI (const ArchSpec &target_arch)
 Returns a string representing current ABI.
 
- Public Member Functions inherited from lldb_private::ExpressionParser
 ExpressionParser (ExecutionContextScope *exe_scope, Expression &expr, bool generate_debug_info)
 Constructor.
 
virtual ~ExpressionParser ()=default
 Destructor.
 
virtual bool Complete (CompletionRequest &request, unsigned line, unsigned pos, unsigned typed_pos)=0
 Attempts to find possible command line completions for the given expression.
 
virtual bool RewriteExpression (DiagnosticManager &diagnostic_manager)
 Try to use the FixIts in the diagnostic_manager to rewrite the expression.
 
virtual Status PrepareForExecution (lldb::addr_t &func_addr, lldb::addr_t &func_end, std::shared_ptr< IRExecutionUnit > &execution_unit_sp, ExecutionContext &exe_ctx, bool &can_interpret, lldb_private::ExecutionPolicy execution_policy)=0
 Ready an already-parsed expression for execution, possibly evaluating it statically.
 
bool GetGenerateDebugInfo () const
 

Private Member Functions

unsigned ParseInternal (DiagnosticManager &diagnostic_manager, clang::CodeCompleteConsumer *completion=nullptr, unsigned completion_line=0, unsigned completion_column=0)
 Parses the expression.
 

Private Attributes

std::unique_ptr< llvm::LLVMContext > m_llvm_context
 The LLVM context to generate IR into.
 
std::unique_ptr< clang::CompilerInstance > m_compiler
 The Clang compiler used to parse expressions into IR.
 
std::unique_ptr< clang::CodeGenerator > m_code_generator
 The Clang object that generates IR.
 
LLDBPreprocessorCallbacksm_pp_callbacks
 Called when the preprocessor encounters module imports.
 
std::shared_ptr< TypeSystemClangm_ast_context
 
std::vector< std::string > m_include_directories
 
std::string m_filename
 File name used for the user expression.
 

Additional Inherited Members

- Protected Attributes inherited from lldb_private::ExpressionParser
Expressionm_expr
 The expression to be parsed.
 
bool m_generate_debug_info
 

Detailed Description

"lldb/Expression/ClangExpressionParser.h" Encapsulates an instance of Clang that can parse expressions.

ClangExpressionParser is responsible for preparing an instance of ClangExpression for execution. ClangExpressionParser uses ClangExpression as a glorified parameter list, performing the required parsing and conversion to formats (DWARF bytecode, or JIT compiled machine code) that can be executed.

Definition at line 45 of file ClangExpressionParser.h.

Constructor & Destructor Documentation

◆ ClangExpressionParser()

ClangExpressionParser::ClangExpressionParser ( ExecutionContextScope exe_scope,
Expression expr,
bool  generate_debug_info,
std::vector< std::string >  include_directories = {},
std::string  filename = "<clang expression>" 
)

Constructor.

Initializes class variables.

Parameters
[in]exe_scopeIf non-NULL, an execution context scope that can help to correctly create an expression with a valid process for optional tuning Objective-C runtime support. Can be NULL.
[in]exprThe expression to be parsed.
[in]include_directoriesList of include directories that should be used when parsing the expression.
[in]filenameName of the source file that should be used when rendering diagnostics (i.e. errors, warnings or notes from Clang).

Definition at line 358 of file ClangExpressionParser.cpp.

References lldb_private::ExecutionContextScope::CalculateProcess(), lldb_private::ExecutionContextScope::CalculateStackFrame(), lldb_private::ExecutionContextScope::CalculateTarget(), lldb_private::ArchSpec::CharIsSignedByDefault(), lldb_private::Expression::DesiredResultType(), lldb_private::ObjCLanguageRuntime::eAppleObjC_V1, lldb_private::ObjCLanguageRuntime::eAppleObjC_V2, lldb_private::ObjCLanguageRuntime::eGNUstep_libobjc2, lldb::eLanguageTypeC, lldb::eLanguageTypeC11, lldb::eLanguageTypeC89, lldb::eLanguageTypeC99, lldb::eLanguageTypeC_plus_plus, lldb::eLanguageTypeC_plus_plus_03, lldb::eLanguageTypeC_plus_plus_11, lldb::eLanguageTypeC_plus_plus_14, lldb::eLanguageTypeC_plus_plus_17, lldb::eLanguageTypeC_plus_plus_20, lldb::eLanguageTypeObjC, lldb::eLanguageTypeObjC_plus_plus, lldb::eLanguageTypeUnknown, lldb_private::ObjCLanguageRuntime::eObjC_VersionUnknown, lldb_private::Expression::eResultTypeId, lldb_private::Expressions, lldb_private::ObjCLanguageRuntime::Get(), GetClangTargetABI(), lldb_private::ArchSpec::GetClangTargetCPU(), lldb_private::GetLog(), lldb_private::ArchSpec::GetMachine(), lldb_private::Language::GetNameForLanguageType(), lldb_private::ArchSpec::GetTriple(), lldb_private::FileSystem::Instance(), lldb_private::ArchSpec::IsValid(), lldb_private::Expression::Language(), LLDB_LOG, LLDB_LOGF, lldbassert, m_ast_context, m_code_generator, m_compiler, lldb_private::ExpressionParser::m_expr, m_filename, m_include_directories, m_llvm_context, m_pp_callbacks, RemoveAllCppKeywords(), SetupDefaultClangDiagnostics(), and SetupModuleHeaderPaths().

◆ ~ClangExpressionParser()

ClangExpressionParser::~ClangExpressionParser ( )
overridedefault

Destructor.

Member Function Documentation

◆ Complete()

bool ClangExpressionParser::Complete ( CompletionRequest request,
unsigned  line,
unsigned  pos,
unsigned  typed_pos 
)
overridevirtual

Attempts to find possible command line completions for the given expression.

Parameters
[out]requestThe 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]lineThe line with the completion cursor inside the expression as a string. The first line in the expression has the number 0.
[in]posThe character position in the line with the completion cursor. If the value is 0, then the cursor is on top of the first character in the line (i.e. the user has requested completion from the start of the expression).
[in]typed_posThe cursor position in the line as typed by the user. If the user expression has not been transformed in some form (e.g. wrapping it in a function body for C languages), then this is equal to the 'pos' parameter. The semantics of this value are otherwise equal to 'pos' (e.g. a value of 0 means the cursor is at start of the expression).
Returns
True if we added any completion results to the output; false otherwise.

Implements lldb_private::ExpressionParser.

Definition at line 984 of file ClangExpressionParser.cpp.

References lldb_private::UserExpression::GetUserText(), m_code_generator, m_compiler, lldb_private::ExpressionParser::m_expr, and ParseInternal().

Referenced by lldb_private::ClangUserExpression::Complete().

◆ GetClangTargetABI()

std::string ClangExpressionParser::GetClangTargetABI ( const ArchSpec target_arch)

Returns a string representing current ABI.

Parameters
[in]target_archThe target architecture.
Returns
A string representing target ABI for the current architecture.

Definition at line 1180 of file ClangExpressionParser.cpp.

References lldb_private::ArchSpec::eMIPSABI_mask, lldb_private::ArchSpec::eMIPSABI_N32, lldb_private::ArchSpec::eMIPSABI_N64, lldb_private::ArchSpec::eMIPSABI_O32, lldb_private::ArchSpec::GetFlags(), and lldb_private::ArchSpec::IsMIPS().

Referenced by ClangExpressionParser().

◆ Parse()

unsigned ClangExpressionParser::Parse ( DiagnosticManager diagnostic_manager)

Parse a single expression and convert it to IR using Clang.

Don't wrap the expression in anything at all.

Parameters
[in]diagnostic_managerThe diagnostic manager to report errors to.
Returns
The number of errors encountered during parsing. 0 means success.

Definition at line 1004 of file ClangExpressionParser.cpp.

References ParseInternal().

Referenced by lldb_private::ClangUtilityFunction::Install().

◆ ParseInternal()

unsigned ClangExpressionParser::ParseInternal ( DiagnosticManager diagnostic_manager,
clang::CodeCompleteConsumer *  completion = nullptr,
unsigned  completion_line = 0,
unsigned  completion_column = 0 
)
private

Parses the expression.

Parameters
[in]diagnostic_managerThe diagnostic manager that should receive the diagnostics from the parsing process.
[in]completionThe completion consumer that should be used during parsing (or a nullptr if no consumer should be attached).
[in]completion_lineThe line in which the completion marker should be placed. The first line is represented by the value 0.
[in]completion_columnThe column in which the completion marker should be placed. The first column is represented by the value 0.
Returns
The number of parsing errors.

Definition at line 1009 of file ClangExpressionParser.cpp.

References lldb_private::DiagnosticManager::AppendMessageToDiagnostic(), lldb_private::ClangExpressionHelper::ASTTransformer(), ClangDiagnosticManagerAdapter::BeginSourceFile(), lldb_private::NativeFile::Close(), lldb_private::ClangExpressionHelper::CommitPersistentDecls(), lldb_private::ClangASTSource::CreateProxy(), lldb_private::ClangExpressionHelper::DeclMap(), lldb_private::eDiagnosticSeverityError, ClangDiagnosticManagerAdapter::EndSourceFile(), lldb_private::File::eOpenOptionWriteOnly, lldb_private::ClangExpressionParser::LLDBPreprocessorCallbacks::getErrorString(), lldb_private::Expression::GetTypeSystemHelper(), lldb_private::ClangExpressionParser::LLDBPreprocessorCallbacks::hasErrors(), lldb_private::ClangASTSource::InstallASTContext(), lldb_private::ClangExpressionDeclMap::InstallCodeGenerator(), lldb_private::ClangExpressionDeclMap::InstallDiagnosticManager(), m_ast_context, m_code_generator, m_compiler, lldb_private::ExpressionParser::m_expr, m_filename, m_pp_callbacks, lldb_private::DiagnosticManager::PutString(), ClangDiagnosticManagerAdapter::ResetManager(), lldb_private::Source, lldb_private::Status::Success(), lldb_private::Expression::Text(), and lldb_private::NativeFile::Write().

Referenced by Complete(), and Parse().

◆ PrepareForExecution()

lldb_private::Status ClangExpressionParser::PrepareForExecution ( lldb::addr_t func_addr,
lldb::addr_t func_end,
lldb::IRExecutionUnitSP execution_unit_sp,
ExecutionContext exe_ctx,
bool &  can_interpret,
lldb_private::ExecutionPolicy  execution_policy 
)
overridevirtual

Ready an already-parsed expression for execution, possibly evaluating it statically.

Parameters
[out]func_addrThe address to which the function has been written.
[out]func_endThe end of the function's allocated memory region. (func_addr and func_end do not delimit an allocated region; the allocated region may begin before func_addr.)
[in]execution_unit_spAfter parsing, ownership of the execution unit for for the expression is handed to this shared pointer.
[in]exe_ctxThe execution context to write the function into.
[in]execution_policyDetermines whether the expression must be JIT-compiled, must be evaluated statically, or whether this decision may be made opportunistically.
Returns
An error code indicating the success or failure of the operation. Test with Success().

Implements lldb_private::ExpressionParser.

Definition at line 1296 of file ClangExpressionParser.cpp.

References lldb_private::Status::AsCString(), lldb_private::ConstString::AsCString(), IRInterpreter::CanInterpret(), lldb_private::Process::CanInterpretFunctionCalls(), lldb_private::ClangExpressionHelper::DeclMap(), lldb_private::DiagnosticManager::Diagnostics(), lldb_private::LLVMUserExpression::IRPasses::EarlyPasses, lldb_private::eExecutionPolicyAlways, lldb_private::eExecutionPolicyNever, lldb_private::eExecutionPolicyTopLevel, lldb::eLanguageTypeUnknown, lldb_private::Expressions, FindFunctionInModule(), lldb_private::Expression::FunctionName(), lldb_private::Process::GetDynamicCheckers(), lldb_private::ExecutionContext::GetFrameSP(), lldb_private::GetLog(), lldb_private::Language::GetNameForLanguageType(), lldb_private::ExecutionContext::GetProcessPtr(), lldb_private::ExecutionContext::GetProcessSP(), lldb_private::StreamString::GetString(), lldb_private::DiagnosticManager::GetString(), lldb_private::ExecutionContext::GetTargetSP(), lldb_private::Expression::GetTypeSystemHelper(), lldb_private::ClangDynamicCheckerFunctions::Install(), lldb_private::Expression::Language(), lldb_private::LLVMUserExpression::IRPasses::LatePasses, LLDB_INVALID_ADDRESS, LLDB_LOGF, m_code_generator, m_compiler, lldb_private::ExpressionParser::m_expr, m_llvm_context, lldb_private::Expression::NeedsValidation(), lldb_private::Expression::NeedsVariableResolution(), IRForTarget::runOnModule(), lldb_private::IRDynamicChecks::runOnModule(), lldb_private::Process::SetDynamicCheckers(), lldb_private::Status::SetErrorString(), lldb_private::Status::SetErrorStringWithFormat(), lldb_private::Status::SetErrorToGenericError(), lldb_private::SymbolContext::target_sp, and lldb_private::toString().

Referenced by lldb_private::ClangUtilityFunction::Install().

◆ RewriteExpression()

bool ClangExpressionParser::RewriteExpression ( DiagnosticManager diagnostic_manager)
overridevirtual

Try to use the FixIts in the diagnostic_manager to rewrite the expression.

If successful, the rewritten expression is stored in the diagnostic_manager, get it out with GetFixedExpression.

Parameters
[in]diagnostic_managerThe diagnostic manager containing fixit's to apply.
Returns
true if the rewrite was successful, false otherwise.

Reimplemented from lldb_private::ExpressionParser.

Definition at line 1223 of file ClangExpressionParser.cpp.

References ApplyFixIt(), lldb_private::DiagnosticManager::Diagnostics(), m_compiler, and lldb_private::DiagnosticManager::SetFixedExpression().

◆ RunStaticInitializers()

lldb_private::Status ClangExpressionParser::RunStaticInitializers ( lldb::IRExecutionUnitSP execution_unit_sp,
ExecutionContext exe_ctx 
)

Run all static initializers for an execution unit.

Parameters
[in]execution_unit_spThe execution unit.
[in]exe_ctxThe execution context to use when running them. Thread can't be null.
Returns
The error code indicating the

Definition at line 1473 of file ClangExpressionParser.cpp.

References lldb::eExpressionCompleted, lldb_private::Thread::GetProcess(), lldb_private::DiagnosticManager::GetString(), lldb_private::ExecutionContext::GetThreadRef(), lldb_private::ExecutionContext::HasThreadScope(), lldbassert, lldb_private::Status::SetErrorString(), and lldb_private::Status::SetErrorStringWithFormat().

Member Data Documentation

◆ m_ast_context

std::shared_ptr<TypeSystemClang> lldb_private::ClangExpressionParser::m_ast_context
private

Definition at line 180 of file ClangExpressionParser.h.

Referenced by ClangExpressionParser(), and ParseInternal().

◆ m_code_generator

std::unique_ptr<clang::CodeGenerator> lldb_private::ClangExpressionParser::m_code_generator
private

The Clang object that generates IR.

Definition at line 175 of file ClangExpressionParser.h.

Referenced by ClangExpressionParser(), Complete(), ParseInternal(), and PrepareForExecution().

◆ m_compiler

std::unique_ptr<clang::CompilerInstance> lldb_private::ClangExpressionParser::m_compiler
private

The Clang compiler used to parse expressions into IR.

Definition at line 173 of file ClangExpressionParser.h.

Referenced by ClangExpressionParser(), Complete(), ParseInternal(), PrepareForExecution(), and RewriteExpression().

◆ m_filename

std::string lldb_private::ClangExpressionParser::m_filename
private

File name used for the user expression.

Definition at line 184 of file ClangExpressionParser.h.

Referenced by ClangExpressionParser(), and ParseInternal().

◆ m_include_directories

std::vector<std::string> lldb_private::ClangExpressionParser::m_include_directories
private

Definition at line 182 of file ClangExpressionParser.h.

Referenced by ClangExpressionParser().

◆ m_llvm_context

std::unique_ptr<llvm::LLVMContext> lldb_private::ClangExpressionParser::m_llvm_context
private

The LLVM context to generate IR into.

Definition at line 171 of file ClangExpressionParser.h.

Referenced by ClangExpressionParser(), and PrepareForExecution().

◆ m_pp_callbacks

LLDBPreprocessorCallbacks* lldb_private::ClangExpressionParser::m_pp_callbacks
private

Called when the preprocessor encounters module imports.

Definition at line 178 of file ClangExpressionParser.h.

Referenced by ClangExpressionParser(), and ParseInternal().


The documentation for this class was generated from the following files: