blob: 705728e27d015ffd438e41a42e95afcdd12dcc6c [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
Zachary Turner7159ab92017-04-28 00:43:38 +0000322static Error parseStreamSpec(StringRef Str, uint32_t &SI, uint32_t &Offset,
323 uint32_t &Size) {
324 if (Str.consumeInteger(0, SI))
325 return make_error<RawError>(raw_error_code::invalid_format,
326 "Invalid Stream Specification");
327 if (Str.consume_front(":")) {
328 if (Str.consumeInteger(0, Offset))
329 return make_error<RawError>(raw_error_code::invalid_format,
330 "Invalid Stream Specification");
331 }
332 if (Str.consume_front("@")) {
333 if (Str.consumeInteger(0, Size))
334 return make_error<RawError>(raw_error_code::invalid_format,
335 "Invalid Stream Specification");
336 }
337 if (!Str.empty())
338 return make_error<RawError>(raw_error_code::invalid_format,
339 "Invalid Stream Specification");
340 return Error::success();
341}
342
Zachary Turner72c5b642016-09-09 18:17:52 +0000343Error LLVMOutputStyle::dumpStreamBytes() {
344 if (opts::raw::DumpStreamData.empty())
Zachary Turnerd3117392016-06-03 19:28:33 +0000345 return Error::success();
346
Zachary Turner6ac232c2017-03-13 23:28:25 +0000347 if (StreamPurposes.empty())
348 discoverStreamPurposes(File, StreamPurposes);
Zachary Turner36efbfa2016-09-09 19:00:49 +0000349
Zachary Turner72c5b642016-09-09 18:17:52 +0000350 DictScope D(P, "Stream Data");
Zachary Turner7159ab92017-04-28 00:43:38 +0000351 for (auto &Str : opts::raw::DumpStreamData) {
352 uint32_t SI = 0;
353 uint32_t Begin = 0;
354 uint32_t Size = 0;
355 uint32_t End = 0;
356
357 if (auto EC = parseStreamSpec(Str, SI, Begin, Size))
358 return EC;
359
Zachary Turner72c5b642016-09-09 18:17:52 +0000360 if (SI >= File.getNumStreams())
361 return make_error<RawError>(raw_error_code::no_stream);
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000362
Zachary Turner72c5b642016-09-09 18:17:52 +0000363 auto S = MappedBlockStream::createIndexedStream(File.getMsfLayout(),
364 File.getMsfBuffer(), SI);
365 if (!S)
366 continue;
Zachary Turner36efbfa2016-09-09 19:00:49 +0000367 DictScope DD(P, "Stream");
Zachary Turner7159ab92017-04-28 00:43:38 +0000368 if (Size == 0)
369 End = S->getLength();
370 else {
371 End = Begin + Size;
372 if (End >= S->getLength())
373 return make_error<RawError>(raw_error_code::index_out_of_bounds,
374 "Stream is not long enough!");
375 }
Zachary Turner36efbfa2016-09-09 19:00:49 +0000376
377 P.printNumber("Index", SI);
378 P.printString("Type", StreamPurposes[SI]);
379 P.printNumber("Size", S->getLength());
380 auto Blocks = File.getMsfLayout().StreamMap[SI];
381 P.printList("Blocks", Blocks);
382
Zachary Turner120faca2017-02-27 22:11:43 +0000383 BinaryStreamReader R(*S);
Zachary Turner72c5b642016-09-09 18:17:52 +0000384 ArrayRef<uint8_t> StreamData;
385 if (auto EC = R.readBytes(StreamData, S->getLength()))
Zachary Turnerd3117392016-06-03 19:28:33 +0000386 return EC;
Zachary Turner7159ab92017-04-28 00:43:38 +0000387 Size = End - Begin;
388 StreamData = StreamData.slice(Begin, Size);
389 P.printBinaryBlock("Data", StreamData, Begin);
Zachary Turnerd3117392016-06-03 19:28:33 +0000390 }
391 return Error::success();
392}
393
Zachary Turner760ad4d2017-01-20 22:42:09 +0000394Error LLVMOutputStyle::dumpStringTable() {
395 if (!opts::raw::DumpStringTable)
396 return Error::success();
397
398 auto IS = File.getStringTable();
399 if (!IS)
400 return IS.takeError();
401
402 DictScope D(P, "String Table");
403 for (uint32_t I : IS->name_ids()) {
404 StringRef S = IS->getStringForID(I);
405 if (!S.empty()) {
406 llvm::SmallString<32> Str;
407 Str.append("'");
408 Str.append(S);
409 Str.append("'");
410 P.printString(Str);
411 }
412 }
413 return Error::success();
414}
415
Zachary Turnerd3117392016-06-03 19:28:33 +0000416Error LLVMOutputStyle::dumpInfoStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000417 if (!opts::raw::DumpHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000418 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000419 if (!File.hasPDBInfoStream()) {
420 P.printString("PDB Stream not present");
421 return Error::success();
422 }
Zachary Turnera1657a92016-06-08 17:26:39 +0000423 auto IS = File.getPDBInfoStream();
424 if (!IS)
425 return IS.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000426
427 DictScope D(P, "PDB Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000428 P.printNumber("Version", IS->getVersion());
429 P.printHex("Signature", IS->getSignature());
430 P.printNumber("Age", IS->getAge());
431 P.printObject("Guid", IS->getGuid());
Zachary Turner05d5e612017-03-16 20:19:11 +0000432 P.printHex("Features", IS->getFeatures());
Zachary Turner760ad4d2017-01-20 22:42:09 +0000433 {
434 DictScope DD(P, "Named Streams");
435 for (const auto &S : IS->getNamedStreams().entries())
436 P.printObject(S.getKey(), S.getValue());
437 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000438 return Error::success();
439}
440
Zachary Turner29da5db2017-01-25 21:17:40 +0000441namespace {
442class RecordBytesVisitor : public TypeVisitorCallbacks {
443public:
444 explicit RecordBytesVisitor(ScopedPrinter &P) : P(P) {}
445
446 Error visitTypeEnd(CVType &Record) override {
447 P.printBinaryBlock("Bytes", Record.content());
448 return Error::success();
449 }
450
451private:
452 ScopedPrinter &P;
453};
Rui Ueyamafd97bf12016-06-03 20:48:51 +0000454}
455
Zachary Turnerd3117392016-06-03 19:28:33 +0000456Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
457 assert(StreamIdx == StreamTPI || StreamIdx == StreamIPI);
458
459 bool DumpRecordBytes = false;
460 bool DumpRecords = false;
Zachary Turner29da5db2017-01-25 21:17:40 +0000461 bool DumpTpiHash = false;
Zachary Turnerd3117392016-06-03 19:28:33 +0000462 StringRef Label;
463 StringRef VerLabel;
464 if (StreamIdx == StreamTPI) {
Bob Haarmana5b43582016-12-05 22:44:00 +0000465 if (!File.hasPDBTpiStream()) {
466 P.printString("Type Info Stream (TPI) not present");
467 return Error::success();
468 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000469 DumpRecordBytes = opts::raw::DumpTpiRecordBytes;
470 DumpRecords = opts::raw::DumpTpiRecords;
Zachary Turner29da5db2017-01-25 21:17:40 +0000471 DumpTpiHash = opts::raw::DumpTpiHash;
Zachary Turnerd3117392016-06-03 19:28:33 +0000472 Label = "Type Info Stream (TPI)";
473 VerLabel = "TPI Version";
474 } else if (StreamIdx == StreamIPI) {
Bob Haarmana5b43582016-12-05 22:44:00 +0000475 if (!File.hasPDBIpiStream()) {
476 P.printString("Type Info Stream (IPI) not present");
477 return Error::success();
478 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000479 DumpRecordBytes = opts::raw::DumpIpiRecordBytes;
480 DumpRecords = opts::raw::DumpIpiRecords;
Zachary Turnerd3117392016-06-03 19:28:33 +0000481 Label = "Type Info Stream (IPI)";
482 VerLabel = "IPI Version";
483 }
Zachary Turner29da5db2017-01-25 21:17:40 +0000484 if (!DumpRecordBytes && !DumpRecords && !DumpTpiHash &&
485 !opts::raw::DumpModuleSyms)
Zachary Turnerd3117392016-06-03 19:28:33 +0000486 return Error::success();
487
Zachary Turner29da5db2017-01-25 21:17:40 +0000488 bool IsSilentDatabaseBuild = !DumpRecordBytes && !DumpRecords && !DumpTpiHash;
489
Zachary Turnera1657a92016-06-08 17:26:39 +0000490 auto Tpi = (StreamIdx == StreamTPI) ? File.getPDBTpiStream()
491 : File.getPDBIpiStream();
492 if (!Tpi)
493 return Tpi.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000494
Zachary Turner29da5db2017-01-25 21:17:40 +0000495 std::unique_ptr<DictScope> StreamScope;
496 std::unique_ptr<ListScope> RecordScope;
497
498 if (!IsSilentDatabaseBuild) {
499 StreamScope = llvm::make_unique<DictScope>(P, Label);
500 P.printNumber(VerLabel, Tpi->getTpiVersion());
501 P.printNumber("Record count", Tpi->NumTypeRecords());
502 }
503
Reid Klecknera5d187b2017-03-23 21:36:25 +0000504 TypeDatabase &StreamDB = (StreamIdx == StreamTPI) ? TypeDB : ItemDB;
505
506 TypeDatabaseVisitor DBV(StreamDB);
507 CompactTypeDumpVisitor CTDV(StreamDB, &P);
Zachary Turner44a643c2017-01-12 22:28:15 +0000508 TypeDumpVisitor TDV(TypeDB, &P, false);
Reid Klecknera5d187b2017-03-23 21:36:25 +0000509 if (StreamIdx == StreamIPI)
510 TDV.setItemDB(ItemDB);
Zachary Turner29da5db2017-01-25 21:17:40 +0000511 RecordBytesVisitor RBV(P);
Zachary Turner44a643c2017-01-12 22:28:15 +0000512 TypeDeserializer Deserializer;
Zachary Turner29da5db2017-01-25 21:17:40 +0000513
514 // We always need to deserialize and add it to the type database. This is
515 // true if even if we're not dumping anything, because we could need the
516 // type database for the purposes of dumping symbols.
Zachary Turner44a643c2017-01-12 22:28:15 +0000517 TypeVisitorCallbackPipeline Pipeline;
518 Pipeline.addCallbackToPipeline(Deserializer);
519 Pipeline.addCallbackToPipeline(DBV);
520
Zachary Turner29da5db2017-01-25 21:17:40 +0000521 // If we're in dump mode, add a dumper with the appropriate detail level.
522 if (DumpRecords) {
Zachary Turner44a643c2017-01-12 22:28:15 +0000523 if (opts::raw::CompactRecords)
524 Pipeline.addCallbackToPipeline(CTDV);
525 else
526 Pipeline.addCallbackToPipeline(TDV);
Zachary Turnerd3117392016-06-03 19:28:33 +0000527 }
Zachary Turner29da5db2017-01-25 21:17:40 +0000528 if (DumpRecordBytes)
529 Pipeline.addCallbackToPipeline(RBV);
530
531 CVTypeVisitor Visitor(Pipeline);
532
533 if (DumpRecords || DumpRecordBytes)
534 RecordScope = llvm::make_unique<ListScope>(P, "Records");
535
536 bool HadError = false;
537
538 TypeIndex T(TypeIndex::FirstNonSimpleIndex);
539 for (auto Type : Tpi->types(&HadError)) {
540 std::unique_ptr<DictScope> OneRecordScope;
541
542 if ((DumpRecords || DumpRecordBytes) && !opts::raw::CompactRecords)
543 OneRecordScope = llvm::make_unique<DictScope>(P, "");
544
545 if (auto EC = Visitor.visitTypeRecord(Type))
546 return EC;
547 }
548 if (HadError)
549 return make_error<RawError>(raw_error_code::corrupt_file,
550 "TPI stream contained corrupt record");
551
552 if (DumpTpiHash) {
553 DictScope DD(P, "Hash");
554 P.printNumber("Number of Hash Buckets", Tpi->NumHashBuckets());
555 P.printNumber("Hash Key Size", Tpi->getHashKeySize());
556 P.printList("Values", Tpi->getHashValues());
557
558 ListScope LHA(P, "Adjusters");
559 auto ExpectedST = File.getStringTable();
560 if (!ExpectedST)
561 return ExpectedST.takeError();
562 const auto &ST = *ExpectedST;
563 for (const auto &E : Tpi->getHashAdjusters()) {
564 DictScope DHA(P);
565 StringRef Name = ST.getStringForID(E.first);
566 P.printString("Type", Name);
567 P.printHex("TI", E.second);
568 }
569 }
570
571 if (!IsSilentDatabaseBuild) {
572 ListScope L(P, "TypeIndexOffsets");
573 for (const auto &IO : Tpi->getTypeIndexOffsets()) {
574 P.printString(formatv("Index: {0:x}, Offset: {1:N}", IO.Type.getIndex(),
575 (uint32_t)IO.Offset)
576 .str());
577 }
578 }
579
Zachary Turnerd3117392016-06-03 19:28:33 +0000580 P.flush();
581 return Error::success();
582}
583
584Error LLVMOutputStyle::dumpDbiStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000585 bool DumpModules = opts::raw::DumpModules || opts::raw::DumpModuleSyms ||
586 opts::raw::DumpModuleFiles || opts::raw::DumpLineInfo;
587 if (!opts::raw::DumpHeaders && !DumpModules)
Zachary Turnerd3117392016-06-03 19:28:33 +0000588 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000589 if (!File.hasPDBDbiStream()) {
590 P.printString("DBI Stream not present");
591 return Error::success();
592 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000593
Zachary Turnera1657a92016-06-08 17:26:39 +0000594 auto DS = File.getPDBDbiStream();
595 if (!DS)
596 return DS.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000597
598 DictScope D(P, "DBI Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000599 P.printNumber("Dbi Version", DS->getDbiVersion());
600 P.printNumber("Age", DS->getAge());
601 P.printBoolean("Incremental Linking", DS->isIncrementallyLinked());
602 P.printBoolean("Has CTypes", DS->hasCTypes());
603 P.printBoolean("Is Stripped", DS->isStripped());
604 P.printObject("Machine Type", DS->getMachineType());
605 P.printNumber("Symbol Record Stream Index", DS->getSymRecordStreamIndex());
606 P.printNumber("Public Symbol Stream Index", DS->getPublicSymbolStreamIndex());
607 P.printNumber("Global Symbol Stream Index", DS->getGlobalSymbolStreamIndex());
Zachary Turnerd3117392016-06-03 19:28:33 +0000608
Zachary Turnera1657a92016-06-08 17:26:39 +0000609 uint16_t Major = DS->getBuildMajorVersion();
610 uint16_t Minor = DS->getBuildMinorVersion();
Zachary Turnerd3117392016-06-03 19:28:33 +0000611 P.printVersion("Toolchain Version", Major, Minor);
612
613 std::string DllName;
614 raw_string_ostream DllStream(DllName);
615 DllStream << "mspdb" << Major << Minor << ".dll version";
616 DllStream.flush();
Zachary Turnera1657a92016-06-08 17:26:39 +0000617 P.printVersion(DllName, Major, Minor, DS->getPdbDllVersion());
Zachary Turnerd3117392016-06-03 19:28:33 +0000618
619 if (DumpModules) {
620 ListScope L(P, "Modules");
Zachary Turnera1657a92016-06-08 17:26:39 +0000621 for (auto &Modi : DS->modules()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000622 DictScope DD(P);
623 P.printString("Name", Modi.Info.getModuleName().str());
624 P.printNumber("Debug Stream Index", Modi.Info.getModuleStreamIndex());
625 P.printString("Object File Name", Modi.Info.getObjFileName().str());
626 P.printNumber("Num Files", Modi.Info.getNumberOfFiles());
627 P.printNumber("Source File Name Idx", Modi.Info.getSourceFileNameIndex());
628 P.printNumber("Pdb File Name Idx", Modi.Info.getPdbFilePathNameIndex());
629 P.printNumber("Line Info Byte Size", Modi.Info.getLineInfoByteSize());
630 P.printNumber("C13 Line Info Byte Size",
631 Modi.Info.getC13LineInfoByteSize());
632 P.printNumber("Symbol Byte Size", Modi.Info.getSymbolDebugInfoByteSize());
633 P.printNumber("Type Server Index", Modi.Info.getTypeServerIndex());
634 P.printBoolean("Has EC Info", Modi.Info.hasECInfo());
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000635 if (opts::raw::DumpModuleFiles) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000636 std::string FileListName =
637 to_string(Modi.SourceFiles.size()) + " Contributing Source Files";
638 ListScope LL(P, FileListName);
639 for (auto File : Modi.SourceFiles)
640 P.printString(File.str());
641 }
642 bool HasModuleDI =
643 (Modi.Info.getModuleStreamIndex() < File.getNumStreams());
644 bool ShouldDumpSymbols =
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000645 (opts::raw::DumpModuleSyms || opts::raw::DumpSymRecordBytes);
646 if (HasModuleDI && (ShouldDumpSymbols || opts::raw::DumpLineInfo)) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000647 auto ModStreamData = MappedBlockStream::createIndexedStream(
Zachary Turnerd66889c2016-07-28 19:12:28 +0000648 File.getMsfLayout(), File.getMsfBuffer(),
649 Modi.Info.getModuleStreamIndex());
650
Zachary Turner67c56012017-04-27 16:11:19 +0000651 ModuleDebugStream ModS(Modi.Info, std::move(ModStreamData));
Zachary Turnerd3117392016-06-03 19:28:33 +0000652 if (auto EC = ModS.reload())
653 return EC;
654
655 if (ShouldDumpSymbols) {
656 ListScope SS(P, "Symbols");
Zachary Turner629cb7d2017-01-11 23:24:22 +0000657 codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
Zachary Turnerd3117392016-06-03 19:28:33 +0000658 bool HadError = false;
Zachary Turner0d840742016-10-07 21:34:46 +0000659 for (auto S : ModS.symbols(&HadError)) {
660 DictScope LL(P, "");
661 if (opts::raw::DumpModuleSyms) {
662 if (auto EC = SD.dump(S)) {
663 llvm::consumeError(std::move(EC));
664 HadError = true;
665 break;
666 }
667 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000668 if (opts::raw::DumpSymRecordBytes)
Zachary Turnerc67b00c2016-09-14 23:00:16 +0000669 P.printBinaryBlock("Bytes", S.content());
Zachary Turnerd3117392016-06-03 19:28:33 +0000670 }
671 if (HadError)
672 return make_error<RawError>(
673 raw_error_code::corrupt_file,
674 "DBI stream contained corrupt symbol record");
675 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000676 if (opts::raw::DumpLineInfo) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000677 ListScope SS(P, "LineInfo");
Zachary Turnerd3117392016-06-03 19:28:33 +0000678 // Define a locally scoped visitor to print the different
679 // substream types types.
Zachary Turner67c56012017-04-27 16:11:19 +0000680 class RecordVisitor : public codeview::ModuleDebugFragmentVisitor {
Zachary Turnerd3117392016-06-03 19:28:33 +0000681 public:
682 RecordVisitor(ScopedPrinter &P, PDBFile &F) : P(P), F(F) {}
Zachary Turnerc37cb0c2017-04-27 16:12:16 +0000683 Error visitUnknown(ModuleDebugUnknownFragment &Fragment) override {
Zachary Turnerd3117392016-06-03 19:28:33 +0000684 DictScope DD(P, "Unknown");
685 ArrayRef<uint8_t> Data;
Zachary Turnerc37cb0c2017-04-27 16:12:16 +0000686 BinaryStreamReader R(Fragment.getData());
Zachary Turnerd3117392016-06-03 19:28:33 +0000687 if (auto EC = R.readBytes(Data, R.bytesRemaining())) {
688 return make_error<RawError>(
689 raw_error_code::corrupt_file,
690 "DBI stream contained corrupt line info record");
691 }
692 P.printBinaryBlock("Data", Data);
693 return Error::success();
694 }
Zachary Turnerc37cb0c2017-04-27 16:12:16 +0000695 Error visitFileChecksums(
696 ModuleDebugFileChecksumFragment &Checksums) override {
Zachary Turnerd3117392016-06-03 19:28:33 +0000697 DictScope DD(P, "FileChecksums");
698 for (const auto &C : Checksums) {
699 DictScope DDD(P, "Checksum");
700 if (auto Result = getFileNameForOffset(C.FileNameOffset))
701 P.printString("FileName", Result.get());
702 else
703 return Result.takeError();
704 P.flush();
705 P.printEnum("Kind", uint8_t(C.Kind), getFileChecksumNames());
706 P.printBinaryBlock("Checksum", C.Checksum);
707 }
708 return Error::success();
709 }
710
Zachary Turnerc37cb0c2017-04-27 16:12:16 +0000711 Error visitLines(ModuleDebugLineFragment &Lines) override {
Zachary Turnerd3117392016-06-03 19:28:33 +0000712 DictScope DD(P, "Lines");
713 for (const auto &L : Lines) {
714 if (auto Result = getFileNameForOffset2(L.NameIndex))
715 P.printString("FileName", Result.get());
716 else
717 return Result.takeError();
718 P.flush();
719 for (const auto &N : L.LineNumbers) {
720 DictScope DDD(P, "Line");
721 LineInfo LI(N.Flags);
722 P.printNumber("Offset", N.Offset);
723 if (LI.isAlwaysStepInto())
724 P.printString("StepInto", StringRef("Always"));
725 else if (LI.isNeverStepInto())
726 P.printString("StepInto", StringRef("Never"));
727 else
728 P.printNumber("LineNumberStart", LI.getStartLine());
729 P.printNumber("EndDelta", LI.getLineDelta());
730 P.printBoolean("IsStatement", LI.isStatement());
731 }
732 for (const auto &C : L.Columns) {
733 DictScope DDD(P, "Column");
734 P.printNumber("Start", C.StartColumn);
735 P.printNumber("End", C.EndColumn);
736 }
737 }
738 return Error::success();
739 }
740
741 private:
742 Expected<StringRef> getFileNameForOffset(uint32_t Offset) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000743 auto ST = F.getStringTable();
744 if (!ST)
745 return ST.takeError();
746
747 return ST->getStringForID(Offset);
Zachary Turnerd3117392016-06-03 19:28:33 +0000748 }
749 Expected<StringRef> getFileNameForOffset2(uint32_t Offset) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000750 auto DS = F.getPDBDbiStream();
751 if (!DS)
752 return DS.takeError();
753 return DS->getFileNameForIndex(Offset);
Zachary Turnerd3117392016-06-03 19:28:33 +0000754 }
755 ScopedPrinter &P;
756 PDBFile &F;
757 };
758
759 RecordVisitor V(P, File);
Zachary Turnerc37cb0c2017-04-27 16:12:16 +0000760 for (const auto &L : ModS.linesAndChecksums()) {
Zachary Turner67c56012017-04-27 16:11:19 +0000761 if (auto EC = codeview::visitModuleDebugFragment(L, V))
Zachary Turnerd3117392016-06-03 19:28:33 +0000762 return EC;
763 }
764 }
765 }
766 }
767 }
768 return Error::success();
769}
770
771Error LLVMOutputStyle::dumpSectionContribs() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000772 if (!opts::raw::DumpSectionContribs)
Zachary Turnerd3117392016-06-03 19:28:33 +0000773 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000774 if (!File.hasPDBDbiStream()) {
775 P.printString("DBI Stream not present");
776 return Error::success();
777 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000778
Zachary Turnera1657a92016-06-08 17:26:39 +0000779 auto Dbi = File.getPDBDbiStream();
780 if (!Dbi)
781 return Dbi.takeError();
782
Zachary Turnerd3117392016-06-03 19:28:33 +0000783 ListScope L(P, "Section Contributions");
784 class Visitor : public ISectionContribVisitor {
785 public:
786 Visitor(ScopedPrinter &P, DbiStream &DS) : P(P), DS(DS) {}
787 void visit(const SectionContrib &SC) override {
788 DictScope D(P, "Contribution");
789 P.printNumber("ISect", SC.ISect);
790 P.printNumber("Off", SC.Off);
791 P.printNumber("Size", SC.Size);
792 P.printFlags("Characteristics", SC.Characteristics,
793 codeview::getImageSectionCharacteristicNames(),
794 COFF::SectionCharacteristics(0x00F00000));
795 {
796 DictScope DD(P, "Module");
797 P.printNumber("Index", SC.Imod);
798 auto M = DS.modules();
799 if (M.size() > SC.Imod) {
800 P.printString("Name", M[SC.Imod].Info.getModuleName());
801 }
802 }
803 P.printNumber("Data CRC", SC.DataCrc);
804 P.printNumber("Reloc CRC", SC.RelocCrc);
805 P.flush();
806 }
807 void visit(const SectionContrib2 &SC) override {
808 visit(SC.Base);
809 P.printNumber("ISect Coff", SC.ISectCoff);
810 P.flush();
811 }
812
813 private:
814 ScopedPrinter &P;
815 DbiStream &DS;
816 };
Zachary Turnera1657a92016-06-08 17:26:39 +0000817 Visitor V(P, *Dbi);
818 Dbi->visitSectionContributions(V);
Zachary Turnerd3117392016-06-03 19:28:33 +0000819 return Error::success();
820}
821
822Error LLVMOutputStyle::dumpSectionMap() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000823 if (!opts::raw::DumpSectionMap)
Zachary Turnerd3117392016-06-03 19:28:33 +0000824 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000825 if (!File.hasPDBDbiStream()) {
826 P.printString("DBI Stream not present");
827 return Error::success();
828 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000829
Zachary Turnera1657a92016-06-08 17:26:39 +0000830 auto Dbi = File.getPDBDbiStream();
831 if (!Dbi)
832 return Dbi.takeError();
833
Zachary Turnerd3117392016-06-03 19:28:33 +0000834 ListScope L(P, "Section Map");
Zachary Turnera1657a92016-06-08 17:26:39 +0000835 for (auto &M : Dbi->getSectionMap()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000836 DictScope D(P, "Entry");
837 P.printFlags("Flags", M.Flags, getOMFSegMapDescFlagNames());
Zachary Turnerd3117392016-06-03 19:28:33 +0000838 P.printNumber("Ovl", M.Ovl);
839 P.printNumber("Group", M.Group);
840 P.printNumber("Frame", M.Frame);
841 P.printNumber("SecName", M.SecName);
842 P.printNumber("ClassName", M.ClassName);
843 P.printNumber("Offset", M.Offset);
844 P.printNumber("SecByteLength", M.SecByteLength);
845 P.flush();
846 }
847 return Error::success();
848}
849
850Error LLVMOutputStyle::dumpPublicsStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000851 if (!opts::raw::DumpPublics)
Zachary Turnerd3117392016-06-03 19:28:33 +0000852 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000853 if (!File.hasPDBPublicsStream()) {
854 P.printString("Publics Stream not present");
855 return Error::success();
856 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000857
Zachary Turnera1657a92016-06-08 17:26:39 +0000858 auto Publics = File.getPDBPublicsStream();
859 if (!Publics)
860 return Publics.takeError();
Bob Haarmana5b43582016-12-05 22:44:00 +0000861 DictScope D(P, "Publics Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000862
863 auto Dbi = File.getPDBDbiStream();
864 if (!Dbi)
865 return Dbi.takeError();
866
867 P.printNumber("Stream number", Dbi->getPublicSymbolStreamIndex());
868 P.printNumber("SymHash", Publics->getSymHash());
869 P.printNumber("AddrMap", Publics->getAddrMap());
870 P.printNumber("Number of buckets", Publics->getNumBuckets());
871 P.printList("Hash Buckets", Publics->getHashBuckets());
872 P.printList("Address Map", Publics->getAddressMap());
873 P.printList("Thunk Map", Publics->getThunkMap());
874 P.printList("Section Offsets", Publics->getSectionOffsets(),
Zachary Turnerd3117392016-06-03 19:28:33 +0000875 printSectionOffset);
876 ListScope L(P, "Symbols");
Zachary Turner629cb7d2017-01-11 23:24:22 +0000877 codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
Zachary Turnerd3117392016-06-03 19:28:33 +0000878 bool HadError = false;
Zachary Turnera1657a92016-06-08 17:26:39 +0000879 for (auto S : Publics->getSymbols(&HadError)) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000880 DictScope DD(P, "");
881
Zachary Turner0d840742016-10-07 21:34:46 +0000882 if (auto EC = SD.dump(S)) {
883 HadError = true;
884 break;
885 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000886 if (opts::raw::DumpSymRecordBytes)
Zachary Turnerc67b00c2016-09-14 23:00:16 +0000887 P.printBinaryBlock("Bytes", S.content());
Zachary Turnerd3117392016-06-03 19:28:33 +0000888 }
889 if (HadError)
890 return make_error<RawError>(
891 raw_error_code::corrupt_file,
892 "Public symbol stream contained corrupt record");
893
894 return Error::success();
895}
896
897Error LLVMOutputStyle::dumpSectionHeaders() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000898 if (!opts::raw::DumpSectionHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000899 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000900 if (!File.hasPDBDbiStream()) {
901 P.printString("DBI Stream not present");
902 return Error::success();
903 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000904
Zachary Turnera1657a92016-06-08 17:26:39 +0000905 auto Dbi = File.getPDBDbiStream();
906 if (!Dbi)
907 return Dbi.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000908
909 ListScope D(P, "Section Headers");
Zachary Turnera1657a92016-06-08 17:26:39 +0000910 for (const object::coff_section &Section : Dbi->getSectionHeaders()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000911 DictScope DD(P, "");
912
913 // If a name is 8 characters long, there is no NUL character at end.
914 StringRef Name(Section.Name, strnlen(Section.Name, sizeof(Section.Name)));
915 P.printString("Name", Name);
916 P.printNumber("Virtual Size", Section.VirtualSize);
917 P.printNumber("Virtual Address", Section.VirtualAddress);
918 P.printNumber("Size of Raw Data", Section.SizeOfRawData);
919 P.printNumber("File Pointer to Raw Data", Section.PointerToRawData);
920 P.printNumber("File Pointer to Relocations", Section.PointerToRelocations);
921 P.printNumber("File Pointer to Linenumbers", Section.PointerToLinenumbers);
922 P.printNumber("Number of Relocations", Section.NumberOfRelocations);
923 P.printNumber("Number of Linenumbers", Section.NumberOfLinenumbers);
Rui Ueyama2c5384a2016-06-06 21:34:55 +0000924 P.printFlags("Characteristics", Section.Characteristics,
925 getImageSectionCharacteristicNames());
Zachary Turnerd3117392016-06-03 19:28:33 +0000926 }
927 return Error::success();
928}
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000929
930Error LLVMOutputStyle::dumpFpoStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000931 if (!opts::raw::DumpFpo)
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000932 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000933 if (!File.hasPDBDbiStream()) {
934 P.printString("DBI Stream not present");
935 return Error::success();
936 }
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000937
Zachary Turnera1657a92016-06-08 17:26:39 +0000938 auto Dbi = File.getPDBDbiStream();
939 if (!Dbi)
940 return Dbi.takeError();
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000941
942 ListScope D(P, "New FPO");
Zachary Turnera1657a92016-06-08 17:26:39 +0000943 for (const object::FpoData &Fpo : Dbi->getFpoRecords()) {
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000944 DictScope DD(P, "");
945 P.printNumber("Offset", Fpo.Offset);
946 P.printNumber("Size", Fpo.Size);
947 P.printNumber("Number of locals", Fpo.NumLocals);
948 P.printNumber("Number of params", Fpo.NumParams);
949 P.printNumber("Size of Prolog", Fpo.getPrologSize());
950 P.printNumber("Number of Saved Registers", Fpo.getNumSavedRegs());
951 P.printBoolean("Has SEH", Fpo.hasSEH());
952 P.printBoolean("Use BP", Fpo.useBP());
953 P.printNumber("Frame Pointer", Fpo.getFP());
954 }
955 return Error::success();
956}
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000957
Zachary Turner7120a472016-06-06 20:37:05 +0000958void LLVMOutputStyle::flush() { P.flush(); }