blob: 20223ac60f430bbe2ca803eee991625bf833ae44 [file] [log] [blame]
Zachary Turnerd3117392016-06-03 19:28:33 +00001//===- LLVMOutputStyle.cpp ------------------------------------ *- 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#include "LLVMOutputStyle.h"
11
Zachary Turner44a643c2017-01-12 22:28:15 +000012#include "CompactTypeDumpVisitor.h"
Zachary Turner6ac232c2017-03-13 23:28:25 +000013#include "StreamUtil.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000014#include "llvm-pdbdump.h"
Zachary Turner44a643c2017-01-12 22:28:15 +000015
Zachary Turner629cb7d2017-01-11 23:24:22 +000016#include "llvm/DebugInfo/CodeView/CVTypeDumper.h"
17#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000018#include "llvm/DebugInfo/CodeView/EnumTables.h"
Zachary Turnerc37cb0c2017-04-27 16:12:16 +000019#include "llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h"
Zachary Turner67c56012017-04-27 16:11:19 +000020#include "llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h"
Zachary Turnerc37cb0c2017-04-27 16:12:16 +000021#include "llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h"
22#include "llvm/DebugInfo/CodeView/ModuleDebugUnknownFragment.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000023#include "llvm/DebugInfo/CodeView/SymbolDumper.h"
Zachary Turner629cb7d2017-01-11 23:24:22 +000024#include "llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h"
25#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
26#include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h"
27#include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h"
Zachary Turnera3225b02016-07-29 20:56:36 +000028#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
Zachary Turner67c56012017-04-27 16:11:19 +000029#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000030#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
31#include "llvm/DebugInfo/PDB/Native/EnumTables.h"
32#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
33#include "llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h"
34#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
Zachary Turner67c56012017-04-27 16:11:19 +000035#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000036#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
37#include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
38#include "llvm/DebugInfo/PDB/Native/RawError.h"
39#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000040#include "llvm/DebugInfo/PDB/PDBExtras.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000041#include "llvm/Object/COFF.h"
Zachary Turnerd9dc2822017-03-02 20:52:51 +000042#include "llvm/Support/BinaryStreamReader.h"
Zachary Turner44a643c2017-01-12 22:28:15 +000043#include "llvm/Support/FormatVariadic.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000044
45#include <unordered_map>
46
47using namespace llvm;
48using namespace llvm::codeview;
Zachary Turnerbac69d32016-07-22 19:56:05 +000049using namespace llvm::msf;
Zachary Turnerd3117392016-06-03 19:28:33 +000050using namespace llvm::pdb;
51
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +000052namespace {
53struct PageStats {
54 explicit PageStats(const BitVector &FreePages)
55 : Upm(FreePages), ActualUsedPages(FreePages.size()),
56 MultiUsePages(FreePages.size()), UseAfterFreePages(FreePages.size()) {
57 const_cast<BitVector &>(Upm).flip();
58 // To calculate orphaned pages, we start with the set of pages that the
59 // MSF thinks are used. Each time we find one that actually *is* used,
60 // we unset it. Whichever bits remain set at the end are orphaned.
61 OrphanedPages = Upm;
62 }
63
64 // The inverse of the MSF File's copy of the Fpm. The basis for which we
65 // determine the allocation status of each page.
66 const BitVector Upm;
67
68 // Pages which are marked as used in the FPM and are used at least once.
69 BitVector ActualUsedPages;
70
71 // Pages which are marked as used in the FPM but are used more than once.
72 BitVector MultiUsePages;
73
74 // Pages which are marked as used in the FPM but are not used at all.
75 BitVector OrphanedPages;
76
77 // Pages which are marked free in the FPM but are used.
78 BitVector UseAfterFreePages;
79};
80}
81
82static void recordKnownUsedPage(PageStats &Stats, uint32_t UsedIndex) {
83 if (Stats.Upm.test(UsedIndex)) {
84 if (Stats.ActualUsedPages.test(UsedIndex))
85 Stats.MultiUsePages.set(UsedIndex);
86 Stats.ActualUsedPages.set(UsedIndex);
87 Stats.OrphanedPages.reset(UsedIndex);
88 } else {
89 // The MSF doesn't think this page is used, but it is.
90 Stats.UseAfterFreePages.set(UsedIndex);
91 }
92}
93
Zachary Turnerd3117392016-06-03 19:28:33 +000094static void printSectionOffset(llvm::raw_ostream &OS,
95 const SectionOffset &Off) {
96 OS << Off.Off << ", " << Off.Isect;
97}
98
Zachary Turner629cb7d2017-01-11 23:24:22 +000099LLVMOutputStyle::LLVMOutputStyle(PDBFile &File) : File(File), P(outs()) {}
Zachary Turnerd3117392016-06-03 19:28:33 +0000100
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000101Error LLVMOutputStyle::dump() {
102 if (auto EC = dumpFileHeaders())
103 return EC;
104
105 if (auto EC = dumpStreamSummary())
106 return EC;
107
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000108 if (auto EC = dumpFreePageMap())
109 return EC;
110
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000111 if (auto EC = dumpStreamBlocks())
112 return EC;
113
Zachary Turner72c5b642016-09-09 18:17:52 +0000114 if (auto EC = dumpBlockRanges())
115 return EC;
116
117 if (auto EC = dumpStreamBytes())
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000118 return EC;
119
Zachary Turner760ad4d2017-01-20 22:42:09 +0000120 if (auto EC = dumpStringTable())
121 return EC;
122
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000123 if (auto EC = dumpInfoStream())
124 return EC;
125
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000126 if (auto EC = dumpTpiStream(StreamTPI))
127 return EC;
128
129 if (auto EC = dumpTpiStream(StreamIPI))
130 return EC;
131
132 if (auto EC = dumpDbiStream())
133 return EC;
134
135 if (auto EC = dumpSectionContribs())
136 return EC;
137
138 if (auto EC = dumpSectionMap())
139 return EC;
140
Bob Haarman653baa22016-10-21 19:43:19 +0000141 if (auto EC = dumpGlobalsStream())
142 return EC;
143
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000144 if (auto EC = dumpPublicsStream())
145 return EC;
146
147 if (auto EC = dumpSectionHeaders())
148 return EC;
149
150 if (auto EC = dumpFpoStream())
151 return EC;
152
153 flush();
154
155 return Error::success();
156}
157
Zachary Turnerd3117392016-06-03 19:28:33 +0000158Error LLVMOutputStyle::dumpFileHeaders() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000159 if (!opts::raw::DumpHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000160 return Error::success();
161
162 DictScope D(P, "FileHeaders");
163 P.printNumber("BlockSize", File.getBlockSize());
Zachary Turnerb927e022016-07-15 22:17:19 +0000164 P.printNumber("FreeBlockMap", File.getFreeBlockMapBlock());
Zachary Turnerd3117392016-06-03 19:28:33 +0000165 P.printNumber("NumBlocks", File.getBlockCount());
166 P.printNumber("NumDirectoryBytes", File.getNumDirectoryBytes());
167 P.printNumber("Unknown1", File.getUnknown1());
168 P.printNumber("BlockMapAddr", File.getBlockMapIndex());
169 P.printNumber("NumDirectoryBlocks", File.getNumDirectoryBlocks());
Zachary Turnerd3117392016-06-03 19:28:33 +0000170
171 // The directory is not contiguous. Instead, the block map contains a
172 // contiguous list of block numbers whose contents, when concatenated in
173 // order, make up the directory.
174 P.printList("DirectoryBlocks", File.getDirectoryBlockArray());
175 P.printNumber("NumStreams", File.getNumStreams());
176 return Error::success();
177}
178
Zachary Turner36efbfa2016-09-09 19:00:49 +0000179Error LLVMOutputStyle::dumpStreamSummary() {
180 if (!opts::raw::DumpStreamSummary)
181 return Error::success();
182
Zachary Turner6ac232c2017-03-13 23:28:25 +0000183 if (StreamPurposes.empty())
184 discoverStreamPurposes(File, StreamPurposes);
Zachary Turner36efbfa2016-09-09 19:00:49 +0000185
186 uint32_t StreamCount = File.getNumStreams();
187
188 ListScope L(P, "Streams");
189 for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
190 std::string Label("Stream ");
191 Label += to_string(StreamIdx);
192
193 std::string Value = "[" + StreamPurposes[StreamIdx] + "] (";
194 Value += to_string(File.getStreamByteSize(StreamIdx));
195 Value += " bytes)";
196
197 P.printString(Label, Value);
198 }
Reid Kleckner11582c52016-06-17 20:38:01 +0000199
Zachary Turnerd3117392016-06-03 19:28:33 +0000200 P.flush();
201 return Error::success();
202}
203
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000204Error LLVMOutputStyle::dumpFreePageMap() {
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000205 if (!opts::raw::DumpPageStats)
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000206 return Error::success();
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000207
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000208 // Start with used pages instead of free pages because
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000209 // the number of free pages is far larger than used pages.
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000210 BitVector FPM = File.getMsfLayout().FreePageMap;
211
212 PageStats PS(FPM);
213
214 recordKnownUsedPage(PS, 0); // MSF Super Block
215
Zachary Turner8cf51c32016-08-03 16:53:21 +0000216 uint32_t BlocksPerSection = msf::getFpmIntervalLength(File.getMsfLayout());
217 uint32_t NumSections = msf::getNumFpmIntervals(File.getMsfLayout());
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000218 for (uint32_t I = 0; I < NumSections; ++I) {
219 uint32_t Fpm0 = 1 + BlocksPerSection * I;
220 // 2 Fpm blocks spaced at `getBlockSize()` block intervals
221 recordKnownUsedPage(PS, Fpm0);
222 recordKnownUsedPage(PS, Fpm0 + 1);
223 }
224
225 recordKnownUsedPage(PS, File.getBlockMapIndex()); // Stream Table
226
Rui Ueyama22e67382016-08-02 23:22:46 +0000227 for (auto DB : File.getDirectoryBlockArray())
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000228 recordKnownUsedPage(PS, DB);
Rui Ueyama22e67382016-08-02 23:22:46 +0000229
230 // Record pages used by streams. Note that pages for stream 0
231 // are considered being unused because that's what MSVC tools do.
232 // Stream 0 doesn't contain actual data, so it makes some sense,
233 // though it's a bit confusing to us.
234 for (auto &SE : File.getStreamMap().drop_front(1))
235 for (auto &S : SE)
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000236 recordKnownUsedPage(PS, S);
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000237
238 dumpBitVector("Msf Free Pages", FPM);
239 dumpBitVector("Orphaned Pages", PS.OrphanedPages);
240 dumpBitVector("Multiply Used Pages", PS.MultiUsePages);
241 dumpBitVector("Use After Free Pages", PS.UseAfterFreePages);
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000242 return Error::success();
243}
244
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000245void LLVMOutputStyle::dumpBitVector(StringRef Name, const BitVector &V) {
246 std::vector<uint32_t> Vec;
247 for (uint32_t I = 0, E = V.size(); I != E; ++I)
248 if (V[I])
249 Vec.push_back(I);
250 P.printList(Name, Vec);
251}
252
Bob Haarman653baa22016-10-21 19:43:19 +0000253Error LLVMOutputStyle::dumpGlobalsStream() {
254 if (!opts::raw::DumpGlobals)
255 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000256 if (!File.hasPDBGlobalsStream()) {
257 P.printString("Globals Stream not present");
258 return Error::success();
259 }
Bob Haarman653baa22016-10-21 19:43:19 +0000260
Bob Haarman653baa22016-10-21 19:43:19 +0000261 auto Globals = File.getPDBGlobalsStream();
262 if (!Globals)
Bob Haarman312fd0e2016-12-06 00:55:55 +0000263 return Globals.takeError();
Bob Haarmana5b43582016-12-05 22:44:00 +0000264 DictScope D(P, "Globals Stream");
Bob Haarman653baa22016-10-21 19:43:19 +0000265
266 auto Dbi = File.getPDBDbiStream();
267 if (!Dbi)
268 return Dbi.takeError();
269
270 P.printNumber("Stream number", Dbi->getGlobalSymbolStreamIndex());
271 P.printNumber("Number of buckets", Globals->getNumBuckets());
272 P.printList("Hash Buckets", Globals->getHashBuckets());
273
274 return Error::success();
275}
276
Zachary Turnerd3117392016-06-03 19:28:33 +0000277Error LLVMOutputStyle::dumpStreamBlocks() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000278 if (!opts::raw::DumpStreamBlocks)
Zachary Turnerd3117392016-06-03 19:28:33 +0000279 return Error::success();
280
281 ListScope L(P, "StreamBlocks");
282 uint32_t StreamCount = File.getNumStreams();
283 for (uint32_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
284 std::string Name("Stream ");
285 Name += to_string(StreamIdx);
286 auto StreamBlocks = File.getStreamBlockList(StreamIdx);
287 P.printList(Name, StreamBlocks);
288 }
289 return Error::success();
290}
291
Zachary Turner72c5b642016-09-09 18:17:52 +0000292Error LLVMOutputStyle::dumpBlockRanges() {
293 if (!opts::raw::DumpBlockRange.hasValue())
294 return Error::success();
295 auto &R = *opts::raw::DumpBlockRange;
296 uint32_t Max = R.Max.getValueOr(R.Min);
297
298 if (Max < R.Min)
299 return make_error<StringError>(
300 "Invalid block range specified. Max < Min",
301 std::make_error_code(std::errc::bad_address));
302 if (Max >= File.getBlockCount())
303 return make_error<StringError>(
304 "Invalid block range specified. Requested block out of bounds",
305 std::make_error_code(std::errc::bad_address));
306
307 DictScope D(P, "Block Data");
308 for (uint32_t I = R.Min; I <= Max; ++I) {
309 auto ExpectedData = File.getBlockData(I, File.getBlockSize());
310 if (!ExpectedData)
311 return ExpectedData.takeError();
312 std::string Label;
313 llvm::raw_string_ostream S(Label);
314 S << "Block " << I;
315 S.flush();
316 P.printBinaryBlock(Label, *ExpectedData);
317 }
318
319 return Error::success();
320}
321
322Error LLVMOutputStyle::dumpStreamBytes() {
323 if (opts::raw::DumpStreamData.empty())
Zachary Turnerd3117392016-06-03 19:28:33 +0000324 return Error::success();
325
Zachary Turner6ac232c2017-03-13 23:28:25 +0000326 if (StreamPurposes.empty())
327 discoverStreamPurposes(File, StreamPurposes);
Zachary Turner36efbfa2016-09-09 19:00:49 +0000328
Zachary Turner72c5b642016-09-09 18:17:52 +0000329 DictScope D(P, "Stream Data");
330 for (uint32_t SI : opts::raw::DumpStreamData) {
331 if (SI >= File.getNumStreams())
332 return make_error<RawError>(raw_error_code::no_stream);
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000333
Zachary Turner72c5b642016-09-09 18:17:52 +0000334 auto S = MappedBlockStream::createIndexedStream(File.getMsfLayout(),
335 File.getMsfBuffer(), SI);
336 if (!S)
337 continue;
Zachary Turner36efbfa2016-09-09 19:00:49 +0000338 DictScope DD(P, "Stream");
339
340 P.printNumber("Index", SI);
341 P.printString("Type", StreamPurposes[SI]);
342 P.printNumber("Size", S->getLength());
343 auto Blocks = File.getMsfLayout().StreamMap[SI];
344 P.printList("Blocks", Blocks);
345
Zachary Turner120faca2017-02-27 22:11:43 +0000346 BinaryStreamReader R(*S);
Zachary Turner72c5b642016-09-09 18:17:52 +0000347 ArrayRef<uint8_t> StreamData;
348 if (auto EC = R.readBytes(StreamData, S->getLength()))
Zachary Turnerd3117392016-06-03 19:28:33 +0000349 return EC;
Zachary Turner36efbfa2016-09-09 19:00:49 +0000350 P.printBinaryBlock("Data", StreamData);
Zachary Turnerd3117392016-06-03 19:28:33 +0000351 }
352 return Error::success();
353}
354
Zachary Turner760ad4d2017-01-20 22:42:09 +0000355Error LLVMOutputStyle::dumpStringTable() {
356 if (!opts::raw::DumpStringTable)
357 return Error::success();
358
359 auto IS = File.getStringTable();
360 if (!IS)
361 return IS.takeError();
362
363 DictScope D(P, "String Table");
364 for (uint32_t I : IS->name_ids()) {
365 StringRef S = IS->getStringForID(I);
366 if (!S.empty()) {
367 llvm::SmallString<32> Str;
368 Str.append("'");
369 Str.append(S);
370 Str.append("'");
371 P.printString(Str);
372 }
373 }
374 return Error::success();
375}
376
Zachary Turnerd3117392016-06-03 19:28:33 +0000377Error LLVMOutputStyle::dumpInfoStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000378 if (!opts::raw::DumpHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000379 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000380 if (!File.hasPDBInfoStream()) {
381 P.printString("PDB Stream not present");
382 return Error::success();
383 }
Zachary Turnera1657a92016-06-08 17:26:39 +0000384 auto IS = File.getPDBInfoStream();
385 if (!IS)
386 return IS.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000387
388 DictScope D(P, "PDB Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000389 P.printNumber("Version", IS->getVersion());
390 P.printHex("Signature", IS->getSignature());
391 P.printNumber("Age", IS->getAge());
392 P.printObject("Guid", IS->getGuid());
Zachary Turner05d5e612017-03-16 20:19:11 +0000393 P.printHex("Features", IS->getFeatures());
Zachary Turner760ad4d2017-01-20 22:42:09 +0000394 {
395 DictScope DD(P, "Named Streams");
396 for (const auto &S : IS->getNamedStreams().entries())
397 P.printObject(S.getKey(), S.getValue());
398 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000399 return Error::success();
400}
401
Zachary Turner29da5db2017-01-25 21:17:40 +0000402namespace {
403class RecordBytesVisitor : public TypeVisitorCallbacks {
404public:
405 explicit RecordBytesVisitor(ScopedPrinter &P) : P(P) {}
406
407 Error visitTypeEnd(CVType &Record) override {
408 P.printBinaryBlock("Bytes", Record.content());
409 return Error::success();
410 }
411
412private:
413 ScopedPrinter &P;
414};
Rui Ueyamafd97bf12016-06-03 20:48:51 +0000415}
416
Zachary Turnerd3117392016-06-03 19:28:33 +0000417Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
418 assert(StreamIdx == StreamTPI || StreamIdx == StreamIPI);
419
420 bool DumpRecordBytes = false;
421 bool DumpRecords = false;
Zachary Turner29da5db2017-01-25 21:17:40 +0000422 bool DumpTpiHash = false;
Zachary Turnerd3117392016-06-03 19:28:33 +0000423 StringRef Label;
424 StringRef VerLabel;
425 if (StreamIdx == StreamTPI) {
Bob Haarmana5b43582016-12-05 22:44:00 +0000426 if (!File.hasPDBTpiStream()) {
427 P.printString("Type Info Stream (TPI) not present");
428 return Error::success();
429 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000430 DumpRecordBytes = opts::raw::DumpTpiRecordBytes;
431 DumpRecords = opts::raw::DumpTpiRecords;
Zachary Turner29da5db2017-01-25 21:17:40 +0000432 DumpTpiHash = opts::raw::DumpTpiHash;
Zachary Turnerd3117392016-06-03 19:28:33 +0000433 Label = "Type Info Stream (TPI)";
434 VerLabel = "TPI Version";
435 } else if (StreamIdx == StreamIPI) {
Bob Haarmana5b43582016-12-05 22:44:00 +0000436 if (!File.hasPDBIpiStream()) {
437 P.printString("Type Info Stream (IPI) not present");
438 return Error::success();
439 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000440 DumpRecordBytes = opts::raw::DumpIpiRecordBytes;
441 DumpRecords = opts::raw::DumpIpiRecords;
Zachary Turnerd3117392016-06-03 19:28:33 +0000442 Label = "Type Info Stream (IPI)";
443 VerLabel = "IPI Version";
444 }
Zachary Turner29da5db2017-01-25 21:17:40 +0000445 if (!DumpRecordBytes && !DumpRecords && !DumpTpiHash &&
446 !opts::raw::DumpModuleSyms)
Zachary Turnerd3117392016-06-03 19:28:33 +0000447 return Error::success();
448
Zachary Turner29da5db2017-01-25 21:17:40 +0000449 bool IsSilentDatabaseBuild = !DumpRecordBytes && !DumpRecords && !DumpTpiHash;
450
Zachary Turnera1657a92016-06-08 17:26:39 +0000451 auto Tpi = (StreamIdx == StreamTPI) ? File.getPDBTpiStream()
452 : File.getPDBIpiStream();
453 if (!Tpi)
454 return Tpi.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000455
Zachary Turner29da5db2017-01-25 21:17:40 +0000456 std::unique_ptr<DictScope> StreamScope;
457 std::unique_ptr<ListScope> RecordScope;
458
459 if (!IsSilentDatabaseBuild) {
460 StreamScope = llvm::make_unique<DictScope>(P, Label);
461 P.printNumber(VerLabel, Tpi->getTpiVersion());
462 P.printNumber("Record count", Tpi->NumTypeRecords());
463 }
464
Reid Klecknera5d187b2017-03-23 21:36:25 +0000465 TypeDatabase &StreamDB = (StreamIdx == StreamTPI) ? TypeDB : ItemDB;
466
467 TypeDatabaseVisitor DBV(StreamDB);
468 CompactTypeDumpVisitor CTDV(StreamDB, &P);
Zachary Turner44a643c2017-01-12 22:28:15 +0000469 TypeDumpVisitor TDV(TypeDB, &P, false);
Reid Klecknera5d187b2017-03-23 21:36:25 +0000470 if (StreamIdx == StreamIPI)
471 TDV.setItemDB(ItemDB);
Zachary Turner29da5db2017-01-25 21:17:40 +0000472 RecordBytesVisitor RBV(P);
Zachary Turner44a643c2017-01-12 22:28:15 +0000473 TypeDeserializer Deserializer;
Zachary Turner29da5db2017-01-25 21:17:40 +0000474
475 // We always need to deserialize and add it to the type database. This is
476 // true if even if we're not dumping anything, because we could need the
477 // type database for the purposes of dumping symbols.
Zachary Turner44a643c2017-01-12 22:28:15 +0000478 TypeVisitorCallbackPipeline Pipeline;
479 Pipeline.addCallbackToPipeline(Deserializer);
480 Pipeline.addCallbackToPipeline(DBV);
481
Zachary Turner29da5db2017-01-25 21:17:40 +0000482 // If we're in dump mode, add a dumper with the appropriate detail level.
483 if (DumpRecords) {
Zachary Turner44a643c2017-01-12 22:28:15 +0000484 if (opts::raw::CompactRecords)
485 Pipeline.addCallbackToPipeline(CTDV);
486 else
487 Pipeline.addCallbackToPipeline(TDV);
Zachary Turnerd3117392016-06-03 19:28:33 +0000488 }
Zachary Turner29da5db2017-01-25 21:17:40 +0000489 if (DumpRecordBytes)
490 Pipeline.addCallbackToPipeline(RBV);
491
492 CVTypeVisitor Visitor(Pipeline);
493
494 if (DumpRecords || DumpRecordBytes)
495 RecordScope = llvm::make_unique<ListScope>(P, "Records");
496
497 bool HadError = false;
498
499 TypeIndex T(TypeIndex::FirstNonSimpleIndex);
500 for (auto Type : Tpi->types(&HadError)) {
501 std::unique_ptr<DictScope> OneRecordScope;
502
503 if ((DumpRecords || DumpRecordBytes) && !opts::raw::CompactRecords)
504 OneRecordScope = llvm::make_unique<DictScope>(P, "");
505
506 if (auto EC = Visitor.visitTypeRecord(Type))
507 return EC;
508 }
509 if (HadError)
510 return make_error<RawError>(raw_error_code::corrupt_file,
511 "TPI stream contained corrupt record");
512
513 if (DumpTpiHash) {
514 DictScope DD(P, "Hash");
515 P.printNumber("Number of Hash Buckets", Tpi->NumHashBuckets());
516 P.printNumber("Hash Key Size", Tpi->getHashKeySize());
517 P.printList("Values", Tpi->getHashValues());
518
519 ListScope LHA(P, "Adjusters");
520 auto ExpectedST = File.getStringTable();
521 if (!ExpectedST)
522 return ExpectedST.takeError();
523 const auto &ST = *ExpectedST;
524 for (const auto &E : Tpi->getHashAdjusters()) {
525 DictScope DHA(P);
526 StringRef Name = ST.getStringForID(E.first);
527 P.printString("Type", Name);
528 P.printHex("TI", E.second);
529 }
530 }
531
532 if (!IsSilentDatabaseBuild) {
533 ListScope L(P, "TypeIndexOffsets");
534 for (const auto &IO : Tpi->getTypeIndexOffsets()) {
535 P.printString(formatv("Index: {0:x}, Offset: {1:N}", IO.Type.getIndex(),
536 (uint32_t)IO.Offset)
537 .str());
538 }
539 }
540
Zachary Turnerd3117392016-06-03 19:28:33 +0000541 P.flush();
542 return Error::success();
543}
544
545Error LLVMOutputStyle::dumpDbiStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000546 bool DumpModules = opts::raw::DumpModules || opts::raw::DumpModuleSyms ||
547 opts::raw::DumpModuleFiles || opts::raw::DumpLineInfo;
548 if (!opts::raw::DumpHeaders && !DumpModules)
Zachary Turnerd3117392016-06-03 19:28:33 +0000549 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000550 if (!File.hasPDBDbiStream()) {
551 P.printString("DBI Stream not present");
552 return Error::success();
553 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000554
Zachary Turnera1657a92016-06-08 17:26:39 +0000555 auto DS = File.getPDBDbiStream();
556 if (!DS)
557 return DS.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000558
559 DictScope D(P, "DBI Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000560 P.printNumber("Dbi Version", DS->getDbiVersion());
561 P.printNumber("Age", DS->getAge());
562 P.printBoolean("Incremental Linking", DS->isIncrementallyLinked());
563 P.printBoolean("Has CTypes", DS->hasCTypes());
564 P.printBoolean("Is Stripped", DS->isStripped());
565 P.printObject("Machine Type", DS->getMachineType());
566 P.printNumber("Symbol Record Stream Index", DS->getSymRecordStreamIndex());
567 P.printNumber("Public Symbol Stream Index", DS->getPublicSymbolStreamIndex());
568 P.printNumber("Global Symbol Stream Index", DS->getGlobalSymbolStreamIndex());
Zachary Turnerd3117392016-06-03 19:28:33 +0000569
Zachary Turnera1657a92016-06-08 17:26:39 +0000570 uint16_t Major = DS->getBuildMajorVersion();
571 uint16_t Minor = DS->getBuildMinorVersion();
Zachary Turnerd3117392016-06-03 19:28:33 +0000572 P.printVersion("Toolchain Version", Major, Minor);
573
574 std::string DllName;
575 raw_string_ostream DllStream(DllName);
576 DllStream << "mspdb" << Major << Minor << ".dll version";
577 DllStream.flush();
Zachary Turnera1657a92016-06-08 17:26:39 +0000578 P.printVersion(DllName, Major, Minor, DS->getPdbDllVersion());
Zachary Turnerd3117392016-06-03 19:28:33 +0000579
580 if (DumpModules) {
581 ListScope L(P, "Modules");
Zachary Turnera1657a92016-06-08 17:26:39 +0000582 for (auto &Modi : DS->modules()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000583 DictScope DD(P);
584 P.printString("Name", Modi.Info.getModuleName().str());
585 P.printNumber("Debug Stream Index", Modi.Info.getModuleStreamIndex());
586 P.printString("Object File Name", Modi.Info.getObjFileName().str());
587 P.printNumber("Num Files", Modi.Info.getNumberOfFiles());
588 P.printNumber("Source File Name Idx", Modi.Info.getSourceFileNameIndex());
589 P.printNumber("Pdb File Name Idx", Modi.Info.getPdbFilePathNameIndex());
590 P.printNumber("Line Info Byte Size", Modi.Info.getLineInfoByteSize());
591 P.printNumber("C13 Line Info Byte Size",
592 Modi.Info.getC13LineInfoByteSize());
593 P.printNumber("Symbol Byte Size", Modi.Info.getSymbolDebugInfoByteSize());
594 P.printNumber("Type Server Index", Modi.Info.getTypeServerIndex());
595 P.printBoolean("Has EC Info", Modi.Info.hasECInfo());
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000596 if (opts::raw::DumpModuleFiles) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000597 std::string FileListName =
598 to_string(Modi.SourceFiles.size()) + " Contributing Source Files";
599 ListScope LL(P, FileListName);
600 for (auto File : Modi.SourceFiles)
601 P.printString(File.str());
602 }
603 bool HasModuleDI =
604 (Modi.Info.getModuleStreamIndex() < File.getNumStreams());
605 bool ShouldDumpSymbols =
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000606 (opts::raw::DumpModuleSyms || opts::raw::DumpSymRecordBytes);
607 if (HasModuleDI && (ShouldDumpSymbols || opts::raw::DumpLineInfo)) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000608 auto ModStreamData = MappedBlockStream::createIndexedStream(
Zachary Turnerd66889c2016-07-28 19:12:28 +0000609 File.getMsfLayout(), File.getMsfBuffer(),
610 Modi.Info.getModuleStreamIndex());
611
Zachary Turner67c56012017-04-27 16:11:19 +0000612 ModuleDebugStream ModS(Modi.Info, std::move(ModStreamData));
Zachary Turnerd3117392016-06-03 19:28:33 +0000613 if (auto EC = ModS.reload())
614 return EC;
615
616 if (ShouldDumpSymbols) {
617 ListScope SS(P, "Symbols");
Zachary Turner629cb7d2017-01-11 23:24:22 +0000618 codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
Zachary Turnerd3117392016-06-03 19:28:33 +0000619 bool HadError = false;
Zachary Turner0d840742016-10-07 21:34:46 +0000620 for (auto S : ModS.symbols(&HadError)) {
621 DictScope LL(P, "");
622 if (opts::raw::DumpModuleSyms) {
623 if (auto EC = SD.dump(S)) {
624 llvm::consumeError(std::move(EC));
625 HadError = true;
626 break;
627 }
628 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000629 if (opts::raw::DumpSymRecordBytes)
Zachary Turnerc67b00c2016-09-14 23:00:16 +0000630 P.printBinaryBlock("Bytes", S.content());
Zachary Turnerd3117392016-06-03 19:28:33 +0000631 }
632 if (HadError)
633 return make_error<RawError>(
634 raw_error_code::corrupt_file,
635 "DBI stream contained corrupt symbol record");
636 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000637 if (opts::raw::DumpLineInfo) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000638 ListScope SS(P, "LineInfo");
Zachary Turnerd3117392016-06-03 19:28:33 +0000639 // Define a locally scoped visitor to print the different
640 // substream types types.
Zachary Turner67c56012017-04-27 16:11:19 +0000641 class RecordVisitor : public codeview::ModuleDebugFragmentVisitor {
Zachary Turnerd3117392016-06-03 19:28:33 +0000642 public:
643 RecordVisitor(ScopedPrinter &P, PDBFile &F) : P(P), F(F) {}
Zachary Turnerc37cb0c2017-04-27 16:12:16 +0000644 Error visitUnknown(ModuleDebugUnknownFragment &Fragment) override {
Zachary Turnerd3117392016-06-03 19:28:33 +0000645 DictScope DD(P, "Unknown");
646 ArrayRef<uint8_t> Data;
Zachary Turnerc37cb0c2017-04-27 16:12:16 +0000647 BinaryStreamReader R(Fragment.getData());
Zachary Turnerd3117392016-06-03 19:28:33 +0000648 if (auto EC = R.readBytes(Data, R.bytesRemaining())) {
649 return make_error<RawError>(
650 raw_error_code::corrupt_file,
651 "DBI stream contained corrupt line info record");
652 }
653 P.printBinaryBlock("Data", Data);
654 return Error::success();
655 }
Zachary Turnerc37cb0c2017-04-27 16:12:16 +0000656 Error visitFileChecksums(
657 ModuleDebugFileChecksumFragment &Checksums) override {
Zachary Turnerd3117392016-06-03 19:28:33 +0000658 DictScope DD(P, "FileChecksums");
659 for (const auto &C : Checksums) {
660 DictScope DDD(P, "Checksum");
661 if (auto Result = getFileNameForOffset(C.FileNameOffset))
662 P.printString("FileName", Result.get());
663 else
664 return Result.takeError();
665 P.flush();
666 P.printEnum("Kind", uint8_t(C.Kind), getFileChecksumNames());
667 P.printBinaryBlock("Checksum", C.Checksum);
668 }
669 return Error::success();
670 }
671
Zachary Turnerc37cb0c2017-04-27 16:12:16 +0000672 Error visitLines(ModuleDebugLineFragment &Lines) override {
Zachary Turnerd3117392016-06-03 19:28:33 +0000673 DictScope DD(P, "Lines");
674 for (const auto &L : Lines) {
675 if (auto Result = getFileNameForOffset2(L.NameIndex))
676 P.printString("FileName", Result.get());
677 else
678 return Result.takeError();
679 P.flush();
680 for (const auto &N : L.LineNumbers) {
681 DictScope DDD(P, "Line");
682 LineInfo LI(N.Flags);
683 P.printNumber("Offset", N.Offset);
684 if (LI.isAlwaysStepInto())
685 P.printString("StepInto", StringRef("Always"));
686 else if (LI.isNeverStepInto())
687 P.printString("StepInto", StringRef("Never"));
688 else
689 P.printNumber("LineNumberStart", LI.getStartLine());
690 P.printNumber("EndDelta", LI.getLineDelta());
691 P.printBoolean("IsStatement", LI.isStatement());
692 }
693 for (const auto &C : L.Columns) {
694 DictScope DDD(P, "Column");
695 P.printNumber("Start", C.StartColumn);
696 P.printNumber("End", C.EndColumn);
697 }
698 }
699 return Error::success();
700 }
701
702 private:
703 Expected<StringRef> getFileNameForOffset(uint32_t Offset) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000704 auto ST = F.getStringTable();
705 if (!ST)
706 return ST.takeError();
707
708 return ST->getStringForID(Offset);
Zachary Turnerd3117392016-06-03 19:28:33 +0000709 }
710 Expected<StringRef> getFileNameForOffset2(uint32_t Offset) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000711 auto DS = F.getPDBDbiStream();
712 if (!DS)
713 return DS.takeError();
714 return DS->getFileNameForIndex(Offset);
Zachary Turnerd3117392016-06-03 19:28:33 +0000715 }
716 ScopedPrinter &P;
717 PDBFile &F;
718 };
719
720 RecordVisitor V(P, File);
Zachary Turnerc37cb0c2017-04-27 16:12:16 +0000721 for (const auto &L : ModS.linesAndChecksums()) {
Zachary Turner67c56012017-04-27 16:11:19 +0000722 if (auto EC = codeview::visitModuleDebugFragment(L, V))
Zachary Turnerd3117392016-06-03 19:28:33 +0000723 return EC;
724 }
725 }
726 }
727 }
728 }
729 return Error::success();
730}
731
732Error LLVMOutputStyle::dumpSectionContribs() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000733 if (!opts::raw::DumpSectionContribs)
Zachary Turnerd3117392016-06-03 19:28:33 +0000734 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000735 if (!File.hasPDBDbiStream()) {
736 P.printString("DBI Stream not present");
737 return Error::success();
738 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000739
Zachary Turnera1657a92016-06-08 17:26:39 +0000740 auto Dbi = File.getPDBDbiStream();
741 if (!Dbi)
742 return Dbi.takeError();
743
Zachary Turnerd3117392016-06-03 19:28:33 +0000744 ListScope L(P, "Section Contributions");
745 class Visitor : public ISectionContribVisitor {
746 public:
747 Visitor(ScopedPrinter &P, DbiStream &DS) : P(P), DS(DS) {}
748 void visit(const SectionContrib &SC) override {
749 DictScope D(P, "Contribution");
750 P.printNumber("ISect", SC.ISect);
751 P.printNumber("Off", SC.Off);
752 P.printNumber("Size", SC.Size);
753 P.printFlags("Characteristics", SC.Characteristics,
754 codeview::getImageSectionCharacteristicNames(),
755 COFF::SectionCharacteristics(0x00F00000));
756 {
757 DictScope DD(P, "Module");
758 P.printNumber("Index", SC.Imod);
759 auto M = DS.modules();
760 if (M.size() > SC.Imod) {
761 P.printString("Name", M[SC.Imod].Info.getModuleName());
762 }
763 }
764 P.printNumber("Data CRC", SC.DataCrc);
765 P.printNumber("Reloc CRC", SC.RelocCrc);
766 P.flush();
767 }
768 void visit(const SectionContrib2 &SC) override {
769 visit(SC.Base);
770 P.printNumber("ISect Coff", SC.ISectCoff);
771 P.flush();
772 }
773
774 private:
775 ScopedPrinter &P;
776 DbiStream &DS;
777 };
Zachary Turnera1657a92016-06-08 17:26:39 +0000778 Visitor V(P, *Dbi);
779 Dbi->visitSectionContributions(V);
Zachary Turnerd3117392016-06-03 19:28:33 +0000780 return Error::success();
781}
782
783Error LLVMOutputStyle::dumpSectionMap() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000784 if (!opts::raw::DumpSectionMap)
Zachary Turnerd3117392016-06-03 19:28:33 +0000785 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000786 if (!File.hasPDBDbiStream()) {
787 P.printString("DBI Stream not present");
788 return Error::success();
789 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000790
Zachary Turnera1657a92016-06-08 17:26:39 +0000791 auto Dbi = File.getPDBDbiStream();
792 if (!Dbi)
793 return Dbi.takeError();
794
Zachary Turnerd3117392016-06-03 19:28:33 +0000795 ListScope L(P, "Section Map");
Zachary Turnera1657a92016-06-08 17:26:39 +0000796 for (auto &M : Dbi->getSectionMap()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000797 DictScope D(P, "Entry");
798 P.printFlags("Flags", M.Flags, getOMFSegMapDescFlagNames());
Zachary Turnerd3117392016-06-03 19:28:33 +0000799 P.printNumber("Ovl", M.Ovl);
800 P.printNumber("Group", M.Group);
801 P.printNumber("Frame", M.Frame);
802 P.printNumber("SecName", M.SecName);
803 P.printNumber("ClassName", M.ClassName);
804 P.printNumber("Offset", M.Offset);
805 P.printNumber("SecByteLength", M.SecByteLength);
806 P.flush();
807 }
808 return Error::success();
809}
810
811Error LLVMOutputStyle::dumpPublicsStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000812 if (!opts::raw::DumpPublics)
Zachary Turnerd3117392016-06-03 19:28:33 +0000813 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000814 if (!File.hasPDBPublicsStream()) {
815 P.printString("Publics Stream not present");
816 return Error::success();
817 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000818
Zachary Turnera1657a92016-06-08 17:26:39 +0000819 auto Publics = File.getPDBPublicsStream();
820 if (!Publics)
821 return Publics.takeError();
Bob Haarmana5b43582016-12-05 22:44:00 +0000822 DictScope D(P, "Publics Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000823
824 auto Dbi = File.getPDBDbiStream();
825 if (!Dbi)
826 return Dbi.takeError();
827
828 P.printNumber("Stream number", Dbi->getPublicSymbolStreamIndex());
829 P.printNumber("SymHash", Publics->getSymHash());
830 P.printNumber("AddrMap", Publics->getAddrMap());
831 P.printNumber("Number of buckets", Publics->getNumBuckets());
832 P.printList("Hash Buckets", Publics->getHashBuckets());
833 P.printList("Address Map", Publics->getAddressMap());
834 P.printList("Thunk Map", Publics->getThunkMap());
835 P.printList("Section Offsets", Publics->getSectionOffsets(),
Zachary Turnerd3117392016-06-03 19:28:33 +0000836 printSectionOffset);
837 ListScope L(P, "Symbols");
Zachary Turner629cb7d2017-01-11 23:24:22 +0000838 codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
Zachary Turnerd3117392016-06-03 19:28:33 +0000839 bool HadError = false;
Zachary Turnera1657a92016-06-08 17:26:39 +0000840 for (auto S : Publics->getSymbols(&HadError)) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000841 DictScope DD(P, "");
842
Zachary Turner0d840742016-10-07 21:34:46 +0000843 if (auto EC = SD.dump(S)) {
844 HadError = true;
845 break;
846 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000847 if (opts::raw::DumpSymRecordBytes)
Zachary Turnerc67b00c2016-09-14 23:00:16 +0000848 P.printBinaryBlock("Bytes", S.content());
Zachary Turnerd3117392016-06-03 19:28:33 +0000849 }
850 if (HadError)
851 return make_error<RawError>(
852 raw_error_code::corrupt_file,
853 "Public symbol stream contained corrupt record");
854
855 return Error::success();
856}
857
858Error LLVMOutputStyle::dumpSectionHeaders() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000859 if (!opts::raw::DumpSectionHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000860 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000861 if (!File.hasPDBDbiStream()) {
862 P.printString("DBI Stream not present");
863 return Error::success();
864 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000865
Zachary Turnera1657a92016-06-08 17:26:39 +0000866 auto Dbi = File.getPDBDbiStream();
867 if (!Dbi)
868 return Dbi.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000869
870 ListScope D(P, "Section Headers");
Zachary Turnera1657a92016-06-08 17:26:39 +0000871 for (const object::coff_section &Section : Dbi->getSectionHeaders()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000872 DictScope DD(P, "");
873
874 // If a name is 8 characters long, there is no NUL character at end.
875 StringRef Name(Section.Name, strnlen(Section.Name, sizeof(Section.Name)));
876 P.printString("Name", Name);
877 P.printNumber("Virtual Size", Section.VirtualSize);
878 P.printNumber("Virtual Address", Section.VirtualAddress);
879 P.printNumber("Size of Raw Data", Section.SizeOfRawData);
880 P.printNumber("File Pointer to Raw Data", Section.PointerToRawData);
881 P.printNumber("File Pointer to Relocations", Section.PointerToRelocations);
882 P.printNumber("File Pointer to Linenumbers", Section.PointerToLinenumbers);
883 P.printNumber("Number of Relocations", Section.NumberOfRelocations);
884 P.printNumber("Number of Linenumbers", Section.NumberOfLinenumbers);
Rui Ueyama2c5384a2016-06-06 21:34:55 +0000885 P.printFlags("Characteristics", Section.Characteristics,
886 getImageSectionCharacteristicNames());
Zachary Turnerd3117392016-06-03 19:28:33 +0000887 }
888 return Error::success();
889}
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000890
891Error LLVMOutputStyle::dumpFpoStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000892 if (!opts::raw::DumpFpo)
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000893 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000894 if (!File.hasPDBDbiStream()) {
895 P.printString("DBI Stream not present");
896 return Error::success();
897 }
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000898
Zachary Turnera1657a92016-06-08 17:26:39 +0000899 auto Dbi = File.getPDBDbiStream();
900 if (!Dbi)
901 return Dbi.takeError();
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000902
903 ListScope D(P, "New FPO");
Zachary Turnera1657a92016-06-08 17:26:39 +0000904 for (const object::FpoData &Fpo : Dbi->getFpoRecords()) {
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000905 DictScope DD(P, "");
906 P.printNumber("Offset", Fpo.Offset);
907 P.printNumber("Size", Fpo.Size);
908 P.printNumber("Number of locals", Fpo.NumLocals);
909 P.printNumber("Number of params", Fpo.NumParams);
910 P.printNumber("Size of Prolog", Fpo.getPrologSize());
911 P.printNumber("Number of Saved Registers", Fpo.getNumSavedRegs());
912 P.printBoolean("Has SEH", Fpo.hasSEH());
913 P.printBoolean("Use BP", Fpo.useBP());
914 P.printNumber("Frame Pointer", Fpo.getFP());
915 }
916 return Error::success();
917}
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000918
Zachary Turner7120a472016-06-06 20:37:05 +0000919void LLVMOutputStyle::flush() { P.flush(); }