1 //===-- IRDynamicChecks.h ---------------------------------------------*- C++
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef liblldb_IRDynamicChecks_h_
12 #define liblldb_IRDynamicChecks_h_
14 #include "lldb/lldb-types.h"
15 #include "llvm/Pass.h"
28 namespace lldb_private {
30 class ClangExpressionDeclMap;
31 class ExecutionContext;
34 //----------------------------------------------------------------------
35 /// @class DynamicCheckerFunctions IRDynamicChecks.h
36 /// "lldb/Expression/IRDynamicChecks.h" Encapsulates dynamic check functions
37 /// used by expressions.
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
43 /// a = *b; // check that b is a valid pointer [b init]; // check that b
44 /// is a valid object to send "init" to
46 /// The class installs each checker function into the target process and makes
47 /// it available to IRDynamicChecks to use.
48 //----------------------------------------------------------------------
49 class DynamicCheckerFunctions {
51 //------------------------------------------------------------------
53 //------------------------------------------------------------------
54 DynamicCheckerFunctions();
56 //------------------------------------------------------------------
58 //------------------------------------------------------------------
59 ~DynamicCheckerFunctions();
61 //------------------------------------------------------------------
62 /// Install the utility functions into a process. This binds the instance
63 /// of DynamicCheckerFunctions to that process.
65 /// @param[in] diagnostic_manager
66 /// A diagnostic manager to report errors to.
68 /// @param[in] exe_ctx
69 /// The execution context to install the functions into.
72 /// True on success; false on failure, or if the functions have
73 /// already been installed.
74 //------------------------------------------------------------------
75 bool Install(DiagnosticManager &diagnostic_manager,
76 ExecutionContext &exe_ctx);
78 bool DoCheckersExplainStop(lldb::addr_t addr, Stream &message);
80 std::unique_ptr<UtilityFunction> m_valid_pointer_check;
81 std::unique_ptr<UtilityFunction> m_objc_object_check;
84 //----------------------------------------------------------------------
85 /// @class IRDynamicChecks IRDynamicChecks.h
86 /// "lldb/Expression/IRDynamicChecks.h" Adds dynamic checks to a user-entered
87 /// expression to reduce its likelihood of crashing
89 /// When an IR function is executed in the target process, it may cause
90 /// crashes or hangs by dereferencing NULL pointers, trying to call
91 /// Objective-C methods on objects that do not respond to them, and so forth.
93 /// IRDynamicChecks adds calls to the functions in DynamicCheckerFunctions to
94 /// appropriate locations in an expression's IR.
95 //----------------------------------------------------------------------
96 class IRDynamicChecks : public llvm::ModulePass {
98 //------------------------------------------------------------------
101 /// @param[in] checker_functions
102 /// The checker functions for the target process.
104 /// @param[in] func_name
105 /// The name of the function to prepare for execution in the target.
107 /// @param[in] decl_map
108 /// The mapping used to look up entities in the target process. In
109 /// this case, used to find objc_msgSend
110 //------------------------------------------------------------------
111 IRDynamicChecks(DynamicCheckerFunctions &checker_functions,
112 const char *func_name = "$__lldb_expr");
114 //------------------------------------------------------------------
116 //------------------------------------------------------------------
117 ~IRDynamicChecks() override;
119 //------------------------------------------------------------------
120 /// Run this IR transformer on a single module
123 /// The module to run on. This module is searched for the function
124 /// $__lldb_expr, and that function is passed to the passes one by
128 /// True on success; false otherwise
129 //------------------------------------------------------------------
130 bool runOnModule(llvm::Module &M) override;
132 //------------------------------------------------------------------
134 //------------------------------------------------------------------
135 void assignPassManager(
137 llvm::PassManagerType T = llvm::PMT_ModulePassManager) override;
139 //------------------------------------------------------------------
140 /// Returns PMT_ModulePassManager
141 //------------------------------------------------------------------
142 llvm::PassManagerType getPotentialPassManagerType() const override;
145 //------------------------------------------------------------------
146 /// A basic block-level pass to find all pointer dereferences and
147 /// validate them before use.
148 //------------------------------------------------------------------
150 //------------------------------------------------------------------
151 /// The top-level pass implementation
154 /// The module currently being processed.
157 /// The basic block currently being processed.
160 /// True on success; false otherwise
161 //------------------------------------------------------------------
162 bool FindDataLoads(llvm::Module &M, llvm::BasicBlock &BB);
164 std::string m_func_name; ///< The name of the function to add checks to
165 DynamicCheckerFunctions
166 &m_checker_functions; ///< The checker functions for the process
169 } // namespace lldb_private
171 #endif // liblldb_IRDynamicChecks_h_