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
13 #include "llvm/ADT/StringRef.h"
21 class RuntimeDyldCheckerImpl;
24 /// \brief RuntimeDyld invariant checker for verifying that RuntimeDyld has
25 /// correctly applied relocations.
27 /// The RuntimeDyldChecker class evaluates expressions against an attached
28 /// RuntimeDyld instance to verify that relocations have been applied
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.
35 /// The language syntax is:
37 /// check = expr '=' expr
39 /// expr = binary_expr
42 /// sliceable_expr = '*{' number '}' load_addr_expr [slice]
43 /// | '(' expr ')' [slice]
44 /// | ident_expr [slice]
47 /// slice = '[' high-bit-index ':' low-bit-index ']'
49 /// load_addr_expr = symbol
50 /// | '(' symbol '+' number ')'
51 /// | '(' symbol '-' number ')'
53 /// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')'
54 /// | 'next_pc' '(' symbol ')'
55 /// | 'stub_addr' '(' file-name ',' section-name ',' symbol ')'
58 /// binary_expr = expr '+' expr
65 class RuntimeDyldChecker {
67 RuntimeDyldChecker(RuntimeDyld &RTDyld, MCDisassembler *Disassembler,
68 MCInstPrinter *InstPrinter, raw_ostream &ErrStream);
69 ~RuntimeDyldChecker();
71 // \brief Get the associated RTDyld instance.
72 RuntimeDyld& getRTDyld();
74 // \brief Get the associated RTDyld instance.
75 const RuntimeDyld& getRTDyld() const;
77 /// \brief Check a single expression against the attached RuntimeDyld
79 bool check(StringRef CheckExpr) const;
81 /// \brief Scan the given memory buffer for lines beginning with the string
82 /// in RulePrefix. The remainder of the line is passed to the check
83 /// method to be evaluated as an expression.
84 bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const;
86 /// \brief Returns the address of the requested section (or an error message
87 /// in the second element of the pair if the address cannot be found).
89 /// if 'LocalAddress' is true, this returns the address of the section
90 /// within the linker's memory. If 'LocalAddress' is false it returns the
91 /// address within the target process (i.e. the load address).
92 std::pair<uint64_t, std::string> getSectionAddr(StringRef FileName,
93 StringRef SectionName,
97 std::unique_ptr<RuntimeDyldCheckerImpl> Impl;
100 } // end namespace llvm