]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Expression/IRDynamicChecks.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / include / lldb / Expression / IRDynamicChecks.h
1 //===-- IRDynamicChecks.h ---------------------------------------------*- C++
2 //-*-===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef liblldb_IRDynamicChecks_h_
12 #define liblldb_IRDynamicChecks_h_
13
14 #include "lldb/lldb-types.h"
15 #include "llvm/Pass.h"
16
17 namespace llvm {
18 class BasicBlock;
19 class CallInst;
20 class Constant;
21 class Function;
22 class Instruction;
23 class Module;
24 class DataLayout;
25 class Value;
26 }
27
28 namespace lldb_private {
29
30 class ClangExpressionDeclMap;
31 class ExecutionContext;
32 class Stream;
33
34 //----------------------------------------------------------------------
35 /// @class DynamicCheckerFunctions IRDynamicChecks.h
36 /// "lldb/Expression/IRDynamicChecks.h"
37 /// @brief Encapsulates dynamic check functions used by expressions.
38 ///
39 /// Each of the utility functions encapsulated in this class is responsible
40 /// for validating some data that an expression is about to use.  Examples are:
41 ///
42 /// a = *b;     // check that b is a valid pointer
43 /// [b init];   // check that b is a valid object to send "init" to
44 ///
45 /// The class installs each checker function into the target process and
46 /// makes it available to IRDynamicChecks to use.
47 //----------------------------------------------------------------------
48 class DynamicCheckerFunctions {
49 public:
50   //------------------------------------------------------------------
51   /// Constructor
52   //------------------------------------------------------------------
53   DynamicCheckerFunctions();
54
55   //------------------------------------------------------------------
56   /// Destructor
57   //------------------------------------------------------------------
58   ~DynamicCheckerFunctions();
59
60   //------------------------------------------------------------------
61   /// Install the utility functions into a process.  This binds the
62   /// instance of DynamicCheckerFunctions to that process.
63   ///
64   /// @param[in] diagnostic_manager
65   ///     A diagnostic manager to report errors to.
66   ///
67   /// @param[in] exe_ctx
68   ///     The execution context to install the functions into.
69   ///
70   /// @return
71   ///     True on success; false on failure, or if the functions have
72   ///     already been installed.
73   //------------------------------------------------------------------
74   bool Install(DiagnosticManager &diagnostic_manager,
75                ExecutionContext &exe_ctx);
76
77   bool DoCheckersExplainStop(lldb::addr_t addr, Stream &message);
78
79   std::unique_ptr<UtilityFunction> m_valid_pointer_check;
80   std::unique_ptr<UtilityFunction> m_objc_object_check;
81 };
82
83 //----------------------------------------------------------------------
84 /// @class IRDynamicChecks IRDynamicChecks.h "lldb/Expression/IRDynamicChecks.h"
85 /// @brief Adds dynamic checks to a user-entered expression to reduce its
86 /// likelihood of crashing
87 ///
88 /// When an IR function is executed in the target process, it may cause
89 /// crashes or hangs by dereferencing NULL pointers, trying to call Objective-C
90 /// methods on objects that do not respond to them, and so forth.
91 ///
92 /// IRDynamicChecks adds calls to the functions in DynamicCheckerFunctions
93 /// to appropriate locations in an expression's IR.
94 //----------------------------------------------------------------------
95 class IRDynamicChecks : public llvm::ModulePass {
96 public:
97   //------------------------------------------------------------------
98   /// Constructor
99   ///
100   /// @param[in] checker_functions
101   ///     The checker functions for the target process.
102   ///
103   /// @param[in] func_name
104   ///     The name of the function to prepare for execution in the target.
105   ///
106   /// @param[in] decl_map
107   ///     The mapping used to look up entities in the target process. In
108   ///     this case, used to find objc_msgSend
109   //------------------------------------------------------------------
110   IRDynamicChecks(DynamicCheckerFunctions &checker_functions,
111                   const char *func_name = "$__lldb_expr");
112
113   //------------------------------------------------------------------
114   /// Destructor
115   //------------------------------------------------------------------
116   ~IRDynamicChecks() override;
117
118   //------------------------------------------------------------------
119   /// Run this IR transformer on a single module
120   ///
121   /// @param[in] M
122   ///     The module to run on.  This module is searched for the function
123   ///     $__lldb_expr, and that function is passed to the passes one by
124   ///     one.
125   ///
126   /// @return
127   ///     True on success; false otherwise
128   //------------------------------------------------------------------
129   bool runOnModule(llvm::Module &M) override;
130
131   //------------------------------------------------------------------
132   /// Interface stub
133   //------------------------------------------------------------------
134   void assignPassManager(
135       llvm::PMStack &PMS,
136       llvm::PassManagerType T = llvm::PMT_ModulePassManager) override;
137
138   //------------------------------------------------------------------
139   /// Returns PMT_ModulePassManager
140   //------------------------------------------------------------------
141   llvm::PassManagerType getPotentialPassManagerType() const override;
142
143 private:
144   //------------------------------------------------------------------
145   /// A basic block-level pass to find all pointer dereferences and
146   /// validate them before use.
147   //------------------------------------------------------------------
148
149   //------------------------------------------------------------------
150   /// The top-level pass implementation
151   ///
152   /// @param[in] M
153   ///     The module currently being processed.
154   ///
155   /// @param[in] BB
156   ///     The basic block currently being processed.
157   ///
158   /// @return
159   ///     True on success; false otherwise
160   //------------------------------------------------------------------
161   bool FindDataLoads(llvm::Module &M, llvm::BasicBlock &BB);
162
163   std::string m_func_name; ///< The name of the function to add checks to
164   DynamicCheckerFunctions
165       &m_checker_functions; ///< The checker functions for the process
166 };
167
168 } // namespace lldb_private
169
170 #endif // liblldb_IRDynamicChecks_h_