RuntimeDyldChecker.h revision 288943
1274955Ssvnmir//===---- RuntimeDyldChecker.h - RuntimeDyld tester framework -----*- C++ -*-=// 2274955Ssvnmir// 3274955Ssvnmir// The LLVM Compiler Infrastructure 4274955Ssvnmir// 5274955Ssvnmir// This file is distributed under the University of Illinois Open Source 6274955Ssvnmir// License. See LICENSE.TXT for details. 7274955Ssvnmir// 8274955Ssvnmir//===----------------------------------------------------------------------===// 9274955Ssvnmir 10280031Sdim#ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H 11280031Sdim#define LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H 12274955Ssvnmir 13280031Sdim#include "llvm/ADT/StringRef.h" 14274955Ssvnmir 15274955Ssvnmirnamespace llvm { 16274955Ssvnmir 17274955Ssvnmirclass MCDisassembler; 18280031Sdimclass MemoryBuffer; 19274955Ssvnmirclass MCInstPrinter; 20280031Sdimclass RuntimeDyld; 21280031Sdimclass RuntimeDyldCheckerImpl; 22280031Sdimclass raw_ostream; 23274955Ssvnmir 24274955Ssvnmir/// \brief RuntimeDyld invariant checker for verifying that RuntimeDyld has 25274955Ssvnmir/// correctly applied relocations. 26274955Ssvnmir/// 27274955Ssvnmir/// The RuntimeDyldChecker class evaluates expressions against an attached 28274955Ssvnmir/// RuntimeDyld instance to verify that relocations have been applied 29274955Ssvnmir/// correctly. 30274955Ssvnmir/// 31274955Ssvnmir/// The expression language supports basic pointer arithmetic and bit-masking, 32274955Ssvnmir/// and has limited disassembler integration for accessing instruction 33274955Ssvnmir/// operands and the next PC (program counter) address for each instruction. 34274955Ssvnmir/// 35274955Ssvnmir/// The language syntax is: 36274955Ssvnmir/// 37274955Ssvnmir/// check = expr '=' expr 38274955Ssvnmir/// 39274955Ssvnmir/// expr = binary_expr 40274955Ssvnmir/// | sliceable_expr 41274955Ssvnmir/// 42274955Ssvnmir/// sliceable_expr = '*{' number '}' load_addr_expr [slice] 43274955Ssvnmir/// | '(' expr ')' [slice] 44274955Ssvnmir/// | ident_expr [slice] 45274955Ssvnmir/// | number [slice] 46274955Ssvnmir/// 47274955Ssvnmir/// slice = '[' high-bit-index ':' low-bit-index ']' 48274955Ssvnmir/// 49274955Ssvnmir/// load_addr_expr = symbol 50274955Ssvnmir/// | '(' symbol '+' number ')' 51274955Ssvnmir/// | '(' symbol '-' number ')' 52274955Ssvnmir/// 53274955Ssvnmir/// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')' 54274955Ssvnmir/// | 'next_pc' '(' symbol ')' 55288943Sdim/// | 'stub_addr' '(' file-name ',' section-name ',' symbol ')' 56274955Ssvnmir/// | symbol 57274955Ssvnmir/// 58274955Ssvnmir/// binary_expr = expr '+' expr 59274955Ssvnmir/// | expr '-' expr 60274955Ssvnmir/// | expr '&' expr 61274955Ssvnmir/// | expr '|' expr 62274955Ssvnmir/// | expr '<<' expr 63274955Ssvnmir/// | expr '>>' expr 64274955Ssvnmir/// 65274955Ssvnmirclass RuntimeDyldChecker { 66274955Ssvnmirpublic: 67280031Sdim RuntimeDyldChecker(RuntimeDyld &RTDyld, MCDisassembler *Disassembler, 68280031Sdim MCInstPrinter *InstPrinter, raw_ostream &ErrStream); 69280031Sdim ~RuntimeDyldChecker(); 70274955Ssvnmir 71280031Sdim // \brief Get the associated RTDyld instance. 72280031Sdim RuntimeDyld& getRTDyld(); 73280031Sdim 74280031Sdim // \brief Get the associated RTDyld instance. 75280031Sdim const RuntimeDyld& getRTDyld() const; 76280031Sdim 77274955Ssvnmir /// \brief Check a single expression against the attached RuntimeDyld 78274955Ssvnmir /// instance. 79274955Ssvnmir bool check(StringRef CheckExpr) const; 80274955Ssvnmir 81274955Ssvnmir /// \brief Scan the given memory buffer for lines beginning with the string 82274955Ssvnmir /// in RulePrefix. The remainder of the line is passed to the check 83274955Ssvnmir /// method to be evaluated as an expression. 84274955Ssvnmir bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const; 85274955Ssvnmir 86280031Sdim /// \brief Returns the address of the requested section (or an error message 87280031Sdim /// in the second element of the pair if the address cannot be found). 88280031Sdim /// 89288943Sdim /// if 'LocalAddress' is true, this returns the address of the section 90288943Sdim /// within the linker's memory. If 'LocalAddress' is false it returns the 91280031Sdim /// address within the target process (i.e. the load address). 92280031Sdim std::pair<uint64_t, std::string> getSectionAddr(StringRef FileName, 93280031Sdim StringRef SectionName, 94288943Sdim bool LocalAddress); 95280031Sdim 96274955Ssvnmirprivate: 97280031Sdim std::unique_ptr<RuntimeDyldCheckerImpl> Impl; 98274955Ssvnmir}; 99274955Ssvnmir 100274955Ssvnmir} // end namespace llvm 101274955Ssvnmir 102280031Sdim#endif 103