Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h
39654 views
//===-- ClangFunctionCaller.h -----------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGFUNCTIONCALLER_H9#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGFUNCTIONCALLER_H1011#include "ClangExpressionHelper.h"1213#include "lldb/Core/Address.h"14#include "lldb/Core/Value.h"15#include "lldb/Core/ValueObjectList.h"16#include "lldb/Expression/FunctionCaller.h"17#include "lldb/Symbol/CompilerType.h"18#include "lldb/Target/Process.h"1920namespace lldb_private {2122class ASTStructExtractor;2324/// \class ClangFunctionCaller ClangFunctionCaller.h25/// "lldb/Expression/ClangFunctionCaller.h" Encapsulates a function that can26/// be called.27///28/// A given ClangFunctionCaller object can handle a single function signature.29/// Once constructed, it can set up any number of concurrent calls to30/// functions with that signature.31///32/// It performs the call by synthesizing a structure that contains the pointer33/// to the function and the arguments that should be passed to that function,34/// and producing a special-purpose JIT-compiled function that accepts a void*35/// pointing to this struct as its only argument and calls the function in the36/// struct with the written arguments. This method lets Clang handle the37/// vagaries of function calling conventions.38///39/// The simplest use of the ClangFunctionCaller is to construct it with a40/// function representative of the signature you want to use, then call41/// ExecuteFunction(ExecutionContext &, Stream &, Value &).42///43/// If you need to reuse the arguments for several calls, you can call44/// InsertFunction() followed by WriteFunctionArguments(), which will return45/// the location of the args struct for the wrapper function in args_addr_ref.46///47/// If you need to call the function on the thread plan stack, you can also48/// call InsertFunction() followed by GetThreadPlanToCallFunction().49///50/// Any of the methods that take arg_addr_ptr or arg_addr_ref can be passed a51/// pointer set to LLDB_INVALID_ADDRESS and new structure will be allocated52/// and its address returned in that variable.53///54/// Any of the methods that take arg_addr_ptr can be passed NULL, and the55/// argument space will be managed for you.56class ClangFunctionCaller : public FunctionCaller {57friend class ASTStructExtractor;5859class ClangFunctionCallerHelper60: public llvm::RTTIExtends<ClangFunctionCallerHelper,61ClangExpressionHelper> {62public:63// LLVM RTTI support64static char ID;6566ClangFunctionCallerHelper(ClangFunctionCaller &owner) : m_owner(owner) {}6768/// Return the object that the parser should use when resolving external69/// values. May be NULL if everything should be self-contained.70ClangExpressionDeclMap *DeclMap() override { return nullptr; }7172/// Return the object that the parser should allow to access ASTs. May be73/// NULL if the ASTs do not need to be transformed.74///75/// \param[in] passthrough76/// The ASTConsumer that the returned transformer should send77/// the ASTs to after transformation.78clang::ASTConsumer *79ASTTransformer(clang::ASTConsumer *passthrough) override;8081private:82ClangFunctionCaller &m_owner;83std::unique_ptr<ASTStructExtractor> m_struct_extractor; ///< The class that84///generates the85///argument struct86///layout.87};8889// LLVM RTTI support90static char ID;9192public:93bool isA(const void *ClassID) const override {94return ClassID == &ID || FunctionCaller::isA(ClassID);95}96static bool classof(const Expression *obj) { return obj->isA(&ID); }9798/// Constructor99///100/// \param[in] exe_scope101/// An execution context scope that gets us at least a target and102/// process.103///104/// \param[in] return_type105/// A compiler type for the function result. Should be106/// defined in ast_context.107///108/// \param[in] function_address109/// The address of the function to call.110///111/// \param[in] arg_value_list112/// The default values to use when calling this function. Can113/// be overridden using WriteFunctionArguments().114ClangFunctionCaller(ExecutionContextScope &exe_scope,115const CompilerType &return_type,116const Address &function_address,117const ValueList &arg_value_list, const char *name);118119~ClangFunctionCaller() override;120121/// Compile the wrapper function122///123/// \param[in] thread_to_use_sp124/// Compilation might end up calling functions. Pass in the thread you125/// want the compilation to use. If you pass in an empty ThreadSP it will126/// use the currently selected thread.127///128/// \param[in] diagnostic_manager129/// The diagnostic manager to report parser errors to.130///131/// \return132/// The number of errors.133unsigned CompileFunction(lldb::ThreadSP thread_to_use_sp,134DiagnosticManager &diagnostic_manager) override;135136ExpressionTypeSystemHelper *GetTypeSystemHelper() override {137return &m_type_system_helper;138}139140protected:141const char *GetWrapperStructName() { return m_wrapper_struct_name.c_str(); }142143private:144// For ClangFunctionCaller only145146// Note: the parser needs to be destructed before the execution unit, so147// declare the execution unit first.148ClangFunctionCallerHelper m_type_system_helper;149};150151} // namespace lldb_private152153#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGFUNCTIONCALLER_H154155156