LLDB  mainline
LLVMUserExpression.h
Go to the documentation of this file.
1 //===-- LLVMUserExpression.h ------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef liblldb_LLVMUserExpression_h
10 #define liblldb_LLVMUserExpression_h
11 
12 #include <map>
13 #include <string>
14 #include <vector>
15 
16 #include "llvm/IR/LegacyPassManager.h"
17 
19 
20 namespace lldb_private {
21 
22 /// \class LLVMUserExpression LLVMUserExpression.h
23 /// "lldb/Expression/LLVMUserExpression.h" Encapsulates a one-time expression
24 /// for use in lldb.
25 ///
26 /// LLDB uses expressions for various purposes, notably to call functions
27 /// and as a backend for the expr command. LLVMUserExpression is a virtual
28 /// base class that encapsulates the objects needed to parse and JIT an
29 /// expression. The actual parsing part will be provided by the specific
30 /// implementations of LLVMUserExpression - which will be vended through the
31 /// appropriate TypeSystem.
33 public:
34  /// LLVM-style RTTI support.
35  static bool classof(const Expression *E) {
36  return E->getKind() == eKindLLVMUserExpression;
37  }
38 
39  // The IRPasses struct is filled in by a runtime after an expression is
40  // compiled and can be used to to run fixups/analysis passes as required.
41  // EarlyPasses are run on the generated module before lldb runs its own IR
42  // fixups and inserts instrumentation code/pointer checks. LatePasses are run
43  // after the module has been processed by llvm, before the module is
44  // assembled and run in the ThreadPlan.
45  struct IRPasses {
46  IRPasses() : EarlyPasses(nullptr), LatePasses(nullptr){};
47  std::shared_ptr<llvm::legacy::PassManager> EarlyPasses;
48  std::shared_ptr<llvm::legacy::PassManager> LatePasses;
49  };
50 
51  LLVMUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
52  llvm::StringRef prefix, lldb::LanguageType language,
53  ResultType desired_type,
54  const EvaluateExpressionOptions &options,
55  ExpressionKind kind);
56  ~LLVMUserExpression() override;
57 
59  DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
60  lldb::ExpressionVariableSP &result,
61  lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS,
62  lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS) override;
63 
64  bool CanInterpret() override { return m_can_interpret; }
65 
66  /// Return the string that the parser should parse. Must be a full
67  /// translation unit.
68  const char *Text() override { return m_transformed_text.c_str(); }
69 
70  lldb::ModuleSP GetJITModule() override;
71 
72 protected:
74  DoExecute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
75  const EvaluateExpressionOptions &options,
76  lldb::UserExpressionSP &shared_ptr_to_me,
77  lldb::ExpressionVariableSP &result) override;
78 
79  virtual void ScanContext(ExecutionContext &exe_ctx,
80  lldb_private::Status &err) = 0;
81 
82  bool PrepareToExecuteJITExpression(DiagnosticManager &diagnostic_manager,
83  ExecutionContext &exe_ctx,
84  lldb::addr_t &struct_address);
85 
86  virtual bool AddArguments(ExecutionContext &exe_ctx,
87  std::vector<lldb::addr_t> &args,
88  lldb::addr_t struct_address,
89  DiagnosticManager &diagnostic_manager) = 0;
90 
92  m_stack_frame_bottom; ///< The bottom of the allocated stack frame.
93  lldb::addr_t m_stack_frame_top; ///< The top of the allocated stack frame.
94 
95  bool m_allow_cxx; ///< True if the language allows C++.
96  bool m_allow_objc; ///< True if the language allows Objective-C.
97  std::string
98  m_transformed_text; ///< The text of the expression, as send to the parser
99 
100  std::shared_ptr<IRExecutionUnit>
101  m_execution_unit_sp; ///< The execution unit the expression is stored in.
102  std::unique_ptr<Materializer> m_materializer_up; ///< The materializer to use
103  /// when running the
104  /// expression.
105  lldb::ModuleWP m_jit_module_wp;
106  bool m_enforce_valid_object; ///< True if the expression parser should enforce
107  ///the presence of a valid class pointer
108  /// in order to generate the expression as a method.
109  bool m_in_cplusplus_method; ///< True if the expression is compiled as a C++
110  ///member function (true if it was parsed
111  /// when exe_ctx was in a C++ method).
112  bool m_in_objectivec_method; ///< True if the expression is compiled as an
113  ///Objective-C method (true if it was parsed
114  /// when exe_ctx was in an Objective-C method).
115  bool m_in_static_method; ///< True if the expression is compiled as a static
116  ///(or class) method (currently true if it
117  /// was parsed when exe_ctx was in an Objective-C class method).
118  bool m_needs_object_ptr; ///< True if "this" or "self" must be looked up and
119  ///passed in. False if the expression
120  /// doesn't really use them and they can be NULL.
121  bool m_const_object; ///< True if "this" is const.
122  Target *m_target; ///< The target for storing persistent data like types and
123  ///variables.
124 
125  bool m_can_interpret; ///< True if the expression could be evaluated
126  ///statically; false otherwise.
127  lldb::addr_t m_materialized_address; ///< The address at which the arguments
128  ///to the expression have been
129  ///materialized.
131 };
132 
133 } // namespace lldb_private
134 #endif
Materializer::DematerializerSP m_dematerializer_sp
The dematerializer.
ExpressionKind
Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
Definition: Expression.h:36
bool m_allow_cxx
True if the language allows C++.
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
virtual bool AddArguments(ExecutionContext &exe_ctx, std::vector< lldb::addr_t > &args, lldb::addr_t struct_address, DiagnosticManager &diagnostic_manager)=0
bool FinalizeJITExecution(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, lldb::ExpressionVariableSP &result, lldb::addr_t function_stack_bottom=LLDB_INVALID_ADDRESS, lldb::addr_t function_stack_top=LLDB_INVALID_ADDRESS) override
Apply the side effects of the function to program state.
Encapsulates a one-time expression for use in lldb.
Encapsulates a single expression for use in lldb.
Definition: Expression.h:33
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
lldb::addr_t m_stack_frame_bottom
The bottom of the allocated stack frame.
lldb::ExpressionResults DoExecute(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options, lldb::UserExpressionSP &shared_ptr_to_me, lldb::ExpressionVariableSP &result) override
std::string m_transformed_text
The text of the expression, as send to the parser.
ExpressionKind getKind() const
LLVM-style RTTI support.
Definition: Expression.h:94
lldb::ModuleSP GetJITModule() override
std::unique_ptr< Materializer > m_materializer_up
The materializer to use when running the expression.
bool m_in_objectivec_method
True if the expression is compiled as an Objective-C method (true if it was parsed when exe_ctx was i...
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
lldb::addr_t m_stack_frame_top
The top of the allocated stack frame.
LanguageType
Programming language type.
std::shared_ptr< IRExecutionUnit > m_execution_unit_sp
The execution unit the expression is stored in.
bool m_enforce_valid_object
True if the expression parser should enforce the presence of a valid class pointer.
bool m_in_static_method
True if the expression is compiled as a static (or class) method (currently true if it...
bool m_can_interpret
True if the expression could be evaluated statically; false otherwise.
bool m_needs_object_ptr
was parsed when exe_ctx was in an Objective-C class method).
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
bool PrepareToExecuteJITExpression(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, lldb::addr_t &struct_address)
static bool classof(const Expression *E)
LLVM-style RTTI support.
Target * m_target
The target for storing persistent data like types and variables.
const char * Text() override
Return the string that the parser should parse.
uint64_t addr_t
Definition: lldb-types.h:83
virtual void ScanContext(ExecutionContext &exe_ctx, lldb_private::Status &err)=0
lldb::addr_t m_materialized_address
The address at which the arguments to the expression have been materialized.
"lldb/Expression/LLVMUserExpression.h" Encapsulates a one-time expression for use in lldb...
LLVMUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language, ResultType desired_type, const EvaluateExpressionOptions &options, ExpressionKind kind)
std::shared_ptr< llvm::legacy::PassManager > EarlyPasses
bool m_allow_objc
True if the language allows Objective-C.
bool m_in_cplusplus_method
in order to generate the expression as a method.
bool m_const_object
True if "this" is const.
std::shared_ptr< Dematerializer > DematerializerSP
Definition: Materializer.h:66
std::shared_ptr< llvm::legacy::PassManager > LatePasses
An error handling class.
Definition: Status.h:44