--- /dev/null
+//===-- DynamicCheckerFunctions.h -------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_DynamicCheckerFunctions_h_
+#define liblldb_DynamicCheckerFunctions_h_
+
+#include "lldb/lldb-types.h"
+
+namespace lldb_private {
+
+class DiagnosticManager;
+class ExecutionContext;
+
+/// Encapsulates dynamic check functions used by expressions.
+///
+/// Each of the utility functions encapsulated in this class is responsible
+/// for validating some data that an expression is about to use. Examples
+/// are:
+///
+/// a = *b; // check that b is a valid pointer
+/// [b init]; // check that b is a valid object to send "init" to
+///
+/// The class installs each checker function into the target process and makes
+/// it available to IRDynamicChecks to use.
+class DynamicCheckerFunctions {
+public:
+ enum DynamicCheckerFunctionsKind {
+ DCF_Clang,
+ };
+
+ DynamicCheckerFunctions(DynamicCheckerFunctionsKind kind) : m_kind(kind) {}
+ virtual ~DynamicCheckerFunctions() = default;
+
+ /// Install the utility functions into a process. This binds the instance
+ /// of DynamicCheckerFunctions to that process.
+ ///
+ /// \param[in] diagnostic_manager
+ /// A diagnostic manager to report errors to.
+ ///
+ /// \param[in] exe_ctx
+ /// The execution context to install the functions into.
+ ///
+ /// \return
+ /// True on success; false on failure, or if the functions have
+ /// already been installed.
+ virtual bool Install(DiagnosticManager &diagnostic_manager,
+ ExecutionContext &exe_ctx) = 0;
+ virtual bool DoCheckersExplainStop(lldb::addr_t addr, Stream &message) = 0;
+
+ DynamicCheckerFunctionsKind GetKind() const { return m_kind; }
+
+private:
+ const DynamicCheckerFunctionsKind m_kind;
+};
+} // namespace lldb_private
+
+#endif // liblldb_DynamicCheckerFunctions_h_
Expression.cpp
ExpressionVariable.cpp
FunctionCaller.cpp
- IRDynamicChecks.cpp
IRExecutionUnit.cpp
IRInterpreter.cpp
IRMemoryMap.cpp
ClangUserExpression.cpp
ClangUtilityFunction.cpp
IRForTarget.cpp
+ IRDynamicChecks.cpp
DEPENDS
${tablegen_deps}
#include "ClangHost.h"
#include "ClangModulesDeclVendor.h"
#include "ClangPersistentVariables.h"
+#include "IRDynamicChecks.h"
#include "IRForTarget.h"
#include "ModuleDependencyCollector.h"
#include "lldb/Core/Disassembler.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/StreamFile.h"
-#include "lldb/Expression/IRDynamicChecks.h"
#include "lldb/Expression/IRExecutionUnit.h"
#include "lldb/Expression/IRInterpreter.h"
#include "lldb/Host/File.h"
(execution_policy != eExecutionPolicyTopLevel && !can_interpret)) {
if (m_expr.NeedsValidation() && process) {
if (!process->GetDynamicCheckers()) {
- DynamicCheckerFunctions *dynamic_checkers =
- new DynamicCheckerFunctions();
+ ClangDynamicCheckerFunctions *dynamic_checkers =
+ new ClangDynamicCheckerFunctions();
DiagnosticManager install_diagnostics;
"Finished installing dynamic checkers ==");
}
- IRDynamicChecks ir_dynamic_checks(*process->GetDynamicCheckers(),
- function_name.AsCString());
+ if (auto *checker_funcs = llvm::dyn_cast<ClangDynamicCheckerFunctions>(
+ process->GetDynamicCheckers())) {
+ IRDynamicChecks ir_dynamic_checks(*checker_funcs,
+ function_name.AsCString());
- llvm::Module *module = execution_unit_sp->GetModule();
- if (!module || !ir_dynamic_checks.runOnModule(*module)) {
- err.SetErrorToGenericError();
- err.SetErrorString("Couldn't add dynamic checks to the expression");
- return err;
- }
+ llvm::Module *module = execution_unit_sp->GetModule();
+ if (!module || !ir_dynamic_checks.runOnModule(*module)) {
+ err.SetErrorToGenericError();
+ err.SetErrorString("Couldn't add dynamic checks to the expression");
+ return err;
+ }
- if (custom_passes.LatePasses) {
- if (log)
- log->Printf("%s - Running Late IR Passes from LanguageRuntime on "
- "expression module '%s'",
- __FUNCTION__, m_expr.FunctionName());
+ if (custom_passes.LatePasses) {
+ if (log)
+ log->Printf("%s - Running Late IR Passes from LanguageRuntime on "
+ "expression module '%s'",
+ __FUNCTION__, m_expr.FunctionName());
- custom_passes.LatePasses->run(*module);
+ custom_passes.LatePasses->run(*module);
+ }
}
}
}
#include "llvm/IR/Value.h"
#include "llvm/Support/raw_ostream.h"
-#include "lldb/Expression/IRDynamicChecks.h"
+#include "IRDynamicChecks.h"
#include "lldb/Expression/UtilityFunction.h"
#include "lldb/Target/ExecutionContext.h"
" unsigned char $__lldb_local_val = *$__lldb_arg_ptr;\n"
"}";
-DynamicCheckerFunctions::DynamicCheckerFunctions() = default;
+ClangDynamicCheckerFunctions::ClangDynamicCheckerFunctions()
+ : DynamicCheckerFunctions(DCF_Clang) {}
-DynamicCheckerFunctions::~DynamicCheckerFunctions() = default;
+ClangDynamicCheckerFunctions::~ClangDynamicCheckerFunctions() = default;
-bool DynamicCheckerFunctions::Install(DiagnosticManager &diagnostic_manager,
- ExecutionContext &exe_ctx) {
+bool ClangDynamicCheckerFunctions::Install(
+ DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) {
Status error;
m_valid_pointer_check.reset(
exe_ctx.GetTargetRef().GetUtilityFunctionForLanguage(
return true;
}
-bool DynamicCheckerFunctions::DoCheckersExplainStop(lldb::addr_t addr,
- Stream &message) {
+bool ClangDynamicCheckerFunctions::DoCheckersExplainStop(lldb::addr_t addr,
+ Stream &message) {
// FIXME: We have to get the checkers to know why they scotched the call in
// more detail,
// so we can print a better message here.
llvm::FunctionCallee m_objc_object_check_func;
};
-IRDynamicChecks::IRDynamicChecks(DynamicCheckerFunctions &checker_functions,
- const char *func_name)
+IRDynamicChecks::IRDynamicChecks(
+ ClangDynamicCheckerFunctions &checker_functions, const char *func_name)
: ModulePass(ID), m_func_name(func_name),
m_checker_functions(checker_functions) {}
#ifndef liblldb_IRDynamicChecks_h_
#define liblldb_IRDynamicChecks_h_
+#include "lldb/Expression/DynamicCheckerFunctions.h"
#include "lldb/lldb-types.h"
#include "llvm/Pass.h"
namespace llvm {
class BasicBlock;
-class CallInst;
-class Constant;
-class Function;
-class Instruction;
class Module;
-class DataLayout;
-class Value;
}
namespace lldb_private {
-class ClangExpressionDeclMap;
class ExecutionContext;
class Stream;
-/// \class DynamicCheckerFunctions IRDynamicChecks.h
-/// "lldb/Expression/IRDynamicChecks.h" Encapsulates dynamic check functions
-/// used by expressions.
-///
-/// Each of the utility functions encapsulated in this class is responsible
-/// for validating some data that an expression is about to use. Examples
-/// are:
-///
-/// a = *b; // check that b is a valid pointer [b init]; // check that b
-/// is a valid object to send "init" to
-///
-/// The class installs each checker function into the target process and makes
-/// it available to IRDynamicChecks to use.
-class DynamicCheckerFunctions {
+class ClangDynamicCheckerFunctions
+ : public lldb_private::DynamicCheckerFunctions {
public:
/// Constructor
- DynamicCheckerFunctions();
+ ClangDynamicCheckerFunctions();
/// Destructor
- ~DynamicCheckerFunctions();
+ virtual ~ClangDynamicCheckerFunctions();
+
+ static bool classof(const DynamicCheckerFunctions *checker_funcs) {
+ return checker_funcs->GetKind() == DCF_Clang;
+ }
/// Install the utility functions into a process. This binds the instance
/// of DynamicCheckerFunctions to that process.
/// True on success; false on failure, or if the functions have
/// already been installed.
bool Install(DiagnosticManager &diagnostic_manager,
- ExecutionContext &exe_ctx);
+ ExecutionContext &exe_ctx) override;
- bool DoCheckersExplainStop(lldb::addr_t addr, Stream &message);
+ bool DoCheckersExplainStop(lldb::addr_t addr, Stream &message) override;
std::shared_ptr<UtilityFunction> m_valid_pointer_check;
std::shared_ptr<UtilityFunction> m_objc_object_check;
/// \param[in] decl_map
/// The mapping used to look up entities in the target process. In
/// this case, used to find objc_msgSend
- IRDynamicChecks(DynamicCheckerFunctions &checker_functions,
+ IRDynamicChecks(ClangDynamicCheckerFunctions &checker_functions,
const char *func_name = "$__lldb_expr");
/// Destructor
bool FindDataLoads(llvm::Module &M, llvm::BasicBlock &BB);
std::string m_func_name; ///< The name of the function to add checks to
- DynamicCheckerFunctions
+ ClangDynamicCheckerFunctions
&m_checker_functions; ///< The checker functions for the process
};
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Expression/DiagnosticManager.h"
-#include "lldb/Expression/IRDynamicChecks.h"
+#include "lldb/Expression/DynamicCheckerFunctions.h"
#include "lldb/Expression/UserExpression.h"
#include "lldb/Expression/UtilityFunction.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Core/Address.h"
#include "lldb/Expression/DiagnosticManager.h"
-#include "lldb/Expression/IRDynamicChecks.h"
+#include "lldb/Expression/DynamicCheckerFunctions.h"
#include "lldb/Expression/UserExpression.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Target/LanguageRuntime.h"