1//===-- RuntimeDyldCheckerImpl.h -- RuntimeDyld test 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_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDCHECKERIMPL_H
11#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDCHECKERIMPL_H
12
13#include "RuntimeDyldImpl.h"
14#include <set>
15
16namespace llvm {
17
18class RuntimeDyldCheckerImpl {
19  friend class RuntimeDyldChecker;
20  friend class RuntimeDyldImpl;
21  friend class RuntimeDyldCheckerExprEval;
22  friend class RuntimeDyldELF;
23
24public:
25  RuntimeDyldCheckerImpl(RuntimeDyld &RTDyld, MCDisassembler *Disassembler,
26                         MCInstPrinter *InstPrinter,
27                         llvm::raw_ostream &ErrStream);
28
29  bool check(StringRef CheckExpr) const;
30  bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const;
31
32private:
33
34  // StubMap typedefs.
35  typedef std::map<std::string, uint64_t> StubOffsetsMap;
36  struct SectionAddressInfo {
37    uint64_t SectionID;
38    StubOffsetsMap StubOffsets;
39  };
40  typedef std::map<std::string, SectionAddressInfo> SectionMap;
41  typedef std::map<std::string, SectionMap> StubMap;
42
43  RuntimeDyldImpl &getRTDyld() const { return *RTDyld.Dyld; }
44
45  bool isSymbolValid(StringRef Symbol) const;
46  uint64_t getSymbolLocalAddr(StringRef Symbol) const;
47  uint64_t getSymbolRemoteAddr(StringRef Symbol) const;
48  uint64_t readMemoryAtAddr(uint64_t Addr, unsigned Size) const;
49
50  std::pair<const SectionAddressInfo*, std::string> findSectionAddrInfo(
51                                                   StringRef FileName,
52                                                   StringRef SectionName) const;
53
54  std::pair<uint64_t, std::string> getSectionAddr(StringRef FileName,
55                                                  StringRef SectionName,
56                                                  bool IsInsideLoad) const;
57
58  std::pair<uint64_t, std::string> getStubAddrFor(StringRef FileName,
59                                                  StringRef SectionName,
60                                                  StringRef Symbol,
61                                                  bool IsInsideLoad) const;
62  StringRef getSubsectionStartingAt(StringRef Name) const;
63
64  void registerSection(StringRef FilePath, unsigned SectionID);
65  void registerStubMap(StringRef FilePath, unsigned SectionID,
66                       const RuntimeDyldImpl::StubMap &RTDyldStubs);
67
68  RuntimeDyld &RTDyld;
69  MCDisassembler *Disassembler;
70  MCInstPrinter *InstPrinter;
71  llvm::raw_ostream &ErrStream;
72
73  StubMap Stubs;
74};
75}
76
77#endif
78