1 //===-- LLVMUserExpression.h ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_LLVMUserExpression_h
11 #define liblldb_LLVMUserExpression_h
20 #include "lldb/Expression/UserExpression.h"
22 namespace lldb_private
25 //----------------------------------------------------------------------
26 /// @class LLVMUserExpression LLVMUserExpression.h "lldb/Expression/LLVMUserExpression.h"
27 /// @brief Encapsulates a one-time expression for use in lldb.
29 /// LLDB uses expressions for various purposes, notably to call functions
30 /// and as a backend for the expr command. LLVMUserExpression is a virtual base
31 /// class that encapsulates the objects needed to parse and JIT an expression.
32 /// The actual parsing part will be provided by the specific implementations
33 /// of LLVMUserExpression - which will be vended through the appropriate TypeSystem.
34 //----------------------------------------------------------------------
35 class LLVMUserExpression : public UserExpression
38 LLVMUserExpression(ExecutionContextScope &exe_scope,
40 const char *expr_prefix,
41 lldb::LanguageType language,
42 ResultType desired_type,
43 const EvaluateExpressionOptions &options);
44 ~LLVMUserExpression() override;
46 lldb::ExpressionResults Execute(Stream &error_stream,
47 ExecutionContext &exe_ctx,
48 const EvaluateExpressionOptions &options,
49 lldb::UserExpressionSP &shared_ptr_to_me,
50 lldb::ExpressionVariableSP &result) override;
52 bool FinalizeJITExecution(Stream &error_stream,
53 ExecutionContext &exe_ctx,
54 lldb::ExpressionVariableSP &result,
55 lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS,
56 lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS) override;
59 CanInterpret() override
61 return m_can_interpret;
64 //------------------------------------------------------------------
65 /// Return the string that the parser should parse. Must be a full
67 //------------------------------------------------------------------
71 return m_transformed_text.c_str();
74 lldb::ModuleSP GetJITModule() override;
77 virtual void ScanContext(ExecutionContext &exe_ctx, lldb_private::Error &err) = 0;
79 bool PrepareToExecuteJITExpression(Stream &error_stream, ExecutionContext &exe_ctx, lldb::addr_t &struct_address);
82 AddArguments (ExecutionContext &exe_ctx,
83 std::vector<lldb::addr_t> &args,
84 lldb::addr_t struct_address,
85 Stream &error_stream) = 0;
88 lldb::addr_t m_stack_frame_bottom; ///< The bottom of the allocated stack frame.
89 lldb::addr_t m_stack_frame_top; ///< The top of the allocated stack frame.
91 bool m_allow_cxx; ///< True if the language allows C++.
92 bool m_allow_objc; ///< True if the language allows Objective-C.
93 std::string m_transformed_text; ///< The text of the expression, as send to the parser
95 std::shared_ptr<IRExecutionUnit> m_execution_unit_sp; ///< The execution unit the expression is stored in.
96 std::unique_ptr<Materializer> m_materializer_ap; ///< The materializer to use when running the expression.
97 lldb::ModuleWP m_jit_module_wp;
98 bool m_enforce_valid_object; ///< True if the expression parser should enforce the presence of a valid class pointer
99 ///in order to generate the expression as a method.
100 bool m_in_cplusplus_method; ///< True if the expression is compiled as a C++ member function (true if it was parsed
101 ///when exe_ctx was in a C++ method).
102 bool m_in_objectivec_method; ///< True if the expression is compiled as an Objective-C method (true if it was parsed
103 ///when exe_ctx was in an Objective-C method).
104 bool m_in_static_method; ///< True if the expression is compiled as a static (or class) method (currently true if it
105 ///was parsed when exe_ctx was in an Objective-C class method).
106 bool m_needs_object_ptr; ///< True if "this" or "self" must be looked up and passed in. False if the expression
107 ///doesn't really use them and they can be NULL.
108 bool m_const_object; ///< True if "this" is const.
109 Target *m_target; ///< The target for storing persistent data like types and variables.
111 bool m_can_interpret; ///< True if the expression could be evaluated statically; false otherwise.
113 m_materialized_address; ///< The address at which the arguments to the expression have been materialized.
114 Materializer::DematerializerSP m_dematerializer_sp; ///< The dematerializer.
117 } // namespace lldb_private