1 //===---- RuntimeDyldChecker.h - RuntimeDyld tester framework -----*- 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 #ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H 11 #define LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H 12 13 #include "llvm/ADT/StringRef.h" 14 15 namespace llvm { 16 17 class MCDisassembler; 18 class MemoryBuffer; 19 class MCInstPrinter; 20 class RuntimeDyld; 21 class RuntimeDyldCheckerImpl; 22 class raw_ostream; 23 24 /// \brief RuntimeDyld invariant checker for verifying that RuntimeDyld has 25 /// correctly applied relocations. 26 /// 27 /// The RuntimeDyldChecker class evaluates expressions against an attached 28 /// RuntimeDyld instance to verify that relocations have been applied 29 /// correctly. 30 /// 31 /// The expression language supports basic pointer arithmetic and bit-masking, 32 /// and has limited disassembler integration for accessing instruction 33 /// operands and the next PC (program counter) address for each instruction. 34 /// 35 /// The language syntax is: 36 /// 37 /// check = expr '=' expr 38 /// 39 /// expr = binary_expr 40 /// | sliceable_expr 41 /// 42 /// sliceable_expr = '*{' number '}' load_addr_expr [slice] 43 /// | '(' expr ')' [slice] 44 /// | ident_expr [slice] 45 /// | number [slice] 46 /// 47 /// slice = '[' high-bit-index ':' low-bit-index ']' 48 /// 49 /// load_addr_expr = symbol 50 /// | '(' symbol '+' number ')' 51 /// | '(' symbol '-' number ')' 52 /// 53 /// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')' 54 /// | 'next_pc' '(' symbol ')' 55 /// | symbol 56 /// 57 /// binary_expr = expr '+' expr 58 /// | expr '-' expr 59 /// | expr '&' expr 60 /// | expr '|' expr 61 /// | expr '<<' expr 62 /// | expr '>>' expr 63 /// 64 class RuntimeDyldChecker { 65 public: 66 RuntimeDyldChecker(RuntimeDyld &RTDyld, MCDisassembler *Disassembler, 67 MCInstPrinter *InstPrinter, raw_ostream &ErrStream); 68 ~RuntimeDyldChecker(); 69 70 // \brief Get the associated RTDyld instance. 71 RuntimeDyld& getRTDyld(); 72 73 // \brief Get the associated RTDyld instance. 74 const RuntimeDyld& getRTDyld() const; 75 76 /// \brief Check a single expression against the attached RuntimeDyld 77 /// instance. 78 bool check(StringRef CheckExpr) const; 79 80 /// \brief Scan the given memory buffer for lines beginning with the string 81 /// in RulePrefix. The remainder of the line is passed to the check 82 /// method to be evaluated as an expression. 83 bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const; 84 85 /// \brief Returns the address of the requested section (or an error message 86 /// in the second element of the pair if the address cannot be found). 87 /// 88 /// if 'LinkerAddress' is true, this returns the address of the section 89 /// within the linker's memory. If 'LinkerAddress' is false it returns the 90 /// address within the target process (i.e. the load address). 91 std::pair<uint64_t, std::string> getSectionAddr(StringRef FileName, 92 StringRef SectionName, 93 bool LinkerAddress); 94 95 private: 96 std::unique_ptr<RuntimeDyldCheckerImpl> Impl; 97 }; 98 99 } // end namespace llvm 100 101 #endif 102