LLDB  mainline
IRDynamicChecks.h
Go to the documentation of this file.
1 //===-- IRDynamicChecks.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 LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_IRDYNAMICCHECKS_H
10 #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_IRDYNAMICCHECKS_H
11 
13 #include "lldb/lldb-types.h"
14 #include "llvm/Pass.h"
15 
16 namespace llvm {
17 class BasicBlock;
18 class Module;
19 }
20 
21 namespace lldb_private {
22 
23 class ExecutionContext;
24 class Stream;
25 
28 public:
29  /// Constructor
31 
32  /// Destructor
34 
35  static bool classof(const DynamicCheckerFunctions *checker_funcs) {
36  return checker_funcs->GetKind() == DCF_Clang;
37  }
38 
39  /// Install the utility functions into a process. This binds the instance
40  /// of DynamicCheckerFunctions to that process.
41  ///
42  /// \param[in] diagnostic_manager
43  /// A diagnostic manager to report errors to.
44  ///
45  /// \param[in] exe_ctx
46  /// The execution context to install the functions into.
47  ///
48  /// \return
49  /// True on success; false on failure, or if the functions have
50  /// already been installed.
51  bool Install(DiagnosticManager &diagnostic_manager,
52  ExecutionContext &exe_ctx) override;
53 
54  bool DoCheckersExplainStop(lldb::addr_t addr, Stream &message) override;
55 
56  std::shared_ptr<UtilityFunction> m_valid_pointer_check;
57  std::shared_ptr<UtilityFunction> m_objc_object_check;
58 };
59 
60 /// \class IRDynamicChecks IRDynamicChecks.h
61 /// "lldb/Expression/IRDynamicChecks.h" Adds dynamic checks to a user-entered
62 /// expression to reduce its likelihood of crashing
63 ///
64 /// When an IR function is executed in the target process, it may cause
65 /// crashes or hangs by dereferencing NULL pointers, trying to call
66 /// Objective-C methods on objects that do not respond to them, and so forth.
67 ///
68 /// IRDynamicChecks adds calls to the functions in DynamicCheckerFunctions to
69 /// appropriate locations in an expression's IR.
70 class IRDynamicChecks : public llvm::ModulePass {
71 public:
72  /// Constructor
73  ///
74  /// \param[in] checker_functions
75  /// The checker functions for the target process.
76  ///
77  /// \param[in] func_name
78  /// The name of the function to prepare for execution in the target.
80  const char *func_name = "$__lldb_expr");
81 
82  /// Destructor
83  ~IRDynamicChecks() override;
84 
85  /// Run this IR transformer on a single module
86  ///
87  /// \param[in] M
88  /// The module to run on. This module is searched for the function
89  /// $__lldb_expr, and that function is passed to the passes one by
90  /// one.
91  ///
92  /// \return
93  /// True on success; false otherwise
94  bool runOnModule(llvm::Module &M) override;
95 
96  /// Interface stub
97  void assignPassManager(
98  llvm::PMStack &PMS,
99  llvm::PassManagerType T = llvm::PMT_ModulePassManager) override;
100 
101  /// Returns PMT_ModulePassManager
102  llvm::PassManagerType getPotentialPassManagerType() const override;
103 
104 private:
105  /// A basic block-level pass to find all pointer dereferences and
106  /// validate them before use.
107 
108  /// The top-level pass implementation
109  ///
110  /// \param[in] M
111  /// The module currently being processed.
112  ///
113  /// \param[in] BB
114  /// The basic block currently being processed.
115  ///
116  /// \return
117  /// True on success; false otherwise
118  bool FindDataLoads(llvm::Module &M, llvm::BasicBlock &BB);
119 
120  std::string m_func_name; ///< The name of the function to add checks to
122  &m_checker_functions; ///< The checker functions for the process
123 };
124 
125 } // namespace lldb_private
126 
127 #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_IRDYNAMICCHECKS_H
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
llvm
Definition: Debugger.h:49
lldb_private::ClangDynamicCheckerFunctions::~ClangDynamicCheckerFunctions
virtual ~ClangDynamicCheckerFunctions()
Destructor.
lldb_private::DynamicCheckerFunctions::DCF_Clang
@ DCF_Clang
Definition: DynamicCheckerFunctions.h:33
lldb_private::ClangDynamicCheckerFunctions::DoCheckersExplainStop
bool DoCheckersExplainStop(lldb::addr_t addr, Stream &message) override
Definition: IRDynamicChecks.cpp:78
lldb_private::IRDynamicChecks::runOnModule
bool runOnModule(llvm::Module &M) override
Run this IR transformer on a single module.
Definition: IRDynamicChecks.cpp:540
lldb_private::ClangDynamicCheckerFunctions::Install
bool Install(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) override
Install the utility functions into a process.
Definition: IRDynamicChecks.cpp:49
lldb_private::CompilerContextKind::Module
@ Module
lldb_private::ClangDynamicCheckerFunctions
Definition: IRDynamicChecks.h:26
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::IRDynamicChecks::getPotentialPassManagerType
llvm::PassManagerType getPotentialPassManagerType() const override
Returns PMT_ModulePassManager.
Definition: IRDynamicChecks.cpp:587
lldb_private::IRDynamicChecks::assignPassManager
void assignPassManager(llvm::PMStack &PMS, llvm::PassManagerType T=llvm::PMT_ModulePassManager) override
Interface stub.
Definition: IRDynamicChecks.cpp:585
lldb_private::IRDynamicChecks::~IRDynamicChecks
~IRDynamicChecks() override
Destructor.
lldb_private::IRDynamicChecks::FindDataLoads
bool FindDataLoads(llvm::Module &M, llvm::BasicBlock &BB)
A basic block-level pass to find all pointer dereferences and validate them before use.
lldb_private::ClangDynamicCheckerFunctions::ClangDynamicCheckerFunctions
ClangDynamicCheckerFunctions()
Constructor.
Definition: IRDynamicChecks.cpp:44
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
DynamicCheckerFunctions.h
lldb_private::DynamicCheckerFunctions::GetKind
DynamicCheckerFunctionsKind GetKind() const
Definition: DynamicCheckerFunctions.h:55
lldb-types.h
lldb_private::IRDynamicChecks::m_checker_functions
ClangDynamicCheckerFunctions & m_checker_functions
The checker functions for the process.
Definition: IRDynamicChecks.h:122
message
message(FATAL_ERROR "invalid libipt include path provided") endif() include_directories($
Definition: Plugins/Trace/intel-pt/CMakeLists.txt:6
lldb_private::ClangDynamicCheckerFunctions::m_objc_object_check
std::shared_ptr< UtilityFunction > m_objc_object_check
Definition: IRDynamicChecks.h:57
lldb_private::DiagnosticManager
Definition: DiagnosticManager.h:93
lldb_private::ClangDynamicCheckerFunctions::m_valid_pointer_check
std::shared_ptr< UtilityFunction > m_valid_pointer_check
Definition: IRDynamicChecks.h:56
lldb_private::IRDynamicChecks
Definition: IRDynamicChecks.h:70
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::DynamicCheckerFunctions
Encapsulates dynamic check functions used by expressions.
Definition: DynamicCheckerFunctions.h:30
lldb_private::IRDynamicChecks::IRDynamicChecks
IRDynamicChecks(ClangDynamicCheckerFunctions &checker_functions, const char *func_name="$__lldb_expr")
Constructor.
Definition: IRDynamicChecks.cpp:533
lldb_private::IRDynamicChecks::m_func_name
std::string m_func_name
The name of the function to add checks to.
Definition: IRDynamicChecks.h:120
lldb_private::ClangDynamicCheckerFunctions::classof
static bool classof(const DynamicCheckerFunctions *checker_funcs)
Definition: IRDynamicChecks.h:35