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/Optional.h"
27 class RuntimeDyldCheckerImpl;
30 /// RuntimeDyld invariant checker for verifying that RuntimeDyld has
31 /// correctly applied relocations.
33 /// The RuntimeDyldChecker class evaluates expressions against an attached
34 /// RuntimeDyld instance to verify that relocations have been applied
37 /// The expression language supports basic pointer arithmetic and bit-masking,
38 /// and has limited disassembler integration for accessing instruction
39 /// operands and the next PC (program counter) address for each instruction.
41 /// The language syntax is:
43 /// check = expr '=' expr
45 /// expr = binary_expr
48 /// sliceable_expr = '*{' number '}' load_addr_expr [slice]
49 /// | '(' expr ')' [slice]
50 /// | ident_expr [slice]
53 /// slice = '[' high-bit-index ':' low-bit-index ']'
55 /// load_addr_expr = symbol
56 /// | '(' symbol '+' number ')'
57 /// | '(' symbol '-' number ')'
59 /// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')'
60 /// | 'next_pc' '(' symbol ')'
61 /// | 'stub_addr' '(' file-name ',' section-name ',' symbol ')'
64 /// binary_expr = expr '+' expr
71 class RuntimeDyldChecker {
73 RuntimeDyldChecker(RuntimeDyld &RTDyld, MCDisassembler *Disassembler,
74 MCInstPrinter *InstPrinter, raw_ostream &ErrStream);
75 ~RuntimeDyldChecker();
77 // Get the associated RTDyld instance.
78 RuntimeDyld& getRTDyld();
80 // Get the associated RTDyld instance.
81 const RuntimeDyld& getRTDyld() const;
83 /// Check a single expression against the attached RuntimeDyld
85 bool check(StringRef CheckExpr) const;
87 /// Scan the given memory buffer for lines beginning with the string
88 /// in RulePrefix. The remainder of the line is passed to the check
89 /// method to be evaluated as an expression.
90 bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const;
92 /// Returns the address of the requested section (or an error message
93 /// in the second element of the pair if the address cannot be found).
95 /// if 'LocalAddress' is true, this returns the address of the section
96 /// within the linker's memory. If 'LocalAddress' is false it returns the
97 /// address within the target process (i.e. the load address).
98 std::pair<uint64_t, std::string> getSectionAddr(StringRef FileName,
99 StringRef SectionName,
102 /// If there is a section at the given local address, return its load
103 /// address, otherwise return none.
104 Optional<uint64_t> getSectionLoadAddress(void *LocalAddress) const;
107 std::unique_ptr<RuntimeDyldCheckerImpl> Impl;
110 } // end namespace llvm