RuntimeDyldChecker.h revision 280031
1274955Ssvnmir//===---- RuntimeDyldChecker.h - RuntimeDyld tester framework -----*- C++ -*-=//
2274955Ssvnmir//
3274955Ssvnmir//                     The LLVM Compiler Infrastructure
4274955Ssvnmir//
5274955Ssvnmir// This file is distributed under the University of Illinois Open Source
6274955Ssvnmir// License. See LICENSE.TXT for details.
7274955Ssvnmir//
8274955Ssvnmir//===----------------------------------------------------------------------===//
9274955Ssvnmir
10280031Sdim#ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
11280031Sdim#define LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
12274955Ssvnmir
13280031Sdim#include "llvm/ADT/StringRef.h"
14274955Ssvnmir
15274955Ssvnmirnamespace llvm {
16274955Ssvnmir
17274955Ssvnmirclass MCDisassembler;
18280031Sdimclass MemoryBuffer;
19274955Ssvnmirclass MCInstPrinter;
20280031Sdimclass RuntimeDyld;
21280031Sdimclass RuntimeDyldCheckerImpl;
22280031Sdimclass raw_ostream;
23274955Ssvnmir
24274955Ssvnmir/// \brief RuntimeDyld invariant checker for verifying that RuntimeDyld has
25274955Ssvnmir///        correctly applied relocations.
26274955Ssvnmir///
27274955Ssvnmir/// The RuntimeDyldChecker class evaluates expressions against an attached
28274955Ssvnmir/// RuntimeDyld instance to verify that relocations have been applied
29274955Ssvnmir/// correctly.
30274955Ssvnmir///
31274955Ssvnmir/// The expression language supports basic pointer arithmetic and bit-masking,
32274955Ssvnmir/// and has limited disassembler integration for accessing instruction
33274955Ssvnmir/// operands and the next PC (program counter) address for each instruction.
34274955Ssvnmir///
35274955Ssvnmir/// The language syntax is:
36274955Ssvnmir///
37274955Ssvnmir/// check = expr '=' expr
38274955Ssvnmir///
39274955Ssvnmir/// expr = binary_expr
40274955Ssvnmir///      | sliceable_expr
41274955Ssvnmir///
42274955Ssvnmir/// sliceable_expr = '*{' number '}' load_addr_expr [slice]
43274955Ssvnmir///                | '(' expr ')' [slice]
44274955Ssvnmir///                | ident_expr [slice]
45274955Ssvnmir///                | number [slice]
46274955Ssvnmir///
47274955Ssvnmir/// slice = '[' high-bit-index ':' low-bit-index ']'
48274955Ssvnmir///
49274955Ssvnmir/// load_addr_expr = symbol
50274955Ssvnmir///                | '(' symbol '+' number ')'
51274955Ssvnmir///                | '(' symbol '-' number ')'
52274955Ssvnmir///
53274955Ssvnmir/// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')'
54274955Ssvnmir///            | 'next_pc'        '(' symbol ')'
55274955Ssvnmir///            | symbol
56274955Ssvnmir///
57274955Ssvnmir/// binary_expr = expr '+' expr
58274955Ssvnmir///             | expr '-' expr
59274955Ssvnmir///             | expr '&' expr
60274955Ssvnmir///             | expr '|' expr
61274955Ssvnmir///             | expr '<<' expr
62274955Ssvnmir///             | expr '>>' expr
63274955Ssvnmir///
64274955Ssvnmirclass RuntimeDyldChecker {
65274955Ssvnmirpublic:
66280031Sdim  RuntimeDyldChecker(RuntimeDyld &RTDyld, MCDisassembler *Disassembler,
67280031Sdim                     MCInstPrinter *InstPrinter, raw_ostream &ErrStream);
68280031Sdim  ~RuntimeDyldChecker();
69274955Ssvnmir
70280031Sdim  // \brief Get the associated RTDyld instance.
71280031Sdim  RuntimeDyld& getRTDyld();
72280031Sdim
73280031Sdim  // \brief Get the associated RTDyld instance.
74280031Sdim  const RuntimeDyld& getRTDyld() const;
75280031Sdim
76274955Ssvnmir  /// \brief Check a single expression against the attached RuntimeDyld
77274955Ssvnmir  ///        instance.
78274955Ssvnmir  bool check(StringRef CheckExpr) const;
79274955Ssvnmir
80274955Ssvnmir  /// \brief Scan the given memory buffer for lines beginning with the string
81274955Ssvnmir  ///        in RulePrefix. The remainder of the line is passed to the check
82274955Ssvnmir  ///        method to be evaluated as an expression.
83274955Ssvnmir  bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const;
84274955Ssvnmir
85280031Sdim  /// \brief Returns the address of the requested section (or an error message
86280031Sdim  ///        in the second element of the pair if the address cannot be found).
87280031Sdim  ///
88280031Sdim  /// if 'LinkerAddress' is true, this returns the address of the section
89280031Sdim  /// within the linker's memory. If 'LinkerAddress' is false it returns the
90280031Sdim  /// address within the target process (i.e. the load address).
91280031Sdim  std::pair<uint64_t, std::string> getSectionAddr(StringRef FileName,
92280031Sdim                                                  StringRef SectionName,
93280031Sdim                                                  bool LinkerAddress);
94280031Sdim
95274955Ssvnmirprivate:
96280031Sdim  std::unique_ptr<RuntimeDyldCheckerImpl> Impl;
97274955Ssvnmir};
98274955Ssvnmir
99274955Ssvnmir} // end namespace llvm
100274955Ssvnmir
101280031Sdim#endif
102