diff options
| author | Alex Langford <apl@fb.com> | 2019-07-12 00:58:02 +0000 |
|---|---|---|
| committer | Alex Langford <apl@fb.com> | 2019-07-12 00:58:02 +0000 |
| commit | bab7e3d78b01d9a4145a08e9c4cd4e7626e34d08 (patch) | |
| tree | c6d475c9d84dcbfecdab6132361304999d1c52b3 | |
| parent | 8955be68cfca54e5f1195bfb338cc49164d929a3 (diff) | |
| download | bcm5719-llvm-bab7e3d78b01d9a4145a08e9c4cd4e7626e34d08.tar.gz bcm5719-llvm-bab7e3d78b01d9a4145a08e9c4cd4e7626e34d08.zip | |
[Expression] Move IRDynamicChecks to ClangExpressionParser
Summary:
IRDynamicChecks in its current form is specific to Clang since it deals
with the C language family. It is possible that we may want to
instrument code generated for other languages, but we can factor in a
more general mechanism to do so at a later time.
This decouples ObCLanguageRuntime from Expression!
Reviewers: compnerd, clayborg, jingham, JDevlieghere
Subscribers: mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D64591
llvm-svn: 365853
| -rw-r--r-- | lldb/include/lldb/Expression/DynamicCheckerFunctions.h | 62 | ||||
| -rw-r--r-- | lldb/source/Expression/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp | 37 | ||||
| -rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp (renamed from lldb/source/Expression/IRDynamicChecks.cpp) | 19 | ||||
| -rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.h (renamed from lldb/include/lldb/Expression/IRDynamicChecks.h) | 40 | ||||
| -rw-r--r-- | lldb/source/Target/Process.cpp | 2 | ||||
| -rw-r--r-- | lldb/source/Target/ThreadPlanCallUserExpression.cpp | 2 |
8 files changed, 108 insertions, 56 deletions
diff --git a/lldb/include/lldb/Expression/DynamicCheckerFunctions.h b/lldb/include/lldb/Expression/DynamicCheckerFunctions.h new file mode 100644 index 00000000000..7be24b6ea96 --- /dev/null +++ b/lldb/include/lldb/Expression/DynamicCheckerFunctions.h @@ -0,0 +1,62 @@ +//===-- 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_ diff --git a/lldb/source/Expression/CMakeLists.txt b/lldb/source/Expression/CMakeLists.txt index fead8d90040..7e2f19ed5b0 100644 --- a/lldb/source/Expression/CMakeLists.txt +++ b/lldb/source/Expression/CMakeLists.txt @@ -8,7 +8,6 @@ add_lldb_library(lldbExpression Expression.cpp ExpressionVariable.cpp FunctionCaller.cpp - IRDynamicChecks.cpp IRExecutionUnit.cpp IRInterpreter.cpp IRMemoryMap.cpp diff --git a/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt b/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt index 084c5b05907..16010bc87e5 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt +++ b/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt @@ -19,6 +19,7 @@ add_lldb_library(lldbPluginExpressionParserClang PLUGIN ClangUserExpression.cpp ClangUtilityFunction.cpp IRForTarget.cpp + IRDynamicChecks.cpp DEPENDS ${tablegen_deps} diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp index a2bc38764f8..1c7f9318986 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp @@ -62,6 +62,7 @@ #include "ClangHost.h" #include "ClangModulesDeclVendor.h" #include "ClangPersistentVariables.h" +#include "IRDynamicChecks.h" #include "IRForTarget.h" #include "ModuleDependencyCollector.h" @@ -69,7 +70,6 @@ #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" @@ -1281,8 +1281,8 @@ lldb_private::Status ClangExpressionParser::PrepareForExecution( (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; @@ -1302,23 +1302,26 @@ lldb_private::Status ClangExpressionParser::PrepareForExecution( "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); + } } } } diff --git a/lldb/source/Expression/IRDynamicChecks.cpp b/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp index 2e7b76b3240..6d34a35ba2b 100644 --- a/lldb/source/Expression/IRDynamicChecks.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp @@ -14,7 +14,7 @@ #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" @@ -40,12 +40,13 @@ static const char g_valid_pointer_check_text[] = " 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( @@ -75,8 +76,8 @@ bool DynamicCheckerFunctions::Install(DiagnosticManager &diagnostic_manager, 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. @@ -533,8 +534,8 @@ private: 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) {} diff --git a/lldb/include/lldb/Expression/IRDynamicChecks.h b/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.h index 0e667394dae..60c0691b21c 100644 --- a/lldb/include/lldb/Expression/IRDynamicChecks.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.h @@ -9,46 +9,32 @@ #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. @@ -63,9 +49,9 @@ public: /// 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; @@ -94,7 +80,7 @@ public: /// \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 @@ -136,7 +122,7 @@ private: 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 }; diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index cd27392bd56..6c634dba00c 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -22,7 +22,7 @@ #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" diff --git a/lldb/source/Target/ThreadPlanCallUserExpression.cpp b/lldb/source/Target/ThreadPlanCallUserExpression.cpp index 2998daa548c..864808a4b5e 100644 --- a/lldb/source/Target/ThreadPlanCallUserExpression.cpp +++ b/lldb/source/Target/ThreadPlanCallUserExpression.cpp @@ -13,7 +13,7 @@ #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" |

