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