1 //===-- IRDynamicChecks.h ---------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_IRDYNAMICCHECKS_H
10 #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_IRDYNAMICCHECKS_H
12 #include "lldb/Expression/DynamicCheckerFunctions.h"
13 #include "lldb/lldb-types.h"
14 #include "llvm/Pass.h"
21 namespace lldb_private
{
23 class ExecutionContext
;
26 class ClangDynamicCheckerFunctions
27 : public lldb_private::DynamicCheckerFunctions
{
30 ClangDynamicCheckerFunctions();
33 ~ClangDynamicCheckerFunctions() override
;
35 static bool classof(const DynamicCheckerFunctions
*checker_funcs
) {
36 return checker_funcs
->GetKind() == DCF_Clang
;
39 /// Install the utility functions into a process. This binds the instance
40 /// of DynamicCheckerFunctions to that process.
42 /// \param[in] diagnostic_manager
43 /// A diagnostic manager to report errors to.
45 /// \param[in] exe_ctx
46 /// The execution context to install the functions into.
49 /// Either llvm::ErrorSuccess or Error with llvm::ErrorInfo
51 llvm::Error
Install(DiagnosticManager
&diagnostic_manager
,
52 ExecutionContext
&exe_ctx
) override
;
54 bool DoCheckersExplainStop(lldb::addr_t addr
, Stream
&message
) override
;
56 std::shared_ptr
<UtilityFunction
> m_valid_pointer_check
;
57 std::shared_ptr
<UtilityFunction
> m_objc_object_check
;
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
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.
68 /// IRDynamicChecks adds calls to the functions in DynamicCheckerFunctions to
69 /// appropriate locations in an expression's IR.
70 class IRDynamicChecks
: public llvm::ModulePass
{
74 /// \param[in] checker_functions
75 /// The checker functions for the target process.
77 /// \param[in] func_name
78 /// The name of the function to prepare for execution in the target.
79 IRDynamicChecks(ClangDynamicCheckerFunctions
&checker_functions
,
80 const char *func_name
= "$__lldb_expr");
83 ~IRDynamicChecks() override
;
85 /// Run this IR transformer on a single module
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
93 /// True on success; false otherwise
94 bool runOnModule(llvm::Module
&M
) override
;
97 void assignPassManager(
99 llvm::PassManagerType T
= llvm::PMT_ModulePassManager
) override
;
101 /// Returns PMT_ModulePassManager
102 llvm::PassManagerType
getPotentialPassManagerType() const override
;
105 /// A basic block-level pass to find all pointer dereferences and
106 /// validate them before use.
108 /// The top-level pass implementation
111 /// The module currently being processed.
114 /// The basic block currently being processed.
117 /// True on success; false otherwise
118 bool FindDataLoads(llvm::Module
&M
, llvm::BasicBlock
&BB
);
120 std::string m_func_name
; ///< The name of the function to add checks to
121 ClangDynamicCheckerFunctions
122 &m_checker_functions
; ///< The checker functions for the process
125 } // namespace lldb_private
127 #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_IRDYNAMICCHECKS_H