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/ExecutionEngine/ExecutionEngine.h"
21#include "llvm/IR/Module.h"
22#include "llvm/TargetParser/Triple.h"
54 :
FunctionCaller(exe_scope, return_type, functionAddress, arg_value_list,
56 m_type_system_helper(*this) {
79 unsigned num_errors = 0;
81 std::string return_type_str(
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;
123 std::string args_buffer;
125 std::string args_list_buffer;
127 for (
size_t i = 0; i < num_args; i++) {
128 std::string type_name;
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");
214 clang::ASTConsumer *passthrough) {
#define LLDB_LOGF(log,...)
A section + offset based address class.
"lldb/Expression/ClangExpressionParser.h" Encapsulates an instance of Clang that can parse expression...
clang::ASTConsumer * ASTTransformer(clang::ASTConsumer *passthrough) override
Return the object that the parser should allow to access ASTs.
ClangFunctionCaller & m_owner
std::unique_ptr< ASTStructExtractor > m_struct_extractor
The class that generates the argument struct layout.
const char * GetWrapperStructName()
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.
Generic representation of a type in a programming language.
CompilerType GetFunctionArgumentTypeAtIndex(size_t idx) const
ConstString GetTypeName(bool BaseOnly=false) const
int GetFunctionArgumentCount() const
Returns -1 if this isn't a function of if the function doesn't have a prototype Returns a value >= 0 ...
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
size_t void PutString(lldb::Severity severity, llvm::StringRef str)
size_t Printf(lldb::Severity severity, const char *format,...) __attribute__((format(printf
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
virtual lldb::ProcessSP CalculateProcess()=0
lldb::ProcessWP m_jit_process_wp
Expression's always have to have a target...
Encapsulates a function that can be called.
std::string m_wrapper_struct_name
The name of the struct that contains the target function address, arguments, and result.
Function * m_function_ptr
The function we're going to call.
ValueList m_arg_values
The default values of the arguments.
std::string m_wrapper_function_name
The name of the wrapper function.
std::string m_wrapper_function_text
The contents of the wrapper function.
CompilerType m_function_return_type
The opaque clang qual type for the function return type.
bool m_compiled
True if the wrapper function has already been parsed.
std::unique_ptr< ExpressionParser > m_parser
The parser responsible for compiling the function.
CompilerType GetCompilerType()
Value * GetValueAtIndex(size_t idx)
const CompilerType & GetCompilerType()
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.
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::weak_ptr< lldb_private::Process > ProcessWP