diff options
author | Sean Callanan <scallanan@apple.com> | 2010-09-01 00:58:00 +0000 |
---|---|---|
committer | Sean Callanan <scallanan@apple.com> | 2010-09-01 00:58:00 +0000 |
commit | 6961e87847cd39a65ecde0342ec5c7d1dee9622c (patch) | |
tree | b49e5acd42822d3575f26dd66242ebce14d65293 /lldb/source/Expression/IRDynamicChecks.cpp | |
parent | 6aaebe877bbff9d9b3b6e639d6e79d79fa50ebea (diff) | |
download | bcm5719-llvm-6961e87847cd39a65ecde0342ec5c7d1dee9622c.tar.gz bcm5719-llvm-6961e87847cd39a65ecde0342ec5c7d1dee9622c.zip |
Added support for dynamic sanity checking in
expressions. Values used by the expression are
checked by validation functions which cause the
program to crash if the values are unsafe.
Major changes:
- Added IRDynamicChecks.[ch], which contains the
core code related to this feature
- Modified CommandObjectExpression to install the
validator functions into the target process.
- Added an accessor to Process that gets/sets the
helper functions
llvm-svn: 112690
Diffstat (limited to 'lldb/source/Expression/IRDynamicChecks.cpp')
-rw-r--r-- | lldb/source/Expression/IRDynamicChecks.cpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/lldb/source/Expression/IRDynamicChecks.cpp b/lldb/source/Expression/IRDynamicChecks.cpp new file mode 100644 index 00000000000..21fd7d26250 --- /dev/null +++ b/lldb/source/Expression/IRDynamicChecks.cpp @@ -0,0 +1,117 @@ +//===-- IRDynamicChecks.cpp -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Expression/IRDynamicChecks.h" +#include "lldb/Expression/ClangUtilityFunction.h" + +#include "lldb/Core/Log.h" + +#include "llvm/Support/raw_ostream.h" +#include "llvm/Function.h" +#include "llvm/Module.h" +#include "llvm/Value.h" + +using namespace llvm; +using namespace lldb_private; + +static char ID; + +static const char valid_pointer_check_text[] = + "extern \"C\" void " + "___clang_valid_pointer_check (unsigned char *ptr)" + "{" + "unsigned char val = *ptr;" + "}"; + +static const char valid_pointer_check_name[] = + "___clang_valid_pointer_check"; + +DynamicCheckerFunctions::DynamicCheckerFunctions () +{ + m_valid_pointer_check.reset(new ClangUtilityFunction(valid_pointer_check_text, + valid_pointer_check_name)); +} + +DynamicCheckerFunctions::~DynamicCheckerFunctions () +{ +} + +bool +DynamicCheckerFunctions::Install(Stream &error_stream, + ExecutionContext &exe_ctx) +{ + if (!m_valid_pointer_check->Install(error_stream, exe_ctx)) + return false; + + return true; +} + +IRDynamicChecks::IRDynamicChecks(DynamicCheckerFunctions &checker_functions, + const char *func_name) : + ModulePass(&ID), + m_checker_functions(checker_functions), + m_func_name(func_name) +{ +} + +/* A handy utility function used at several places in the code */ + +static std::string +PrintValue(llvm::Value *V, bool truncate = false) +{ + std::string s; + raw_string_ostream rso(s); + V->print(rso); + rso.flush(); + if (truncate) + s.resize(s.length() - 1); + return s; +} + +IRDynamicChecks::~IRDynamicChecks() +{ +} + +bool +IRDynamicChecks::runOnModule(llvm::Module &M) +{ + lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); + + llvm::Function* function = M.getFunction(StringRef(m_func_name.c_str())); + + if (!function) + { + if (log) + log->Printf("Couldn't find %s() in the module", m_func_name.c_str()); + + return false; + } + + llvm::Function::iterator bbi; + + for (bbi = function->begin(); + bbi != function->end(); + ++bbi) + { + } + + return true; +} + +void +IRDynamicChecks::assignPassManager(PMStack &PMS, + PassManagerType T) +{ +} + +PassManagerType +IRDynamicChecks::getPotentialPassManagerType() const +{ + return PMT_ModulePassManager; +} |