LLVM: lib/DebugInfo/PDB/Native/LinePrinter.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
10
25
26#include
27
28using namespace llvm;
31
32namespace {
34 std::listllvm::Regex &IncludeFilters,
35 std::listllvm::Regex &ExcludeFilters) {
37 return false;
38
39 auto match_pred = [Item](llvm::Regex &R) { return R.match(Item); };
40
41
42
43 if (!IncludeFilters.empty() && (IncludeFilters, match_pred))
44 return true;
45
46 if (any_of(ExcludeFilters, match_pred))
47 return true;
48
49 return false;
50}
51}
52
53using namespace llvm;
54
57 : OS(Stream), IndentSpaces(Indent), CurrentIndent(0), UseColor(UseColor),
58 Filters(Filters) {
59 SetFilters(ExcludeTypeFilters, Filters.ExcludeTypes.begin(),
61 SetFilters(ExcludeSymbolFilters, Filters.ExcludeSymbols.begin(),
63 SetFilters(ExcludeCompilandFilters, Filters.ExcludeCompilands.begin(),
65
66 SetFilters(IncludeTypeFilters, Filters.IncludeTypes.begin(),
68 SetFilters(IncludeSymbolFilters, Filters.IncludeSymbols.begin(),
70 SetFilters(IncludeCompilandFilters, Filters.IncludeCompilands.begin(),
72}
73
75 if (Amount == 0)
76 Amount = IndentSpaces;
77 CurrentIndent += Amount;
78}
79
81 if (Amount == 0)
82 Amount = IndentSpaces;
83 CurrentIndent = std::max(0, CurrentIndent - Amount);
84}
85
87 OS << "\n";
88 OS.indent(CurrentIndent);
89}
90
92
95 OS << T;
96}
97
100 return true;
102 return true;
103 return false;
104}
105
109 OS << Label << " (";
110 if (.empty()) {
111 OS << "\n";
113 CurrentIndent + IndentSpaces, true);
115 }
116 OS << ")";
117}
118
122 OS << Label << " (";
123 if (.empty()) {
124 OS << "\n";
125 Base += StartOffset;
127 CurrentIndent + IndentSpaces, true);
129 }
130 OS << ")";
131}
132
133namespace {
134struct Run {
135 Run() = default;
139};
140}
141
144 std::vector Runs;
145 if (Layout.Length == 0)
146 return Runs;
147
152 Runs.emplace_back(CurrentBlock);
153 while (.empty()) {
154 Run *CurrentRun = &Runs.back();
156 if (NextBlock < CurrentBlock || (NextBlock - CurrentBlock > 1)) {
157 Runs.emplace_back(NextBlock);
158 CurrentRun = &Runs.back();
159 }
161 std::min(static_cast<uint64_t>(BlockSize), StreamBytesRemaining);
162 CurrentRun->ByteLen += Used;
163 StreamBytesRemaining -= Used;
164 CurrentBlock = NextBlock;
166 }
167 return Runs;
168}
169
171 for (const auto &R : Runs) {
172 if (Offset < R.ByteLen)
173 return std::make_pair(R, Offset);
175 }
177}
178
183 if (StreamIdx >= File.getNumStreams()) {
184 formatLine("Stream {0}: Not present", StreamIdx);
185 return;
186 }
187 if (Size + Offset > File.getStreamByteSize(StreamIdx)) {
189 "Stream {0}: Invalid offset and size, range out of stream bounds",
190 StreamIdx);
191 return;
192 }
193
194 auto S = File.createIndexedStream(StreamIdx);
195 if (!S) {
197 formatLine("Stream {0}: Not present", StreamIdx);
198 return;
199 }
200
202 (Size == 0) ? S->getLength() : std::min(Offset + Size, S->getLength());
204
205 formatLine("Stream {0}: {1} (dumping {2:N} / {3:N} bytes)", StreamIdx,
206 StreamPurpose, Size, S->getLength());
212
213 auto Layout = File.getStreamLayout(StreamIdx);
215}
216
221
223
225 OS << Label << " (";
227 OS << "\n";
228
229 Run FoundRun;
231 std::tie(FoundRun, RunOffset) = findRun(Substream.Offset, Runs);
232 assert(FoundRun.ByteLen >= RunOffset);
233 uint64_t Len = FoundRun.ByteLen - RunOffset;
235 uint64_t Base = FoundRun.Block * File.getBlockSize() + RunOffset;
239 CurrentIndent + IndentSpaces, true);
244 }
245 Substream.Offset += Len;
246 }
248 OS << ")";
249}
250
255
256 while (L > 0) {
261 std::min(L, static_cast<uint64_t>(File.getBlockSize()));
263 cantFail(File.getBlockData(Blocks.front(), File.getBlockSize()));
265 BaseOffset *= File.getBlockSize();
267 CurrentIndent + IndentSpaces, true);
269 OS << ")";
271 L -= UsedBytes;
273 }
274}
275
277 if (IsItemExcluded(TypeName, IncludeTypeFilters, ExcludeTypeFilters))
278 return true;
280 return true;
281 return false;
282}
283
285 return IsItemExcluded(SymbolName, IncludeSymbolFilters, ExcludeSymbolFilters);
286}
287
289 return IsItemExcluded(CompilandName, IncludeCompilandFilters,
290 ExcludeCompilandFilters);
291}
292
295 if (UseColor)
296 applyColor(C);
297}
298
300 if (UseColor)
302}
303
305 switch (C) {
308 return;
311 return;
314 return;
317 return;
321 return;
324 return;
327 return;
330 return;
334 return;
337 return;
338 }
339}
DenseMap< Block *, BlockRelaxAux > Blocks
static std::pair< Run, uint64_t > findRun(uint64_t Offset, ArrayRef< Run > Runs)
static std::vector< Run > computeBlockRuns(uint32_t BlockSize, const msf::MSFStreamLayout &Layout)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const int BlockSize
static ManagedStatic< cl::opt< cl::boolOrDefault >, CreateUseColor > UseColor
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Provides read only access to a subclass of BinaryStream.
Error readBytes(ArrayRef< uint8_t > &Buffer, uint32_t Size)
Read Size bytes from the underlying stream at the current offset and and set Buffer to the resulting ...
uint64_t bytesRemaining() const
RefType drop_front(uint64_t N) const
Return a new BinaryStreamRef with the first N elements removed.
RefType keep_front(uint64_t N) const
Return a new BinaryStreamRef with only the first N elements remaining.
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Describes the layout of a stream in an MSF layout.
std::vector< support::ulittle32_t > Blocks
void print(const Twine &T)
void printLine(const Twine &T)
void Unindent(uint32_t Amount=0)
void formatMsfStreamData(StringRef Label, PDBFile &File, uint32_t StreamIdx, StringRef StreamPurpose, uint64_t Offset, uint64_t Size)
bool IsSymbolExcluded(llvm::StringRef SymbolName)
LinePrinter(int Indent, bool UseColor, raw_ostream &Stream, const FilterOptions &Filters)
void formatMsfStreamBlocks(PDBFile &File, const msf::MSFStreamLayout &Stream)
void formatLine(const char *Fmt, Ts &&...Items)
void formatBinary(StringRef Label, ArrayRef< uint8_t > Data, uint64_t StartOffset)
bool IsTypeExcluded(llvm::StringRef TypeName, uint64_t Size)
bool IsClassExcluded(const ClassLayout &Class)
bool IsCompilandExcluded(llvm::StringRef CompilandName)
void Indent(uint32_t Amount=0)
WithColor(LinePrinter &P, PDB_ColorItem C)
This class implements an extremely fast bulk output stream that can only output to a stream.
static constexpr Colors YELLOW
static constexpr Colors CYAN
virtual raw_ostream & changeColor(enum Colors Color, bool Bold=false, bool BG=false)
Changes the foreground color of text that will be output from this point forward.
virtual raw_ostream & resetColor()
Resets the colors to terminal defaults.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
static constexpr Colors MAGENTA
static constexpr Colors GREEN
static constexpr Colors RED
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
FormattedBytes format_bytes_with_ascii(ArrayRef< uint8_t > Bytes, std::optional< uint64_t > FirstByteOffset=std::nullopt, uint32_t NumPerLine=16, uint8_t ByteGroupSize=4, uint32_t IndentLevel=0, bool Upper=false)
support::detail::AlignAdapter< T > fmt_align(T &&Item, AlignStyle Where, size_t Amount, char Fill=' ')
void consumeError(Error Err)
Consume a Error without doing anything.
std::list< std::string > IncludeCompilands
std::list< std::string > IncludeTypes
std::list< std::string > IncludeSymbols
std::list< std::string > ExcludeTypes
uint32_t PaddingThreshold
std::list< std::string > ExcludeCompilands
std::list< std::string > ExcludeSymbols
BinaryStreamRef StreamData