LLVM  8.0.1
RuntimeDyldChecker.h
Go to the documentation of this file.
1 //===---- RuntimeDyldChecker.h - RuntimeDyld tester framework -----*- C++ -*-=//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
11 #define LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
12 
13 #include "llvm/ADT/Optional.h"
14 
15 #include <cstdint>
16 #include <memory>
17 #include <string>
18 #include <utility>
19 
20 namespace llvm {
21 
22 class StringRef;
23 class MCDisassembler;
24 class MemoryBuffer;
25 class MCInstPrinter;
26 class RuntimeDyld;
27 class RuntimeDyldCheckerImpl;
28 class raw_ostream;
29 
30 /// RuntimeDyld invariant checker for verifying that RuntimeDyld has
31 /// correctly applied relocations.
32 ///
33 /// The RuntimeDyldChecker class evaluates expressions against an attached
34 /// RuntimeDyld instance to verify that relocations have been applied
35 /// correctly.
36 ///
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.
40 ///
41 /// The language syntax is:
42 ///
43 /// check = expr '=' expr
44 ///
45 /// expr = binary_expr
46 /// | sliceable_expr
47 ///
48 /// sliceable_expr = '*{' number '}' load_addr_expr [slice]
49 /// | '(' expr ')' [slice]
50 /// | ident_expr [slice]
51 /// | number [slice]
52 ///
53 /// slice = '[' high-bit-index ':' low-bit-index ']'
54 ///
55 /// load_addr_expr = symbol
56 /// | '(' symbol '+' number ')'
57 /// | '(' symbol '-' number ')'
58 ///
59 /// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')'
60 /// | 'next_pc' '(' symbol ')'
61 /// | 'stub_addr' '(' file-name ',' section-name ',' symbol ')'
62 /// | symbol
63 ///
64 /// binary_expr = expr '+' expr
65 /// | expr '-' expr
66 /// | expr '&' expr
67 /// | expr '|' expr
68 /// | expr '<<' expr
69 /// | expr '>>' expr
70 ///
72 public:
73  RuntimeDyldChecker(RuntimeDyld &RTDyld, MCDisassembler *Disassembler,
74  MCInstPrinter *InstPrinter, raw_ostream &ErrStream);
76 
77  // Get the associated RTDyld instance.
79 
80  // Get the associated RTDyld instance.
81  const RuntimeDyld& getRTDyld() const;
82 
83  /// Check a single expression against the attached RuntimeDyld
84  /// instance.
85  bool check(StringRef CheckExpr) const;
86 
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;
91 
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).
94  ///
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,
100  bool LocalAddress);
101 
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;
105 
106 private:
107  std::unique_ptr<RuntimeDyldCheckerImpl> Impl;
108 };
109 
110 } // end namespace llvm
111 
112 #endif
bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const
Scan the given memory buffer for lines beginning with the string in RulePrefix.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Superclass for all disassemblers.
Optional< uint64_t > getSectionLoadAddress(void *LocalAddress) const
If there is a section at the given local address, return its load address, otherwise return none...
std::pair< uint64_t, std::string > getSectionAddr(StringRef FileName, StringRef SectionName, bool LocalAddress)
Returns the address of the requested section (or an error message in the second element of the pair i...
RuntimeDyld invariant checker for verifying that RuntimeDyld has correctly applied relocations...
bool check(StringRef CheckExpr) const
Check a single expression against the attached RuntimeDyld instance.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:42
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:40
RuntimeDyldChecker(RuntimeDyld &RTDyld, MCDisassembler *Disassembler, MCInstPrinter *InstPrinter, raw_ostream &ErrStream)
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49