1 | //===----- DebugUtils.h - Utilities for debugging ORC JITs ------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // Utilities for debugging ORC-based JITs. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef LLVM_EXECUTIONENGINE_ORC_DEBUGUTILS_H |
14 | #define LLVM_EXECUTIONENGINE_ORC_DEBUGUTILS_H |
15 | |
16 | #include "llvm/ADT/ArrayRef.h" |
17 | #include "llvm/ExecutionEngine/Orc/Core.h" |
18 | #include "llvm/ExecutionEngine/Orc/SymbolStringPool.h" |
19 | #include "llvm/Support/Compiler.h" |
20 | #include "llvm/Support/Error.h" |
21 | #include "llvm/Support/raw_ostream.h" |
22 | #include <memory> |
23 | #include <string> |
24 | |
25 | namespace llvm { |
26 | |
27 | class MemoryBuffer; |
28 | |
29 | namespace orc { |
30 | |
31 | // --raw_ostream operators for ORC types-- |
32 | |
33 | /// Render a SymbolNameSet. |
34 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const SymbolNameSet &Symbols); |
35 | |
36 | /// Render a SymbolNameVector. |
37 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, |
38 | const SymbolNameVector &Symbols); |
39 | |
40 | /// Render an array of SymbolStringPtrs. |
41 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, |
42 | ArrayRef<SymbolStringPtr> Symbols); |
43 | |
44 | /// Render JITSymbolFlags. |
45 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const JITSymbolFlags &Flags); |
46 | |
47 | /// Render a SymbolFlagsMap entry. |
48 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, |
49 | const SymbolFlagsMap::value_type &KV); |
50 | |
51 | /// Render a SymbolMap entry. |
52 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, |
53 | const SymbolMap::value_type &KV); |
54 | |
55 | /// Render a SymbolFlagsMap. |
56 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, |
57 | const SymbolFlagsMap &SymbolFlags); |
58 | |
59 | /// Render a SymbolMap. |
60 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const SymbolMap &Symbols); |
61 | |
62 | /// Render a SymbolDependenceMap entry. |
63 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, |
64 | const SymbolDependenceMap::value_type &KV); |
65 | |
66 | /// Render a SymbolDependendeMap. |
67 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, |
68 | const SymbolDependenceMap &Deps); |
69 | |
70 | /// Render a MaterializationUnit. |
71 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, |
72 | const MaterializationUnit &MU); |
73 | |
74 | //// Render a JITDylibLookupFlags instance. |
75 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, |
76 | const JITDylibLookupFlags &JDLookupFlags); |
77 | |
78 | /// Render a SymbolLookupFlags instance. |
79 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, |
80 | const SymbolLookupFlags &LookupFlags); |
81 | |
82 | /// Render a SymbolLookupSet entry. |
83 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, |
84 | const SymbolLookupSet::value_type &KV); |
85 | |
86 | /// Render a SymbolLookupSet. |
87 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, |
88 | const SymbolLookupSet &LookupSet); |
89 | |
90 | /// Render a JITDylibSearchOrder. |
91 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, |
92 | const JITDylibSearchOrder &SearchOrder); |
93 | |
94 | /// Render a SymbolAliasMap. |
95 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, |
96 | const SymbolAliasMap &Aliases); |
97 | |
98 | /// Render a SymbolState. |
99 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const SymbolState &S); |
100 | |
101 | /// Render a LookupKind. |
102 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const LookupKind &K); |
103 | |
104 | /// Dump a SymbolStringPool. Useful for debugging dangling-pointer crashes. |
105 | LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const SymbolStringPool &SSP); |
106 | |
107 | /// A function object that can be used as an ObjectTransformLayer transform |
108 | /// to dump object files to disk at a specified path. |
109 | class DumpObjects { |
110 | public: |
111 | /// Construct a DumpObjects transform that will dump objects to disk. |
112 | /// |
113 | /// @param DumpDir specifies the path to write dumped objects to. DumpDir may |
114 | /// be empty, in which case files will be dumped to the working directory. If |
115 | /// DumpDir is non-empty then any trailing separators will be discarded. |
116 | /// |
117 | /// @param IdentifierOverride specifies a file name stem to use when dumping |
118 | /// objects. If empty, each MemoryBuffer's identifier will be used (with a .o |
119 | /// suffix added if not already present). If an identifier override is |
120 | /// supplied it will be used instead (since all buffers will use the same |
121 | /// identifier, the resulting files will be named <ident>.o, <ident>.2.o, |
122 | /// <ident>.3.o, and so on). IdentifierOverride should not contain an |
123 | /// extension, as a .o suffix will be added by DumpObjects. |
124 | LLVM_ABI DumpObjects(std::string DumpDir = "" , |
125 | std::string IdentifierOverride = "" ); |
126 | |
127 | /// Dumps the given buffer to disk. |
128 | LLVM_ABI Expected<std::unique_ptr<MemoryBuffer>> |
129 | operator()(std::unique_ptr<MemoryBuffer> Obj); |
130 | |
131 | private: |
132 | StringRef getBufferIdentifier(MemoryBuffer &B); |
133 | std::string DumpDir; |
134 | std::string IdentifierOverride; |
135 | }; |
136 | |
137 | } // End namespace orc |
138 | } // End namespace llvm |
139 | |
140 | #endif // LLVM_EXECUTIONENGINE_ORC_DEBUGUTILS_H |
141 | |