blob: 833cd810468263008c140f9a60187c8715e8a968 [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 Turner5b6e4e02017-04-29 01:13:21 +000012#include "C13DebugFragmentVisitor.h"
Zachary Turner44a643c2017-01-12 22:28:15 +000013#include "CompactTypeDumpVisitor.h"
Zachary Turner6ac232c2017-03-13 23:28:25 +000014#include "StreamUtil.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000015#include "llvm-pdbdump.h"
Zachary Turner44a643c2017-01-12 22:28:15 +000016
Zachary Turner629cb7d2017-01-11 23:24:22 +000017#include "llvm/DebugInfo/CodeView/CVTypeDumper.h"
18#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000019#include "llvm/DebugInfo/CodeView/EnumTables.h"
Zachary Turner5b6e4e02017-04-29 01:13:21 +000020#include "llvm/DebugInfo/CodeView/Line.h"
Zachary Turnerc37cb0c2017-04-27 16:12:16 +000021#include "llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h"
Zachary Turner67c56012017-04-27 16:11:19 +000022#include "llvm/DebugInfo/CodeView/ModuleDebugFragmentVisitor.h"
Zachary Turnerc37cb0c2017-04-27 16:12:16 +000023#include "llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h"
24#include "llvm/DebugInfo/CodeView/ModuleDebugUnknownFragment.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000025#include "llvm/DebugInfo/CodeView/SymbolDumper.h"
Zachary Turner629cb7d2017-01-11 23:24:22 +000026#include "llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h"
27#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
28#include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h"
29#include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h"
Zachary Turnera3225b02016-07-29 20:56:36 +000030#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
Zachary Turner67c56012017-04-27 16:11:19 +000031#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000032#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
33#include "llvm/DebugInfo/PDB/Native/EnumTables.h"
34#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
35#include "llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h"
36#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
Zachary Turner67c56012017-04-27 16:11:19 +000037#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000038#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
39#include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
40#include "llvm/DebugInfo/PDB/Native/RawError.h"
41#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000042#include "llvm/DebugInfo/PDB/PDBExtras.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000043#include "llvm/Object/COFF.h"
Zachary Turnerd9dc2822017-03-02 20:52:51 +000044#include "llvm/Support/BinaryStreamReader.h"
Zachary Turner44a643c2017-01-12 22:28:15 +000045#include "llvm/Support/FormatVariadic.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000046
47#include <unordered_map>
48
49using namespace llvm;
50using namespace llvm::codeview;
Zachary Turnerbac69d32016-07-22 19:56:05 +000051using namespace llvm::msf;
Zachary Turnerd3117392016-06-03 19:28:33 +000052using namespace llvm::pdb;
53
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +000054namespace {
55struct PageStats {
56 explicit PageStats(const BitVector &FreePages)
57 : Upm(FreePages), ActualUsedPages(FreePages.size()),
58 MultiUsePages(FreePages.size()), UseAfterFreePages(FreePages.size()) {
59 const_cast<BitVector &>(Upm).flip();
60 // To calculate orphaned pages, we start with the set of pages that the
61 // MSF thinks are used. Each time we find one that actually *is* used,
62 // we unset it. Whichever bits remain set at the end are orphaned.
63 OrphanedPages = Upm;
64 }
65
66 // The inverse of the MSF File's copy of the Fpm. The basis for which we
67 // determine the allocation status of each page.
68 const BitVector Upm;
69
70 // Pages which are marked as used in the FPM and are used at least once.
71 BitVector ActualUsedPages;
72
73 // Pages which are marked as used in the FPM but are used more than once.
74 BitVector MultiUsePages;
75
76 // Pages which are marked as used in the FPM but are not used at all.
77 BitVector OrphanedPages;
78
79 // Pages which are marked free in the FPM but are used.
80 BitVector UseAfterFreePages;
81};
Zachary Turner5b6e4e02017-04-29 01:13:21 +000082
Zachary Turner5b6e4e02017-04-29 01:13:21 +000083class C13RawVisitor : public C13DebugFragmentVisitor {
84public:
Zachary Turnerdf1d9762017-04-29 05:30:19 +000085 C13RawVisitor(ScopedPrinter &P, PDBFile &F)
86 : C13DebugFragmentVisitor(F), P(P) {}
Zachary Turner5b6e4e02017-04-29 01:13:21 +000087
88 Error handleLines() override {
89 DictScope DD(P, "Lines");
90
91 for (const auto &Fragment : Lines) {
Zachary Turner8a2ebfb2017-05-01 23:27:42 +000092 DictScope DDD(P, "Block");
Zachary Turner5b6e4e02017-04-29 01:13:21 +000093 P.printNumber("RelocSegment", Fragment.header()->RelocSegment);
94 P.printNumber("RelocOffset", Fragment.header()->RelocOffset);
95 P.printNumber("CodeSize", Fragment.header()->CodeSize);
Zachary Turner8a2ebfb2017-05-01 23:27:42 +000096 P.printBoolean("HasColumns", Fragment.hasColumnInfo());
Zachary Turner5b6e4e02017-04-29 01:13:21 +000097
98 for (const auto &L : Fragment) {
99 DictScope DDDD(P, "Lines");
100
101 if (auto EC = printFileName("FileName", L.NameIndex))
102 return EC;
103
104 for (const auto &N : L.LineNumbers) {
105 DictScope DDD(P, "Line");
106 LineInfo LI(N.Flags);
107 P.printNumber("Offset", N.Offset);
108 if (LI.isAlwaysStepInto())
109 P.printString("StepInto", StringRef("Always"));
110 else if (LI.isNeverStepInto())
111 P.printString("StepInto", StringRef("Never"));
112 else
113 P.printNumber("LineNumberStart", LI.getStartLine());
114 P.printNumber("EndDelta", LI.getLineDelta());
115 P.printBoolean("IsStatement", LI.isStatement());
116 }
117 for (const auto &C : L.Columns) {
118 DictScope DDD(P, "Column");
119 P.printNumber("Start", C.StartColumn);
120 P.printNumber("End", C.EndColumn);
121 }
122 }
123 }
124
125 return Error::success();
126 }
127
128 Error handleFileChecksums() override {
129 DictScope DD(P, "FileChecksums");
130 for (const auto &CS : *Checksums) {
131 DictScope DDD(P, "Checksum");
132 if (auto Result = getNameFromStringTable(CS.FileNameOffset))
133 P.printString("FileName", *Result);
134 else
135 return Result.takeError();
136 P.printEnum("Kind", uint8_t(CS.Kind), getFileChecksumNames());
137 P.printBinaryBlock("Checksum", CS.Checksum);
138 }
139 return Error::success();
140 }
141
142private:
143 Error printFileName(StringRef Label, uint32_t Offset) {
144 if (auto Result = getNameFromChecksumsBuffer(Offset)) {
145 P.printString(Label, *Result);
146 return Error::success();
147 } else
148 return Result.takeError();
149 }
150
151 ScopedPrinter &P;
Zachary Turner5b6e4e02017-04-29 01:13:21 +0000152};
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000153}
154
155static void recordKnownUsedPage(PageStats &Stats, uint32_t UsedIndex) {
156 if (Stats.Upm.test(UsedIndex)) {
157 if (Stats.ActualUsedPages.test(UsedIndex))
158 Stats.MultiUsePages.set(UsedIndex);
159 Stats.ActualUsedPages.set(UsedIndex);
160 Stats.OrphanedPages.reset(UsedIndex);
161 } else {
162 // The MSF doesn't think this page is used, but it is.
163 Stats.UseAfterFreePages.set(UsedIndex);
164 }
165}
166
Zachary Turnerd3117392016-06-03 19:28:33 +0000167static void printSectionOffset(llvm::raw_ostream &OS,
168 const SectionOffset &Off) {
169 OS << Off.Off << ", " << Off.Isect;
170}
171
Zachary Turner629cb7d2017-01-11 23:24:22 +0000172LLVMOutputStyle::LLVMOutputStyle(PDBFile &File) : File(File), P(outs()) {}
Zachary Turnerd3117392016-06-03 19:28:33 +0000173
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000174Error LLVMOutputStyle::dump() {
175 if (auto EC = dumpFileHeaders())
176 return EC;
177
178 if (auto EC = dumpStreamSummary())
179 return EC;
180
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000181 if (auto EC = dumpFreePageMap())
182 return EC;
183
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000184 if (auto EC = dumpStreamBlocks())
185 return EC;
186
Zachary Turner72c5b642016-09-09 18:17:52 +0000187 if (auto EC = dumpBlockRanges())
188 return EC;
189
190 if (auto EC = dumpStreamBytes())
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000191 return EC;
192
Zachary Turner760ad4d2017-01-20 22:42:09 +0000193 if (auto EC = dumpStringTable())
194 return EC;
195
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000196 if (auto EC = dumpInfoStream())
197 return EC;
198
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000199 if (auto EC = dumpTpiStream(StreamTPI))
200 return EC;
201
202 if (auto EC = dumpTpiStream(StreamIPI))
203 return EC;
204
205 if (auto EC = dumpDbiStream())
206 return EC;
207
208 if (auto EC = dumpSectionContribs())
209 return EC;
210
211 if (auto EC = dumpSectionMap())
212 return EC;
213
Bob Haarman653baa22016-10-21 19:43:19 +0000214 if (auto EC = dumpGlobalsStream())
215 return EC;
216
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000217 if (auto EC = dumpPublicsStream())
218 return EC;
219
220 if (auto EC = dumpSectionHeaders())
221 return EC;
222
223 if (auto EC = dumpFpoStream())
224 return EC;
225
226 flush();
227
228 return Error::success();
229}
230
Zachary Turnerd3117392016-06-03 19:28:33 +0000231Error LLVMOutputStyle::dumpFileHeaders() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000232 if (!opts::raw::DumpHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000233 return Error::success();
234
235 DictScope D(P, "FileHeaders");
236 P.printNumber("BlockSize", File.getBlockSize());
Zachary Turnerb927e022016-07-15 22:17:19 +0000237 P.printNumber("FreeBlockMap", File.getFreeBlockMapBlock());
Zachary Turnerd3117392016-06-03 19:28:33 +0000238 P.printNumber("NumBlocks", File.getBlockCount());
239 P.printNumber("NumDirectoryBytes", File.getNumDirectoryBytes());
240 P.printNumber("Unknown1", File.getUnknown1());
241 P.printNumber("BlockMapAddr", File.getBlockMapIndex());
242 P.printNumber("NumDirectoryBlocks", File.getNumDirectoryBlocks());
Zachary Turnerd3117392016-06-03 19:28:33 +0000243
244 // The directory is not contiguous. Instead, the block map contains a
245 // contiguous list of block numbers whose contents, when concatenated in
246 // order, make up the directory.
247 P.printList("DirectoryBlocks", File.getDirectoryBlockArray());
248 P.printNumber("NumStreams", File.getNumStreams());
249 return Error::success();
250}
251
Zachary Turner36efbfa2016-09-09 19:00:49 +0000252Error LLVMOutputStyle::dumpStreamSummary() {
253 if (!opts::raw::DumpStreamSummary)
254 return Error::success();
255
Zachary Turner6ac232c2017-03-13 23:28:25 +0000256 if (StreamPurposes.empty())
257 discoverStreamPurposes(File, StreamPurposes);
Zachary Turner36efbfa2016-09-09 19:00:49 +0000258
259 uint32_t StreamCount = File.getNumStreams();
260
261 ListScope L(P, "Streams");
262 for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
263 std::string Label("Stream ");
264 Label += to_string(StreamIdx);
265
266 std::string Value = "[" + StreamPurposes[StreamIdx] + "] (";
267 Value += to_string(File.getStreamByteSize(StreamIdx));
268 Value += " bytes)";
269
270 P.printString(Label, Value);
271 }
Reid Kleckner11582c52016-06-17 20:38:01 +0000272
Zachary Turnerd3117392016-06-03 19:28:33 +0000273 P.flush();
274 return Error::success();
275}
276
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000277Error LLVMOutputStyle::dumpFreePageMap() {
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000278 if (!opts::raw::DumpPageStats)
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000279 return Error::success();
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000280
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000281 // Start with used pages instead of free pages because
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000282 // the number of free pages is far larger than used pages.
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000283 BitVector FPM = File.getMsfLayout().FreePageMap;
284
285 PageStats PS(FPM);
286
287 recordKnownUsedPage(PS, 0); // MSF Super Block
288
Zachary Turner8cf51c32016-08-03 16:53:21 +0000289 uint32_t BlocksPerSection = msf::getFpmIntervalLength(File.getMsfLayout());
290 uint32_t NumSections = msf::getNumFpmIntervals(File.getMsfLayout());
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000291 for (uint32_t I = 0; I < NumSections; ++I) {
292 uint32_t Fpm0 = 1 + BlocksPerSection * I;
293 // 2 Fpm blocks spaced at `getBlockSize()` block intervals
294 recordKnownUsedPage(PS, Fpm0);
295 recordKnownUsedPage(PS, Fpm0 + 1);
296 }
297
298 recordKnownUsedPage(PS, File.getBlockMapIndex()); // Stream Table
299
Rui Ueyama22e67382016-08-02 23:22:46 +0000300 for (auto DB : File.getDirectoryBlockArray())
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000301 recordKnownUsedPage(PS, DB);
Rui Ueyama22e67382016-08-02 23:22:46 +0000302
303 // Record pages used by streams. Note that pages for stream 0
304 // are considered being unused because that's what MSVC tools do.
305 // Stream 0 doesn't contain actual data, so it makes some sense,
306 // though it's a bit confusing to us.
307 for (auto &SE : File.getStreamMap().drop_front(1))
308 for (auto &S : SE)
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000309 recordKnownUsedPage(PS, S);
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000310
311 dumpBitVector("Msf Free Pages", FPM);
312 dumpBitVector("Orphaned Pages", PS.OrphanedPages);
313 dumpBitVector("Multiply Used Pages", PS.MultiUsePages);
314 dumpBitVector("Use After Free Pages", PS.UseAfterFreePages);
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000315 return Error::success();
316}
317
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000318void LLVMOutputStyle::dumpBitVector(StringRef Name, const BitVector &V) {
319 std::vector<uint32_t> Vec;
320 for (uint32_t I = 0, E = V.size(); I != E; ++I)
321 if (V[I])
322 Vec.push_back(I);
323 P.printList(Name, Vec);
324}
325
Bob Haarman653baa22016-10-21 19:43:19 +0000326Error LLVMOutputStyle::dumpGlobalsStream() {
327 if (!opts::raw::DumpGlobals)
328 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000329 if (!File.hasPDBGlobalsStream()) {
330 P.printString("Globals Stream not present");
331 return Error::success();
332 }
Bob Haarman653baa22016-10-21 19:43:19 +0000333
Bob Haarman653baa22016-10-21 19:43:19 +0000334 auto Globals = File.getPDBGlobalsStream();
335 if (!Globals)
Bob Haarman312fd0e2016-12-06 00:55:55 +0000336 return Globals.takeError();
Bob Haarmana5b43582016-12-05 22:44:00 +0000337 DictScope D(P, "Globals Stream");
Bob Haarman653baa22016-10-21 19:43:19 +0000338
339 auto Dbi = File.getPDBDbiStream();
340 if (!Dbi)
341 return Dbi.takeError();
342
343 P.printNumber("Stream number", Dbi->getGlobalSymbolStreamIndex());
344 P.printNumber("Number of buckets", Globals->getNumBuckets());
345 P.printList("Hash Buckets", Globals->getHashBuckets());
346
347 return Error::success();
348}
349
Zachary Turnerd3117392016-06-03 19:28:33 +0000350Error LLVMOutputStyle::dumpStreamBlocks() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000351 if (!opts::raw::DumpStreamBlocks)
Zachary Turnerd3117392016-06-03 19:28:33 +0000352 return Error::success();
353
354 ListScope L(P, "StreamBlocks");
355 uint32_t StreamCount = File.getNumStreams();
356 for (uint32_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
357 std::string Name("Stream ");
358 Name += to_string(StreamIdx);
359 auto StreamBlocks = File.getStreamBlockList(StreamIdx);
360 P.printList(Name, StreamBlocks);
361 }
362 return Error::success();
363}
364
Zachary Turner72c5b642016-09-09 18:17:52 +0000365Error LLVMOutputStyle::dumpBlockRanges() {
366 if (!opts::raw::DumpBlockRange.hasValue())
367 return Error::success();
368 auto &R = *opts::raw::DumpBlockRange;
369 uint32_t Max = R.Max.getValueOr(R.Min);
370
371 if (Max < R.Min)
372 return make_error<StringError>(
373 "Invalid block range specified. Max < Min",
374 std::make_error_code(std::errc::bad_address));
375 if (Max >= File.getBlockCount())
376 return make_error<StringError>(
377 "Invalid block range specified. Requested block out of bounds",
378 std::make_error_code(std::errc::bad_address));
379
380 DictScope D(P, "Block Data");
381 for (uint32_t I = R.Min; I <= Max; ++I) {
382 auto ExpectedData = File.getBlockData(I, File.getBlockSize());
383 if (!ExpectedData)
384 return ExpectedData.takeError();
385 std::string Label;
386 llvm::raw_string_ostream S(Label);
387 S << "Block " << I;
388 S.flush();
389 P.printBinaryBlock(Label, *ExpectedData);
390 }
391
392 return Error::success();
393}
394
Zachary Turner7159ab92017-04-28 00:43:38 +0000395static Error parseStreamSpec(StringRef Str, uint32_t &SI, uint32_t &Offset,
396 uint32_t &Size) {
397 if (Str.consumeInteger(0, SI))
398 return make_error<RawError>(raw_error_code::invalid_format,
399 "Invalid Stream Specification");
400 if (Str.consume_front(":")) {
401 if (Str.consumeInteger(0, Offset))
402 return make_error<RawError>(raw_error_code::invalid_format,
403 "Invalid Stream Specification");
404 }
405 if (Str.consume_front("@")) {
406 if (Str.consumeInteger(0, Size))
407 return make_error<RawError>(raw_error_code::invalid_format,
408 "Invalid Stream Specification");
409 }
410 if (!Str.empty())
411 return make_error<RawError>(raw_error_code::invalid_format,
412 "Invalid Stream Specification");
413 return Error::success();
414}
415
Zachary Turner72c5b642016-09-09 18:17:52 +0000416Error LLVMOutputStyle::dumpStreamBytes() {
417 if (opts::raw::DumpStreamData.empty())
Zachary Turnerd3117392016-06-03 19:28:33 +0000418 return Error::success();
419
Zachary Turner6ac232c2017-03-13 23:28:25 +0000420 if (StreamPurposes.empty())
421 discoverStreamPurposes(File, StreamPurposes);
Zachary Turner36efbfa2016-09-09 19:00:49 +0000422
Zachary Turner72c5b642016-09-09 18:17:52 +0000423 DictScope D(P, "Stream Data");
Zachary Turner7159ab92017-04-28 00:43:38 +0000424 for (auto &Str : opts::raw::DumpStreamData) {
425 uint32_t SI = 0;
426 uint32_t Begin = 0;
427 uint32_t Size = 0;
428 uint32_t End = 0;
429
430 if (auto EC = parseStreamSpec(Str, SI, Begin, Size))
431 return EC;
432
Zachary Turner72c5b642016-09-09 18:17:52 +0000433 if (SI >= File.getNumStreams())
434 return make_error<RawError>(raw_error_code::no_stream);
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000435
Zachary Turner72c5b642016-09-09 18:17:52 +0000436 auto S = MappedBlockStream::createIndexedStream(File.getMsfLayout(),
437 File.getMsfBuffer(), SI);
438 if (!S)
439 continue;
Zachary Turner36efbfa2016-09-09 19:00:49 +0000440 DictScope DD(P, "Stream");
Zachary Turner7159ab92017-04-28 00:43:38 +0000441 if (Size == 0)
442 End = S->getLength();
443 else {
444 End = Begin + Size;
445 if (End >= S->getLength())
446 return make_error<RawError>(raw_error_code::index_out_of_bounds,
447 "Stream is not long enough!");
448 }
Zachary Turner36efbfa2016-09-09 19:00:49 +0000449
450 P.printNumber("Index", SI);
451 P.printString("Type", StreamPurposes[SI]);
452 P.printNumber("Size", S->getLength());
453 auto Blocks = File.getMsfLayout().StreamMap[SI];
454 P.printList("Blocks", Blocks);
455
Zachary Turner120faca2017-02-27 22:11:43 +0000456 BinaryStreamReader R(*S);
Zachary Turner72c5b642016-09-09 18:17:52 +0000457 ArrayRef<uint8_t> StreamData;
458 if (auto EC = R.readBytes(StreamData, S->getLength()))
Zachary Turnerd3117392016-06-03 19:28:33 +0000459 return EC;
Zachary Turner7159ab92017-04-28 00:43:38 +0000460 Size = End - Begin;
461 StreamData = StreamData.slice(Begin, Size);
462 P.printBinaryBlock("Data", StreamData, Begin);
Zachary Turnerd3117392016-06-03 19:28:33 +0000463 }
464 return Error::success();
465}
466
Zachary Turner760ad4d2017-01-20 22:42:09 +0000467Error LLVMOutputStyle::dumpStringTable() {
468 if (!opts::raw::DumpStringTable)
469 return Error::success();
470
471 auto IS = File.getStringTable();
472 if (!IS)
473 return IS.takeError();
474
475 DictScope D(P, "String Table");
476 for (uint32_t I : IS->name_ids()) {
477 StringRef S = IS->getStringForID(I);
478 if (!S.empty()) {
479 llvm::SmallString<32> Str;
480 Str.append("'");
481 Str.append(S);
482 Str.append("'");
483 P.printString(Str);
484 }
485 }
486 return Error::success();
487}
488
Zachary Turnerd3117392016-06-03 19:28:33 +0000489Error LLVMOutputStyle::dumpInfoStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000490 if (!opts::raw::DumpHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000491 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000492 if (!File.hasPDBInfoStream()) {
493 P.printString("PDB Stream not present");
494 return Error::success();
495 }
Zachary Turnera1657a92016-06-08 17:26:39 +0000496 auto IS = File.getPDBInfoStream();
497 if (!IS)
498 return IS.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000499
500 DictScope D(P, "PDB Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000501 P.printNumber("Version", IS->getVersion());
502 P.printHex("Signature", IS->getSignature());
503 P.printNumber("Age", IS->getAge());
504 P.printObject("Guid", IS->getGuid());
Zachary Turner05d5e612017-03-16 20:19:11 +0000505 P.printHex("Features", IS->getFeatures());
Zachary Turner760ad4d2017-01-20 22:42:09 +0000506 {
507 DictScope DD(P, "Named Streams");
508 for (const auto &S : IS->getNamedStreams().entries())
509 P.printObject(S.getKey(), S.getValue());
510 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000511 return Error::success();
512}
513
Zachary Turner29da5db2017-01-25 21:17:40 +0000514namespace {
515class RecordBytesVisitor : public TypeVisitorCallbacks {
516public:
517 explicit RecordBytesVisitor(ScopedPrinter &P) : P(P) {}
518
519 Error visitTypeEnd(CVType &Record) override {
520 P.printBinaryBlock("Bytes", Record.content());
521 return Error::success();
522 }
523
524private:
525 ScopedPrinter &P;
526};
Rui Ueyamafd97bf12016-06-03 20:48:51 +0000527}
528
Zachary Turnerd3117392016-06-03 19:28:33 +0000529Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
530 assert(StreamIdx == StreamTPI || StreamIdx == StreamIPI);
531
532 bool DumpRecordBytes = false;
533 bool DumpRecords = false;
Zachary Turner29da5db2017-01-25 21:17:40 +0000534 bool DumpTpiHash = false;
Zachary Turnerd3117392016-06-03 19:28:33 +0000535 StringRef Label;
536 StringRef VerLabel;
537 if (StreamIdx == StreamTPI) {
Bob Haarmana5b43582016-12-05 22:44:00 +0000538 if (!File.hasPDBTpiStream()) {
539 P.printString("Type Info Stream (TPI) not present");
540 return Error::success();
541 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000542 DumpRecordBytes = opts::raw::DumpTpiRecordBytes;
543 DumpRecords = opts::raw::DumpTpiRecords;
Zachary Turner29da5db2017-01-25 21:17:40 +0000544 DumpTpiHash = opts::raw::DumpTpiHash;
Zachary Turnerd3117392016-06-03 19:28:33 +0000545 Label = "Type Info Stream (TPI)";
546 VerLabel = "TPI Version";
547 } else if (StreamIdx == StreamIPI) {
Bob Haarmana5b43582016-12-05 22:44:00 +0000548 if (!File.hasPDBIpiStream()) {
549 P.printString("Type Info Stream (IPI) not present");
550 return Error::success();
551 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000552 DumpRecordBytes = opts::raw::DumpIpiRecordBytes;
553 DumpRecords = opts::raw::DumpIpiRecords;
Zachary Turnerd3117392016-06-03 19:28:33 +0000554 Label = "Type Info Stream (IPI)";
555 VerLabel = "IPI Version";
556 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000557
Zachary Turner29da5db2017-01-25 21:17:40 +0000558 bool IsSilentDatabaseBuild = !DumpRecordBytes && !DumpRecords && !DumpTpiHash;
Zachary Turner5b6e4e02017-04-29 01:13:21 +0000559 if (IsSilentDatabaseBuild) {
Zachary Turner8a2ebfb2017-05-01 23:27:42 +0000560 outs().flush();
Zachary Turner5b6e4e02017-04-29 01:13:21 +0000561 errs() << "Building Type Information For " << Label << "\n";
562 }
Zachary Turner29da5db2017-01-25 21:17:40 +0000563
Zachary Turnera1657a92016-06-08 17:26:39 +0000564 auto Tpi = (StreamIdx == StreamTPI) ? File.getPDBTpiStream()
565 : File.getPDBIpiStream();
566 if (!Tpi)
567 return Tpi.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000568
Zachary Turner29da5db2017-01-25 21:17:40 +0000569 std::unique_ptr<DictScope> StreamScope;
570 std::unique_ptr<ListScope> RecordScope;
571
572 if (!IsSilentDatabaseBuild) {
573 StreamScope = llvm::make_unique<DictScope>(P, Label);
574 P.printNumber(VerLabel, Tpi->getTpiVersion());
575 P.printNumber("Record count", Tpi->NumTypeRecords());
576 }
577
Reid Klecknera5d187b2017-03-23 21:36:25 +0000578 TypeDatabase &StreamDB = (StreamIdx == StreamTPI) ? TypeDB : ItemDB;
579
580 TypeDatabaseVisitor DBV(StreamDB);
581 CompactTypeDumpVisitor CTDV(StreamDB, &P);
Zachary Turner44a643c2017-01-12 22:28:15 +0000582 TypeDumpVisitor TDV(TypeDB, &P, false);
Reid Klecknera5d187b2017-03-23 21:36:25 +0000583 if (StreamIdx == StreamIPI)
584 TDV.setItemDB(ItemDB);
Zachary Turner29da5db2017-01-25 21:17:40 +0000585 RecordBytesVisitor RBV(P);
Zachary Turner44a643c2017-01-12 22:28:15 +0000586 TypeDeserializer Deserializer;
Zachary Turner29da5db2017-01-25 21:17:40 +0000587
588 // We always need to deserialize and add it to the type database. This is
589 // true if even if we're not dumping anything, because we could need the
590 // type database for the purposes of dumping symbols.
Zachary Turner44a643c2017-01-12 22:28:15 +0000591 TypeVisitorCallbackPipeline Pipeline;
592 Pipeline.addCallbackToPipeline(Deserializer);
593 Pipeline.addCallbackToPipeline(DBV);
594
Zachary Turner29da5db2017-01-25 21:17:40 +0000595 // If we're in dump mode, add a dumper with the appropriate detail level.
596 if (DumpRecords) {
Zachary Turner44a643c2017-01-12 22:28:15 +0000597 if (opts::raw::CompactRecords)
598 Pipeline.addCallbackToPipeline(CTDV);
599 else
600 Pipeline.addCallbackToPipeline(TDV);
Zachary Turnerd3117392016-06-03 19:28:33 +0000601 }
Zachary Turner29da5db2017-01-25 21:17:40 +0000602 if (DumpRecordBytes)
603 Pipeline.addCallbackToPipeline(RBV);
604
605 CVTypeVisitor Visitor(Pipeline);
606
607 if (DumpRecords || DumpRecordBytes)
608 RecordScope = llvm::make_unique<ListScope>(P, "Records");
609
610 bool HadError = false;
611
612 TypeIndex T(TypeIndex::FirstNonSimpleIndex);
613 for (auto Type : Tpi->types(&HadError)) {
614 std::unique_ptr<DictScope> OneRecordScope;
615
616 if ((DumpRecords || DumpRecordBytes) && !opts::raw::CompactRecords)
617 OneRecordScope = llvm::make_unique<DictScope>(P, "");
618
619 if (auto EC = Visitor.visitTypeRecord(Type))
620 return EC;
621 }
622 if (HadError)
623 return make_error<RawError>(raw_error_code::corrupt_file,
624 "TPI stream contained corrupt record");
625
626 if (DumpTpiHash) {
627 DictScope DD(P, "Hash");
628 P.printNumber("Number of Hash Buckets", Tpi->NumHashBuckets());
629 P.printNumber("Hash Key Size", Tpi->getHashKeySize());
630 P.printList("Values", Tpi->getHashValues());
631
632 ListScope LHA(P, "Adjusters");
633 auto ExpectedST = File.getStringTable();
634 if (!ExpectedST)
635 return ExpectedST.takeError();
636 const auto &ST = *ExpectedST;
637 for (const auto &E : Tpi->getHashAdjusters()) {
638 DictScope DHA(P);
639 StringRef Name = ST.getStringForID(E.first);
640 P.printString("Type", Name);
641 P.printHex("TI", E.second);
642 }
643 }
644
645 if (!IsSilentDatabaseBuild) {
646 ListScope L(P, "TypeIndexOffsets");
647 for (const auto &IO : Tpi->getTypeIndexOffsets()) {
648 P.printString(formatv("Index: {0:x}, Offset: {1:N}", IO.Type.getIndex(),
649 (uint32_t)IO.Offset)
650 .str());
651 }
652 }
653
Zachary Turnerd3117392016-06-03 19:28:33 +0000654 P.flush();
655 return Error::success();
656}
657
658Error LLVMOutputStyle::dumpDbiStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000659 bool DumpModules = opts::raw::DumpModules || opts::raw::DumpModuleSyms ||
660 opts::raw::DumpModuleFiles || opts::raw::DumpLineInfo;
661 if (!opts::raw::DumpHeaders && !DumpModules)
Zachary Turnerd3117392016-06-03 19:28:33 +0000662 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000663 if (!File.hasPDBDbiStream()) {
664 P.printString("DBI Stream not present");
665 return Error::success();
666 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000667
Zachary Turnera1657a92016-06-08 17:26:39 +0000668 auto DS = File.getPDBDbiStream();
669 if (!DS)
670 return DS.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000671
672 DictScope D(P, "DBI Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000673 P.printNumber("Dbi Version", DS->getDbiVersion());
674 P.printNumber("Age", DS->getAge());
675 P.printBoolean("Incremental Linking", DS->isIncrementallyLinked());
676 P.printBoolean("Has CTypes", DS->hasCTypes());
677 P.printBoolean("Is Stripped", DS->isStripped());
678 P.printObject("Machine Type", DS->getMachineType());
679 P.printNumber("Symbol Record Stream Index", DS->getSymRecordStreamIndex());
680 P.printNumber("Public Symbol Stream Index", DS->getPublicSymbolStreamIndex());
681 P.printNumber("Global Symbol Stream Index", DS->getGlobalSymbolStreamIndex());
Zachary Turnerd3117392016-06-03 19:28:33 +0000682
Zachary Turnera1657a92016-06-08 17:26:39 +0000683 uint16_t Major = DS->getBuildMajorVersion();
684 uint16_t Minor = DS->getBuildMinorVersion();
Zachary Turnerd3117392016-06-03 19:28:33 +0000685 P.printVersion("Toolchain Version", Major, Minor);
686
687 std::string DllName;
688 raw_string_ostream DllStream(DllName);
689 DllStream << "mspdb" << Major << Minor << ".dll version";
690 DllStream.flush();
Zachary Turnera1657a92016-06-08 17:26:39 +0000691 P.printVersion(DllName, Major, Minor, DS->getPdbDllVersion());
Zachary Turnerd3117392016-06-03 19:28:33 +0000692
693 if (DumpModules) {
694 ListScope L(P, "Modules");
Zachary Turnera1657a92016-06-08 17:26:39 +0000695 for (auto &Modi : DS->modules()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000696 DictScope DD(P);
697 P.printString("Name", Modi.Info.getModuleName().str());
698 P.printNumber("Debug Stream Index", Modi.Info.getModuleStreamIndex());
699 P.printString("Object File Name", Modi.Info.getObjFileName().str());
700 P.printNumber("Num Files", Modi.Info.getNumberOfFiles());
701 P.printNumber("Source File Name Idx", Modi.Info.getSourceFileNameIndex());
702 P.printNumber("Pdb File Name Idx", Modi.Info.getPdbFilePathNameIndex());
Zachary Turner5b6e4e02017-04-29 01:13:21 +0000703 P.printNumber("Line Info Byte Size", Modi.Info.getC11LineInfoByteSize());
Zachary Turnerd3117392016-06-03 19:28:33 +0000704 P.printNumber("C13 Line Info Byte Size",
705 Modi.Info.getC13LineInfoByteSize());
706 P.printNumber("Symbol Byte Size", Modi.Info.getSymbolDebugInfoByteSize());
707 P.printNumber("Type Server Index", Modi.Info.getTypeServerIndex());
708 P.printBoolean("Has EC Info", Modi.Info.hasECInfo());
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000709 if (opts::raw::DumpModuleFiles) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000710 std::string FileListName =
711 to_string(Modi.SourceFiles.size()) + " Contributing Source Files";
712 ListScope LL(P, FileListName);
713 for (auto File : Modi.SourceFiles)
714 P.printString(File.str());
715 }
716 bool HasModuleDI =
717 (Modi.Info.getModuleStreamIndex() < File.getNumStreams());
718 bool ShouldDumpSymbols =
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000719 (opts::raw::DumpModuleSyms || opts::raw::DumpSymRecordBytes);
720 if (HasModuleDI && (ShouldDumpSymbols || opts::raw::DumpLineInfo)) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000721 auto ModStreamData = MappedBlockStream::createIndexedStream(
Zachary Turnerd66889c2016-07-28 19:12:28 +0000722 File.getMsfLayout(), File.getMsfBuffer(),
723 Modi.Info.getModuleStreamIndex());
724
Zachary Turner7cc13e52017-05-01 16:46:39 +0000725 ModuleDebugStreamRef ModS(Modi.Info, std::move(ModStreamData));
Zachary Turnerd3117392016-06-03 19:28:33 +0000726 if (auto EC = ModS.reload())
727 return EC;
728
729 if (ShouldDumpSymbols) {
730 ListScope SS(P, "Symbols");
Zachary Turner629cb7d2017-01-11 23:24:22 +0000731 codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
Zachary Turnerd3117392016-06-03 19:28:33 +0000732 bool HadError = false;
Zachary Turner0d840742016-10-07 21:34:46 +0000733 for (auto S : ModS.symbols(&HadError)) {
734 DictScope LL(P, "");
735 if (opts::raw::DumpModuleSyms) {
736 if (auto EC = SD.dump(S)) {
737 llvm::consumeError(std::move(EC));
738 HadError = true;
739 break;
740 }
741 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000742 if (opts::raw::DumpSymRecordBytes)
Zachary Turnerc67b00c2016-09-14 23:00:16 +0000743 P.printBinaryBlock("Bytes", S.content());
Zachary Turnerd3117392016-06-03 19:28:33 +0000744 }
745 if (HadError)
746 return make_error<RawError>(
747 raw_error_code::corrupt_file,
748 "DBI stream contained corrupt symbol record");
749 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000750 if (opts::raw::DumpLineInfo) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000751 ListScope SS(P, "LineInfo");
Zachary Turnerd3117392016-06-03 19:28:33 +0000752
Zachary Turnerdf1d9762017-04-29 05:30:19 +0000753 C13RawVisitor V(P, File);
Zachary Turner5b6e4e02017-04-29 01:13:21 +0000754 if (auto EC = codeview::visitModuleDebugFragments(
755 ModS.linesAndChecksums(), V))
756 return EC;
Zachary Turnerd3117392016-06-03 19:28:33 +0000757 }
758 }
759 }
760 }
761 return Error::success();
762}
763
764Error LLVMOutputStyle::dumpSectionContribs() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000765 if (!opts::raw::DumpSectionContribs)
Zachary Turnerd3117392016-06-03 19:28:33 +0000766 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000767 if (!File.hasPDBDbiStream()) {
768 P.printString("DBI Stream not present");
769 return Error::success();
770 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000771
Zachary Turnera1657a92016-06-08 17:26:39 +0000772 auto Dbi = File.getPDBDbiStream();
773 if (!Dbi)
774 return Dbi.takeError();
775
Zachary Turnerd3117392016-06-03 19:28:33 +0000776 ListScope L(P, "Section Contributions");
777 class Visitor : public ISectionContribVisitor {
778 public:
779 Visitor(ScopedPrinter &P, DbiStream &DS) : P(P), DS(DS) {}
780 void visit(const SectionContrib &SC) override {
781 DictScope D(P, "Contribution");
782 P.printNumber("ISect", SC.ISect);
783 P.printNumber("Off", SC.Off);
784 P.printNumber("Size", SC.Size);
785 P.printFlags("Characteristics", SC.Characteristics,
786 codeview::getImageSectionCharacteristicNames(),
787 COFF::SectionCharacteristics(0x00F00000));
788 {
789 DictScope DD(P, "Module");
790 P.printNumber("Index", SC.Imod);
791 auto M = DS.modules();
792 if (M.size() > SC.Imod) {
793 P.printString("Name", M[SC.Imod].Info.getModuleName());
794 }
795 }
796 P.printNumber("Data CRC", SC.DataCrc);
797 P.printNumber("Reloc CRC", SC.RelocCrc);
798 P.flush();
799 }
800 void visit(const SectionContrib2 &SC) override {
801 visit(SC.Base);
802 P.printNumber("ISect Coff", SC.ISectCoff);
803 P.flush();
804 }
805
806 private:
807 ScopedPrinter &P;
808 DbiStream &DS;
809 };
Zachary Turnera1657a92016-06-08 17:26:39 +0000810 Visitor V(P, *Dbi);
811 Dbi->visitSectionContributions(V);
Zachary Turnerd3117392016-06-03 19:28:33 +0000812 return Error::success();
813}
814
815Error LLVMOutputStyle::dumpSectionMap() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000816 if (!opts::raw::DumpSectionMap)
Zachary Turnerd3117392016-06-03 19:28:33 +0000817 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000818 if (!File.hasPDBDbiStream()) {
819 P.printString("DBI Stream not present");
820 return Error::success();
821 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000822
Zachary Turnera1657a92016-06-08 17:26:39 +0000823 auto Dbi = File.getPDBDbiStream();
824 if (!Dbi)
825 return Dbi.takeError();
826
Zachary Turnerd3117392016-06-03 19:28:33 +0000827 ListScope L(P, "Section Map");
Zachary Turnera1657a92016-06-08 17:26:39 +0000828 for (auto &M : Dbi->getSectionMap()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000829 DictScope D(P, "Entry");
830 P.printFlags("Flags", M.Flags, getOMFSegMapDescFlagNames());
Zachary Turnerd3117392016-06-03 19:28:33 +0000831 P.printNumber("Ovl", M.Ovl);
832 P.printNumber("Group", M.Group);
833 P.printNumber("Frame", M.Frame);
834 P.printNumber("SecName", M.SecName);
835 P.printNumber("ClassName", M.ClassName);
836 P.printNumber("Offset", M.Offset);
837 P.printNumber("SecByteLength", M.SecByteLength);
838 P.flush();
839 }
840 return Error::success();
841}
842
843Error LLVMOutputStyle::dumpPublicsStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000844 if (!opts::raw::DumpPublics)
Zachary Turnerd3117392016-06-03 19:28:33 +0000845 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000846 if (!File.hasPDBPublicsStream()) {
847 P.printString("Publics Stream not present");
848 return Error::success();
849 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000850
Zachary Turnera1657a92016-06-08 17:26:39 +0000851 auto Publics = File.getPDBPublicsStream();
852 if (!Publics)
853 return Publics.takeError();
Bob Haarmana5b43582016-12-05 22:44:00 +0000854 DictScope D(P, "Publics Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000855
856 auto Dbi = File.getPDBDbiStream();
857 if (!Dbi)
858 return Dbi.takeError();
859
860 P.printNumber("Stream number", Dbi->getPublicSymbolStreamIndex());
861 P.printNumber("SymHash", Publics->getSymHash());
862 P.printNumber("AddrMap", Publics->getAddrMap());
863 P.printNumber("Number of buckets", Publics->getNumBuckets());
864 P.printList("Hash Buckets", Publics->getHashBuckets());
865 P.printList("Address Map", Publics->getAddressMap());
866 P.printList("Thunk Map", Publics->getThunkMap());
867 P.printList("Section Offsets", Publics->getSectionOffsets(),
Zachary Turnerd3117392016-06-03 19:28:33 +0000868 printSectionOffset);
869 ListScope L(P, "Symbols");
Zachary Turner629cb7d2017-01-11 23:24:22 +0000870 codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
Zachary Turnerd3117392016-06-03 19:28:33 +0000871 bool HadError = false;
Zachary Turnera1657a92016-06-08 17:26:39 +0000872 for (auto S : Publics->getSymbols(&HadError)) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000873 DictScope DD(P, "");
874
Zachary Turner0d840742016-10-07 21:34:46 +0000875 if (auto EC = SD.dump(S)) {
876 HadError = true;
877 break;
878 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000879 if (opts::raw::DumpSymRecordBytes)
Zachary Turnerc67b00c2016-09-14 23:00:16 +0000880 P.printBinaryBlock("Bytes", S.content());
Zachary Turnerd3117392016-06-03 19:28:33 +0000881 }
882 if (HadError)
883 return make_error<RawError>(
884 raw_error_code::corrupt_file,
885 "Public symbol stream contained corrupt record");
886
887 return Error::success();
888}
889
890Error LLVMOutputStyle::dumpSectionHeaders() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000891 if (!opts::raw::DumpSectionHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000892 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000893 if (!File.hasPDBDbiStream()) {
894 P.printString("DBI Stream not present");
895 return Error::success();
896 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000897
Zachary Turnera1657a92016-06-08 17:26:39 +0000898 auto Dbi = File.getPDBDbiStream();
899 if (!Dbi)
900 return Dbi.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000901
902 ListScope D(P, "Section Headers");
Zachary Turnera1657a92016-06-08 17:26:39 +0000903 for (const object::coff_section &Section : Dbi->getSectionHeaders()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000904 DictScope DD(P, "");
905
906 // If a name is 8 characters long, there is no NUL character at end.
907 StringRef Name(Section.Name, strnlen(Section.Name, sizeof(Section.Name)));
908 P.printString("Name", Name);
909 P.printNumber("Virtual Size", Section.VirtualSize);
910 P.printNumber("Virtual Address", Section.VirtualAddress);
911 P.printNumber("Size of Raw Data", Section.SizeOfRawData);
912 P.printNumber("File Pointer to Raw Data", Section.PointerToRawData);
913 P.printNumber("File Pointer to Relocations", Section.PointerToRelocations);
914 P.printNumber("File Pointer to Linenumbers", Section.PointerToLinenumbers);
915 P.printNumber("Number of Relocations", Section.NumberOfRelocations);
916 P.printNumber("Number of Linenumbers", Section.NumberOfLinenumbers);
Rui Ueyama2c5384a2016-06-06 21:34:55 +0000917 P.printFlags("Characteristics", Section.Characteristics,
918 getImageSectionCharacteristicNames());
Zachary Turnerd3117392016-06-03 19:28:33 +0000919 }
920 return Error::success();
921}
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000922
923Error LLVMOutputStyle::dumpFpoStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000924 if (!opts::raw::DumpFpo)
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000925 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000926 if (!File.hasPDBDbiStream()) {
927 P.printString("DBI Stream not present");
928 return Error::success();
929 }
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000930
Zachary Turnera1657a92016-06-08 17:26:39 +0000931 auto Dbi = File.getPDBDbiStream();
932 if (!Dbi)
933 return Dbi.takeError();
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000934
935 ListScope D(P, "New FPO");
Zachary Turnera1657a92016-06-08 17:26:39 +0000936 for (const object::FpoData &Fpo : Dbi->getFpoRecords()) {
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000937 DictScope DD(P, "");
938 P.printNumber("Offset", Fpo.Offset);
939 P.printNumber("Size", Fpo.Size);
940 P.printNumber("Number of locals", Fpo.NumLocals);
941 P.printNumber("Number of params", Fpo.NumParams);
942 P.printNumber("Size of Prolog", Fpo.getPrologSize());
943 P.printNumber("Number of Saved Registers", Fpo.getNumSavedRegs());
944 P.printBoolean("Has SEH", Fpo.hasSEH());
945 P.printBoolean("Use BP", Fpo.useBP());
946 P.printNumber("Frame Pointer", Fpo.getFP());
947 }
948 return Error::success();
949}
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000950
Zachary Turner7120a472016-06-06 20:37:05 +0000951void LLVMOutputStyle::flush() { P.flush(); }