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