RuntimeDyldChecker.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
  10. #define LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
  11. #include "llvm/ADT/StringRef.h"
  12. namespace llvm {
  13. class MCDisassembler;
  14. class MemoryBuffer;
  15. class MCInstPrinter;
  16. class RuntimeDyld;
  17. class RuntimeDyldCheckerImpl;
  18. class raw_ostream;
  19. /// \brief RuntimeDyld invariant checker for verifying that RuntimeDyld has
  20. /// correctly applied relocations.
  21. ///
  22. /// The RuntimeDyldChecker class evaluates expressions against an attached
  23. /// RuntimeDyld instance to verify that relocations have been applied
  24. /// correctly.
  25. ///
  26. /// The expression language supports basic pointer arithmetic and bit-masking,
  27. /// and has limited disassembler integration for accessing instruction
  28. /// operands and the next PC (program counter) address for each instruction.
  29. ///
  30. /// The language syntax is:
  31. ///
  32. /// check = expr '=' expr
  33. ///
  34. /// expr = binary_expr
  35. /// | sliceable_expr
  36. ///
  37. /// sliceable_expr = '*{' number '}' load_addr_expr [slice]
  38. /// | '(' expr ')' [slice]
  39. /// | ident_expr [slice]
  40. /// | number [slice]
  41. ///
  42. /// slice = '[' high-bit-index ':' low-bit-index ']'
  43. ///
  44. /// load_addr_expr = symbol
  45. /// | '(' symbol '+' number ')'
  46. /// | '(' symbol '-' number ')'
  47. ///
  48. /// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')'
  49. /// | 'next_pc' '(' symbol ')'
  50. /// | 'stub_addr' '(' file-name ',' section-name ',' symbol ')'
  51. /// | symbol
  52. ///
  53. /// binary_expr = expr '+' expr
  54. /// | expr '-' expr
  55. /// | expr '&' expr
  56. /// | expr '|' expr
  57. /// | expr '<<' expr
  58. /// | expr '>>' expr
  59. ///
  60. class RuntimeDyldChecker {
  61. public:
  62. RuntimeDyldChecker(RuntimeDyld &RTDyld, MCDisassembler *Disassembler,
  63. MCInstPrinter *InstPrinter, raw_ostream &ErrStream);
  64. ~RuntimeDyldChecker();
  65. // \brief Get the associated RTDyld instance.
  66. RuntimeDyld& getRTDyld();
  67. // \brief Get the associated RTDyld instance.
  68. const RuntimeDyld& getRTDyld() const;
  69. /// \brief Check a single expression against the attached RuntimeDyld
  70. /// instance.
  71. bool check(StringRef CheckExpr) const;
  72. /// \brief Scan the given memory buffer for lines beginning with the string
  73. /// in RulePrefix. The remainder of the line is passed to the check
  74. /// method to be evaluated as an expression.
  75. bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const;
  76. /// \brief Returns the address of the requested section (or an error message
  77. /// in the second element of the pair if the address cannot be found).
  78. ///
  79. /// if 'LocalAddress' is true, this returns the address of the section
  80. /// within the linker's memory. If 'LocalAddress' is false it returns the
  81. /// address within the target process (i.e. the load address).
  82. std::pair<uint64_t, std::string> getSectionAddr(StringRef FileName,
  83. StringRef SectionName,
  84. bool LocalAddress);
  85. private:
  86. std::unique_ptr<RuntimeDyldCheckerImpl> Impl;
  87. };
  88. } // end namespace llvm
  89. #endif