1 //===- LinePrinter.h ------------------------------------------ *- 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 #ifndef LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
10 #define LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/Twine.h"
15 #include "llvm/Support/BinaryStreamRef.h"
16 #include "llvm/Support/FormatVariadic.h"
17 #include "llvm/Support/Regex.h"
18 #include "llvm/Support/raw_ostream.h"
23 class BinaryStreamReader;
25 class MSFStreamLayout;
33 friend class WithColor;
36 LinePrinter(int Indent, bool UseColor, raw_ostream &Stream);
38 void Indent(uint32_t Amount = 0);
39 void Unindent(uint32_t Amount = 0);
42 void printLine(const Twine &T);
43 void print(const Twine &T);
44 template <typename... Ts> void formatLine(const char *Fmt, Ts &&... Items) {
45 printLine(formatv(Fmt, std::forward<Ts>(Items)...));
47 template <typename... Ts> void format(const char *Fmt, Ts &&... Items) {
48 print(formatv(Fmt, std::forward<Ts>(Items)...));
51 void formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
52 uint32_t StartOffset);
53 void formatBinary(StringRef Label, ArrayRef<uint8_t> Data, uint64_t BaseAddr,
54 uint32_t StartOffset);
56 void formatMsfStreamData(StringRef Label, PDBFile &File, uint32_t StreamIdx,
57 StringRef StreamPurpose, uint32_t Offset,
59 void formatMsfStreamData(StringRef Label, PDBFile &File,
60 const msf::MSFStreamLayout &Stream,
61 BinarySubstreamRef Substream);
62 void formatMsfStreamBlocks(PDBFile &File, const msf::MSFStreamLayout &Stream);
64 bool hasColor() const { return UseColor; }
65 raw_ostream &getStream() { return OS; }
66 int getIndentLevel() const { return CurrentIndent; }
68 bool IsClassExcluded(const ClassLayout &Class);
69 bool IsTypeExcluded(llvm::StringRef TypeName, uint32_t Size);
70 bool IsSymbolExcluded(llvm::StringRef SymbolName);
71 bool IsCompilandExcluded(llvm::StringRef CompilandName);
74 template <typename Iter>
75 void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
77 for (; Begin != End; ++Begin)
78 List.emplace_back(StringRef(*Begin));
86 std::list<Regex> ExcludeCompilandFilters;
87 std::list<Regex> ExcludeTypeFilters;
88 std::list<Regex> ExcludeSymbolFilters;
90 std::list<Regex> IncludeCompilandFilters;
91 std::list<Regex> IncludeTypeFilters;
92 std::list<Regex> IncludeSymbolFilters;
96 explicit PrintScope(LinePrinter &P, uint32_t IndentLevel)
97 : P(P), IndentLevel(IndentLevel) {}
98 explicit PrintScope(const PrintScope &Other, uint32_t LabelWidth)
99 : P(Other.P), IndentLevel(Other.IndentLevel), LabelWidth(LabelWidth) {}
102 uint32_t IndentLevel;
103 uint32_t LabelWidth = 0;
106 inline Optional<PrintScope> withLabelWidth(const Optional<PrintScope> &Scope,
110 return PrintScope{*Scope, W};
114 explicit AutoIndent(LinePrinter &L, uint32_t Amount = 0)
115 : L(&L), Amount(Amount) {
118 explicit AutoIndent(const Optional<PrintScope> &Scope) {
119 if (Scope.hasValue()) {
121 Amount = Scope->IndentLevel;
129 LinePrinter *L = nullptr;
134 inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
135 return Printer.getStream() << Item;
138 enum class PDB_ColorItem {
155 WithColor(LinePrinter &P, PDB_ColorItem C);
158 raw_ostream &get() { return OS; }
161 void applyColor(PDB_ColorItem C);