Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.h
39653 views
//===-- IRDynamicChecks.h ---------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_IRDYNAMICCHECKS_H9#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_IRDYNAMICCHECKS_H1011#include "lldb/Expression/DynamicCheckerFunctions.h"12#include "lldb/lldb-types.h"13#include "llvm/Pass.h"1415namespace llvm {16class BasicBlock;17class Module;18}1920namespace lldb_private {2122class ExecutionContext;23class Stream;2425class ClangDynamicCheckerFunctions26: public lldb_private::DynamicCheckerFunctions {27public:28/// Constructor29ClangDynamicCheckerFunctions();3031/// Destructor32~ClangDynamicCheckerFunctions() override;3334static bool classof(const DynamicCheckerFunctions *checker_funcs) {35return checker_funcs->GetKind() == DCF_Clang;36}3738/// Install the utility functions into a process. This binds the instance39/// of DynamicCheckerFunctions to that process.40///41/// \param[in] diagnostic_manager42/// A diagnostic manager to report errors to.43///44/// \param[in] exe_ctx45/// The execution context to install the functions into.46///47/// \return48/// Either llvm::ErrorSuccess or Error with llvm::ErrorInfo49///50llvm::Error Install(DiagnosticManager &diagnostic_manager,51ExecutionContext &exe_ctx) override;5253bool DoCheckersExplainStop(lldb::addr_t addr, Stream &message) override;5455std::shared_ptr<UtilityFunction> m_valid_pointer_check;56std::shared_ptr<UtilityFunction> m_objc_object_check;57};5859/// \class IRDynamicChecks IRDynamicChecks.h60/// "lldb/Expression/IRDynamicChecks.h" Adds dynamic checks to a user-entered61/// expression to reduce its likelihood of crashing62///63/// When an IR function is executed in the target process, it may cause64/// crashes or hangs by dereferencing NULL pointers, trying to call65/// Objective-C methods on objects that do not respond to them, and so forth.66///67/// IRDynamicChecks adds calls to the functions in DynamicCheckerFunctions to68/// appropriate locations in an expression's IR.69class IRDynamicChecks : public llvm::ModulePass {70public:71/// Constructor72///73/// \param[in] checker_functions74/// The checker functions for the target process.75///76/// \param[in] func_name77/// The name of the function to prepare for execution in the target.78IRDynamicChecks(ClangDynamicCheckerFunctions &checker_functions,79const char *func_name = "$__lldb_expr");8081/// Destructor82~IRDynamicChecks() override;8384/// Run this IR transformer on a single module85///86/// \param[in] M87/// The module to run on. This module is searched for the function88/// $__lldb_expr, and that function is passed to the passes one by89/// one.90///91/// \return92/// True on success; false otherwise93bool runOnModule(llvm::Module &M) override;9495/// Interface stub96void assignPassManager(97llvm::PMStack &PMS,98llvm::PassManagerType T = llvm::PMT_ModulePassManager) override;99100/// Returns PMT_ModulePassManager101llvm::PassManagerType getPotentialPassManagerType() const override;102103private:104/// A basic block-level pass to find all pointer dereferences and105/// validate them before use.106107/// The top-level pass implementation108///109/// \param[in] M110/// The module currently being processed.111///112/// \param[in] BB113/// The basic block currently being processed.114///115/// \return116/// True on success; false otherwise117bool FindDataLoads(llvm::Module &M, llvm::BasicBlock &BB);118119std::string m_func_name; ///< The name of the function to add checks to120ClangDynamicCheckerFunctions121&m_checker_functions; ///< The checker functions for the process122};123124} // namespace lldb_private125126#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_IRDYNAMICCHECKS_H127128129