annotate tools/llvm-pdbutil/LinePrinter.cpp @ 133:c60214abe0e8

fix intrin.h
author mir3636
date Fri, 16 Feb 2018 19:10:49 +0900
parents 803732b1fca8
children c2174574ed3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===- LinePrinter.cpp ------------------------------------------*- C++ -*-===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 #include "LinePrinter.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 #include "llvm-pdbutil.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 #include "llvm/ADT/STLExtras.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15 #include "llvm/DebugInfo/MSF/MSFCommon.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 #include "llvm/DebugInfo/PDB/UDTLayout.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 #include "llvm/Support/BinaryStreamReader.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 #include "llvm/Support/Format.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21 #include "llvm/Support/FormatAdapters.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 #include "llvm/Support/FormatVariadic.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 #include "llvm/Support/Regex.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 #include <algorithm>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 using namespace llvm;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 using namespace llvm::msf;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 using namespace llvm::pdb;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 namespace {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32 bool IsItemExcluded(llvm::StringRef Item,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 std::list<llvm::Regex> &IncludeFilters,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 std::list<llvm::Regex> &ExcludeFilters) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 if (Item.empty())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 return false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 auto match_pred = [Item](llvm::Regex &R) { return R.match(Item); };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 // Include takes priority over exclude. If the user specified include
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 // filters, and none of them include this item, them item is gone.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 if (!IncludeFilters.empty() && !any_of(IncludeFilters, match_pred))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 return true;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45 if (any_of(ExcludeFilters, match_pred))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 return true;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 return false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 using namespace llvm;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 LinePrinter::LinePrinter(int Indent, bool UseColor, llvm::raw_ostream &Stream)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 : OS(Stream), IndentSpaces(Indent), CurrentIndent(0), UseColor(UseColor) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 SetFilters(ExcludeTypeFilters, opts::pretty::ExcludeTypes.begin(),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 opts::pretty::ExcludeTypes.end());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 SetFilters(ExcludeSymbolFilters, opts::pretty::ExcludeSymbols.begin(),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59 opts::pretty::ExcludeSymbols.end());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60 SetFilters(ExcludeCompilandFilters, opts::pretty::ExcludeCompilands.begin(),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61 opts::pretty::ExcludeCompilands.end());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63 SetFilters(IncludeTypeFilters, opts::pretty::IncludeTypes.begin(),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 opts::pretty::IncludeTypes.end());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 SetFilters(IncludeSymbolFilters, opts::pretty::IncludeSymbols.begin(),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66 opts::pretty::IncludeSymbols.end());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67 SetFilters(IncludeCompilandFilters, opts::pretty::IncludeCompilands.begin(),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68 opts::pretty::IncludeCompilands.end());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71 void LinePrinter::Indent(uint32_t Amount) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72 if (Amount == 0)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73 Amount = IndentSpaces;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74 CurrentIndent += Amount;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77 void LinePrinter::Unindent(uint32_t Amount) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78 if (Amount == 0)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
79 Amount = IndentSpaces;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
80 CurrentIndent = std::max<int>(0, CurrentIndent - Amount);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
81 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
82
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
83 void LinePrinter::NewLine() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
84 OS << "\n";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
85 OS.indent(CurrentIndent);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
86 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
87
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
88 void LinePrinter::print(const Twine &T) { OS << T; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
89
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
90 void LinePrinter::printLine(const Twine &T) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
91 NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
92 OS << T;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
93 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
94
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
95 bool LinePrinter::IsClassExcluded(const ClassLayout &Class) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
96 if (IsTypeExcluded(Class.getName(), Class.getSize()))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
97 return true;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
98 if (Class.deepPaddingSize() < opts::pretty::PaddingThreshold)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
99 return true;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
100 return false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
101 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
102
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
103 void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
104 uint32_t StartOffset) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
105 NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
106 OS << Label << " (";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
107 if (!Data.empty()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
108 OS << "\n";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
109 OS << format_bytes_with_ascii(Data, StartOffset, 32, 4,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
110 CurrentIndent + IndentSpaces, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
111 NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
112 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
113 OS << ")";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
114 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
115
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
116 void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
117 uint64_t Base, uint32_t StartOffset) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
118 NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
119 OS << Label << " (";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
120 if (!Data.empty()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
121 OS << "\n";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
122 Base += StartOffset;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
123 OS << format_bytes_with_ascii(Data, Base, 32, 4,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
124 CurrentIndent + IndentSpaces, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
125 NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
126 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
127 OS << ")";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
128 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
129
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
130 namespace {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
131 struct Run {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
132 Run() = default;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
133 explicit Run(uint32_t Block) : Block(Block) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
134 uint32_t Block = 0;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
135 uint32_t ByteLen = 0;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
136 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
137 } // namespace
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
138
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
139 static std::vector<Run> computeBlockRuns(uint32_t BlockSize,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
140 const msf::MSFStreamLayout &Layout) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
141 std::vector<Run> Runs;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
142 if (Layout.Length == 0)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
143 return Runs;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
144
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
145 ArrayRef<support::ulittle32_t> Blocks = Layout.Blocks;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
146 assert(!Blocks.empty());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
147 uint32_t StreamBytesRemaining = Layout.Length;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
148 uint32_t CurrentBlock = Blocks[0];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
149 Runs.emplace_back(CurrentBlock);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
150 while (!Blocks.empty()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
151 Run *CurrentRun = &Runs.back();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
152 uint32_t NextBlock = Blocks.front();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
153 if (NextBlock < CurrentBlock || (NextBlock - CurrentBlock > 1)) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
154 Runs.emplace_back(NextBlock);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
155 CurrentRun = &Runs.back();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
156 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
157 uint32_t Used = std::min(BlockSize, StreamBytesRemaining);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
158 CurrentRun->ByteLen += Used;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
159 StreamBytesRemaining -= Used;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
160 CurrentBlock = NextBlock;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
161 Blocks = Blocks.drop_front();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
162 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
163 return Runs;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
164 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
165
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
166 static std::pair<Run, uint32_t> findRun(uint32_t Offset, ArrayRef<Run> Runs) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
167 for (const auto &R : Runs) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
168 if (Offset < R.ByteLen)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
169 return std::make_pair(R, Offset);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
170 Offset -= R.ByteLen;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
171 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
172 llvm_unreachable("Invalid offset!");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
173 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
174
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
175 void LinePrinter::formatMsfStreamData(StringRef Label, PDBFile &File,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
176 uint32_t StreamIdx,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
177 StringRef StreamPurpose, uint32_t Offset,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
178 uint32_t Size) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
179 if (StreamIdx >= File.getNumStreams()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
180 formatLine("Stream {0}: Not present", StreamIdx);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
181 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
182 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
183 if (Size + Offset > File.getStreamByteSize(StreamIdx)) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
184 formatLine(
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
185 "Stream {0}: Invalid offset and size, range out of stream bounds",
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
186 StreamIdx);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
187 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
188 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
189
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
190 auto S = MappedBlockStream::createIndexedStream(
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
191 File.getMsfLayout(), File.getMsfBuffer(), StreamIdx, File.getAllocator());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
192 if (!S) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
193 NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
194 formatLine("Stream {0}: Not present", StreamIdx);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
195 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
196 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
197
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
198 uint32_t End =
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
199 (Size == 0) ? S->getLength() : std::min(Offset + Size, S->getLength());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
200 Size = End - Offset;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
201
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
202 formatLine("Stream {0}: {1} (dumping {2:N} / {3:N} bytes)", StreamIdx,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
203 StreamPurpose, Size, S->getLength());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
204 AutoIndent Indent(*this);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
205 BinaryStreamRef Slice(*S);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
206 BinarySubstreamRef Substream;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
207 Substream.Offset = Offset;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
208 Substream.StreamData = Slice.drop_front(Offset).keep_front(Size);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
209
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
210 auto Layout = File.getStreamLayout(StreamIdx);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
211 formatMsfStreamData(Label, File, Layout, Substream);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
212 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
213
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
214 void LinePrinter::formatMsfStreamData(StringRef Label, PDBFile &File,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
215 const msf::MSFStreamLayout &Stream,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
216 BinarySubstreamRef Substream) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
217 BinaryStreamReader Reader(Substream.StreamData);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
218
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
219 auto Runs = computeBlockRuns(File.getBlockSize(), Stream);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
220
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
221 NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
222 OS << Label << " (";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
223 while (Reader.bytesRemaining() > 0) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
224 OS << "\n";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
225
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
226 Run FoundRun;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
227 uint32_t RunOffset;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
228 std::tie(FoundRun, RunOffset) = findRun(Substream.Offset, Runs);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
229 assert(FoundRun.ByteLen >= RunOffset);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
230 uint32_t Len = FoundRun.ByteLen - RunOffset;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
231 Len = std::min(Len, Reader.bytesRemaining());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
232 uint64_t Base = FoundRun.Block * File.getBlockSize() + RunOffset;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
233 ArrayRef<uint8_t> Data;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
234 consumeError(Reader.readBytes(Data, Len));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
235 OS << format_bytes_with_ascii(Data, Base, 32, 4,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
236 CurrentIndent + IndentSpaces, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
237 if (Reader.bytesRemaining() > 0) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
238 NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
239 OS << formatv(" {0}",
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
240 fmt_align("<discontinuity>", AlignStyle::Center, 114, '-'));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
241 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
242 Substream.Offset += Len;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
243 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
244 NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
245 OS << ")";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
246 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
247
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
248 void LinePrinter::formatMsfStreamBlocks(
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
249 PDBFile &File, const msf::MSFStreamLayout &StreamLayout) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
250 auto Blocks = makeArrayRef(StreamLayout.Blocks);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
251 uint32_t L = StreamLayout.Length;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
252
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
253 while (L > 0) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
254 NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
255 assert(!Blocks.empty());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
256 OS << formatv("Block {0} (\n", uint32_t(Blocks.front()));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
257 uint32_t UsedBytes = std::min(L, File.getBlockSize());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
258 ArrayRef<uint8_t> BlockData =
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
259 cantFail(File.getBlockData(Blocks.front(), File.getBlockSize()));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
260 uint64_t BaseOffset = Blocks.front();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
261 BaseOffset *= File.getBlockSize();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
262 OS << format_bytes_with_ascii(BlockData, BaseOffset, 32, 4,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
263 CurrentIndent + IndentSpaces, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
264 NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
265 OS << ")";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
266 NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
267 L -= UsedBytes;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
268 Blocks = Blocks.drop_front();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
269 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
270 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
271
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
272 bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName, uint32_t Size) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
273 if (IsItemExcluded(TypeName, IncludeTypeFilters, ExcludeTypeFilters))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
274 return true;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
275 if (Size < opts::pretty::SizeThreshold)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
276 return true;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
277 return false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
278 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
279
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
280 bool LinePrinter::IsSymbolExcluded(llvm::StringRef SymbolName) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
281 return IsItemExcluded(SymbolName, IncludeSymbolFilters, ExcludeSymbolFilters);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
282 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
283
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
284 bool LinePrinter::IsCompilandExcluded(llvm::StringRef CompilandName) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
285 return IsItemExcluded(CompilandName, IncludeCompilandFilters,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
286 ExcludeCompilandFilters);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
287 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
288
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
289 WithColor::WithColor(LinePrinter &P, PDB_ColorItem C)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
290 : OS(P.OS), UseColor(P.hasColor()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
291 if (UseColor)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
292 applyColor(C);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
293 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
294
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
295 WithColor::~WithColor() {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
296 if (UseColor)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
297 OS.resetColor();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
298 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
299
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
300 void WithColor::applyColor(PDB_ColorItem C) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
301 switch (C) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
302 case PDB_ColorItem::None:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
303 OS.resetColor();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
304 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
305 case PDB_ColorItem::Comment:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
306 OS.changeColor(raw_ostream::GREEN, false);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
307 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
308 case PDB_ColorItem::Address:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
309 OS.changeColor(raw_ostream::YELLOW, /*bold=*/true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
310 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
311 case PDB_ColorItem::Keyword:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
312 OS.changeColor(raw_ostream::MAGENTA, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
313 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
314 case PDB_ColorItem::Register:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
315 case PDB_ColorItem::Offset:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
316 OS.changeColor(raw_ostream::YELLOW, false);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
317 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
318 case PDB_ColorItem::Type:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
319 OS.changeColor(raw_ostream::CYAN, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
320 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
321 case PDB_ColorItem::Identifier:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
322 OS.changeColor(raw_ostream::CYAN, false);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
323 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
324 case PDB_ColorItem::Path:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
325 OS.changeColor(raw_ostream::CYAN, false);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
326 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
327 case PDB_ColorItem::Padding:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
328 case PDB_ColorItem::SectionHeader:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
329 OS.changeColor(raw_ostream::RED, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
330 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
331 case PDB_ColorItem::LiteralValue:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
332 OS.changeColor(raw_ostream::GREEN, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
333 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
334 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
335 }