LLVM API Documentation
00001 //===---- RuntimeDyldChecker.h - RuntimeDyld tester framework -----*- C++ -*-=// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H 00011 #define LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H 00012 00013 #include "llvm/ADT/StringRef.h" 00014 00015 namespace llvm { 00016 00017 class MCDisassembler; 00018 class MemoryBuffer; 00019 class MCInstPrinter; 00020 class RuntimeDyld; 00021 class RuntimeDyldCheckerImpl; 00022 class raw_ostream; 00023 00024 /// \brief RuntimeDyld invariant checker for verifying that RuntimeDyld has 00025 /// correctly applied relocations. 00026 /// 00027 /// The RuntimeDyldChecker class evaluates expressions against an attached 00028 /// RuntimeDyld instance to verify that relocations have been applied 00029 /// correctly. 00030 /// 00031 /// The expression language supports basic pointer arithmetic and bit-masking, 00032 /// and has limited disassembler integration for accessing instruction 00033 /// operands and the next PC (program counter) address for each instruction. 00034 /// 00035 /// The language syntax is: 00036 /// 00037 /// check = expr '=' expr 00038 /// 00039 /// expr = binary_expr 00040 /// | sliceable_expr 00041 /// 00042 /// sliceable_expr = '*{' number '}' load_addr_expr [slice] 00043 /// | '(' expr ')' [slice] 00044 /// | ident_expr [slice] 00045 /// | number [slice] 00046 /// 00047 /// slice = '[' high-bit-index ':' low-bit-index ']' 00048 /// 00049 /// load_addr_expr = symbol 00050 /// | '(' symbol '+' number ')' 00051 /// | '(' symbol '-' number ')' 00052 /// 00053 /// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')' 00054 /// | 'next_pc' '(' symbol ')' 00055 /// | symbol 00056 /// 00057 /// binary_expr = expr '+' expr 00058 /// | expr '-' expr 00059 /// | expr '&' expr 00060 /// | expr '|' expr 00061 /// | expr '<<' expr 00062 /// | expr '>>' expr 00063 /// 00064 class RuntimeDyldChecker { 00065 public: 00066 RuntimeDyldChecker(RuntimeDyld &RTDyld, MCDisassembler *Disassembler, 00067 MCInstPrinter *InstPrinter, raw_ostream &ErrStream); 00068 ~RuntimeDyldChecker(); 00069 00070 // \brief Get the associated RTDyld instance. 00071 RuntimeDyld& getRTDyld(); 00072 00073 // \brief Get the associated RTDyld instance. 00074 const RuntimeDyld& getRTDyld() const; 00075 00076 /// \brief Check a single expression against the attached RuntimeDyld 00077 /// instance. 00078 bool check(StringRef CheckExpr) const; 00079 00080 /// \brief Scan the given memory buffer for lines beginning with the string 00081 /// in RulePrefix. The remainder of the line is passed to the check 00082 /// method to be evaluated as an expression. 00083 bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const; 00084 00085 /// \brief Returns the address of the requested section (or an error message 00086 /// in the second element of the pair if the address cannot be found). 00087 /// 00088 /// if 'LinkerAddress' is true, this returns the address of the section 00089 /// within the linker's memory. If 'LinkerAddress' is false it returns the 00090 /// address within the target process (i.e. the load address). 00091 std::pair<uint64_t, std::string> getSectionAddr(StringRef FileName, 00092 StringRef SectionName, 00093 bool LinkerAddress); 00094 00095 private: 00096 std::unique_ptr<RuntimeDyldCheckerImpl> Impl; 00097 }; 00098 00099 } // end namespace llvm 00100 00101 #endif