blob: 68ce321a27ecf07246cfd4746507dbb9d06bf5ee [file] [log] [blame]
Zachary Turner2d11c202015-02-27 09:15:59 +00001//===- LinePrinter.h ------------------------------------------ *- C++ --*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
11#define LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
12
Zachary Turner63055452017-06-15 22:24:24 +000013#include "llvm/ADT/ArrayRef.h"
Zachary Turner98162462015-03-01 06:59:57 +000014#include "llvm/ADT/StringRef.h"
Zachary Turner2d11c202015-02-27 09:15:59 +000015#include "llvm/ADT/Twine.h"
Zachary Turner0b36c3e2017-06-23 18:52:13 +000016#include "llvm/Support/BinaryStreamRef.h"
Zachary Turner63055452017-06-15 22:24:24 +000017#include "llvm/Support/FormatVariadic.h"
Zachary Turnerda504b72017-06-15 20:55:51 +000018#include "llvm/Support/Regex.h"
Zachary Turner63055452017-06-15 22:24:24 +000019#include "llvm/Support/raw_ostream.h"
Zachary Turnerf5abda22015-03-01 06:49:49 +000020
21#include <list>
Zachary Turner2d11c202015-02-27 09:15:59 +000022
23namespace llvm {
Zachary Turner0b36c3e2017-06-23 18:52:13 +000024class BinaryStreamReader;
25namespace msf {
26class MSFStreamLayout;
27} // namespace msf
Zachary Turnerec28fc32016-05-04 20:32:13 +000028namespace pdb {
Zachary Turner2d11c202015-02-27 09:15:59 +000029
Zachary Turner4dc4f012017-04-13 21:11:00 +000030class ClassLayout;
Zachary Turner0b36c3e2017-06-23 18:52:13 +000031class PDBFile;
Zachary Turner4dc4f012017-04-13 21:11:00 +000032
Zachary Turner2d11c202015-02-27 09:15:59 +000033class LinePrinter {
34 friend class WithColor;
35
36public:
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000037 LinePrinter(int Indent, bool UseColor, raw_ostream &Stream);
Zachary Turner2d11c202015-02-27 09:15:59 +000038
Zachary Turner63055452017-06-15 22:24:24 +000039 void Indent(uint32_t Amount = 0);
40 void Unindent(uint32_t Amount = 0);
Zachary Turner2d11c202015-02-27 09:15:59 +000041 void NewLine();
42
Zachary Turner63055452017-06-15 22:24:24 +000043 void printLine(const Twine &T);
44 void print(const Twine &T);
45 template <typename... Ts> void formatLine(const char *Fmt, Ts &&... Items) {
46 printLine(formatv(Fmt, std::forward<Ts>(Items)...));
47 }
48 template <typename... Ts> void format(const char *Fmt, Ts &&... Items) {
49 print(formatv(Fmt, std::forward<Ts>(Items)...));
50 }
51
52 void formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
53 uint32_t StartOffset);
Zachary Turner99402032017-06-22 20:58:11 +000054 void formatBinary(StringRef Label, ArrayRef<uint8_t> Data, uint64_t BaseAddr,
55 uint32_t StartOffset);
Zachary Turner63055452017-06-15 22:24:24 +000056
Zachary Turner0b36c3e2017-06-23 18:52:13 +000057 void formatMsfStreamData(StringRef Label, PDBFile &File, uint32_t StreamIdx,
58 StringRef StreamPurpose, uint32_t Offset,
59 uint32_t Size);
60 void formatMsfStreamData(StringRef Label, PDBFile &File,
61 const msf::MSFStreamLayout &Stream,
62 BinarySubstreamRef Substream);
Zachary Turner0b36c3e2017-06-23 18:52:13 +000063
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000064 bool hasColor() const { return UseColor; }
Zachary Turner2d11c202015-02-27 09:15:59 +000065 raw_ostream &getStream() { return OS; }
Zachary Turner7797c722015-03-02 04:39:56 +000066 int getIndentLevel() const { return CurrentIndent; }
Zachary Turner2d11c202015-02-27 09:15:59 +000067
Zachary Turner4dc4f012017-04-13 21:11:00 +000068 bool IsClassExcluded(const ClassLayout &Class);
69 bool IsTypeExcluded(llvm::StringRef TypeName, uint32_t Size);
Zachary Turnerf5abda22015-03-01 06:49:49 +000070 bool IsSymbolExcluded(llvm::StringRef SymbolName);
71 bool IsCompilandExcluded(llvm::StringRef CompilandName);
72
Zachary Turner2d11c202015-02-27 09:15:59 +000073private:
Zachary Turner7797c722015-03-02 04:39:56 +000074 template <typename Iter>
75 void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
76 List.clear();
77 for (; Begin != End; ++Begin)
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +000078 List.emplace_back(StringRef(*Begin));
Zachary Turner7797c722015-03-02 04:39:56 +000079 }
80
Zachary Turner2d11c202015-02-27 09:15:59 +000081 raw_ostream &OS;
82 int IndentSpaces;
83 int CurrentIndent;
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000084 bool UseColor;
Zachary Turnerf5abda22015-03-01 06:49:49 +000085
Zachary Turner4dddcc62015-09-29 19:49:06 +000086 std::list<Regex> ExcludeCompilandFilters;
87 std::list<Regex> ExcludeTypeFilters;
88 std::list<Regex> ExcludeSymbolFilters;
89
90 std::list<Regex> IncludeCompilandFilters;
91 std::list<Regex> IncludeTypeFilters;
92 std::list<Regex> IncludeSymbolFilters;
Zachary Turner2d11c202015-02-27 09:15:59 +000093};
94
Zachary Turner63055452017-06-15 22:24:24 +000095struct AutoIndent {
96 explicit AutoIndent(LinePrinter &L, uint32_t Amount = 0)
97 : L(L), Amount(Amount) {
98 L.Indent(Amount);
99 }
100 ~AutoIndent() { L.Unindent(Amount); }
101
102 LinePrinter &L;
103 uint32_t Amount = 0;
104};
105
Zachary Turner2d11c202015-02-27 09:15:59 +0000106template <class T>
107inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
108 Printer.getStream() << Item;
109 return Printer.getStream();
110}
111
112enum class PDB_ColorItem {
113 None,
114 Address,
115 Type,
Zachary Turner0c990bbe2017-04-10 19:33:29 +0000116 Comment,
117 Padding,
Zachary Turner2d11c202015-02-27 09:15:59 +0000118 Keyword,
119 Offset,
120 Identifier,
121 Path,
122 SectionHeader,
123 LiteralValue,
Zachary Turner7797c722015-03-02 04:39:56 +0000124 Register,
Zachary Turner2d11c202015-02-27 09:15:59 +0000125};
126
127class WithColor {
128public:
129 WithColor(LinePrinter &P, PDB_ColorItem C);
130 ~WithColor();
131
132 raw_ostream &get() { return OS; }
133
134private:
Rui Ueyamafa05aac2015-11-03 01:04:44 +0000135 void applyColor(PDB_ColorItem C);
Zachary Turner2d11c202015-02-27 09:15:59 +0000136 raw_ostream &OS;
Adrian McCarthy5fcfc2c2017-03-29 17:11:27 +0000137 bool UseColor;
Zachary Turner2d11c202015-02-27 09:15:59 +0000138};
139}
Zachary Turnerec28fc32016-05-04 20:32:13 +0000140}
Zachary Turner2d11c202015-02-27 09:15:59 +0000141
142#endif