blob: 7ce410d10c0dba707b231d3c18124ad0eb595801 [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);
63 void formatMsfStreamData(StringRef Label, PDBFile &File,
64 const msf::MSFStreamLayout &Stream,
65 BinaryStreamReader &Reader);
66
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000067 bool hasColor() const { return UseColor; }
Zachary Turner2d11c202015-02-27 09:15:59 +000068 raw_ostream &getStream() { return OS; }
Zachary Turner7797c722015-03-02 04:39:56 +000069 int getIndentLevel() const { return CurrentIndent; }
Zachary Turner2d11c202015-02-27 09:15:59 +000070
Zachary Turner4dc4f012017-04-13 21:11:00 +000071 bool IsClassExcluded(const ClassLayout &Class);
72 bool IsTypeExcluded(llvm::StringRef TypeName, uint32_t Size);
Zachary Turnerf5abda22015-03-01 06:49:49 +000073 bool IsSymbolExcluded(llvm::StringRef SymbolName);
74 bool IsCompilandExcluded(llvm::StringRef CompilandName);
75
Zachary Turner2d11c202015-02-27 09:15:59 +000076private:
Zachary Turner7797c722015-03-02 04:39:56 +000077 template <typename Iter>
78 void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
79 List.clear();
80 for (; Begin != End; ++Begin)
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +000081 List.emplace_back(StringRef(*Begin));
Zachary Turner7797c722015-03-02 04:39:56 +000082 }
83
Zachary Turner2d11c202015-02-27 09:15:59 +000084 raw_ostream &OS;
85 int IndentSpaces;
86 int CurrentIndent;
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000087 bool UseColor;
Zachary Turnerf5abda22015-03-01 06:49:49 +000088
Zachary Turner4dddcc62015-09-29 19:49:06 +000089 std::list<Regex> ExcludeCompilandFilters;
90 std::list<Regex> ExcludeTypeFilters;
91 std::list<Regex> ExcludeSymbolFilters;
92
93 std::list<Regex> IncludeCompilandFilters;
94 std::list<Regex> IncludeTypeFilters;
95 std::list<Regex> IncludeSymbolFilters;
Zachary Turner2d11c202015-02-27 09:15:59 +000096};
97
Zachary Turner63055452017-06-15 22:24:24 +000098struct AutoIndent {
99 explicit AutoIndent(LinePrinter &L, uint32_t Amount = 0)
100 : L(L), Amount(Amount) {
101 L.Indent(Amount);
102 }
103 ~AutoIndent() { L.Unindent(Amount); }
104
105 LinePrinter &L;
106 uint32_t Amount = 0;
107};
108
Zachary Turner2d11c202015-02-27 09:15:59 +0000109template <class T>
110inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
111 Printer.getStream() << Item;
112 return Printer.getStream();
113}
114
115enum class PDB_ColorItem {
116 None,
117 Address,
118 Type,
Zachary Turner0c990bbe2017-04-10 19:33:29 +0000119 Comment,
120 Padding,
Zachary Turner2d11c202015-02-27 09:15:59 +0000121 Keyword,
122 Offset,
123 Identifier,
124 Path,
125 SectionHeader,
126 LiteralValue,
Zachary Turner7797c722015-03-02 04:39:56 +0000127 Register,
Zachary Turner2d11c202015-02-27 09:15:59 +0000128};
129
130class WithColor {
131public:
132 WithColor(LinePrinter &P, PDB_ColorItem C);
133 ~WithColor();
134
135 raw_ostream &get() { return OS; }
136
137private:
Rui Ueyamafa05aac2015-11-03 01:04:44 +0000138 void applyColor(PDB_ColorItem C);
Zachary Turner2d11c202015-02-27 09:15:59 +0000139 raw_ostream &OS;
Adrian McCarthy5fcfc2c2017-03-29 17:11:27 +0000140 bool UseColor;
Zachary Turner2d11c202015-02-27 09:15:59 +0000141};
142}
Zachary Turnerec28fc32016-05-04 20:32:13 +0000143}
Zachary Turner2d11c202015-02-27 09:15:59 +0000144
145#endif