LLVM  4.0.0
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 <cstdint>
14 #include <memory>
15 #include <string>
16 #include <utility>
17 
18 namespace llvm {
19 
20 class StringRef;
21 class MCDisassembler;
22 class MemoryBuffer;
23 class MCInstPrinter;
24 class RuntimeDyld;
25 class RuntimeDyldCheckerImpl;
26 class raw_ostream;
27 
28 /// \brief RuntimeDyld invariant checker for verifying that RuntimeDyld has
29 /// correctly applied relocations.
30 ///
31 /// The RuntimeDyldChecker class evaluates expressions against an attached
32 /// RuntimeDyld instance to verify that relocations have been applied
33 /// correctly.
34 ///
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.
38 ///
39 /// The language syntax is:
40 ///
41 /// check = expr '=' expr
42 ///
43 /// expr = binary_expr
44 /// | sliceable_expr
45 ///
46 /// sliceable_expr = '*{' number '}' load_addr_expr [slice]
47 /// | '(' expr ')' [slice]
48 /// | ident_expr [slice]
49 /// | number [slice]
50 ///
51 /// slice = '[' high-bit-index ':' low-bit-index ']'
52 ///
53 /// load_addr_expr = symbol
54 /// | '(' symbol '+' number ')'
55 /// | '(' symbol '-' number ')'
56 ///
57 /// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')'
58 /// | 'next_pc' '(' symbol ')'
59 /// | 'stub_addr' '(' file-name ',' section-name ',' symbol ')'
60 /// | symbol
61 ///
62 /// binary_expr = expr '+' expr
63 /// | expr '-' expr
64 /// | expr '&' expr
65 /// | expr '|' expr
66 /// | expr '<<' expr
67 /// | expr '>>' expr
68 ///
70 public:
71  RuntimeDyldChecker(RuntimeDyld &RTDyld, MCDisassembler *Disassembler,
72  MCInstPrinter *InstPrinter, raw_ostream &ErrStream);
74 
75  // \brief Get the associated RTDyld instance.
77 
78  // \brief Get the associated RTDyld instance.
79  const RuntimeDyld& getRTDyld() const;
80 
81  /// \brief Check a single expression against the attached RuntimeDyld
82  /// instance.
83  bool check(StringRef CheckExpr) const;
84 
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;
89 
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).
92  ///
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,
98  bool LocalAddress);
99 
100 private:
101  std::unique_ptr<RuntimeDyldCheckerImpl> Impl;
102 };
103 
104 } // end namespace llvm
105 
106 #endif
Superclass for all disassemblers.
bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const
Scan the given memory buffer for lines beginning with the string in RulePrefix.
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:40
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:41
const char SectionName[]
Definition: AMDGPUPTNote.h:24
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:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47