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_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
11 #define LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
25 class RuntimeDyldCheckerImpl;
28 /// \brief RuntimeDyld invariant checker for verifying that RuntimeDyld has
29 /// correctly applied relocations.
31 /// The RuntimeDyldChecker class evaluates expressions against an attached
32 /// RuntimeDyld instance to verify that relocations have been applied
35 /// The expression language supports basic pointer arithmetic and bit-masking,
36 /// and has limited disassembler integration for accessing instruction
37 /// operands and the next PC (program counter) address for each instruction.
39 /// The language syntax is:
41 /// check = expr '=' expr
43 /// expr = binary_expr
46 /// sliceable_expr = '*{' number '}' load_addr_expr [slice]
47 /// | '(' expr ')' [slice]
48 /// | ident_expr [slice]
51 /// slice = '[' high-bit-index ':' low-bit-index ']'
53 /// load_addr_expr = symbol
54 /// | '(' symbol '+' number ')'
55 /// | '(' symbol '-' number ')'
57 /// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')'
58 /// | 'next_pc' '(' symbol ')'
59 /// | 'stub_addr' '(' file-name ',' section-name ',' symbol ')'
62 /// binary_expr = expr '+' expr
69 class RuntimeDyldChecker {
71 RuntimeDyldChecker(RuntimeDyld &RTDyld, MCDisassembler *Disassembler,
72 MCInstPrinter *InstPrinter, raw_ostream &ErrStream);
73 ~RuntimeDyldChecker();
75 // \brief Get the associated RTDyld instance.
76 RuntimeDyld& getRTDyld();
78 // \brief Get the associated RTDyld instance.
79 const RuntimeDyld& getRTDyld() const;
81 /// \brief Check a single expression against the attached RuntimeDyld
83 bool check(StringRef CheckExpr) const;
85 /// \brief Scan the given memory buffer for lines beginning with the string
86 /// in RulePrefix. The remainder of the line is passed to the check
87 /// method to be evaluated as an expression.
88 bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const;
90 /// \brief Returns the address of the requested section (or an error message
91 /// in the second element of the pair if the address cannot be found).
93 /// if 'LocalAddress' is true, this returns the address of the section
94 /// within the linker's memory. If 'LocalAddress' is false it returns the
95 /// address within the target process (i.e. the load address).
96 std::pair<uint64_t, std::string> getSectionAddr(StringRef FileName,
97 StringRef SectionName,
101 std::unique_ptr<RuntimeDyldCheckerImpl> Impl;
104 } // end namespace llvm