1 //===----- DebugUtils.h - Utilities for debugging ORC JITs ------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Utilities for debugging ORC-based JITs.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_EXECUTIONENGINE_ORC_DEBUGUTILS_H
14 #define LLVM_EXECUTIONENGINE_ORC_DEBUGUTILS_H
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"
30 // --raw_ostream operators for ORC types--
32 /// Render a SymbolStringPtr.
33 raw_ostream &operator<<(raw_ostream &OS, const SymbolStringPtr &Sym);
35 /// Render a SymbolNameSet.
36 raw_ostream &operator<<(raw_ostream &OS, const SymbolNameSet &Symbols);
38 /// Render a SymbolNameVector.
39 raw_ostream &operator<<(raw_ostream &OS, const SymbolNameVector &Symbols);
41 /// Render an array of SymbolStringPtrs.
42 raw_ostream &operator<<(raw_ostream &OS, ArrayRef<SymbolStringPtr> Symbols);
44 /// Render JITSymbolFlags.
45 raw_ostream &operator<<(raw_ostream &OS, const JITSymbolFlags &Flags);
47 /// Render a SymbolFlagsMap entry.
48 raw_ostream &operator<<(raw_ostream &OS, const SymbolFlagsMap::value_type &KV);
50 /// Render a SymbolMap entry.
51 raw_ostream &operator<<(raw_ostream &OS, const SymbolMap::value_type &KV);
53 /// Render a SymbolFlagsMap.
54 raw_ostream &operator<<(raw_ostream &OS, const SymbolFlagsMap &SymbolFlags);
56 /// Render a SymbolMap.
57 raw_ostream &operator<<(raw_ostream &OS, const SymbolMap &Symbols);
59 /// Render a SymbolDependenceMap entry.
60 raw_ostream &operator<<(raw_ostream &OS,
61 const SymbolDependenceMap::value_type &KV);
63 /// Render a SymbolDependendeMap.
64 raw_ostream &operator<<(raw_ostream &OS, const SymbolDependenceMap &Deps);
66 /// Render a MaterializationUnit.
67 raw_ostream &operator<<(raw_ostream &OS, const MaterializationUnit &MU);
69 //// Render a JITDylibLookupFlags instance.
70 raw_ostream &operator<<(raw_ostream &OS,
71 const JITDylibLookupFlags &JDLookupFlags);
73 /// Rendar a SymbolLookupFlags instance.
74 raw_ostream &operator<<(raw_ostream &OS, const SymbolLookupFlags &LookupFlags);
76 /// Render a SymbolLookupSet entry.
77 raw_ostream &operator<<(raw_ostream &OS, const SymbolLookupSet::value_type &KV);
79 /// Render a SymbolLookupSet.
80 raw_ostream &operator<<(raw_ostream &OS, const SymbolLookupSet &LookupSet);
82 /// Render a JITDylibSearchOrder.
83 raw_ostream &operator<<(raw_ostream &OS,
84 const JITDylibSearchOrder &SearchOrder);
86 /// Render a SymbolAliasMap.
87 raw_ostream &operator<<(raw_ostream &OS, const SymbolAliasMap &Aliases);
89 /// Render a SymbolState.
90 raw_ostream &operator<<(raw_ostream &OS, const SymbolState &S);
92 /// Render a LookupKind.
93 raw_ostream &operator<<(raw_ostream &OS, const LookupKind &K);
95 /// Dump a SymbolStringPool. Useful for debugging dangling-pointer crashes.
96 raw_ostream &operator<<(raw_ostream &OS, const SymbolStringPool &SSP);
98 /// A function object that can be used as an ObjectTransformLayer transform
99 /// to dump object files to disk at a specified path.
102 /// Construct a DumpObjects transform that will dump objects to disk.
104 /// @param DumpDir specifies the path to write dumped objects to. DumpDir may
105 /// be empty, in which case files will be dumped to the working directory. If
106 /// DumpDir is non-empty then any trailing separators will be discarded.
108 /// @param IdentifierOverride specifies a file name stem to use when dumping
109 /// objects. If empty, each MemoryBuffer's identifier will be used (with a .o
110 /// suffix added if not already present). If an identifier override is
111 /// supplied it will be used instead (since all buffers will use the same
112 /// identifier, the resulting files will be named <ident>.o, <ident>.2.o,
113 /// <ident>.3.o, and so on). IdentifierOverride should not contain an
114 /// extension, as a .o suffix will be added by DumpObjects.
115 DumpObjects(std::string DumpDir = "", std::string IdentifierOverride = "");
117 /// Dumps the given buffer to disk.
118 Expected<std::unique_ptr<MemoryBuffer>>
119 operator()(std::unique_ptr<MemoryBuffer> Obj);
122 StringRef getBufferIdentifier(MemoryBuffer &B);
124 std::string IdentifierOverride;
127 } // End namespace orc
128 } // End namespace llvm
130 #endif // LLVM_EXECUTIONENGINE_ORC_DEBUGUTILS_H