Go to the documentation of this file.
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/RecordLayout.h"
16 #include "clang/CodeGen/CodeGenAction.h"
17 #include "clang/CodeGen/ModuleBuilder.h"
18 #include "clang/Frontend/CompilerInstance.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/ADT/Triple.h"
21 #include "llvm/ExecutionEngine/ExecutionEngine.h"
22 #include "llvm/IR/Module.h"
54 :
FunctionCaller(exe_scope, return_type, functionAddress, arg_value_list,
56 m_type_system_helper(*this) {
79 unsigned num_errors = 0;
106 bool trust_function =
false;
111 if (function_clang_type) {
113 if (num_func_args >= 0) {
114 trust_function =
true;
115 num_args = num_func_args;
127 for (
size_t i = 0; i < num_args; i++) {
130 if (trust_function) {
137 if (clang_qual_type) {
140 diagnostic_manager.
Printf(
142 "Could not determine type of input value %" PRIu64
".",
149 if (i < num_args - 1)
153 args_buffer.append(
" ");
154 args_buffer.append(type_name);
155 snprintf(arg_buf, 31,
"arg_%" PRIu64, (uint64_t)i);
156 args_buffer.push_back(
' ');
157 args_buffer.append(arg_buf);
158 args_buffer.append(
";\n");
160 args_list_buffer.append(
"__lldb_fn_data->");
161 args_list_buffer.append(arg_buf);
162 if (i < num_args - 1)
163 args_list_buffer.append(
", ");
180 " __lldb_fn_data->return_value = __lldb_fn_data->fn_ptr (");
190 if (jit_process_sp) {
191 const bool generate_debug_info =
true;
193 generate_debug_info);
194 num_errors = clang_parser->Parse(diagnostic_manager);
198 "no process - unable to inject function");
212 clang::ASTConsumer *passthrough) {
std::string m_wrapper_function_name
The name of the wrapper function.
Function * m_function_ptr
The function we're going to call.
Value * GetValueAtIndex(size_t idx)
clang::ASTConsumer * ASTTransformer(clang::ASTConsumer *passthrough) override
Return the object that the parser should allow to access ASTs.
lldb::ProcessWP m_jit_process_wp
Expression's always have to have a target...
#define LLDB_LOGF(log,...)
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
~ClangFunctionCaller() override
CompilerType GetFunctionArgumentTypeAtIndex(size_t idx) const
std::string m_wrapper_function_text
The contents of the wrapper function.
@ eDiagnosticSeverityError
std::string m_wrapper_struct_name
The name of the struct that contains the target function address, arguments, and result.
unsigned CompileFunction(lldb::ThreadSP thread_to_use_sp, DiagnosticManager &diagnostic_manager) override
Compile the wrapper function.
ValueList m_arg_values
The default values of the arguments.
const char * GetWrapperStructName()
string(SUBSTRING ${p} 10 -1 pStripped) if($
ClangFunctionCaller & m_owner
int GetFunctionArgumentCount() const
Returns -1 if this isn't a function of if the function doesn't have a prototype Returns a value >= 0 ...
size_t void PutString(DiagnosticSeverity severity, llvm::StringRef str)
ConstString GetTypeName() const
std::unique_ptr< ExpressionParser > m_parser
The parser responsible for compiling the function.
ClangFunctionCaller(ExecutionContextScope &exe_scope, const CompilerType &return_type, const Address &function_address, const ValueList &arg_value_list, const char *name)
Constructor.
Generic representation of a type in a programming language.
const CompilerType & GetCompilerType()
CompilerType m_function_return_type
The opaque clang qual type for the function return type.
virtual lldb::ProcessSP CalculateProcess()=0
A class that represents a running process on the host machine.
CompilerType GetCompilerType()
std::unique_ptr< ASTStructExtractor > m_struct_extractor
The class that generates the argument struct layout.
bool m_compiled
True if the wrapper function has already been parsed.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
size_t Printf(DiagnosticSeverity severity, const char *format,...) __attribute__((format(printf