LLDB mainline
|
"lldb/Expression/ClangFunctionCaller.h" Encapsulates a function that can be called. More...
#include <ClangFunctionCaller.h>
Classes | |
class | ClangFunctionCallerHelper |
Public Member Functions | |
bool | isA (const void *ClassID) const override |
ClangFunctionCaller (ExecutionContextScope &exe_scope, const CompilerType &return_type, const Address &function_address, const ValueList &arg_value_list, const char *name) | |
Constructor. | |
~ClangFunctionCaller () override | |
unsigned | CompileFunction (lldb::ThreadSP thread_to_use_sp, DiagnosticManager &diagnostic_manager) override |
Compile the wrapper function. | |
ExpressionTypeSystemHelper * | GetTypeSystemHelper () override |
Public Member Functions inherited from lldb_private::FunctionCaller | |
bool | isA (const void *ClassID) const override |
FunctionCaller (ExecutionContextScope &exe_scope, const CompilerType &return_type, const Address &function_address, const ValueList &arg_value_list, const char *name) | |
Constructor. | |
~FunctionCaller () override | |
Destructor. | |
virtual unsigned | CompileFunction (lldb::ThreadSP thread_to_use_sp, DiagnosticManager &diagnostic_manager)=0 |
Compile the wrapper function. | |
bool | InsertFunction (ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref, DiagnosticManager &diagnostic_manager) |
Insert the default function wrapper and its default argument struct. | |
bool | WriteFunctionWrapper (ExecutionContext &exe_ctx, DiagnosticManager &diagnostic_manager) |
Insert the default function wrapper (using the JIT) | |
bool | WriteFunctionArguments (ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref, DiagnosticManager &diagnostic_manager) |
Insert the default function argument struct. | |
bool | WriteFunctionArguments (ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref, ValueList &arg_values, DiagnosticManager &diagnostic_manager) |
Insert an argument struct with a non-default function address and non- default argument values. | |
lldb::ExpressionResults | ExecuteFunction (ExecutionContext &exe_ctx, lldb::addr_t *args_addr_ptr, const EvaluateExpressionOptions &options, DiagnosticManager &diagnostic_manager, Value &results) |
Run the function this FunctionCaller was created with. | |
lldb::ThreadPlanSP | GetThreadPlanToCallFunction (ExecutionContext &exe_ctx, lldb::addr_t args_addr, const EvaluateExpressionOptions &options, DiagnosticManager &diagnostic_manager) |
Get a thread plan to run the function this FunctionCaller was created with. | |
bool | FetchFunctionResults (ExecutionContext &exe_ctx, lldb::addr_t args_addr, Value &ret_value) |
Get the result of the function from its struct. | |
void | DeallocateFunctionResults (ExecutionContext &exe_ctx, lldb::addr_t args_addr) |
Deallocate the arguments structure. | |
const char * | Text () override |
Interface for ClangExpression. | |
const char * | FunctionName () override |
Return the function name that should be used for executing the expression. | |
ExpressionVariableList * | LocalVariables () |
Return the object that the parser should use when registering local variables. | |
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. | |
ValueList | GetArgumentValues () const |
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 Public Member Functions inherited from lldb_private::FunctionCaller | |
static bool | classof (const Expression *obj) |
Protected Member Functions | |
const char * | GetWrapperStructName () |
Private Attributes | |
ClangFunctionCallerHelper | m_type_system_helper |
Static Private Attributes | |
static char | ID |
Friends | |
class | ASTStructExtractor |
Additional Inherited Members | |
Public Types inherited from lldb_private::Expression | |
enum | ResultType { eResultTypeAny , eResultTypeId } |
Protected Attributes inherited from lldb_private::FunctionCaller | |
std::shared_ptr< IRExecutionUnit > | m_execution_unit_sp |
std::unique_ptr< ExpressionParser > | m_parser |
The parser responsible for compiling the function. | |
lldb::ModuleWP | m_jit_module_wp |
std::string | m_name |
The name of this clang function - for debugging purposes. | |
Function * | m_function_ptr |
The function we're going to call. | |
Address | m_function_addr |
If we don't have the FunctionSP, we at least need the address & return type. | |
CompilerType | m_function_return_type |
The opaque clang qual type for the function return type. | |
std::string | m_wrapper_function_name |
The name of the wrapper function. | |
std::string | m_wrapper_function_text |
The contents of the wrapper function. | |
std::string | m_wrapper_struct_name |
The name of the struct that contains the target function address, arguments, and result. | |
std::list< lldb::addr_t > | m_wrapper_args_addrs |
The addresses of the arguments to the wrapper function. | |
bool | m_struct_valid |
True if the ASTStructExtractor has populated the variables below. | |
size_t | m_struct_size |
These values are populated by the ASTStructExtractor. | |
std::vector< uint64_t > | m_member_offsets |
The offset of each member in the struct, in bytes. | |
uint64_t | m_return_size |
The size of the result variable, in bytes. | |
uint64_t | m_return_offset |
The offset of the result variable in the struct, in bytes. | |
ValueList | m_arg_values |
The default values of the arguments. | |
bool | m_compiled |
True if the wrapper function has already been parsed. | |
bool | m_JITted |
True if the wrapper function has already been JIT-compiled. | |
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. | |
"lldb/Expression/ClangFunctionCaller.h" Encapsulates a function that can be called.
A given ClangFunctionCaller object can handle a single function signature. Once constructed, it can set up any number of concurrent calls to functions with that signature.
It performs the call by synthesizing a structure that contains the pointer to the function and the arguments that should be passed to that function, and producing a special-purpose JIT-compiled function that accepts a void* pointing to this struct as its only argument and calls the function in the struct with the written arguments. This method lets Clang handle the vagaries of function calling conventions.
The simplest use of the ClangFunctionCaller is to construct it with a function representative of the signature you want to use, then call ExecuteFunction(ExecutionContext &, Stream &, Value &).
If you need to reuse the arguments for several calls, you can call InsertFunction() followed by WriteFunctionArguments(), which will return the location of the args struct for the wrapper function in args_addr_ref.
If you need to call the function on the thread plan stack, you can also call InsertFunction() followed by GetThreadPlanToCallFunction().
Any of the methods that take arg_addr_ptr or arg_addr_ref can be passed a pointer set to LLDB_INVALID_ADDRESS and new structure will be allocated and its address returned in that variable.
Any of the methods that take arg_addr_ptr can be passed NULL, and the argument space will be managed for you.
Definition at line 57 of file ClangFunctionCaller.h.
ClangFunctionCaller::ClangFunctionCaller | ( | ExecutionContextScope & | exe_scope, |
const CompilerType & | return_type, | ||
const Address & | function_address, | ||
const ValueList & | arg_value_list, | ||
const char * | name | ||
) |
Constructor.
[in] | exe_scope | An execution context scope that gets us at least a target and process. |
[in] | return_type | A compiler type for the function result. Should be defined in ast_context. |
[in] | function_address | The address of the function to call. |
[in] | arg_value_list | The default values to use when calling this function. Can be overridden using WriteFunctionArguments(). |
Definition at line 49 of file ClangFunctionCaller.cpp.
References lldb_private::ExecutionContextScope::CalculateProcess(), and lldb_private::Expression::m_jit_process_wp.
|
overridedefault |
|
inlinestatic |
Definition at line 97 of file ClangFunctionCaller.h.
References ID, and lldb_private::Expression::isA().
|
overridevirtual |
Compile the wrapper function.
[in] | thread_to_use_sp | Compilation might end up calling functions. Pass in the thread you want the compilation to use. If you pass in an empty ThreadSP it will use the currently selected thread. |
[in] | diagnostic_manager | The diagnostic manager to report parser errors to. |
Implements lldb_private::FunctionCaller.
Definition at line 67 of file ClangFunctionCaller.cpp.
References lldb_private::ConstString::AsCString(), lldb::eSeverityError, lldb_private::Expressions, lldb_private::Value::GetCompilerType(), lldb_private::Function::GetCompilerType(), lldb_private::CompilerType::GetFunctionArgumentCount(), lldb_private::CompilerType::GetFunctionArgumentTypeAtIndex(), lldb_private::GetLog(), lldb_private::ValueList::GetSize(), lldb_private::CompilerType::GetTypeName(), lldb_private::ValueList::GetValueAtIndex(), LLDB_LOGF, lldb_private::FunctionCaller::m_arg_values, lldb_private::FunctionCaller::m_compiled, lldb_private::FunctionCaller::m_function_ptr, lldb_private::FunctionCaller::m_function_return_type, lldb_private::Expression::m_jit_process_wp, lldb_private::FunctionCaller::m_parser, lldb_private::FunctionCaller::m_wrapper_function_name, lldb_private::FunctionCaller::m_wrapper_function_text, lldb_private::FunctionCaller::m_wrapper_struct_name, lldb_private::DiagnosticManager::Printf(), lldb_private::DiagnosticManager::PutString(), and UINT32_MAX.
|
inlineoverridevirtual |
Reimplemented from lldb_private::Expression.
Definition at line 137 of file ClangFunctionCaller.h.
References m_type_system_helper.
|
inlineprotected |
Definition at line 142 of file ClangFunctionCaller.h.
References lldb_private::FunctionCaller::m_wrapper_struct_name.
Referenced by lldb_private::ClangFunctionCaller::ClangFunctionCallerHelper::ASTTransformer().
|
inlineoverridevirtual |
Reimplemented from lldb_private::FunctionCaller.
Definition at line 94 of file ClangFunctionCaller.h.
References ID, and lldb_private::FunctionCaller::isA().
|
friend |
Definition at line 58 of file ClangFunctionCaller.h.
|
staticprivate |
Definition at line 91 of file ClangFunctionCaller.h.
|
private |
Definition at line 149 of file ClangFunctionCaller.h.
Referenced by GetTypeSystemHelper().