]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Expression/LLVMUserExpression.h
tcpdump: remove undesired svn:keywords property from contrib
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Expression / LLVMUserExpression.h
1 //===-- LLVMUserExpression.h ------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_LLVMUserExpression_h
11 #define liblldb_LLVMUserExpression_h
12
13 // C Includes
14 // C++ Includes
15 #include <map>
16 #include <string>
17 #include <vector>
18
19 // Other libraries and framework includes
20 #include "llvm/IR/LegacyPassManager.h"
21
22 // Project includes
23 #include "lldb/Expression/UserExpression.h"
24
25 namespace lldb_private {
26
27 //----------------------------------------------------------------------
28 /// @class LLVMUserExpression LLVMUserExpression.h
29 /// "lldb/Expression/LLVMUserExpression.h"
30 /// @brief Encapsulates a one-time expression for use in lldb.
31 ///
32 /// LLDB uses expressions for various purposes, notably to call functions
33 /// and as a backend for the expr command.  LLVMUserExpression is a virtual base
34 /// class that encapsulates the objects needed to parse and JIT an expression.
35 /// The actual parsing part will be provided by the specific implementations
36 /// of LLVMUserExpression - which will be vended through the appropriate
37 /// TypeSystem.
38 //----------------------------------------------------------------------
39 class LLVMUserExpression : public UserExpression {
40 public:
41   // The IRPasses struct is filled in by a runtime after an expression is
42   // compiled and can be used to to run
43   // fixups/analysis passes as required. EarlyPasses are run on the generated
44   // module before lldb runs its own IR
45   // fixups and inserts instrumentation code/pointer checks. LatePasses are run
46   // after the module has been processed by
47   // llvm, before the module is assembled and run in the ThreadPlan.
48   struct IRPasses {
49     IRPasses() : EarlyPasses(nullptr), LatePasses(nullptr){};
50     std::shared_ptr<llvm::legacy::PassManager> EarlyPasses;
51     std::shared_ptr<llvm::legacy::PassManager> LatePasses;
52   };
53
54   LLVMUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
55                      llvm::StringRef prefix, lldb::LanguageType language,
56                      ResultType desired_type,
57                      const EvaluateExpressionOptions &options);
58   ~LLVMUserExpression() override;
59
60   bool FinalizeJITExecution(
61       DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
62       lldb::ExpressionVariableSP &result,
63       lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS,
64       lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS) override;
65
66   bool CanInterpret() override { return m_can_interpret; }
67
68   //------------------------------------------------------------------
69   /// Return the string that the parser should parse.  Must be a full
70   /// translation unit.
71   //------------------------------------------------------------------
72   const char *Text() override { return m_transformed_text.c_str(); }
73
74   lldb::ModuleSP GetJITModule() override;
75
76 protected:
77   lldb::ExpressionResults
78   DoExecute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
79             const EvaluateExpressionOptions &options,
80             lldb::UserExpressionSP &shared_ptr_to_me,
81             lldb::ExpressionVariableSP &result) override;
82
83   virtual void ScanContext(ExecutionContext &exe_ctx,
84                            lldb_private::Status &err) = 0;
85
86   bool PrepareToExecuteJITExpression(DiagnosticManager &diagnostic_manager,
87                                      ExecutionContext &exe_ctx,
88                                      lldb::addr_t &struct_address);
89
90   virtual bool AddArguments(ExecutionContext &exe_ctx,
91                             std::vector<lldb::addr_t> &args,
92                             lldb::addr_t struct_address,
93                             DiagnosticManager &diagnostic_manager) = 0;
94
95   lldb::addr_t
96       m_stack_frame_bottom;       ///< The bottom of the allocated stack frame.
97   lldb::addr_t m_stack_frame_top; ///< The top of the allocated stack frame.
98
99   bool m_allow_cxx;  ///< True if the language allows C++.
100   bool m_allow_objc; ///< True if the language allows Objective-C.
101   std::string
102       m_transformed_text; ///< The text of the expression, as send to the parser
103
104   std::shared_ptr<IRExecutionUnit>
105       m_execution_unit_sp; ///< The execution unit the expression is stored in.
106   std::unique_ptr<Materializer> m_materializer_ap; ///< The materializer to use
107                                                    ///when running the
108                                                    ///expression.
109   lldb::ModuleWP m_jit_module_wp;
110   bool m_enforce_valid_object; ///< True if the expression parser should enforce
111                                ///the presence of a valid class pointer
112   /// in order to generate the expression as a method.
113   bool m_in_cplusplus_method;  ///< True if the expression is compiled as a C++
114                                ///member function (true if it was parsed
115                                /// when exe_ctx was in a C++ method).
116   bool m_in_objectivec_method; ///< True if the expression is compiled as an
117                                ///Objective-C method (true if it was parsed
118                                /// when exe_ctx was in an Objective-C method).
119   bool m_in_static_method; ///< True if the expression is compiled as a static
120                            ///(or class) method (currently true if it
121   /// was parsed when exe_ctx was in an Objective-C class method).
122   bool m_needs_object_ptr; ///< True if "this" or "self" must be looked up and
123                            ///passed in.  False if the expression
124                            /// doesn't really use them and they can be NULL.
125   bool m_const_object;     ///< True if "this" is const.
126   Target *m_target; ///< The target for storing persistent data like types and
127                     ///variables.
128
129   bool m_can_interpret; ///< True if the expression could be evaluated
130                         ///statically; false otherwise.
131   lldb::addr_t m_materialized_address; ///< The address at which the arguments
132                                        ///to the expression have been
133                                        ///materialized.
134   Materializer::DematerializerSP m_dematerializer_sp; ///< The dematerializer.
135 };
136
137 } // namespace lldb_private
138 #endif