blob: a086b609fe399e5d4407318b31b57790a4fd2f97 [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
83// Define a locally scoped visitor to print the different
84// substream types types.
85class C13RawVisitor : public C13DebugFragmentVisitor {
86public:
87 C13RawVisitor(ScopedPrinter &P, PDBFile &F, TypeDatabase &TypeDB)
88 : C13DebugFragmentVisitor(F), P(P), DB(TypeDB) {}
89
90 Error handleLines() override {
91 DictScope DD(P, "Lines");
92
93 for (const auto &Fragment : Lines) {
94 DictScope DDD(P, "LineFragment");
95 P.printNumber("RelocSegment", Fragment.header()->RelocSegment);
96 P.printNumber("RelocOffset", Fragment.header()->RelocOffset);
97 P.printNumber("CodeSize", Fragment.header()->CodeSize);
98 P.printNumber("HasColumns", Fragment.hasColumnInfo());
99
100 for (const auto &L : Fragment) {
101 DictScope DDDD(P, "Lines");
102
103 if (auto EC = printFileName("FileName", L.NameIndex))
104 return EC;
105
106 for (const auto &N : L.LineNumbers) {
107 DictScope DDD(P, "Line");
108 LineInfo LI(N.Flags);
109 P.printNumber("Offset", N.Offset);
110 if (LI.isAlwaysStepInto())
111 P.printString("StepInto", StringRef("Always"));
112 else if (LI.isNeverStepInto())
113 P.printString("StepInto", StringRef("Never"));
114 else
115 P.printNumber("LineNumberStart", LI.getStartLine());
116 P.printNumber("EndDelta", LI.getLineDelta());
117 P.printBoolean("IsStatement", LI.isStatement());
118 }
119 for (const auto &C : L.Columns) {
120 DictScope DDD(P, "Column");
121 P.printNumber("Start", C.StartColumn);
122 P.printNumber("End", C.EndColumn);
123 }
124 }
125 }
126
127 return Error::success();
128 }
129
130 Error handleFileChecksums() override {
131 DictScope DD(P, "FileChecksums");
132 for (const auto &CS : *Checksums) {
133 DictScope DDD(P, "Checksum");
134 if (auto Result = getNameFromStringTable(CS.FileNameOffset))
135 P.printString("FileName", *Result);
136 else
137 return Result.takeError();
138 P.printEnum("Kind", uint8_t(CS.Kind), getFileChecksumNames());
139 P.printBinaryBlock("Checksum", CS.Checksum);
140 }
141 return Error::success();
142 }
143
144private:
145 Error printFileName(StringRef Label, uint32_t Offset) {
146 if (auto Result = getNameFromChecksumsBuffer(Offset)) {
147 P.printString(Label, *Result);
148 return Error::success();
149 } else
150 return Result.takeError();
151 }
152
153 ScopedPrinter &P;
154 TypeDatabase &DB;
155};
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000156}
157
158static void recordKnownUsedPage(PageStats &Stats, uint32_t UsedIndex) {
159 if (Stats.Upm.test(UsedIndex)) {
160 if (Stats.ActualUsedPages.test(UsedIndex))
161 Stats.MultiUsePages.set(UsedIndex);
162 Stats.ActualUsedPages.set(UsedIndex);
163 Stats.OrphanedPages.reset(UsedIndex);
164 } else {
165 // The MSF doesn't think this page is used, but it is.
166 Stats.UseAfterFreePages.set(UsedIndex);
167 }
168}
169
Zachary Turnerd3117392016-06-03 19:28:33 +0000170static void printSectionOffset(llvm::raw_ostream &OS,
171 const SectionOffset &Off) {
172 OS << Off.Off << ", " << Off.Isect;
173}
174
Zachary Turner629cb7d2017-01-11 23:24:22 +0000175LLVMOutputStyle::LLVMOutputStyle(PDBFile &File) : File(File), P(outs()) {}
Zachary Turnerd3117392016-06-03 19:28:33 +0000176
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000177Error LLVMOutputStyle::dump() {
178 if (auto EC = dumpFileHeaders())
179 return EC;
180
181 if (auto EC = dumpStreamSummary())
182 return EC;
183
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000184 if (auto EC = dumpFreePageMap())
185 return EC;
186
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000187 if (auto EC = dumpStreamBlocks())
188 return EC;
189
Zachary Turner72c5b642016-09-09 18:17:52 +0000190 if (auto EC = dumpBlockRanges())
191 return EC;
192
193 if (auto EC = dumpStreamBytes())
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000194 return EC;
195
Zachary Turner760ad4d2017-01-20 22:42:09 +0000196 if (auto EC = dumpStringTable())
197 return EC;
198
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000199 if (auto EC = dumpInfoStream())
200 return EC;
201
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000202 if (auto EC = dumpTpiStream(StreamTPI))
203 return EC;
204
205 if (auto EC = dumpTpiStream(StreamIPI))
206 return EC;
207
208 if (auto EC = dumpDbiStream())
209 return EC;
210
211 if (auto EC = dumpSectionContribs())
212 return EC;
213
214 if (auto EC = dumpSectionMap())
215 return EC;
216
Bob Haarman653baa22016-10-21 19:43:19 +0000217 if (auto EC = dumpGlobalsStream())
218 return EC;
219
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000220 if (auto EC = dumpPublicsStream())
221 return EC;
222
223 if (auto EC = dumpSectionHeaders())
224 return EC;
225
226 if (auto EC = dumpFpoStream())
227 return EC;
228
229 flush();
230
231 return Error::success();
232}
233
Zachary Turnerd3117392016-06-03 19:28:33 +0000234Error LLVMOutputStyle::dumpFileHeaders() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000235 if (!opts::raw::DumpHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000236 return Error::success();
237
238 DictScope D(P, "FileHeaders");
239 P.printNumber("BlockSize", File.getBlockSize());
Zachary Turnerb927e022016-07-15 22:17:19 +0000240 P.printNumber("FreeBlockMap", File.getFreeBlockMapBlock());
Zachary Turnerd3117392016-06-03 19:28:33 +0000241 P.printNumber("NumBlocks", File.getBlockCount());
242 P.printNumber("NumDirectoryBytes", File.getNumDirectoryBytes());
243 P.printNumber("Unknown1", File.getUnknown1());
244 P.printNumber("BlockMapAddr", File.getBlockMapIndex());
245 P.printNumber("NumDirectoryBlocks", File.getNumDirectoryBlocks());
Zachary Turnerd3117392016-06-03 19:28:33 +0000246
247 // The directory is not contiguous. Instead, the block map contains a
248 // contiguous list of block numbers whose contents, when concatenated in
249 // order, make up the directory.
250 P.printList("DirectoryBlocks", File.getDirectoryBlockArray());
251 P.printNumber("NumStreams", File.getNumStreams());
252 return Error::success();
253}
254
Zachary Turner36efbfa2016-09-09 19:00:49 +0000255Error LLVMOutputStyle::dumpStreamSummary() {
256 if (!opts::raw::DumpStreamSummary)
257 return Error::success();
258
Zachary Turner6ac232c2017-03-13 23:28:25 +0000259 if (StreamPurposes.empty())
260 discoverStreamPurposes(File, StreamPurposes);
Zachary Turner36efbfa2016-09-09 19:00:49 +0000261
262 uint32_t StreamCount = File.getNumStreams();
263
264 ListScope L(P, "Streams");
265 for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
266 std::string Label("Stream ");
267 Label += to_string(StreamIdx);
268
269 std::string Value = "[" + StreamPurposes[StreamIdx] + "] (";
270 Value += to_string(File.getStreamByteSize(StreamIdx));
271 Value += " bytes)";
272
273 P.printString(Label, Value);
274 }
Reid Kleckner11582c52016-06-17 20:38:01 +0000275
Zachary Turnerd3117392016-06-03 19:28:33 +0000276 P.flush();
277 return Error::success();
278}
279
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000280Error LLVMOutputStyle::dumpFreePageMap() {
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000281 if (!opts::raw::DumpPageStats)
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000282 return Error::success();
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000283
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000284 // Start with used pages instead of free pages because
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000285 // the number of free pages is far larger than used pages.
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000286 BitVector FPM = File.getMsfLayout().FreePageMap;
287
288 PageStats PS(FPM);
289
290 recordKnownUsedPage(PS, 0); // MSF Super Block
291
Zachary Turner8cf51c32016-08-03 16:53:21 +0000292 uint32_t BlocksPerSection = msf::getFpmIntervalLength(File.getMsfLayout());
293 uint32_t NumSections = msf::getNumFpmIntervals(File.getMsfLayout());
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000294 for (uint32_t I = 0; I < NumSections; ++I) {
295 uint32_t Fpm0 = 1 + BlocksPerSection * I;
296 // 2 Fpm blocks spaced at `getBlockSize()` block intervals
297 recordKnownUsedPage(PS, Fpm0);
298 recordKnownUsedPage(PS, Fpm0 + 1);
299 }
300
301 recordKnownUsedPage(PS, File.getBlockMapIndex()); // Stream Table
302
Rui Ueyama22e67382016-08-02 23:22:46 +0000303 for (auto DB : File.getDirectoryBlockArray())
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000304 recordKnownUsedPage(PS, DB);
Rui Ueyama22e67382016-08-02 23:22:46 +0000305
306 // Record pages used by streams. Note that pages for stream 0
307 // are considered being unused because that's what MSVC tools do.
308 // Stream 0 doesn't contain actual data, so it makes some sense,
309 // though it's a bit confusing to us.
310 for (auto &SE : File.getStreamMap().drop_front(1))
311 for (auto &S : SE)
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000312 recordKnownUsedPage(PS, S);
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000313
314 dumpBitVector("Msf Free Pages", FPM);
315 dumpBitVector("Orphaned Pages", PS.OrphanedPages);
316 dumpBitVector("Multiply Used Pages", PS.MultiUsePages);
317 dumpBitVector("Use After Free Pages", PS.UseAfterFreePages);
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000318 return Error::success();
319}
320
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000321void LLVMOutputStyle::dumpBitVector(StringRef Name, const BitVector &V) {
322 std::vector<uint32_t> Vec;
323 for (uint32_t I = 0, E = V.size(); I != E; ++I)
324 if (V[I])
325 Vec.push_back(I);
326 P.printList(Name, Vec);
327}
328
Bob Haarman653baa22016-10-21 19:43:19 +0000329Error LLVMOutputStyle::dumpGlobalsStream() {
330 if (!opts::raw::DumpGlobals)
331 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000332 if (!File.hasPDBGlobalsStream()) {
333 P.printString("Globals Stream not present");
334 return Error::success();
335 }
Bob Haarman653baa22016-10-21 19:43:19 +0000336
Bob Haarman653baa22016-10-21 19:43:19 +0000337 auto Globals = File.getPDBGlobalsStream();
338 if (!Globals)
Bob Haarman312fd0e2016-12-06 00:55:55 +0000339 return Globals.takeError();
Bob Haarmana5b43582016-12-05 22:44:00 +0000340 DictScope D(P, "Globals Stream");
Bob Haarman653baa22016-10-21 19:43:19 +0000341
342 auto Dbi = File.getPDBDbiStream();
343 if (!Dbi)
344 return Dbi.takeError();
345
346 P.printNumber("Stream number", Dbi->getGlobalSymbolStreamIndex());
347 P.printNumber("Number of buckets", Globals->getNumBuckets());
348 P.printList("Hash Buckets", Globals->getHashBuckets());
349
350 return Error::success();
351}
352
Zachary Turnerd3117392016-06-03 19:28:33 +0000353Error LLVMOutputStyle::dumpStreamBlocks() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000354 if (!opts::raw::DumpStreamBlocks)
Zachary Turnerd3117392016-06-03 19:28:33 +0000355 return Error::success();
356
357 ListScope L(P, "StreamBlocks");
358 uint32_t StreamCount = File.getNumStreams();
359 for (uint32_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
360 std::string Name("Stream ");
361 Name += to_string(StreamIdx);
362 auto StreamBlocks = File.getStreamBlockList(StreamIdx);
363 P.printList(Name, StreamBlocks);
364 }
365 return Error::success();
366}
367
Zachary Turner72c5b642016-09-09 18:17:52 +0000368Error LLVMOutputStyle::dumpBlockRanges() {
369 if (!opts::raw::DumpBlockRange.hasValue())
370 return Error::success();
371 auto &R = *opts::raw::DumpBlockRange;
372 uint32_t Max = R.Max.getValueOr(R.Min);
373
374 if (Max < R.Min)
375 return make_error<StringError>(
376 "Invalid block range specified. Max < Min",
377 std::make_error_code(std::errc::bad_address));
378 if (Max >= File.getBlockCount())
379 return make_error<StringError>(
380 "Invalid block range specified. Requested block out of bounds",
381 std::make_error_code(std::errc::bad_address));
382
383 DictScope D(P, "Block Data");
384 for (uint32_t I = R.Min; I <= Max; ++I) {
385 auto ExpectedData = File.getBlockData(I, File.getBlockSize());
386 if (!ExpectedData)
387 return ExpectedData.takeError();
388 std::string Label;
389 llvm::raw_string_ostream S(Label);
390 S << "Block " << I;
391 S.flush();
392 P.printBinaryBlock(Label, *ExpectedData);
393 }
394
395 return Error::success();
396}
397
Zachary Turner7159ab92017-04-28 00:43:38 +0000398static Error parseStreamSpec(StringRef Str, uint32_t &SI, uint32_t &Offset,
399 uint32_t &Size) {
400 if (Str.consumeInteger(0, SI))
401 return make_error<RawError>(raw_error_code::invalid_format,
402 "Invalid Stream Specification");
403 if (Str.consume_front(":")) {
404 if (Str.consumeInteger(0, Offset))
405 return make_error<RawError>(raw_error_code::invalid_format,
406 "Invalid Stream Specification");
407 }
408 if (Str.consume_front("@")) {
409 if (Str.consumeInteger(0, Size))
410 return make_error<RawError>(raw_error_code::invalid_format,
411 "Invalid Stream Specification");
412 }
413 if (!Str.empty())
414 return make_error<RawError>(raw_error_code::invalid_format,
415 "Invalid Stream Specification");
416 return Error::success();
417}
418
Zachary Turner72c5b642016-09-09 18:17:52 +0000419Error LLVMOutputStyle::dumpStreamBytes() {
420 if (opts::raw::DumpStreamData.empty())
Zachary Turnerd3117392016-06-03 19:28:33 +0000421 return Error::success();
422
Zachary Turner6ac232c2017-03-13 23:28:25 +0000423 if (StreamPurposes.empty())
424 discoverStreamPurposes(File, StreamPurposes);
Zachary Turner36efbfa2016-09-09 19:00:49 +0000425
Zachary Turner72c5b642016-09-09 18:17:52 +0000426 DictScope D(P, "Stream Data");
Zachary Turner7159ab92017-04-28 00:43:38 +0000427 for (auto &Str : opts::raw::DumpStreamData) {
428 uint32_t SI = 0;
429 uint32_t Begin = 0;
430 uint32_t Size = 0;
431 uint32_t End = 0;
432
433 if (auto EC = parseStreamSpec(Str, SI, Begin, Size))
434 return EC;
435
Zachary Turner72c5b642016-09-09 18:17:52 +0000436 if (SI >= File.getNumStreams())
437 return make_error<RawError>(raw_error_code::no_stream);
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000438
Zachary Turner72c5b642016-09-09 18:17:52 +0000439 auto S = MappedBlockStream::createIndexedStream(File.getMsfLayout(),
440 File.getMsfBuffer(), SI);
441 if (!S)
442 continue;
Zachary Turner36efbfa2016-09-09 19:00:49 +0000443 DictScope DD(P, "Stream");
Zachary Turner7159ab92017-04-28 00:43:38 +0000444 if (Size == 0)
445 End = S->getLength();
446 else {
447 End = Begin + Size;
448 if (End >= S->getLength())
449 return make_error<RawError>(raw_error_code::index_out_of_bounds,
450 "Stream is not long enough!");
451 }
Zachary Turner36efbfa2016-09-09 19:00:49 +0000452
453 P.printNumber("Index", SI);
454 P.printString("Type", StreamPurposes[SI]);
455 P.printNumber("Size", S->getLength());
456 auto Blocks = File.getMsfLayout().StreamMap[SI];
457 P.printList("Blocks", Blocks);
458
Zachary Turner120faca2017-02-27 22:11:43 +0000459 BinaryStreamReader R(*S);
Zachary Turner72c5b642016-09-09 18:17:52 +0000460 ArrayRef<uint8_t> StreamData;
461 if (auto EC = R.readBytes(StreamData, S->getLength()))
Zachary Turnerd3117392016-06-03 19:28:33 +0000462 return EC;
Zachary Turner7159ab92017-04-28 00:43:38 +0000463 Size = End - Begin;
464 StreamData = StreamData.slice(Begin, Size);
465 P.printBinaryBlock("Data", StreamData, Begin);
Zachary Turnerd3117392016-06-03 19:28:33 +0000466 }
467 return Error::success();
468}
469
Zachary Turner760ad4d2017-01-20 22:42:09 +0000470Error LLVMOutputStyle::dumpStringTable() {
471 if (!opts::raw::DumpStringTable)
472 return Error::success();
473
474 auto IS = File.getStringTable();
475 if (!IS)
476 return IS.takeError();
477
478 DictScope D(P, "String Table");
479 for (uint32_t I : IS->name_ids()) {
480 StringRef S = IS->getStringForID(I);
481 if (!S.empty()) {
482 llvm::SmallString<32> Str;
483 Str.append("'");
484 Str.append(S);
485 Str.append("'");
486 P.printString(Str);
487 }
488 }
489 return Error::success();
490}
491
Zachary Turnerd3117392016-06-03 19:28:33 +0000492Error LLVMOutputStyle::dumpInfoStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000493 if (!opts::raw::DumpHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000494 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000495 if (!File.hasPDBInfoStream()) {
496 P.printString("PDB Stream not present");
497 return Error::success();
498 }
Zachary Turnera1657a92016-06-08 17:26:39 +0000499 auto IS = File.getPDBInfoStream();
500 if (!IS)
501 return IS.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000502
503 DictScope D(P, "PDB Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000504 P.printNumber("Version", IS->getVersion());
505 P.printHex("Signature", IS->getSignature());
506 P.printNumber("Age", IS->getAge());
507 P.printObject("Guid", IS->getGuid());
Zachary Turner05d5e612017-03-16 20:19:11 +0000508 P.printHex("Features", IS->getFeatures());
Zachary Turner760ad4d2017-01-20 22:42:09 +0000509 {
510 DictScope DD(P, "Named Streams");
511 for (const auto &S : IS->getNamedStreams().entries())
512 P.printObject(S.getKey(), S.getValue());
513 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000514 return Error::success();
515}
516
Zachary Turner29da5db2017-01-25 21:17:40 +0000517namespace {
518class RecordBytesVisitor : public TypeVisitorCallbacks {
519public:
520 explicit RecordBytesVisitor(ScopedPrinter &P) : P(P) {}
521
522 Error visitTypeEnd(CVType &Record) override {
523 P.printBinaryBlock("Bytes", Record.content());
524 return Error::success();
525 }
526
527private:
528 ScopedPrinter &P;
529};
Rui Ueyamafd97bf12016-06-03 20:48:51 +0000530}
531
Zachary Turnerd3117392016-06-03 19:28:33 +0000532Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
533 assert(StreamIdx == StreamTPI || StreamIdx == StreamIPI);
534
535 bool DumpRecordBytes = false;
536 bool DumpRecords = false;
Zachary Turner29da5db2017-01-25 21:17:40 +0000537 bool DumpTpiHash = false;
Zachary Turnerd3117392016-06-03 19:28:33 +0000538 StringRef Label;
539 StringRef VerLabel;
540 if (StreamIdx == StreamTPI) {
Bob Haarmana5b43582016-12-05 22:44:00 +0000541 if (!File.hasPDBTpiStream()) {
542 P.printString("Type Info Stream (TPI) not present");
543 return Error::success();
544 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000545 DumpRecordBytes = opts::raw::DumpTpiRecordBytes;
546 DumpRecords = opts::raw::DumpTpiRecords;
Zachary Turner29da5db2017-01-25 21:17:40 +0000547 DumpTpiHash = opts::raw::DumpTpiHash;
Zachary Turnerd3117392016-06-03 19:28:33 +0000548 Label = "Type Info Stream (TPI)";
549 VerLabel = "TPI Version";
550 } else if (StreamIdx == StreamIPI) {
Bob Haarmana5b43582016-12-05 22:44:00 +0000551 if (!File.hasPDBIpiStream()) {
552 P.printString("Type Info Stream (IPI) not present");
553 return Error::success();
554 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000555 DumpRecordBytes = opts::raw::DumpIpiRecordBytes;
556 DumpRecords = opts::raw::DumpIpiRecords;
Zachary Turnerd3117392016-06-03 19:28:33 +0000557 Label = "Type Info Stream (IPI)";
558 VerLabel = "IPI Version";
559 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000560
Zachary Turner29da5db2017-01-25 21:17:40 +0000561 bool IsSilentDatabaseBuild = !DumpRecordBytes && !DumpRecords && !DumpTpiHash;
Zachary Turner5b6e4e02017-04-29 01:13:21 +0000562 if (IsSilentDatabaseBuild) {
563 errs() << "Building Type Information For " << Label << "\n";
564 }
Zachary Turner29da5db2017-01-25 21:17:40 +0000565
Zachary Turnera1657a92016-06-08 17:26:39 +0000566 auto Tpi = (StreamIdx == StreamTPI) ? File.getPDBTpiStream()
567 : File.getPDBIpiStream();
568 if (!Tpi)
569 return Tpi.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000570
Zachary Turner29da5db2017-01-25 21:17:40 +0000571 std::unique_ptr<DictScope> StreamScope;
572 std::unique_ptr<ListScope> RecordScope;
573
574 if (!IsSilentDatabaseBuild) {
575 StreamScope = llvm::make_unique<DictScope>(P, Label);
576 P.printNumber(VerLabel, Tpi->getTpiVersion());
577 P.printNumber("Record count", Tpi->NumTypeRecords());
578 }
579
Reid Klecknera5d187b2017-03-23 21:36:25 +0000580 TypeDatabase &StreamDB = (StreamIdx == StreamTPI) ? TypeDB : ItemDB;
581
582 TypeDatabaseVisitor DBV(StreamDB);
583 CompactTypeDumpVisitor CTDV(StreamDB, &P);
Zachary Turner44a643c2017-01-12 22:28:15 +0000584 TypeDumpVisitor TDV(TypeDB, &P, false);
Reid Klecknera5d187b2017-03-23 21:36:25 +0000585 if (StreamIdx == StreamIPI)
586 TDV.setItemDB(ItemDB);
Zachary Turner29da5db2017-01-25 21:17:40 +0000587 RecordBytesVisitor RBV(P);
Zachary Turner44a643c2017-01-12 22:28:15 +0000588 TypeDeserializer Deserializer;
Zachary Turner29da5db2017-01-25 21:17:40 +0000589
590 // We always need to deserialize and add it to the type database. This is
591 // true if even if we're not dumping anything, because we could need the
592 // type database for the purposes of dumping symbols.
Zachary Turner44a643c2017-01-12 22:28:15 +0000593 TypeVisitorCallbackPipeline Pipeline;
594 Pipeline.addCallbackToPipeline(Deserializer);
595 Pipeline.addCallbackToPipeline(DBV);
596
Zachary Turner29da5db2017-01-25 21:17:40 +0000597 // If we're in dump mode, add a dumper with the appropriate detail level.
598 if (DumpRecords) {
Zachary Turner44a643c2017-01-12 22:28:15 +0000599 if (opts::raw::CompactRecords)
600 Pipeline.addCallbackToPipeline(CTDV);
601 else
602 Pipeline.addCallbackToPipeline(TDV);
Zachary Turnerd3117392016-06-03 19:28:33 +0000603 }
Zachary Turner29da5db2017-01-25 21:17:40 +0000604 if (DumpRecordBytes)
605 Pipeline.addCallbackToPipeline(RBV);
606
607 CVTypeVisitor Visitor(Pipeline);
608
609 if (DumpRecords || DumpRecordBytes)
610 RecordScope = llvm::make_unique<ListScope>(P, "Records");
611
612 bool HadError = false;
613
614 TypeIndex T(TypeIndex::FirstNonSimpleIndex);
615 for (auto Type : Tpi->types(&HadError)) {
616 std::unique_ptr<DictScope> OneRecordScope;
617
618 if ((DumpRecords || DumpRecordBytes) && !opts::raw::CompactRecords)
619 OneRecordScope = llvm::make_unique<DictScope>(P, "");
620
621 if (auto EC = Visitor.visitTypeRecord(Type))
622 return EC;
623 }
624 if (HadError)
625 return make_error<RawError>(raw_error_code::corrupt_file,
626 "TPI stream contained corrupt record");
627
628 if (DumpTpiHash) {
629 DictScope DD(P, "Hash");
630 P.printNumber("Number of Hash Buckets", Tpi->NumHashBuckets());
631 P.printNumber("Hash Key Size", Tpi->getHashKeySize());
632 P.printList("Values", Tpi->getHashValues());
633
634 ListScope LHA(P, "Adjusters");
635 auto ExpectedST = File.getStringTable();
636 if (!ExpectedST)
637 return ExpectedST.takeError();
638 const auto &ST = *ExpectedST;
639 for (const auto &E : Tpi->getHashAdjusters()) {
640 DictScope DHA(P);
641 StringRef Name = ST.getStringForID(E.first);
642 P.printString("Type", Name);
643 P.printHex("TI", E.second);
644 }
645 }
646
647 if (!IsSilentDatabaseBuild) {
648 ListScope L(P, "TypeIndexOffsets");
649 for (const auto &IO : Tpi->getTypeIndexOffsets()) {
650 P.printString(formatv("Index: {0:x}, Offset: {1:N}", IO.Type.getIndex(),
651 (uint32_t)IO.Offset)
652 .str());
653 }
654 }
655
Zachary Turnerd3117392016-06-03 19:28:33 +0000656 P.flush();
657 return Error::success();
658}
659
660Error LLVMOutputStyle::dumpDbiStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000661 bool DumpModules = opts::raw::DumpModules || opts::raw::DumpModuleSyms ||
662 opts::raw::DumpModuleFiles || opts::raw::DumpLineInfo;
663 if (!opts::raw::DumpHeaders && !DumpModules)
Zachary Turnerd3117392016-06-03 19:28:33 +0000664 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000665 if (!File.hasPDBDbiStream()) {
666 P.printString("DBI Stream not present");
667 return Error::success();
668 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000669
Zachary Turnera1657a92016-06-08 17:26:39 +0000670 auto DS = File.getPDBDbiStream();
671 if (!DS)
672 return DS.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000673
674 DictScope D(P, "DBI Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000675 P.printNumber("Dbi Version", DS->getDbiVersion());
676 P.printNumber("Age", DS->getAge());
677 P.printBoolean("Incremental Linking", DS->isIncrementallyLinked());
678 P.printBoolean("Has CTypes", DS->hasCTypes());
679 P.printBoolean("Is Stripped", DS->isStripped());
680 P.printObject("Machine Type", DS->getMachineType());
681 P.printNumber("Symbol Record Stream Index", DS->getSymRecordStreamIndex());
682 P.printNumber("Public Symbol Stream Index", DS->getPublicSymbolStreamIndex());
683 P.printNumber("Global Symbol Stream Index", DS->getGlobalSymbolStreamIndex());
Zachary Turnerd3117392016-06-03 19:28:33 +0000684
Zachary Turnera1657a92016-06-08 17:26:39 +0000685 uint16_t Major = DS->getBuildMajorVersion();
686 uint16_t Minor = DS->getBuildMinorVersion();
Zachary Turnerd3117392016-06-03 19:28:33 +0000687 P.printVersion("Toolchain Version", Major, Minor);
688
689 std::string DllName;
690 raw_string_ostream DllStream(DllName);
691 DllStream << "mspdb" << Major << Minor << ".dll version";
692 DllStream.flush();
Zachary Turnera1657a92016-06-08 17:26:39 +0000693 P.printVersion(DllName, Major, Minor, DS->getPdbDllVersion());
Zachary Turnerd3117392016-06-03 19:28:33 +0000694
695 if (DumpModules) {
696 ListScope L(P, "Modules");
Zachary Turnera1657a92016-06-08 17:26:39 +0000697 for (auto &Modi : DS->modules()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000698 DictScope DD(P);
699 P.printString("Name", Modi.Info.getModuleName().str());
700 P.printNumber("Debug Stream Index", Modi.Info.getModuleStreamIndex());
701 P.printString("Object File Name", Modi.Info.getObjFileName().str());
702 P.printNumber("Num Files", Modi.Info.getNumberOfFiles());
703 P.printNumber("Source File Name Idx", Modi.Info.getSourceFileNameIndex());
704 P.printNumber("Pdb File Name Idx", Modi.Info.getPdbFilePathNameIndex());
Zachary Turner5b6e4e02017-04-29 01:13:21 +0000705 P.printNumber("Line Info Byte Size", Modi.Info.getC11LineInfoByteSize());
Zachary Turnerd3117392016-06-03 19:28:33 +0000706 P.printNumber("C13 Line Info Byte Size",
707 Modi.Info.getC13LineInfoByteSize());
708 P.printNumber("Symbol Byte Size", Modi.Info.getSymbolDebugInfoByteSize());
709 P.printNumber("Type Server Index", Modi.Info.getTypeServerIndex());
710 P.printBoolean("Has EC Info", Modi.Info.hasECInfo());
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000711 if (opts::raw::DumpModuleFiles) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000712 std::string FileListName =
713 to_string(Modi.SourceFiles.size()) + " Contributing Source Files";
714 ListScope LL(P, FileListName);
715 for (auto File : Modi.SourceFiles)
716 P.printString(File.str());
717 }
718 bool HasModuleDI =
719 (Modi.Info.getModuleStreamIndex() < File.getNumStreams());
720 bool ShouldDumpSymbols =
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000721 (opts::raw::DumpModuleSyms || opts::raw::DumpSymRecordBytes);
722 if (HasModuleDI && (ShouldDumpSymbols || opts::raw::DumpLineInfo)) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000723 auto ModStreamData = MappedBlockStream::createIndexedStream(
Zachary Turnerd66889c2016-07-28 19:12:28 +0000724 File.getMsfLayout(), File.getMsfBuffer(),
725 Modi.Info.getModuleStreamIndex());
726
Zachary Turner67c56012017-04-27 16:11:19 +0000727 ModuleDebugStream ModS(Modi.Info, std::move(ModStreamData));
Zachary Turnerd3117392016-06-03 19:28:33 +0000728 if (auto EC = ModS.reload())
729 return EC;
730
731 if (ShouldDumpSymbols) {
732 ListScope SS(P, "Symbols");
Zachary Turner629cb7d2017-01-11 23:24:22 +0000733 codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
Zachary Turnerd3117392016-06-03 19:28:33 +0000734 bool HadError = false;
Zachary Turner0d840742016-10-07 21:34:46 +0000735 for (auto S : ModS.symbols(&HadError)) {
736 DictScope LL(P, "");
737 if (opts::raw::DumpModuleSyms) {
738 if (auto EC = SD.dump(S)) {
739 llvm::consumeError(std::move(EC));
740 HadError = true;
741 break;
742 }
743 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000744 if (opts::raw::DumpSymRecordBytes)
Zachary Turnerc67b00c2016-09-14 23:00:16 +0000745 P.printBinaryBlock("Bytes", S.content());
Zachary Turnerd3117392016-06-03 19:28:33 +0000746 }
747 if (HadError)
748 return make_error<RawError>(
749 raw_error_code::corrupt_file,
750 "DBI stream contained corrupt symbol record");
751 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000752 if (opts::raw::DumpLineInfo) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000753 ListScope SS(P, "LineInfo");
Zachary Turnerd3117392016-06-03 19:28:33 +0000754
Zachary Turner5b6e4e02017-04-29 01:13:21 +0000755 // Inlinee Line Type Indices refer to the IPI stream.
756 C13RawVisitor V(P, File, ItemDB);
757 if (auto EC = codeview::visitModuleDebugFragments(
758 ModS.linesAndChecksums(), V))
759 return EC;
Zachary Turnerd3117392016-06-03 19:28:33 +0000760 }
761 }
762 }
763 }
764 return Error::success();
765}
766
767Error LLVMOutputStyle::dumpSectionContribs() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000768 if (!opts::raw::DumpSectionContribs)
Zachary Turnerd3117392016-06-03 19:28:33 +0000769 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000770 if (!File.hasPDBDbiStream()) {
771 P.printString("DBI Stream not present");
772 return Error::success();
773 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000774
Zachary Turnera1657a92016-06-08 17:26:39 +0000775 auto Dbi = File.getPDBDbiStream();
776 if (!Dbi)
777 return Dbi.takeError();
778
Zachary Turnerd3117392016-06-03 19:28:33 +0000779 ListScope L(P, "Section Contributions");
780 class Visitor : public ISectionContribVisitor {
781 public:
782 Visitor(ScopedPrinter &P, DbiStream &DS) : P(P), DS(DS) {}
783 void visit(const SectionContrib &SC) override {
784 DictScope D(P, "Contribution");
785 P.printNumber("ISect", SC.ISect);
786 P.printNumber("Off", SC.Off);
787 P.printNumber("Size", SC.Size);
788 P.printFlags("Characteristics", SC.Characteristics,
789 codeview::getImageSectionCharacteristicNames(),
790 COFF::SectionCharacteristics(0x00F00000));
791 {
792 DictScope DD(P, "Module");
793 P.printNumber("Index", SC.Imod);
794 auto M = DS.modules();
795 if (M.size() > SC.Imod) {
796 P.printString("Name", M[SC.Imod].Info.getModuleName());
797 }
798 }
799 P.printNumber("Data CRC", SC.DataCrc);
800 P.printNumber("Reloc CRC", SC.RelocCrc);
801 P.flush();
802 }
803 void visit(const SectionContrib2 &SC) override {
804 visit(SC.Base);
805 P.printNumber("ISect Coff", SC.ISectCoff);
806 P.flush();
807 }
808
809 private:
810 ScopedPrinter &P;
811 DbiStream &DS;
812 };
Zachary Turnera1657a92016-06-08 17:26:39 +0000813 Visitor V(P, *Dbi);
814 Dbi->visitSectionContributions(V);
Zachary Turnerd3117392016-06-03 19:28:33 +0000815 return Error::success();
816}
817
818Error LLVMOutputStyle::dumpSectionMap() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000819 if (!opts::raw::DumpSectionMap)
Zachary Turnerd3117392016-06-03 19:28:33 +0000820 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000821 if (!File.hasPDBDbiStream()) {
822 P.printString("DBI Stream not present");
823 return Error::success();
824 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000825
Zachary Turnera1657a92016-06-08 17:26:39 +0000826 auto Dbi = File.getPDBDbiStream();
827 if (!Dbi)
828 return Dbi.takeError();
829
Zachary Turnerd3117392016-06-03 19:28:33 +0000830 ListScope L(P, "Section Map");
Zachary Turnera1657a92016-06-08 17:26:39 +0000831 for (auto &M : Dbi->getSectionMap()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000832 DictScope D(P, "Entry");
833 P.printFlags("Flags", M.Flags, getOMFSegMapDescFlagNames());
Zachary Turnerd3117392016-06-03 19:28:33 +0000834 P.printNumber("Ovl", M.Ovl);
835 P.printNumber("Group", M.Group);
836 P.printNumber("Frame", M.Frame);
837 P.printNumber("SecName", M.SecName);
838 P.printNumber("ClassName", M.ClassName);
839 P.printNumber("Offset", M.Offset);
840 P.printNumber("SecByteLength", M.SecByteLength);
841 P.flush();
842 }
843 return Error::success();
844}
845
846Error LLVMOutputStyle::dumpPublicsStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000847 if (!opts::raw::DumpPublics)
Zachary Turnerd3117392016-06-03 19:28:33 +0000848 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000849 if (!File.hasPDBPublicsStream()) {
850 P.printString("Publics Stream not present");
851 return Error::success();
852 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000853
Zachary Turnera1657a92016-06-08 17:26:39 +0000854 auto Publics = File.getPDBPublicsStream();
855 if (!Publics)
856 return Publics.takeError();
Bob Haarmana5b43582016-12-05 22:44:00 +0000857 DictScope D(P, "Publics Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000858
859 auto Dbi = File.getPDBDbiStream();
860 if (!Dbi)
861 return Dbi.takeError();
862
863 P.printNumber("Stream number", Dbi->getPublicSymbolStreamIndex());
864 P.printNumber("SymHash", Publics->getSymHash());
865 P.printNumber("AddrMap", Publics->getAddrMap());
866 P.printNumber("Number of buckets", Publics->getNumBuckets());
867 P.printList("Hash Buckets", Publics->getHashBuckets());
868 P.printList("Address Map", Publics->getAddressMap());
869 P.printList("Thunk Map", Publics->getThunkMap());
870 P.printList("Section Offsets", Publics->getSectionOffsets(),
Zachary Turnerd3117392016-06-03 19:28:33 +0000871 printSectionOffset);
872 ListScope L(P, "Symbols");
Zachary Turner629cb7d2017-01-11 23:24:22 +0000873 codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
Zachary Turnerd3117392016-06-03 19:28:33 +0000874 bool HadError = false;
Zachary Turnera1657a92016-06-08 17:26:39 +0000875 for (auto S : Publics->getSymbols(&HadError)) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000876 DictScope DD(P, "");
877
Zachary Turner0d840742016-10-07 21:34:46 +0000878 if (auto EC = SD.dump(S)) {
879 HadError = true;
880 break;
881 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000882 if (opts::raw::DumpSymRecordBytes)
Zachary Turnerc67b00c2016-09-14 23:00:16 +0000883 P.printBinaryBlock("Bytes", S.content());
Zachary Turnerd3117392016-06-03 19:28:33 +0000884 }
885 if (HadError)
886 return make_error<RawError>(
887 raw_error_code::corrupt_file,
888 "Public symbol stream contained corrupt record");
889
890 return Error::success();
891}
892
893Error LLVMOutputStyle::dumpSectionHeaders() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000894 if (!opts::raw::DumpSectionHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +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 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000900
Zachary Turnera1657a92016-06-08 17:26:39 +0000901 auto Dbi = File.getPDBDbiStream();
902 if (!Dbi)
903 return Dbi.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000904
905 ListScope D(P, "Section Headers");
Zachary Turnera1657a92016-06-08 17:26:39 +0000906 for (const object::coff_section &Section : Dbi->getSectionHeaders()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000907 DictScope DD(P, "");
908
909 // If a name is 8 characters long, there is no NUL character at end.
910 StringRef Name(Section.Name, strnlen(Section.Name, sizeof(Section.Name)));
911 P.printString("Name", Name);
912 P.printNumber("Virtual Size", Section.VirtualSize);
913 P.printNumber("Virtual Address", Section.VirtualAddress);
914 P.printNumber("Size of Raw Data", Section.SizeOfRawData);
915 P.printNumber("File Pointer to Raw Data", Section.PointerToRawData);
916 P.printNumber("File Pointer to Relocations", Section.PointerToRelocations);
917 P.printNumber("File Pointer to Linenumbers", Section.PointerToLinenumbers);
918 P.printNumber("Number of Relocations", Section.NumberOfRelocations);
919 P.printNumber("Number of Linenumbers", Section.NumberOfLinenumbers);
Rui Ueyama2c5384a2016-06-06 21:34:55 +0000920 P.printFlags("Characteristics", Section.Characteristics,
921 getImageSectionCharacteristicNames());
Zachary Turnerd3117392016-06-03 19:28:33 +0000922 }
923 return Error::success();
924}
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000925
926Error LLVMOutputStyle::dumpFpoStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000927 if (!opts::raw::DumpFpo)
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000928 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000929 if (!File.hasPDBDbiStream()) {
930 P.printString("DBI Stream not present");
931 return Error::success();
932 }
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000933
Zachary Turnera1657a92016-06-08 17:26:39 +0000934 auto Dbi = File.getPDBDbiStream();
935 if (!Dbi)
936 return Dbi.takeError();
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000937
938 ListScope D(P, "New FPO");
Zachary Turnera1657a92016-06-08 17:26:39 +0000939 for (const object::FpoData &Fpo : Dbi->getFpoRecords()) {
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000940 DictScope DD(P, "");
941 P.printNumber("Offset", Fpo.Offset);
942 P.printNumber("Size", Fpo.Size);
943 P.printNumber("Number of locals", Fpo.NumLocals);
944 P.printNumber("Number of params", Fpo.NumParams);
945 P.printNumber("Size of Prolog", Fpo.getPrologSize());
946 P.printNumber("Number of Saved Registers", Fpo.getNumSavedRegs());
947 P.printBoolean("Has SEH", Fpo.hasSEH());
948 P.printBoolean("Use BP", Fpo.useBP());
949 P.printNumber("Frame Pointer", Fpo.getFP());
950 }
951 return Error::success();
952}
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000953
Zachary Turner7120a472016-06-06 20:37:05 +0000954void LLVMOutputStyle::flush() { P.flush(); }