1 //===---- RuntimeDyldChecker.h - RuntimeDyld tester framework -----*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_RUNTIMEDYLDCHECKER_H
11 #define LLVM_RUNTIMEDYLDCHECKER_H
13 #include "RuntimeDyld.h"
14 #include "llvm/Support/Debug.h"
15 #include "llvm/Support/raw_ostream.h"
23 /// \brief RuntimeDyld invariant checker for verifying that RuntimeDyld has
24 /// correctly applied relocations.
26 /// The RuntimeDyldChecker class evaluates expressions against an attached
27 /// RuntimeDyld instance to verify that relocations have been applied
30 /// The expression language supports basic pointer arithmetic and bit-masking,
31 /// and has limited disassembler integration for accessing instruction
32 /// operands and the next PC (program counter) address for each instruction.
34 /// The language syntax is:
36 /// check = expr '=' expr
38 /// expr = binary_expr
41 /// sliceable_expr = '*{' number '}' load_addr_expr [slice]
42 /// | '(' expr ')' [slice]
43 /// | ident_expr [slice]
46 /// slice = '[' high-bit-index ':' low-bit-index ']'
48 /// load_addr_expr = symbol
49 /// | '(' symbol '+' number ')'
50 /// | '(' symbol '-' number ')'
52 /// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')'
53 /// | 'next_pc' '(' symbol ')'
56 /// binary_expr = expr '+' expr
63 class RuntimeDyldChecker {
64 friend class RuntimeDyldCheckerExprEval;
66 RuntimeDyldChecker(RuntimeDyld &RTDyld,
67 MCDisassembler *Disassembler,
68 MCInstPrinter *InstPrinter,
69 llvm::raw_ostream &ErrStream)
70 : RTDyld(*RTDyld.Dyld), Disassembler(Disassembler),
71 InstPrinter(InstPrinter), ErrStream(ErrStream) {}
73 /// \brief Check a single expression against the attached RuntimeDyld
75 bool check(StringRef CheckExpr) const;
77 /// \brief Scan the given memory buffer for lines beginning with the string
78 /// in RulePrefix. The remainder of the line is passed to the check
79 /// method to be evaluated as an expression.
80 bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const;
84 bool isSymbolValid(StringRef Symbol) const;
85 uint64_t getSymbolAddress(StringRef Symbol) const;
86 uint64_t readMemoryAtSymbol(StringRef Symbol, int64_t Offset,
88 StringRef getSubsectionStartingAt(StringRef Name) const;
90 RuntimeDyldImpl &RTDyld;
91 MCDisassembler *Disassembler;
92 MCInstPrinter *InstPrinter;
93 llvm::raw_ostream &ErrStream;
96 } // end namespace llvm
98 #endif // LLVM_RUNTIMEDYLDCHECKER_H