Sean Callanan | f18d91c | 2010-09-01 00:58:00 +0000 | [diff] [blame^] | 1 | //===-- IRDynamicChecks.cpp -------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/Expression/IRDynamicChecks.h" |
| 11 | #include "lldb/Expression/ClangUtilityFunction.h" |
| 12 | |
| 13 | #include "lldb/Core/Log.h" |
| 14 | |
| 15 | #include "llvm/Support/raw_ostream.h" |
| 16 | #include "llvm/Function.h" |
| 17 | #include "llvm/Module.h" |
| 18 | #include "llvm/Value.h" |
| 19 | |
| 20 | using namespace llvm; |
| 21 | using namespace lldb_private; |
| 22 | |
| 23 | static char ID; |
| 24 | |
| 25 | static const char valid_pointer_check_text[] = |
| 26 | "extern \"C\" void " |
| 27 | "___clang_valid_pointer_check (unsigned char *ptr)" |
| 28 | "{" |
| 29 | "unsigned char val = *ptr;" |
| 30 | "}"; |
| 31 | |
| 32 | static const char valid_pointer_check_name[] = |
| 33 | "___clang_valid_pointer_check"; |
| 34 | |
| 35 | DynamicCheckerFunctions::DynamicCheckerFunctions () |
| 36 | { |
| 37 | m_valid_pointer_check.reset(new ClangUtilityFunction(valid_pointer_check_text, |
| 38 | valid_pointer_check_name)); |
| 39 | } |
| 40 | |
| 41 | DynamicCheckerFunctions::~DynamicCheckerFunctions () |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | bool |
| 46 | DynamicCheckerFunctions::Install(Stream &error_stream, |
| 47 | ExecutionContext &exe_ctx) |
| 48 | { |
| 49 | if (!m_valid_pointer_check->Install(error_stream, exe_ctx)) |
| 50 | return false; |
| 51 | |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | IRDynamicChecks::IRDynamicChecks(DynamicCheckerFunctions &checker_functions, |
| 56 | const char *func_name) : |
| 57 | ModulePass(&ID), |
| 58 | m_checker_functions(checker_functions), |
| 59 | m_func_name(func_name) |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | /* A handy utility function used at several places in the code */ |
| 64 | |
| 65 | static std::string |
| 66 | PrintValue(llvm::Value *V, bool truncate = false) |
| 67 | { |
| 68 | std::string s; |
| 69 | raw_string_ostream rso(s); |
| 70 | V->print(rso); |
| 71 | rso.flush(); |
| 72 | if (truncate) |
| 73 | s.resize(s.length() - 1); |
| 74 | return s; |
| 75 | } |
| 76 | |
| 77 | IRDynamicChecks::~IRDynamicChecks() |
| 78 | { |
| 79 | } |
| 80 | |
| 81 | bool |
| 82 | IRDynamicChecks::runOnModule(llvm::Module &M) |
| 83 | { |
| 84 | lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); |
| 85 | |
| 86 | llvm::Function* function = M.getFunction(StringRef(m_func_name.c_str())); |
| 87 | |
| 88 | if (!function) |
| 89 | { |
| 90 | if (log) |
| 91 | log->Printf("Couldn't find %s() in the module", m_func_name.c_str()); |
| 92 | |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | llvm::Function::iterator bbi; |
| 97 | |
| 98 | for (bbi = function->begin(); |
| 99 | bbi != function->end(); |
| 100 | ++bbi) |
| 101 | { |
| 102 | } |
| 103 | |
| 104 | return true; |
| 105 | } |
| 106 | |
| 107 | void |
| 108 | IRDynamicChecks::assignPassManager(PMStack &PMS, |
| 109 | PassManagerType T) |
| 110 | { |
| 111 | } |
| 112 | |
| 113 | PassManagerType |
| 114 | IRDynamicChecks::getPotentialPassManagerType() const |
| 115 | { |
| 116 | return PMT_ModulePassManager; |
| 117 | } |