blob: a831dbd9e6eb48fcd5f1b50f0200a84cfaaeeb27 [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 Turnerc3d8eec2017-08-02 22:25:52 +000063 void formatMsfStreamBlocks(PDBFile &File, const msf::MSFStreamLayout &Stream);
Zachary Turner0b36c3e2017-06-23 18:52:13 +000064
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000065 bool hasColor() const { return UseColor; }
Zachary Turner2d11c202015-02-27 09:15:59 +000066 raw_ostream &getStream() { return OS; }
Zachary Turner7797c722015-03-02 04:39:56 +000067 int getIndentLevel() const { return CurrentIndent; }
Zachary Turner2d11c202015-02-27 09:15:59 +000068
Zachary Turner4dc4f012017-04-13 21:11:00 +000069 bool IsClassExcluded(const ClassLayout &Class);
70 bool IsTypeExcluded(llvm::StringRef TypeName, uint32_t Size);
Zachary Turnerf5abda22015-03-01 06:49:49 +000071 bool IsSymbolExcluded(llvm::StringRef SymbolName);
72 bool IsCompilandExcluded(llvm::StringRef CompilandName);
73
Zachary Turner2d11c202015-02-27 09:15:59 +000074private:
Zachary Turner7797c722015-03-02 04:39:56 +000075 template <typename Iter>
76 void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
77 List.clear();
78 for (; Begin != End; ++Begin)
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +000079 List.emplace_back(StringRef(*Begin));
Zachary Turner7797c722015-03-02 04:39:56 +000080 }
81
Zachary Turner2d11c202015-02-27 09:15:59 +000082 raw_ostream &OS;
83 int IndentSpaces;
84 int CurrentIndent;
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000085 bool UseColor;
Zachary Turnerf5abda22015-03-01 06:49:49 +000086
Zachary Turner4dddcc62015-09-29 19:49:06 +000087 std::list<Regex> ExcludeCompilandFilters;
88 std::list<Regex> ExcludeTypeFilters;
89 std::list<Regex> ExcludeSymbolFilters;
90
91 std::list<Regex> IncludeCompilandFilters;
92 std::list<Regex> IncludeTypeFilters;
93 std::list<Regex> IncludeSymbolFilters;
Zachary Turner2d11c202015-02-27 09:15:59 +000094};
95
Zachary Turner63055452017-06-15 22:24:24 +000096struct AutoIndent {
97 explicit AutoIndent(LinePrinter &L, uint32_t Amount = 0)
98 : L(L), Amount(Amount) {
99 L.Indent(Amount);
100 }
101 ~AutoIndent() { L.Unindent(Amount); }
102
103 LinePrinter &L;
104 uint32_t Amount = 0;
105};
106
Zachary Turner2d11c202015-02-27 09:15:59 +0000107template <class T>
108inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
109 Printer.getStream() << Item;
110 return Printer.getStream();
111}
112
113enum class PDB_ColorItem {
114 None,
115 Address,
116 Type,
Zachary Turner0c990bbe2017-04-10 19:33:29 +0000117 Comment,
118 Padding,
Zachary Turner2d11c202015-02-27 09:15:59 +0000119 Keyword,
120 Offset,
121 Identifier,
122 Path,
123 SectionHeader,
124 LiteralValue,
Zachary Turner7797c722015-03-02 04:39:56 +0000125 Register,
Zachary Turner2d11c202015-02-27 09:15:59 +0000126};
127
128class WithColor {
129public:
130 WithColor(LinePrinter &P, PDB_ColorItem C);
131 ~WithColor();
132
133 raw_ostream &get() { return OS; }
134
135private:
Rui Ueyamafa05aac2015-11-03 01:04:44 +0000136 void applyColor(PDB_ColorItem C);
Zachary Turner2d11c202015-02-27 09:15:59 +0000137 raw_ostream &OS;
Adrian McCarthy5fcfc2c2017-03-29 17:11:27 +0000138 bool UseColor;
Zachary Turner2d11c202015-02-27 09:15:59 +0000139};
140}
Zachary Turnerec28fc32016-05-04 20:32:13 +0000141}
Zachary Turner2d11c202015-02-27 09:15:59 +0000142
143#endif