blob: a4df5d09b4f7774efba223173ccbc359c66f5f11 [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 Turner67c56012017-04-27 16:11:19 +000019#include "llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000020#include "llvm/DebugInfo/CodeView/SymbolDumper.h"
Zachary Turner629cb7d2017-01-11 23:24:22 +000021#include "llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h"
22#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
23#include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h"
24#include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h"
Zachary Turnera3225b02016-07-29 20:56:36 +000025#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
Zachary Turner67c56012017-04-27 16:11:19 +000026#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000027#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
28#include "llvm/DebugInfo/PDB/Native/EnumTables.h"
29#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
30#include "llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h"
31#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
Zachary Turner67c56012017-04-27 16:11:19 +000032#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000033#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
34#include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
35#include "llvm/DebugInfo/PDB/Native/RawError.h"
36#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000037#include "llvm/DebugInfo/PDB/PDBExtras.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000038#include "llvm/Object/COFF.h"
Zachary Turnerd9dc2822017-03-02 20:52:51 +000039#include "llvm/Support/BinaryStreamReader.h"
Zachary Turner44a643c2017-01-12 22:28:15 +000040#include "llvm/Support/FormatVariadic.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000041
42#include <unordered_map>
43
44using namespace llvm;
45using namespace llvm::codeview;
Zachary Turnerbac69d32016-07-22 19:56:05 +000046using namespace llvm::msf;
Zachary Turnerd3117392016-06-03 19:28:33 +000047using namespace llvm::pdb;
48
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +000049namespace {
50struct PageStats {
51 explicit PageStats(const BitVector &FreePages)
52 : Upm(FreePages), ActualUsedPages(FreePages.size()),
53 MultiUsePages(FreePages.size()), UseAfterFreePages(FreePages.size()) {
54 const_cast<BitVector &>(Upm).flip();
55 // To calculate orphaned pages, we start with the set of pages that the
56 // MSF thinks are used. Each time we find one that actually *is* used,
57 // we unset it. Whichever bits remain set at the end are orphaned.
58 OrphanedPages = Upm;
59 }
60
61 // The inverse of the MSF File's copy of the Fpm. The basis for which we
62 // determine the allocation status of each page.
63 const BitVector Upm;
64
65 // Pages which are marked as used in the FPM and are used at least once.
66 BitVector ActualUsedPages;
67
68 // Pages which are marked as used in the FPM but are used more than once.
69 BitVector MultiUsePages;
70
71 // Pages which are marked as used in the FPM but are not used at all.
72 BitVector OrphanedPages;
73
74 // Pages which are marked free in the FPM but are used.
75 BitVector UseAfterFreePages;
76};
77}
78
79static void recordKnownUsedPage(PageStats &Stats, uint32_t UsedIndex) {
80 if (Stats.Upm.test(UsedIndex)) {
81 if (Stats.ActualUsedPages.test(UsedIndex))
82 Stats.MultiUsePages.set(UsedIndex);
83 Stats.ActualUsedPages.set(UsedIndex);
84 Stats.OrphanedPages.reset(UsedIndex);
85 } else {
86 // The MSF doesn't think this page is used, but it is.
87 Stats.UseAfterFreePages.set(UsedIndex);
88 }
89}
90
Zachary Turnerd3117392016-06-03 19:28:33 +000091static void printSectionOffset(llvm::raw_ostream &OS,
92 const SectionOffset &Off) {
93 OS << Off.Off << ", " << Off.Isect;
94}
95
Zachary Turner629cb7d2017-01-11 23:24:22 +000096LLVMOutputStyle::LLVMOutputStyle(PDBFile &File) : File(File), P(outs()) {}
Zachary Turnerd3117392016-06-03 19:28:33 +000097
Zachary Turnera30bd1a2016-06-30 17:42:48 +000098Error LLVMOutputStyle::dump() {
99 if (auto EC = dumpFileHeaders())
100 return EC;
101
102 if (auto EC = dumpStreamSummary())
103 return EC;
104
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000105 if (auto EC = dumpFreePageMap())
106 return EC;
107
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000108 if (auto EC = dumpStreamBlocks())
109 return EC;
110
Zachary Turner72c5b642016-09-09 18:17:52 +0000111 if (auto EC = dumpBlockRanges())
112 return EC;
113
114 if (auto EC = dumpStreamBytes())
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000115 return EC;
116
Zachary Turner760ad4d2017-01-20 22:42:09 +0000117 if (auto EC = dumpStringTable())
118 return EC;
119
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000120 if (auto EC = dumpInfoStream())
121 return EC;
122
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000123 if (auto EC = dumpTpiStream(StreamTPI))
124 return EC;
125
126 if (auto EC = dumpTpiStream(StreamIPI))
127 return EC;
128
129 if (auto EC = dumpDbiStream())
130 return EC;
131
132 if (auto EC = dumpSectionContribs())
133 return EC;
134
135 if (auto EC = dumpSectionMap())
136 return EC;
137
Bob Haarman653baa22016-10-21 19:43:19 +0000138 if (auto EC = dumpGlobalsStream())
139 return EC;
140
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000141 if (auto EC = dumpPublicsStream())
142 return EC;
143
144 if (auto EC = dumpSectionHeaders())
145 return EC;
146
147 if (auto EC = dumpFpoStream())
148 return EC;
149
150 flush();
151
152 return Error::success();
153}
154
Zachary Turnerd3117392016-06-03 19:28:33 +0000155Error LLVMOutputStyle::dumpFileHeaders() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000156 if (!opts::raw::DumpHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000157 return Error::success();
158
159 DictScope D(P, "FileHeaders");
160 P.printNumber("BlockSize", File.getBlockSize());
Zachary Turnerb927e022016-07-15 22:17:19 +0000161 P.printNumber("FreeBlockMap", File.getFreeBlockMapBlock());
Zachary Turnerd3117392016-06-03 19:28:33 +0000162 P.printNumber("NumBlocks", File.getBlockCount());
163 P.printNumber("NumDirectoryBytes", File.getNumDirectoryBytes());
164 P.printNumber("Unknown1", File.getUnknown1());
165 P.printNumber("BlockMapAddr", File.getBlockMapIndex());
166 P.printNumber("NumDirectoryBlocks", File.getNumDirectoryBlocks());
Zachary Turnerd3117392016-06-03 19:28:33 +0000167
168 // The directory is not contiguous. Instead, the block map contains a
169 // contiguous list of block numbers whose contents, when concatenated in
170 // order, make up the directory.
171 P.printList("DirectoryBlocks", File.getDirectoryBlockArray());
172 P.printNumber("NumStreams", File.getNumStreams());
173 return Error::success();
174}
175
Zachary Turner36efbfa2016-09-09 19:00:49 +0000176Error LLVMOutputStyle::dumpStreamSummary() {
177 if (!opts::raw::DumpStreamSummary)
178 return Error::success();
179
Zachary Turner6ac232c2017-03-13 23:28:25 +0000180 if (StreamPurposes.empty())
181 discoverStreamPurposes(File, StreamPurposes);
Zachary Turner36efbfa2016-09-09 19:00:49 +0000182
183 uint32_t StreamCount = File.getNumStreams();
184
185 ListScope L(P, "Streams");
186 for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
187 std::string Label("Stream ");
188 Label += to_string(StreamIdx);
189
190 std::string Value = "[" + StreamPurposes[StreamIdx] + "] (";
191 Value += to_string(File.getStreamByteSize(StreamIdx));
192 Value += " bytes)";
193
194 P.printString(Label, Value);
195 }
Reid Kleckner11582c52016-06-17 20:38:01 +0000196
Zachary Turnerd3117392016-06-03 19:28:33 +0000197 P.flush();
198 return Error::success();
199}
200
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000201Error LLVMOutputStyle::dumpFreePageMap() {
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000202 if (!opts::raw::DumpPageStats)
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000203 return Error::success();
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000204
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000205 // Start with used pages instead of free pages because
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000206 // the number of free pages is far larger than used pages.
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000207 BitVector FPM = File.getMsfLayout().FreePageMap;
208
209 PageStats PS(FPM);
210
211 recordKnownUsedPage(PS, 0); // MSF Super Block
212
Zachary Turner8cf51c32016-08-03 16:53:21 +0000213 uint32_t BlocksPerSection = msf::getFpmIntervalLength(File.getMsfLayout());
214 uint32_t NumSections = msf::getNumFpmIntervals(File.getMsfLayout());
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000215 for (uint32_t I = 0; I < NumSections; ++I) {
216 uint32_t Fpm0 = 1 + BlocksPerSection * I;
217 // 2 Fpm blocks spaced at `getBlockSize()` block intervals
218 recordKnownUsedPage(PS, Fpm0);
219 recordKnownUsedPage(PS, Fpm0 + 1);
220 }
221
222 recordKnownUsedPage(PS, File.getBlockMapIndex()); // Stream Table
223
Rui Ueyama22e67382016-08-02 23:22:46 +0000224 for (auto DB : File.getDirectoryBlockArray())
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000225 recordKnownUsedPage(PS, DB);
Rui Ueyama22e67382016-08-02 23:22:46 +0000226
227 // Record pages used by streams. Note that pages for stream 0
228 // are considered being unused because that's what MSVC tools do.
229 // Stream 0 doesn't contain actual data, so it makes some sense,
230 // though it's a bit confusing to us.
231 for (auto &SE : File.getStreamMap().drop_front(1))
232 for (auto &S : SE)
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000233 recordKnownUsedPage(PS, S);
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000234
235 dumpBitVector("Msf Free Pages", FPM);
236 dumpBitVector("Orphaned Pages", PS.OrphanedPages);
237 dumpBitVector("Multiply Used Pages", PS.MultiUsePages);
238 dumpBitVector("Use After Free Pages", PS.UseAfterFreePages);
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000239 return Error::success();
240}
241
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000242void LLVMOutputStyle::dumpBitVector(StringRef Name, const BitVector &V) {
243 std::vector<uint32_t> Vec;
244 for (uint32_t I = 0, E = V.size(); I != E; ++I)
245 if (V[I])
246 Vec.push_back(I);
247 P.printList(Name, Vec);
248}
249
Bob Haarman653baa22016-10-21 19:43:19 +0000250Error LLVMOutputStyle::dumpGlobalsStream() {
251 if (!opts::raw::DumpGlobals)
252 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000253 if (!File.hasPDBGlobalsStream()) {
254 P.printString("Globals Stream not present");
255 return Error::success();
256 }
Bob Haarman653baa22016-10-21 19:43:19 +0000257
Bob Haarman653baa22016-10-21 19:43:19 +0000258 auto Globals = File.getPDBGlobalsStream();
259 if (!Globals)
Bob Haarman312fd0e2016-12-06 00:55:55 +0000260 return Globals.takeError();
Bob Haarmana5b43582016-12-05 22:44:00 +0000261 DictScope D(P, "Globals Stream");
Bob Haarman653baa22016-10-21 19:43:19 +0000262
263 auto Dbi = File.getPDBDbiStream();
264 if (!Dbi)
265 return Dbi.takeError();
266
267 P.printNumber("Stream number", Dbi->getGlobalSymbolStreamIndex());
268 P.printNumber("Number of buckets", Globals->getNumBuckets());
269 P.printList("Hash Buckets", Globals->getHashBuckets());
270
271 return Error::success();
272}
273
Zachary Turnerd3117392016-06-03 19:28:33 +0000274Error LLVMOutputStyle::dumpStreamBlocks() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000275 if (!opts::raw::DumpStreamBlocks)
Zachary Turnerd3117392016-06-03 19:28:33 +0000276 return Error::success();
277
278 ListScope L(P, "StreamBlocks");
279 uint32_t StreamCount = File.getNumStreams();
280 for (uint32_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
281 std::string Name("Stream ");
282 Name += to_string(StreamIdx);
283 auto StreamBlocks = File.getStreamBlockList(StreamIdx);
284 P.printList(Name, StreamBlocks);
285 }
286 return Error::success();
287}
288
Zachary Turner72c5b642016-09-09 18:17:52 +0000289Error LLVMOutputStyle::dumpBlockRanges() {
290 if (!opts::raw::DumpBlockRange.hasValue())
291 return Error::success();
292 auto &R = *opts::raw::DumpBlockRange;
293 uint32_t Max = R.Max.getValueOr(R.Min);
294
295 if (Max < R.Min)
296 return make_error<StringError>(
297 "Invalid block range specified. Max < Min",
298 std::make_error_code(std::errc::bad_address));
299 if (Max >= File.getBlockCount())
300 return make_error<StringError>(
301 "Invalid block range specified. Requested block out of bounds",
302 std::make_error_code(std::errc::bad_address));
303
304 DictScope D(P, "Block Data");
305 for (uint32_t I = R.Min; I <= Max; ++I) {
306 auto ExpectedData = File.getBlockData(I, File.getBlockSize());
307 if (!ExpectedData)
308 return ExpectedData.takeError();
309 std::string Label;
310 llvm::raw_string_ostream S(Label);
311 S << "Block " << I;
312 S.flush();
313 P.printBinaryBlock(Label, *ExpectedData);
314 }
315
316 return Error::success();
317}
318
319Error LLVMOutputStyle::dumpStreamBytes() {
320 if (opts::raw::DumpStreamData.empty())
Zachary Turnerd3117392016-06-03 19:28:33 +0000321 return Error::success();
322
Zachary Turner6ac232c2017-03-13 23:28:25 +0000323 if (StreamPurposes.empty())
324 discoverStreamPurposes(File, StreamPurposes);
Zachary Turner36efbfa2016-09-09 19:00:49 +0000325
Zachary Turner72c5b642016-09-09 18:17:52 +0000326 DictScope D(P, "Stream Data");
327 for (uint32_t SI : opts::raw::DumpStreamData) {
328 if (SI >= File.getNumStreams())
329 return make_error<RawError>(raw_error_code::no_stream);
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000330
Zachary Turner72c5b642016-09-09 18:17:52 +0000331 auto S = MappedBlockStream::createIndexedStream(File.getMsfLayout(),
332 File.getMsfBuffer(), SI);
333 if (!S)
334 continue;
Zachary Turner36efbfa2016-09-09 19:00:49 +0000335 DictScope DD(P, "Stream");
336
337 P.printNumber("Index", SI);
338 P.printString("Type", StreamPurposes[SI]);
339 P.printNumber("Size", S->getLength());
340 auto Blocks = File.getMsfLayout().StreamMap[SI];
341 P.printList("Blocks", Blocks);
342
Zachary Turner120faca2017-02-27 22:11:43 +0000343 BinaryStreamReader R(*S);
Zachary Turner72c5b642016-09-09 18:17:52 +0000344 ArrayRef<uint8_t> StreamData;
345 if (auto EC = R.readBytes(StreamData, S->getLength()))
Zachary Turnerd3117392016-06-03 19:28:33 +0000346 return EC;
Zachary Turner36efbfa2016-09-09 19:00:49 +0000347 P.printBinaryBlock("Data", StreamData);
Zachary Turnerd3117392016-06-03 19:28:33 +0000348 }
349 return Error::success();
350}
351
Zachary Turner760ad4d2017-01-20 22:42:09 +0000352Error LLVMOutputStyle::dumpStringTable() {
353 if (!opts::raw::DumpStringTable)
354 return Error::success();
355
356 auto IS = File.getStringTable();
357 if (!IS)
358 return IS.takeError();
359
360 DictScope D(P, "String Table");
361 for (uint32_t I : IS->name_ids()) {
362 StringRef S = IS->getStringForID(I);
363 if (!S.empty()) {
364 llvm::SmallString<32> Str;
365 Str.append("'");
366 Str.append(S);
367 Str.append("'");
368 P.printString(Str);
369 }
370 }
371 return Error::success();
372}
373
Zachary Turnerd3117392016-06-03 19:28:33 +0000374Error LLVMOutputStyle::dumpInfoStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000375 if (!opts::raw::DumpHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000376 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000377 if (!File.hasPDBInfoStream()) {
378 P.printString("PDB Stream not present");
379 return Error::success();
380 }
Zachary Turnera1657a92016-06-08 17:26:39 +0000381 auto IS = File.getPDBInfoStream();
382 if (!IS)
383 return IS.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000384
385 DictScope D(P, "PDB Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000386 P.printNumber("Version", IS->getVersion());
387 P.printHex("Signature", IS->getSignature());
388 P.printNumber("Age", IS->getAge());
389 P.printObject("Guid", IS->getGuid());
Zachary Turner05d5e612017-03-16 20:19:11 +0000390 P.printHex("Features", IS->getFeatures());
Zachary Turner760ad4d2017-01-20 22:42:09 +0000391 {
392 DictScope DD(P, "Named Streams");
393 for (const auto &S : IS->getNamedStreams().entries())
394 P.printObject(S.getKey(), S.getValue());
395 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000396 return Error::success();
397}
398
Zachary Turner29da5db2017-01-25 21:17:40 +0000399namespace {
400class RecordBytesVisitor : public TypeVisitorCallbacks {
401public:
402 explicit RecordBytesVisitor(ScopedPrinter &P) : P(P) {}
403
404 Error visitTypeEnd(CVType &Record) override {
405 P.printBinaryBlock("Bytes", Record.content());
406 return Error::success();
407 }
408
409private:
410 ScopedPrinter &P;
411};
Rui Ueyamafd97bf12016-06-03 20:48:51 +0000412}
413
Zachary Turnerd3117392016-06-03 19:28:33 +0000414Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
415 assert(StreamIdx == StreamTPI || StreamIdx == StreamIPI);
416
417 bool DumpRecordBytes = false;
418 bool DumpRecords = false;
Zachary Turner29da5db2017-01-25 21:17:40 +0000419 bool DumpTpiHash = false;
Zachary Turnerd3117392016-06-03 19:28:33 +0000420 StringRef Label;
421 StringRef VerLabel;
422 if (StreamIdx == StreamTPI) {
Bob Haarmana5b43582016-12-05 22:44:00 +0000423 if (!File.hasPDBTpiStream()) {
424 P.printString("Type Info Stream (TPI) not present");
425 return Error::success();
426 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000427 DumpRecordBytes = opts::raw::DumpTpiRecordBytes;
428 DumpRecords = opts::raw::DumpTpiRecords;
Zachary Turner29da5db2017-01-25 21:17:40 +0000429 DumpTpiHash = opts::raw::DumpTpiHash;
Zachary Turnerd3117392016-06-03 19:28:33 +0000430 Label = "Type Info Stream (TPI)";
431 VerLabel = "TPI Version";
432 } else if (StreamIdx == StreamIPI) {
Bob Haarmana5b43582016-12-05 22:44:00 +0000433 if (!File.hasPDBIpiStream()) {
434 P.printString("Type Info Stream (IPI) not present");
435 return Error::success();
436 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000437 DumpRecordBytes = opts::raw::DumpIpiRecordBytes;
438 DumpRecords = opts::raw::DumpIpiRecords;
Zachary Turnerd3117392016-06-03 19:28:33 +0000439 Label = "Type Info Stream (IPI)";
440 VerLabel = "IPI Version";
441 }
Zachary Turner29da5db2017-01-25 21:17:40 +0000442 if (!DumpRecordBytes && !DumpRecords && !DumpTpiHash &&
443 !opts::raw::DumpModuleSyms)
Zachary Turnerd3117392016-06-03 19:28:33 +0000444 return Error::success();
445
Zachary Turner29da5db2017-01-25 21:17:40 +0000446 bool IsSilentDatabaseBuild = !DumpRecordBytes && !DumpRecords && !DumpTpiHash;
447
Zachary Turnera1657a92016-06-08 17:26:39 +0000448 auto Tpi = (StreamIdx == StreamTPI) ? File.getPDBTpiStream()
449 : File.getPDBIpiStream();
450 if (!Tpi)
451 return Tpi.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000452
Zachary Turner29da5db2017-01-25 21:17:40 +0000453 std::unique_ptr<DictScope> StreamScope;
454 std::unique_ptr<ListScope> RecordScope;
455
456 if (!IsSilentDatabaseBuild) {
457 StreamScope = llvm::make_unique<DictScope>(P, Label);
458 P.printNumber(VerLabel, Tpi->getTpiVersion());
459 P.printNumber("Record count", Tpi->NumTypeRecords());
460 }
461
Reid Klecknera5d187b2017-03-23 21:36:25 +0000462 TypeDatabase &StreamDB = (StreamIdx == StreamTPI) ? TypeDB : ItemDB;
463
464 TypeDatabaseVisitor DBV(StreamDB);
465 CompactTypeDumpVisitor CTDV(StreamDB, &P);
Zachary Turner44a643c2017-01-12 22:28:15 +0000466 TypeDumpVisitor TDV(TypeDB, &P, false);
Reid Klecknera5d187b2017-03-23 21:36:25 +0000467 if (StreamIdx == StreamIPI)
468 TDV.setItemDB(ItemDB);
Zachary Turner29da5db2017-01-25 21:17:40 +0000469 RecordBytesVisitor RBV(P);
Zachary Turner44a643c2017-01-12 22:28:15 +0000470 TypeDeserializer Deserializer;
Zachary Turner29da5db2017-01-25 21:17:40 +0000471
472 // We always need to deserialize and add it to the type database. This is
473 // true if even if we're not dumping anything, because we could need the
474 // type database for the purposes of dumping symbols.
Zachary Turner44a643c2017-01-12 22:28:15 +0000475 TypeVisitorCallbackPipeline Pipeline;
476 Pipeline.addCallbackToPipeline(Deserializer);
477 Pipeline.addCallbackToPipeline(DBV);
478
Zachary Turner29da5db2017-01-25 21:17:40 +0000479 // If we're in dump mode, add a dumper with the appropriate detail level.
480 if (DumpRecords) {
Zachary Turner44a643c2017-01-12 22:28:15 +0000481 if (opts::raw::CompactRecords)
482 Pipeline.addCallbackToPipeline(CTDV);
483 else
484 Pipeline.addCallbackToPipeline(TDV);
Zachary Turnerd3117392016-06-03 19:28:33 +0000485 }
Zachary Turner29da5db2017-01-25 21:17:40 +0000486 if (DumpRecordBytes)
487 Pipeline.addCallbackToPipeline(RBV);
488
489 CVTypeVisitor Visitor(Pipeline);
490
491 if (DumpRecords || DumpRecordBytes)
492 RecordScope = llvm::make_unique<ListScope>(P, "Records");
493
494 bool HadError = false;
495
496 TypeIndex T(TypeIndex::FirstNonSimpleIndex);
497 for (auto Type : Tpi->types(&HadError)) {
498 std::unique_ptr<DictScope> OneRecordScope;
499
500 if ((DumpRecords || DumpRecordBytes) && !opts::raw::CompactRecords)
501 OneRecordScope = llvm::make_unique<DictScope>(P, "");
502
503 if (auto EC = Visitor.visitTypeRecord(Type))
504 return EC;
505 }
506 if (HadError)
507 return make_error<RawError>(raw_error_code::corrupt_file,
508 "TPI stream contained corrupt record");
509
510 if (DumpTpiHash) {
511 DictScope DD(P, "Hash");
512 P.printNumber("Number of Hash Buckets", Tpi->NumHashBuckets());
513 P.printNumber("Hash Key Size", Tpi->getHashKeySize());
514 P.printList("Values", Tpi->getHashValues());
515
516 ListScope LHA(P, "Adjusters");
517 auto ExpectedST = File.getStringTable();
518 if (!ExpectedST)
519 return ExpectedST.takeError();
520 const auto &ST = *ExpectedST;
521 for (const auto &E : Tpi->getHashAdjusters()) {
522 DictScope DHA(P);
523 StringRef Name = ST.getStringForID(E.first);
524 P.printString("Type", Name);
525 P.printHex("TI", E.second);
526 }
527 }
528
529 if (!IsSilentDatabaseBuild) {
530 ListScope L(P, "TypeIndexOffsets");
531 for (const auto &IO : Tpi->getTypeIndexOffsets()) {
532 P.printString(formatv("Index: {0:x}, Offset: {1:N}", IO.Type.getIndex(),
533 (uint32_t)IO.Offset)
534 .str());
535 }
536 }
537
Zachary Turnerd3117392016-06-03 19:28:33 +0000538 P.flush();
539 return Error::success();
540}
541
542Error LLVMOutputStyle::dumpDbiStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000543 bool DumpModules = opts::raw::DumpModules || opts::raw::DumpModuleSyms ||
544 opts::raw::DumpModuleFiles || opts::raw::DumpLineInfo;
545 if (!opts::raw::DumpHeaders && !DumpModules)
Zachary Turnerd3117392016-06-03 19:28:33 +0000546 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000547 if (!File.hasPDBDbiStream()) {
548 P.printString("DBI Stream not present");
549 return Error::success();
550 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000551
Zachary Turnera1657a92016-06-08 17:26:39 +0000552 auto DS = File.getPDBDbiStream();
553 if (!DS)
554 return DS.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000555
556 DictScope D(P, "DBI Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000557 P.printNumber("Dbi Version", DS->getDbiVersion());
558 P.printNumber("Age", DS->getAge());
559 P.printBoolean("Incremental Linking", DS->isIncrementallyLinked());
560 P.printBoolean("Has CTypes", DS->hasCTypes());
561 P.printBoolean("Is Stripped", DS->isStripped());
562 P.printObject("Machine Type", DS->getMachineType());
563 P.printNumber("Symbol Record Stream Index", DS->getSymRecordStreamIndex());
564 P.printNumber("Public Symbol Stream Index", DS->getPublicSymbolStreamIndex());
565 P.printNumber("Global Symbol Stream Index", DS->getGlobalSymbolStreamIndex());
Zachary Turnerd3117392016-06-03 19:28:33 +0000566
Zachary Turnera1657a92016-06-08 17:26:39 +0000567 uint16_t Major = DS->getBuildMajorVersion();
568 uint16_t Minor = DS->getBuildMinorVersion();
Zachary Turnerd3117392016-06-03 19:28:33 +0000569 P.printVersion("Toolchain Version", Major, Minor);
570
571 std::string DllName;
572 raw_string_ostream DllStream(DllName);
573 DllStream << "mspdb" << Major << Minor << ".dll version";
574 DllStream.flush();
Zachary Turnera1657a92016-06-08 17:26:39 +0000575 P.printVersion(DllName, Major, Minor, DS->getPdbDllVersion());
Zachary Turnerd3117392016-06-03 19:28:33 +0000576
577 if (DumpModules) {
578 ListScope L(P, "Modules");
Zachary Turnera1657a92016-06-08 17:26:39 +0000579 for (auto &Modi : DS->modules()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000580 DictScope DD(P);
581 P.printString("Name", Modi.Info.getModuleName().str());
582 P.printNumber("Debug Stream Index", Modi.Info.getModuleStreamIndex());
583 P.printString("Object File Name", Modi.Info.getObjFileName().str());
584 P.printNumber("Num Files", Modi.Info.getNumberOfFiles());
585 P.printNumber("Source File Name Idx", Modi.Info.getSourceFileNameIndex());
586 P.printNumber("Pdb File Name Idx", Modi.Info.getPdbFilePathNameIndex());
587 P.printNumber("Line Info Byte Size", Modi.Info.getLineInfoByteSize());
588 P.printNumber("C13 Line Info Byte Size",
589 Modi.Info.getC13LineInfoByteSize());
590 P.printNumber("Symbol Byte Size", Modi.Info.getSymbolDebugInfoByteSize());
591 P.printNumber("Type Server Index", Modi.Info.getTypeServerIndex());
592 P.printBoolean("Has EC Info", Modi.Info.hasECInfo());
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000593 if (opts::raw::DumpModuleFiles) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000594 std::string FileListName =
595 to_string(Modi.SourceFiles.size()) + " Contributing Source Files";
596 ListScope LL(P, FileListName);
597 for (auto File : Modi.SourceFiles)
598 P.printString(File.str());
599 }
600 bool HasModuleDI =
601 (Modi.Info.getModuleStreamIndex() < File.getNumStreams());
602 bool ShouldDumpSymbols =
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000603 (opts::raw::DumpModuleSyms || opts::raw::DumpSymRecordBytes);
604 if (HasModuleDI && (ShouldDumpSymbols || opts::raw::DumpLineInfo)) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000605 auto ModStreamData = MappedBlockStream::createIndexedStream(
Zachary Turnerd66889c2016-07-28 19:12:28 +0000606 File.getMsfLayout(), File.getMsfBuffer(),
607 Modi.Info.getModuleStreamIndex());
608
Zachary Turner67c56012017-04-27 16:11:19 +0000609 ModuleDebugStream ModS(Modi.Info, std::move(ModStreamData));
Zachary Turnerd3117392016-06-03 19:28:33 +0000610 if (auto EC = ModS.reload())
611 return EC;
612
613 if (ShouldDumpSymbols) {
614 ListScope SS(P, "Symbols");
Zachary Turner629cb7d2017-01-11 23:24:22 +0000615 codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
Zachary Turnerd3117392016-06-03 19:28:33 +0000616 bool HadError = false;
Zachary Turner0d840742016-10-07 21:34:46 +0000617 for (auto S : ModS.symbols(&HadError)) {
618 DictScope LL(P, "");
619 if (opts::raw::DumpModuleSyms) {
620 if (auto EC = SD.dump(S)) {
621 llvm::consumeError(std::move(EC));
622 HadError = true;
623 break;
624 }
625 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000626 if (opts::raw::DumpSymRecordBytes)
Zachary Turnerc67b00c2016-09-14 23:00:16 +0000627 P.printBinaryBlock("Bytes", S.content());
Zachary Turnerd3117392016-06-03 19:28:33 +0000628 }
629 if (HadError)
630 return make_error<RawError>(
631 raw_error_code::corrupt_file,
632 "DBI stream contained corrupt symbol record");
633 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000634 if (opts::raw::DumpLineInfo) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000635 ListScope SS(P, "LineInfo");
636 bool HadError = false;
637 // Define a locally scoped visitor to print the different
638 // substream types types.
Zachary Turner67c56012017-04-27 16:11:19 +0000639 class RecordVisitor : public codeview::ModuleDebugFragmentVisitor {
Zachary Turnerd3117392016-06-03 19:28:33 +0000640 public:
641 RecordVisitor(ScopedPrinter &P, PDBFile &F) : P(P), F(F) {}
Zachary Turner67c56012017-04-27 16:11:19 +0000642 Error visitUnknown(ModuleDebugFragmentKind Kind,
Zachary Turner120faca2017-02-27 22:11:43 +0000643 BinaryStreamRef Stream) override {
Zachary Turnerd3117392016-06-03 19:28:33 +0000644 DictScope DD(P, "Unknown");
645 ArrayRef<uint8_t> Data;
Zachary Turner120faca2017-02-27 22:11:43 +0000646 BinaryStreamReader R(Stream);
Zachary Turnerd3117392016-06-03 19:28:33 +0000647 if (auto EC = R.readBytes(Data, R.bytesRemaining())) {
648 return make_error<RawError>(
649 raw_error_code::corrupt_file,
650 "DBI stream contained corrupt line info record");
651 }
652 P.printBinaryBlock("Data", Data);
653 return Error::success();
654 }
655 Error
Zachary Turner120faca2017-02-27 22:11:43 +0000656 visitFileChecksums(BinaryStreamRef Data,
Zachary Turnerd3117392016-06-03 19:28:33 +0000657 const FileChecksumArray &Checksums) override {
658 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 Turner120faca2017-02-27 22:11:43 +0000672 Error visitLines(BinaryStreamRef Data,
Zachary Turner67c56012017-04-27 16:11:19 +0000673 const LineFragmentHeader *Header,
Zachary Turnerd3117392016-06-03 19:28:33 +0000674 const LineInfoArray &Lines) override {
675 DictScope DD(P, "Lines");
676 for (const auto &L : Lines) {
677 if (auto Result = getFileNameForOffset2(L.NameIndex))
678 P.printString("FileName", Result.get());
679 else
680 return Result.takeError();
681 P.flush();
682 for (const auto &N : L.LineNumbers) {
683 DictScope DDD(P, "Line");
684 LineInfo LI(N.Flags);
685 P.printNumber("Offset", N.Offset);
686 if (LI.isAlwaysStepInto())
687 P.printString("StepInto", StringRef("Always"));
688 else if (LI.isNeverStepInto())
689 P.printString("StepInto", StringRef("Never"));
690 else
691 P.printNumber("LineNumberStart", LI.getStartLine());
692 P.printNumber("EndDelta", LI.getLineDelta());
693 P.printBoolean("IsStatement", LI.isStatement());
694 }
695 for (const auto &C : L.Columns) {
696 DictScope DDD(P, "Column");
697 P.printNumber("Start", C.StartColumn);
698 P.printNumber("End", C.EndColumn);
699 }
700 }
701 return Error::success();
702 }
703
704 private:
705 Expected<StringRef> getFileNameForOffset(uint32_t Offset) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000706 auto ST = F.getStringTable();
707 if (!ST)
708 return ST.takeError();
709
710 return ST->getStringForID(Offset);
Zachary Turnerd3117392016-06-03 19:28:33 +0000711 }
712 Expected<StringRef> getFileNameForOffset2(uint32_t Offset) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000713 auto DS = F.getPDBDbiStream();
714 if (!DS)
715 return DS.takeError();
716 return DS->getFileNameForIndex(Offset);
Zachary Turnerd3117392016-06-03 19:28:33 +0000717 }
718 ScopedPrinter &P;
719 PDBFile &F;
720 };
721
722 RecordVisitor V(P, File);
723 for (const auto &L : ModS.lines(&HadError)) {
Zachary Turner67c56012017-04-27 16:11:19 +0000724 if (auto EC = codeview::visitModuleDebugFragment(L, V))
Zachary Turnerd3117392016-06-03 19:28:33 +0000725 return EC;
726 }
727 }
728 }
729 }
730 }
731 return Error::success();
732}
733
734Error LLVMOutputStyle::dumpSectionContribs() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000735 if (!opts::raw::DumpSectionContribs)
Zachary Turnerd3117392016-06-03 19:28:33 +0000736 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000737 if (!File.hasPDBDbiStream()) {
738 P.printString("DBI Stream not present");
739 return Error::success();
740 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000741
Zachary Turnera1657a92016-06-08 17:26:39 +0000742 auto Dbi = File.getPDBDbiStream();
743 if (!Dbi)
744 return Dbi.takeError();
745
Zachary Turnerd3117392016-06-03 19:28:33 +0000746 ListScope L(P, "Section Contributions");
747 class Visitor : public ISectionContribVisitor {
748 public:
749 Visitor(ScopedPrinter &P, DbiStream &DS) : P(P), DS(DS) {}
750 void visit(const SectionContrib &SC) override {
751 DictScope D(P, "Contribution");
752 P.printNumber("ISect", SC.ISect);
753 P.printNumber("Off", SC.Off);
754 P.printNumber("Size", SC.Size);
755 P.printFlags("Characteristics", SC.Characteristics,
756 codeview::getImageSectionCharacteristicNames(),
757 COFF::SectionCharacteristics(0x00F00000));
758 {
759 DictScope DD(P, "Module");
760 P.printNumber("Index", SC.Imod);
761 auto M = DS.modules();
762 if (M.size() > SC.Imod) {
763 P.printString("Name", M[SC.Imod].Info.getModuleName());
764 }
765 }
766 P.printNumber("Data CRC", SC.DataCrc);
767 P.printNumber("Reloc CRC", SC.RelocCrc);
768 P.flush();
769 }
770 void visit(const SectionContrib2 &SC) override {
771 visit(SC.Base);
772 P.printNumber("ISect Coff", SC.ISectCoff);
773 P.flush();
774 }
775
776 private:
777 ScopedPrinter &P;
778 DbiStream &DS;
779 };
Zachary Turnera1657a92016-06-08 17:26:39 +0000780 Visitor V(P, *Dbi);
781 Dbi->visitSectionContributions(V);
Zachary Turnerd3117392016-06-03 19:28:33 +0000782 return Error::success();
783}
784
785Error LLVMOutputStyle::dumpSectionMap() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000786 if (!opts::raw::DumpSectionMap)
Zachary Turnerd3117392016-06-03 19:28:33 +0000787 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000788 if (!File.hasPDBDbiStream()) {
789 P.printString("DBI Stream not present");
790 return Error::success();
791 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000792
Zachary Turnera1657a92016-06-08 17:26:39 +0000793 auto Dbi = File.getPDBDbiStream();
794 if (!Dbi)
795 return Dbi.takeError();
796
Zachary Turnerd3117392016-06-03 19:28:33 +0000797 ListScope L(P, "Section Map");
Zachary Turnera1657a92016-06-08 17:26:39 +0000798 for (auto &M : Dbi->getSectionMap()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000799 DictScope D(P, "Entry");
800 P.printFlags("Flags", M.Flags, getOMFSegMapDescFlagNames());
Zachary Turnerd3117392016-06-03 19:28:33 +0000801 P.printNumber("Ovl", M.Ovl);
802 P.printNumber("Group", M.Group);
803 P.printNumber("Frame", M.Frame);
804 P.printNumber("SecName", M.SecName);
805 P.printNumber("ClassName", M.ClassName);
806 P.printNumber("Offset", M.Offset);
807 P.printNumber("SecByteLength", M.SecByteLength);
808 P.flush();
809 }
810 return Error::success();
811}
812
813Error LLVMOutputStyle::dumpPublicsStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000814 if (!opts::raw::DumpPublics)
Zachary Turnerd3117392016-06-03 19:28:33 +0000815 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000816 if (!File.hasPDBPublicsStream()) {
817 P.printString("Publics Stream not present");
818 return Error::success();
819 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000820
Zachary Turnera1657a92016-06-08 17:26:39 +0000821 auto Publics = File.getPDBPublicsStream();
822 if (!Publics)
823 return Publics.takeError();
Bob Haarmana5b43582016-12-05 22:44:00 +0000824 DictScope D(P, "Publics Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000825
826 auto Dbi = File.getPDBDbiStream();
827 if (!Dbi)
828 return Dbi.takeError();
829
830 P.printNumber("Stream number", Dbi->getPublicSymbolStreamIndex());
831 P.printNumber("SymHash", Publics->getSymHash());
832 P.printNumber("AddrMap", Publics->getAddrMap());
833 P.printNumber("Number of buckets", Publics->getNumBuckets());
834 P.printList("Hash Buckets", Publics->getHashBuckets());
835 P.printList("Address Map", Publics->getAddressMap());
836 P.printList("Thunk Map", Publics->getThunkMap());
837 P.printList("Section Offsets", Publics->getSectionOffsets(),
Zachary Turnerd3117392016-06-03 19:28:33 +0000838 printSectionOffset);
839 ListScope L(P, "Symbols");
Zachary Turner629cb7d2017-01-11 23:24:22 +0000840 codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
Zachary Turnerd3117392016-06-03 19:28:33 +0000841 bool HadError = false;
Zachary Turnera1657a92016-06-08 17:26:39 +0000842 for (auto S : Publics->getSymbols(&HadError)) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000843 DictScope DD(P, "");
844
Zachary Turner0d840742016-10-07 21:34:46 +0000845 if (auto EC = SD.dump(S)) {
846 HadError = true;
847 break;
848 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000849 if (opts::raw::DumpSymRecordBytes)
Zachary Turnerc67b00c2016-09-14 23:00:16 +0000850 P.printBinaryBlock("Bytes", S.content());
Zachary Turnerd3117392016-06-03 19:28:33 +0000851 }
852 if (HadError)
853 return make_error<RawError>(
854 raw_error_code::corrupt_file,
855 "Public symbol stream contained corrupt record");
856
857 return Error::success();
858}
859
860Error LLVMOutputStyle::dumpSectionHeaders() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000861 if (!opts::raw::DumpSectionHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000862 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000863 if (!File.hasPDBDbiStream()) {
864 P.printString("DBI Stream not present");
865 return Error::success();
866 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000867
Zachary Turnera1657a92016-06-08 17:26:39 +0000868 auto Dbi = File.getPDBDbiStream();
869 if (!Dbi)
870 return Dbi.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000871
872 ListScope D(P, "Section Headers");
Zachary Turnera1657a92016-06-08 17:26:39 +0000873 for (const object::coff_section &Section : Dbi->getSectionHeaders()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000874 DictScope DD(P, "");
875
876 // If a name is 8 characters long, there is no NUL character at end.
877 StringRef Name(Section.Name, strnlen(Section.Name, sizeof(Section.Name)));
878 P.printString("Name", Name);
879 P.printNumber("Virtual Size", Section.VirtualSize);
880 P.printNumber("Virtual Address", Section.VirtualAddress);
881 P.printNumber("Size of Raw Data", Section.SizeOfRawData);
882 P.printNumber("File Pointer to Raw Data", Section.PointerToRawData);
883 P.printNumber("File Pointer to Relocations", Section.PointerToRelocations);
884 P.printNumber("File Pointer to Linenumbers", Section.PointerToLinenumbers);
885 P.printNumber("Number of Relocations", Section.NumberOfRelocations);
886 P.printNumber("Number of Linenumbers", Section.NumberOfLinenumbers);
Rui Ueyama2c5384a2016-06-06 21:34:55 +0000887 P.printFlags("Characteristics", Section.Characteristics,
888 getImageSectionCharacteristicNames());
Zachary Turnerd3117392016-06-03 19:28:33 +0000889 }
890 return Error::success();
891}
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000892
893Error LLVMOutputStyle::dumpFpoStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000894 if (!opts::raw::DumpFpo)
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000895 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000896 if (!File.hasPDBDbiStream()) {
897 P.printString("DBI Stream not present");
898 return Error::success();
899 }
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000900
Zachary Turnera1657a92016-06-08 17:26:39 +0000901 auto Dbi = File.getPDBDbiStream();
902 if (!Dbi)
903 return Dbi.takeError();
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000904
905 ListScope D(P, "New FPO");
Zachary Turnera1657a92016-06-08 17:26:39 +0000906 for (const object::FpoData &Fpo : Dbi->getFpoRecords()) {
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000907 DictScope DD(P, "");
908 P.printNumber("Offset", Fpo.Offset);
909 P.printNumber("Size", Fpo.Size);
910 P.printNumber("Number of locals", Fpo.NumLocals);
911 P.printNumber("Number of params", Fpo.NumParams);
912 P.printNumber("Size of Prolog", Fpo.getPrologSize());
913 P.printNumber("Number of Saved Registers", Fpo.getNumSavedRegs());
914 P.printBoolean("Has SEH", Fpo.hasSEH());
915 P.printBoolean("Use BP", Fpo.useBP());
916 P.printNumber("Frame Pointer", Fpo.getFP());
917 }
918 return Error::success();
919}
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000920
Zachary Turner7120a472016-06-06 20:37:05 +0000921void LLVMOutputStyle::flush() { P.flush(); }