LLVM 20.0.0git
DebugUtils.h
Go to the documentation of this file.
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"
19#include "llvm/Support/Error.h"
21#include <memory>
22#include <string>
23
24namespace llvm {
25
26class MemoryBuffer;
27
28namespace orc {
29
30// --raw_ostream operators for ORC types--
31
32/// Render a SymbolStringPtr.
33raw_ostream &operator<<(raw_ostream &OS, const SymbolStringPtr &Sym);
34
35/// Render a NonOwningSymbolStringPtr.
36raw_ostream &operator<<(raw_ostream &OS, NonOwningSymbolStringPtr Sym);
37
38/// Render a SymbolNameSet.
39raw_ostream &operator<<(raw_ostream &OS, const SymbolNameSet &Symbols);
40
41/// Render a SymbolNameVector.
42raw_ostream &operator<<(raw_ostream &OS, const SymbolNameVector &Symbols);
43
44/// Render an array of SymbolStringPtrs.
45raw_ostream &operator<<(raw_ostream &OS, ArrayRef<SymbolStringPtr> Symbols);
46
47/// Render JITSymbolFlags.
48raw_ostream &operator<<(raw_ostream &OS, const JITSymbolFlags &Flags);
49
50/// Render a SymbolFlagsMap entry.
51raw_ostream &operator<<(raw_ostream &OS, const SymbolFlagsMap::value_type &KV);
52
53/// Render a SymbolMap entry.
54raw_ostream &operator<<(raw_ostream &OS, const SymbolMap::value_type &KV);
55
56/// Render a SymbolFlagsMap.
57raw_ostream &operator<<(raw_ostream &OS, const SymbolFlagsMap &SymbolFlags);
58
59/// Render a SymbolMap.
60raw_ostream &operator<<(raw_ostream &OS, const SymbolMap &Symbols);
61
62/// Render a SymbolDependenceMap entry.
63raw_ostream &operator<<(raw_ostream &OS,
65
66/// Render a SymbolDependendeMap.
67raw_ostream &operator<<(raw_ostream &OS, const SymbolDependenceMap &Deps);
68
69/// Render a MaterializationUnit.
70raw_ostream &operator<<(raw_ostream &OS, const MaterializationUnit &MU);
71
72//// Render a JITDylibLookupFlags instance.
73raw_ostream &operator<<(raw_ostream &OS,
74 const JITDylibLookupFlags &JDLookupFlags);
75
76/// Render a SymbolLookupFlags instance.
77raw_ostream &operator<<(raw_ostream &OS, const SymbolLookupFlags &LookupFlags);
78
79/// Render a SymbolLookupSet entry.
80raw_ostream &operator<<(raw_ostream &OS, const SymbolLookupSet::value_type &KV);
81
82/// Render a SymbolLookupSet.
83raw_ostream &operator<<(raw_ostream &OS, const SymbolLookupSet &LookupSet);
84
85/// Render a JITDylibSearchOrder.
86raw_ostream &operator<<(raw_ostream &OS,
87 const JITDylibSearchOrder &SearchOrder);
88
89/// Render a SymbolAliasMap.
90raw_ostream &operator<<(raw_ostream &OS, const SymbolAliasMap &Aliases);
91
92/// Render a SymbolState.
93raw_ostream &operator<<(raw_ostream &OS, const SymbolState &S);
94
95/// Render a LookupKind.
96raw_ostream &operator<<(raw_ostream &OS, const LookupKind &K);
97
98/// Dump a SymbolStringPool. Useful for debugging dangling-pointer crashes.
99raw_ostream &operator<<(raw_ostream &OS, const SymbolStringPool &SSP);
100
101/// A function object that can be used as an ObjectTransformLayer transform
102/// to dump object files to disk at a specified path.
104public:
105 /// Construct a DumpObjects transform that will dump objects to disk.
106 ///
107 /// @param DumpDir specifies the path to write dumped objects to. DumpDir may
108 /// be empty, in which case files will be dumped to the working directory. If
109 /// DumpDir is non-empty then any trailing separators will be discarded.
110 ///
111 /// @param IdentifierOverride specifies a file name stem to use when dumping
112 /// objects. If empty, each MemoryBuffer's identifier will be used (with a .o
113 /// suffix added if not already present). If an identifier override is
114 /// supplied it will be used instead (since all buffers will use the same
115 /// identifier, the resulting files will be named <ident>.o, <ident>.2.o,
116 /// <ident>.3.o, and so on). IdentifierOverride should not contain an
117 /// extension, as a .o suffix will be added by DumpObjects.
118 DumpObjects(std::string DumpDir = "", std::string IdentifierOverride = "");
119
120 /// Dumps the given buffer to disk.
122 operator()(std::unique_ptr<MemoryBuffer> Obj);
123
124private:
125 StringRef getBufferIdentifier(MemoryBuffer &B);
126 std::string DumpDir;
127 std::string IdentifierOverride;
128};
129
130} // End namespace orc
131} // End namespace llvm
132
133#endif // LLVM_EXECUTIONENGINE_ORC_DEBUGUTILS_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Symbol * Sym
Definition: ELF_riscv.cpp:479
raw_pwrite_stream & OS
BucketT value_type
Definition: DenseMap.h:69
Tagged union holding either a T or a Error.
Definition: Error.h:481
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:51
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
A function object that can be used as an ObjectTransformLayer transform to dump object files to disk ...
Definition: DebugUtils.h:103
Expected< std::unique_ptr< MemoryBuffer > > operator()(std::unique_ptr< MemoryBuffer > Obj)
Dumps the given buffer to disk.
Definition: DebugUtils.cpp:325
std::pair< SymbolStringPtr, SymbolLookupFlags > value_type
Definition: Core.h:185
std::vector< std::pair< JITDylib *, JITDylibLookupFlags > > JITDylibSearchOrder
A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search order during symbol lookup.
Definition: Core.h:162
SymbolLookupFlags
Lookup flags that apply to each symbol in a lookup.
Definition: Core.h:145
DenseMap< SymbolStringPtr, SymbolAliasMapEntry > SymbolAliasMap
A map of Symbols to (Symbol, Flags) pairs.
Definition: Core.h:396
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
Definition: Core.h:135
DenseMap< SymbolStringPtr, ExecutorSymbolDef > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
Definition: Core.h:121
DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
Definition: Core.h:124
DenseSet< SymbolStringPtr > SymbolNameSet
A set of symbol names (represented by SymbolStringPtrs for.
Definition: Core.h:114
LookupKind
Describes the kind of lookup being performed.
Definition: Core.h:157
std::vector< SymbolStringPtr > SymbolNameVector
A vector of symbol names.
Definition: Core.h:117
SymbolState
Represents the state that a symbol has reached during materialization.
Definition: Core.h:859
DenseMap< JITDylib *, SymbolNameSet > SymbolDependenceMap
A map from JITDylibs to sets of symbols.
Definition: Core.h:127
raw_ostream & operator<<(raw_ostream &OS, const SymbolStringPtr &Sym)
Render a SymbolStringPtr.
Definition: DebugUtils.cpp:141
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18