blob: 8ed1a9020c4446ee60d60f1f447961c8babe07b0 [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:
Zachary Turnerdf1d9762017-04-29 05:30:19 +000087 C13RawVisitor(ScopedPrinter &P, PDBFile &F)
88 : C13DebugFragmentVisitor(F), P(P) {}
Zachary Turner5b6e4e02017-04-29 01:13:21 +000089
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;
Zachary Turner5b6e4e02017-04-29 01:13:21 +0000154};
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000155}
156
157static void recordKnownUsedPage(PageStats &Stats, uint32_t UsedIndex) {
158 if (Stats.Upm.test(UsedIndex)) {
159 if (Stats.ActualUsedPages.test(UsedIndex))
160 Stats.MultiUsePages.set(UsedIndex);
161 Stats.ActualUsedPages.set(UsedIndex);
162 Stats.OrphanedPages.reset(UsedIndex);
163 } else {
164 // The MSF doesn't think this page is used, but it is.
165 Stats.UseAfterFreePages.set(UsedIndex);
166 }
167}
168
Zachary Turnerd3117392016-06-03 19:28:33 +0000169static void printSectionOffset(llvm::raw_ostream &OS,
170 const SectionOffset &Off) {
171 OS << Off.Off << ", " << Off.Isect;
172}
173
Zachary Turner629cb7d2017-01-11 23:24:22 +0000174LLVMOutputStyle::LLVMOutputStyle(PDBFile &File) : File(File), P(outs()) {}
Zachary Turnerd3117392016-06-03 19:28:33 +0000175
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000176Error LLVMOutputStyle::dump() {
177 if (auto EC = dumpFileHeaders())
178 return EC;
179
180 if (auto EC = dumpStreamSummary())
181 return EC;
182
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000183 if (auto EC = dumpFreePageMap())
184 return EC;
185
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000186 if (auto EC = dumpStreamBlocks())
187 return EC;
188
Zachary Turner72c5b642016-09-09 18:17:52 +0000189 if (auto EC = dumpBlockRanges())
190 return EC;
191
192 if (auto EC = dumpStreamBytes())
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000193 return EC;
194
Zachary Turner760ad4d2017-01-20 22:42:09 +0000195 if (auto EC = dumpStringTable())
196 return EC;
197
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000198 if (auto EC = dumpInfoStream())
199 return EC;
200
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000201 if (auto EC = dumpTpiStream(StreamTPI))
202 return EC;
203
204 if (auto EC = dumpTpiStream(StreamIPI))
205 return EC;
206
207 if (auto EC = dumpDbiStream())
208 return EC;
209
210 if (auto EC = dumpSectionContribs())
211 return EC;
212
213 if (auto EC = dumpSectionMap())
214 return EC;
215
Bob Haarman653baa22016-10-21 19:43:19 +0000216 if (auto EC = dumpGlobalsStream())
217 return EC;
218
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000219 if (auto EC = dumpPublicsStream())
220 return EC;
221
222 if (auto EC = dumpSectionHeaders())
223 return EC;
224
225 if (auto EC = dumpFpoStream())
226 return EC;
227
228 flush();
229
230 return Error::success();
231}
232
Zachary Turnerd3117392016-06-03 19:28:33 +0000233Error LLVMOutputStyle::dumpFileHeaders() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000234 if (!opts::raw::DumpHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000235 return Error::success();
236
237 DictScope D(P, "FileHeaders");
238 P.printNumber("BlockSize", File.getBlockSize());
Zachary Turnerb927e022016-07-15 22:17:19 +0000239 P.printNumber("FreeBlockMap", File.getFreeBlockMapBlock());
Zachary Turnerd3117392016-06-03 19:28:33 +0000240 P.printNumber("NumBlocks", File.getBlockCount());
241 P.printNumber("NumDirectoryBytes", File.getNumDirectoryBytes());
242 P.printNumber("Unknown1", File.getUnknown1());
243 P.printNumber("BlockMapAddr", File.getBlockMapIndex());
244 P.printNumber("NumDirectoryBlocks", File.getNumDirectoryBlocks());
Zachary Turnerd3117392016-06-03 19:28:33 +0000245
246 // The directory is not contiguous. Instead, the block map contains a
247 // contiguous list of block numbers whose contents, when concatenated in
248 // order, make up the directory.
249 P.printList("DirectoryBlocks", File.getDirectoryBlockArray());
250 P.printNumber("NumStreams", File.getNumStreams());
251 return Error::success();
252}
253
Zachary Turner36efbfa2016-09-09 19:00:49 +0000254Error LLVMOutputStyle::dumpStreamSummary() {
255 if (!opts::raw::DumpStreamSummary)
256 return Error::success();
257
Zachary Turner6ac232c2017-03-13 23:28:25 +0000258 if (StreamPurposes.empty())
259 discoverStreamPurposes(File, StreamPurposes);
Zachary Turner36efbfa2016-09-09 19:00:49 +0000260
261 uint32_t StreamCount = File.getNumStreams();
262
263 ListScope L(P, "Streams");
264 for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
265 std::string Label("Stream ");
266 Label += to_string(StreamIdx);
267
268 std::string Value = "[" + StreamPurposes[StreamIdx] + "] (";
269 Value += to_string(File.getStreamByteSize(StreamIdx));
270 Value += " bytes)";
271
272 P.printString(Label, Value);
273 }
Reid Kleckner11582c52016-06-17 20:38:01 +0000274
Zachary Turnerd3117392016-06-03 19:28:33 +0000275 P.flush();
276 return Error::success();
277}
278
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000279Error LLVMOutputStyle::dumpFreePageMap() {
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000280 if (!opts::raw::DumpPageStats)
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000281 return Error::success();
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000282
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000283 // Start with used pages instead of free pages because
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000284 // the number of free pages is far larger than used pages.
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000285 BitVector FPM = File.getMsfLayout().FreePageMap;
286
287 PageStats PS(FPM);
288
289 recordKnownUsedPage(PS, 0); // MSF Super Block
290
Zachary Turner8cf51c32016-08-03 16:53:21 +0000291 uint32_t BlocksPerSection = msf::getFpmIntervalLength(File.getMsfLayout());
292 uint32_t NumSections = msf::getNumFpmIntervals(File.getMsfLayout());
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000293 for (uint32_t I = 0; I < NumSections; ++I) {
294 uint32_t Fpm0 = 1 + BlocksPerSection * I;
295 // 2 Fpm blocks spaced at `getBlockSize()` block intervals
296 recordKnownUsedPage(PS, Fpm0);
297 recordKnownUsedPage(PS, Fpm0 + 1);
298 }
299
300 recordKnownUsedPage(PS, File.getBlockMapIndex()); // Stream Table
301
Rui Ueyama22e67382016-08-02 23:22:46 +0000302 for (auto DB : File.getDirectoryBlockArray())
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000303 recordKnownUsedPage(PS, DB);
Rui Ueyama22e67382016-08-02 23:22:46 +0000304
305 // Record pages used by streams. Note that pages for stream 0
306 // are considered being unused because that's what MSVC tools do.
307 // Stream 0 doesn't contain actual data, so it makes some sense,
308 // though it's a bit confusing to us.
309 for (auto &SE : File.getStreamMap().drop_front(1))
310 for (auto &S : SE)
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000311 recordKnownUsedPage(PS, S);
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000312
313 dumpBitVector("Msf Free Pages", FPM);
314 dumpBitVector("Orphaned Pages", PS.OrphanedPages);
315 dumpBitVector("Multiply Used Pages", PS.MultiUsePages);
316 dumpBitVector("Use After Free Pages", PS.UseAfterFreePages);
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000317 return Error::success();
318}
319
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000320void LLVMOutputStyle::dumpBitVector(StringRef Name, const BitVector &V) {
321 std::vector<uint32_t> Vec;
322 for (uint32_t I = 0, E = V.size(); I != E; ++I)
323 if (V[I])
324 Vec.push_back(I);
325 P.printList(Name, Vec);
326}
327
Bob Haarman653baa22016-10-21 19:43:19 +0000328Error LLVMOutputStyle::dumpGlobalsStream() {
329 if (!opts::raw::DumpGlobals)
330 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000331 if (!File.hasPDBGlobalsStream()) {
332 P.printString("Globals Stream not present");
333 return Error::success();
334 }
Bob Haarman653baa22016-10-21 19:43:19 +0000335
Bob Haarman653baa22016-10-21 19:43:19 +0000336 auto Globals = File.getPDBGlobalsStream();
337 if (!Globals)
Bob Haarman312fd0e2016-12-06 00:55:55 +0000338 return Globals.takeError();
Bob Haarmana5b43582016-12-05 22:44:00 +0000339 DictScope D(P, "Globals Stream");
Bob Haarman653baa22016-10-21 19:43:19 +0000340
341 auto Dbi = File.getPDBDbiStream();
342 if (!Dbi)
343 return Dbi.takeError();
344
345 P.printNumber("Stream number", Dbi->getGlobalSymbolStreamIndex());
346 P.printNumber("Number of buckets", Globals->getNumBuckets());
347 P.printList("Hash Buckets", Globals->getHashBuckets());
348
349 return Error::success();
350}
351
Zachary Turnerd3117392016-06-03 19:28:33 +0000352Error LLVMOutputStyle::dumpStreamBlocks() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000353 if (!opts::raw::DumpStreamBlocks)
Zachary Turnerd3117392016-06-03 19:28:33 +0000354 return Error::success();
355
356 ListScope L(P, "StreamBlocks");
357 uint32_t StreamCount = File.getNumStreams();
358 for (uint32_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
359 std::string Name("Stream ");
360 Name += to_string(StreamIdx);
361 auto StreamBlocks = File.getStreamBlockList(StreamIdx);
362 P.printList(Name, StreamBlocks);
363 }
364 return Error::success();
365}
366
Zachary Turner72c5b642016-09-09 18:17:52 +0000367Error LLVMOutputStyle::dumpBlockRanges() {
368 if (!opts::raw::DumpBlockRange.hasValue())
369 return Error::success();
370 auto &R = *opts::raw::DumpBlockRange;
371 uint32_t Max = R.Max.getValueOr(R.Min);
372
373 if (Max < R.Min)
374 return make_error<StringError>(
375 "Invalid block range specified. Max < Min",
376 std::make_error_code(std::errc::bad_address));
377 if (Max >= File.getBlockCount())
378 return make_error<StringError>(
379 "Invalid block range specified. Requested block out of bounds",
380 std::make_error_code(std::errc::bad_address));
381
382 DictScope D(P, "Block Data");
383 for (uint32_t I = R.Min; I <= Max; ++I) {
384 auto ExpectedData = File.getBlockData(I, File.getBlockSize());
385 if (!ExpectedData)
386 return ExpectedData.takeError();
387 std::string Label;
388 llvm::raw_string_ostream S(Label);
389 S << "Block " << I;
390 S.flush();
391 P.printBinaryBlock(Label, *ExpectedData);
392 }
393
394 return Error::success();
395}
396
Zachary Turner7159ab92017-04-28 00:43:38 +0000397static Error parseStreamSpec(StringRef Str, uint32_t &SI, uint32_t &Offset,
398 uint32_t &Size) {
399 if (Str.consumeInteger(0, SI))
400 return make_error<RawError>(raw_error_code::invalid_format,
401 "Invalid Stream Specification");
402 if (Str.consume_front(":")) {
403 if (Str.consumeInteger(0, Offset))
404 return make_error<RawError>(raw_error_code::invalid_format,
405 "Invalid Stream Specification");
406 }
407 if (Str.consume_front("@")) {
408 if (Str.consumeInteger(0, Size))
409 return make_error<RawError>(raw_error_code::invalid_format,
410 "Invalid Stream Specification");
411 }
412 if (!Str.empty())
413 return make_error<RawError>(raw_error_code::invalid_format,
414 "Invalid Stream Specification");
415 return Error::success();
416}
417
Zachary Turner72c5b642016-09-09 18:17:52 +0000418Error LLVMOutputStyle::dumpStreamBytes() {
419 if (opts::raw::DumpStreamData.empty())
Zachary Turnerd3117392016-06-03 19:28:33 +0000420 return Error::success();
421
Zachary Turner6ac232c2017-03-13 23:28:25 +0000422 if (StreamPurposes.empty())
423 discoverStreamPurposes(File, StreamPurposes);
Zachary Turner36efbfa2016-09-09 19:00:49 +0000424
Zachary Turner72c5b642016-09-09 18:17:52 +0000425 DictScope D(P, "Stream Data");
Zachary Turner7159ab92017-04-28 00:43:38 +0000426 for (auto &Str : opts::raw::DumpStreamData) {
427 uint32_t SI = 0;
428 uint32_t Begin = 0;
429 uint32_t Size = 0;
430 uint32_t End = 0;
431
432 if (auto EC = parseStreamSpec(Str, SI, Begin, Size))
433 return EC;
434
Zachary Turner72c5b642016-09-09 18:17:52 +0000435 if (SI >= File.getNumStreams())
436 return make_error<RawError>(raw_error_code::no_stream);
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000437
Zachary Turner72c5b642016-09-09 18:17:52 +0000438 auto S = MappedBlockStream::createIndexedStream(File.getMsfLayout(),
439 File.getMsfBuffer(), SI);
440 if (!S)
441 continue;
Zachary Turner36efbfa2016-09-09 19:00:49 +0000442 DictScope DD(P, "Stream");
Zachary Turner7159ab92017-04-28 00:43:38 +0000443 if (Size == 0)
444 End = S->getLength();
445 else {
446 End = Begin + Size;
447 if (End >= S->getLength())
448 return make_error<RawError>(raw_error_code::index_out_of_bounds,
449 "Stream is not long enough!");
450 }
Zachary Turner36efbfa2016-09-09 19:00:49 +0000451
452 P.printNumber("Index", SI);
453 P.printString("Type", StreamPurposes[SI]);
454 P.printNumber("Size", S->getLength());
455 auto Blocks = File.getMsfLayout().StreamMap[SI];
456 P.printList("Blocks", Blocks);
457
Zachary Turner120faca2017-02-27 22:11:43 +0000458 BinaryStreamReader R(*S);
Zachary Turner72c5b642016-09-09 18:17:52 +0000459 ArrayRef<uint8_t> StreamData;
460 if (auto EC = R.readBytes(StreamData, S->getLength()))
Zachary Turnerd3117392016-06-03 19:28:33 +0000461 return EC;
Zachary Turner7159ab92017-04-28 00:43:38 +0000462 Size = End - Begin;
463 StreamData = StreamData.slice(Begin, Size);
464 P.printBinaryBlock("Data", StreamData, Begin);
Zachary Turnerd3117392016-06-03 19:28:33 +0000465 }
466 return Error::success();
467}
468
Zachary Turner760ad4d2017-01-20 22:42:09 +0000469Error LLVMOutputStyle::dumpStringTable() {
470 if (!opts::raw::DumpStringTable)
471 return Error::success();
472
473 auto IS = File.getStringTable();
474 if (!IS)
475 return IS.takeError();
476
477 DictScope D(P, "String Table");
478 for (uint32_t I : IS->name_ids()) {
479 StringRef S = IS->getStringForID(I);
480 if (!S.empty()) {
481 llvm::SmallString<32> Str;
482 Str.append("'");
483 Str.append(S);
484 Str.append("'");
485 P.printString(Str);
486 }
487 }
488 return Error::success();
489}
490
Zachary Turnerd3117392016-06-03 19:28:33 +0000491Error LLVMOutputStyle::dumpInfoStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000492 if (!opts::raw::DumpHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000493 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000494 if (!File.hasPDBInfoStream()) {
495 P.printString("PDB Stream not present");
496 return Error::success();
497 }
Zachary Turnera1657a92016-06-08 17:26:39 +0000498 auto IS = File.getPDBInfoStream();
499 if (!IS)
500 return IS.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000501
502 DictScope D(P, "PDB Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000503 P.printNumber("Version", IS->getVersion());
504 P.printHex("Signature", IS->getSignature());
505 P.printNumber("Age", IS->getAge());
506 P.printObject("Guid", IS->getGuid());
Zachary Turner05d5e612017-03-16 20:19:11 +0000507 P.printHex("Features", IS->getFeatures());
Zachary Turner760ad4d2017-01-20 22:42:09 +0000508 {
509 DictScope DD(P, "Named Streams");
510 for (const auto &S : IS->getNamedStreams().entries())
511 P.printObject(S.getKey(), S.getValue());
512 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000513 return Error::success();
514}
515
Zachary Turner29da5db2017-01-25 21:17:40 +0000516namespace {
517class RecordBytesVisitor : public TypeVisitorCallbacks {
518public:
519 explicit RecordBytesVisitor(ScopedPrinter &P) : P(P) {}
520
521 Error visitTypeEnd(CVType &Record) override {
522 P.printBinaryBlock("Bytes", Record.content());
523 return Error::success();
524 }
525
526private:
527 ScopedPrinter &P;
528};
Rui Ueyamafd97bf12016-06-03 20:48:51 +0000529}
530
Zachary Turnerd3117392016-06-03 19:28:33 +0000531Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
532 assert(StreamIdx == StreamTPI || StreamIdx == StreamIPI);
533
534 bool DumpRecordBytes = false;
535 bool DumpRecords = false;
Zachary Turner29da5db2017-01-25 21:17:40 +0000536 bool DumpTpiHash = false;
Zachary Turnerd3117392016-06-03 19:28:33 +0000537 StringRef Label;
538 StringRef VerLabel;
539 if (StreamIdx == StreamTPI) {
Bob Haarmana5b43582016-12-05 22:44:00 +0000540 if (!File.hasPDBTpiStream()) {
541 P.printString("Type Info Stream (TPI) not present");
542 return Error::success();
543 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000544 DumpRecordBytes = opts::raw::DumpTpiRecordBytes;
545 DumpRecords = opts::raw::DumpTpiRecords;
Zachary Turner29da5db2017-01-25 21:17:40 +0000546 DumpTpiHash = opts::raw::DumpTpiHash;
Zachary Turnerd3117392016-06-03 19:28:33 +0000547 Label = "Type Info Stream (TPI)";
548 VerLabel = "TPI Version";
549 } else if (StreamIdx == StreamIPI) {
Bob Haarmana5b43582016-12-05 22:44:00 +0000550 if (!File.hasPDBIpiStream()) {
551 P.printString("Type Info Stream (IPI) not present");
552 return Error::success();
553 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000554 DumpRecordBytes = opts::raw::DumpIpiRecordBytes;
555 DumpRecords = opts::raw::DumpIpiRecords;
Zachary Turnerd3117392016-06-03 19:28:33 +0000556 Label = "Type Info Stream (IPI)";
557 VerLabel = "IPI Version";
558 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000559
Zachary Turner29da5db2017-01-25 21:17:40 +0000560 bool IsSilentDatabaseBuild = !DumpRecordBytes && !DumpRecords && !DumpTpiHash;
Zachary Turner5b6e4e02017-04-29 01:13:21 +0000561 if (IsSilentDatabaseBuild) {
562 errs() << "Building Type Information For " << Label << "\n";
563 }
Zachary Turner29da5db2017-01-25 21:17:40 +0000564
Zachary Turnera1657a92016-06-08 17:26:39 +0000565 auto Tpi = (StreamIdx == StreamTPI) ? File.getPDBTpiStream()
566 : File.getPDBIpiStream();
567 if (!Tpi)
568 return Tpi.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000569
Zachary Turner29da5db2017-01-25 21:17:40 +0000570 std::unique_ptr<DictScope> StreamScope;
571 std::unique_ptr<ListScope> RecordScope;
572
573 if (!IsSilentDatabaseBuild) {
574 StreamScope = llvm::make_unique<DictScope>(P, Label);
575 P.printNumber(VerLabel, Tpi->getTpiVersion());
576 P.printNumber("Record count", Tpi->NumTypeRecords());
577 }
578
Reid Klecknera5d187b2017-03-23 21:36:25 +0000579 TypeDatabase &StreamDB = (StreamIdx == StreamTPI) ? TypeDB : ItemDB;
580
581 TypeDatabaseVisitor DBV(StreamDB);
582 CompactTypeDumpVisitor CTDV(StreamDB, &P);
Zachary Turner44a643c2017-01-12 22:28:15 +0000583 TypeDumpVisitor TDV(TypeDB, &P, false);
Reid Klecknera5d187b2017-03-23 21:36:25 +0000584 if (StreamIdx == StreamIPI)
585 TDV.setItemDB(ItemDB);
Zachary Turner29da5db2017-01-25 21:17:40 +0000586 RecordBytesVisitor RBV(P);
Zachary Turner44a643c2017-01-12 22:28:15 +0000587 TypeDeserializer Deserializer;
Zachary Turner29da5db2017-01-25 21:17:40 +0000588
589 // We always need to deserialize and add it to the type database. This is
590 // true if even if we're not dumping anything, because we could need the
591 // type database for the purposes of dumping symbols.
Zachary Turner44a643c2017-01-12 22:28:15 +0000592 TypeVisitorCallbackPipeline Pipeline;
593 Pipeline.addCallbackToPipeline(Deserializer);
594 Pipeline.addCallbackToPipeline(DBV);
595
Zachary Turner29da5db2017-01-25 21:17:40 +0000596 // If we're in dump mode, add a dumper with the appropriate detail level.
597 if (DumpRecords) {
Zachary Turner44a643c2017-01-12 22:28:15 +0000598 if (opts::raw::CompactRecords)
599 Pipeline.addCallbackToPipeline(CTDV);
600 else
601 Pipeline.addCallbackToPipeline(TDV);
Zachary Turnerd3117392016-06-03 19:28:33 +0000602 }
Zachary Turner29da5db2017-01-25 21:17:40 +0000603 if (DumpRecordBytes)
604 Pipeline.addCallbackToPipeline(RBV);
605
606 CVTypeVisitor Visitor(Pipeline);
607
608 if (DumpRecords || DumpRecordBytes)
609 RecordScope = llvm::make_unique<ListScope>(P, "Records");
610
611 bool HadError = false;
612
613 TypeIndex T(TypeIndex::FirstNonSimpleIndex);
614 for (auto Type : Tpi->types(&HadError)) {
615 std::unique_ptr<DictScope> OneRecordScope;
616
617 if ((DumpRecords || DumpRecordBytes) && !opts::raw::CompactRecords)
618 OneRecordScope = llvm::make_unique<DictScope>(P, "");
619
620 if (auto EC = Visitor.visitTypeRecord(Type))
621 return EC;
622 }
623 if (HadError)
624 return make_error<RawError>(raw_error_code::corrupt_file,
625 "TPI stream contained corrupt record");
626
627 if (DumpTpiHash) {
628 DictScope DD(P, "Hash");
629 P.printNumber("Number of Hash Buckets", Tpi->NumHashBuckets());
630 P.printNumber("Hash Key Size", Tpi->getHashKeySize());
631 P.printList("Values", Tpi->getHashValues());
632
633 ListScope LHA(P, "Adjusters");
634 auto ExpectedST = File.getStringTable();
635 if (!ExpectedST)
636 return ExpectedST.takeError();
637 const auto &ST = *ExpectedST;
638 for (const auto &E : Tpi->getHashAdjusters()) {
639 DictScope DHA(P);
640 StringRef Name = ST.getStringForID(E.first);
641 P.printString("Type", Name);
642 P.printHex("TI", E.second);
643 }
644 }
645
646 if (!IsSilentDatabaseBuild) {
647 ListScope L(P, "TypeIndexOffsets");
648 for (const auto &IO : Tpi->getTypeIndexOffsets()) {
649 P.printString(formatv("Index: {0:x}, Offset: {1:N}", IO.Type.getIndex(),
650 (uint32_t)IO.Offset)
651 .str());
652 }
653 }
654
Zachary Turnerd3117392016-06-03 19:28:33 +0000655 P.flush();
656 return Error::success();
657}
658
659Error LLVMOutputStyle::dumpDbiStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000660 bool DumpModules = opts::raw::DumpModules || opts::raw::DumpModuleSyms ||
661 opts::raw::DumpModuleFiles || opts::raw::DumpLineInfo;
662 if (!opts::raw::DumpHeaders && !DumpModules)
Zachary Turnerd3117392016-06-03 19:28:33 +0000663 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000664 if (!File.hasPDBDbiStream()) {
665 P.printString("DBI Stream not present");
666 return Error::success();
667 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000668
Zachary Turnera1657a92016-06-08 17:26:39 +0000669 auto DS = File.getPDBDbiStream();
670 if (!DS)
671 return DS.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000672
673 DictScope D(P, "DBI Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000674 P.printNumber("Dbi Version", DS->getDbiVersion());
675 P.printNumber("Age", DS->getAge());
676 P.printBoolean("Incremental Linking", DS->isIncrementallyLinked());
677 P.printBoolean("Has CTypes", DS->hasCTypes());
678 P.printBoolean("Is Stripped", DS->isStripped());
679 P.printObject("Machine Type", DS->getMachineType());
680 P.printNumber("Symbol Record Stream Index", DS->getSymRecordStreamIndex());
681 P.printNumber("Public Symbol Stream Index", DS->getPublicSymbolStreamIndex());
682 P.printNumber("Global Symbol Stream Index", DS->getGlobalSymbolStreamIndex());
Zachary Turnerd3117392016-06-03 19:28:33 +0000683
Zachary Turnera1657a92016-06-08 17:26:39 +0000684 uint16_t Major = DS->getBuildMajorVersion();
685 uint16_t Minor = DS->getBuildMinorVersion();
Zachary Turnerd3117392016-06-03 19:28:33 +0000686 P.printVersion("Toolchain Version", Major, Minor);
687
688 std::string DllName;
689 raw_string_ostream DllStream(DllName);
690 DllStream << "mspdb" << Major << Minor << ".dll version";
691 DllStream.flush();
Zachary Turnera1657a92016-06-08 17:26:39 +0000692 P.printVersion(DllName, Major, Minor, DS->getPdbDllVersion());
Zachary Turnerd3117392016-06-03 19:28:33 +0000693
694 if (DumpModules) {
695 ListScope L(P, "Modules");
Zachary Turnera1657a92016-06-08 17:26:39 +0000696 for (auto &Modi : DS->modules()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000697 DictScope DD(P);
698 P.printString("Name", Modi.Info.getModuleName().str());
699 P.printNumber("Debug Stream Index", Modi.Info.getModuleStreamIndex());
700 P.printString("Object File Name", Modi.Info.getObjFileName().str());
701 P.printNumber("Num Files", Modi.Info.getNumberOfFiles());
702 P.printNumber("Source File Name Idx", Modi.Info.getSourceFileNameIndex());
703 P.printNumber("Pdb File Name Idx", Modi.Info.getPdbFilePathNameIndex());
Zachary Turner5b6e4e02017-04-29 01:13:21 +0000704 P.printNumber("Line Info Byte Size", Modi.Info.getC11LineInfoByteSize());
Zachary Turnerd3117392016-06-03 19:28:33 +0000705 P.printNumber("C13 Line Info Byte Size",
706 Modi.Info.getC13LineInfoByteSize());
707 P.printNumber("Symbol Byte Size", Modi.Info.getSymbolDebugInfoByteSize());
708 P.printNumber("Type Server Index", Modi.Info.getTypeServerIndex());
709 P.printBoolean("Has EC Info", Modi.Info.hasECInfo());
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000710 if (opts::raw::DumpModuleFiles) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000711 std::string FileListName =
712 to_string(Modi.SourceFiles.size()) + " Contributing Source Files";
713 ListScope LL(P, FileListName);
714 for (auto File : Modi.SourceFiles)
715 P.printString(File.str());
716 }
717 bool HasModuleDI =
718 (Modi.Info.getModuleStreamIndex() < File.getNumStreams());
719 bool ShouldDumpSymbols =
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000720 (opts::raw::DumpModuleSyms || opts::raw::DumpSymRecordBytes);
721 if (HasModuleDI && (ShouldDumpSymbols || opts::raw::DumpLineInfo)) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000722 auto ModStreamData = MappedBlockStream::createIndexedStream(
Zachary Turnerd66889c2016-07-28 19:12:28 +0000723 File.getMsfLayout(), File.getMsfBuffer(),
724 Modi.Info.getModuleStreamIndex());
725
Zachary Turner67c56012017-04-27 16:11:19 +0000726 ModuleDebugStream ModS(Modi.Info, std::move(ModStreamData));
Zachary Turnerd3117392016-06-03 19:28:33 +0000727 if (auto EC = ModS.reload())
728 return EC;
729
730 if (ShouldDumpSymbols) {
731 ListScope SS(P, "Symbols");
Zachary Turner629cb7d2017-01-11 23:24:22 +0000732 codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
Zachary Turnerd3117392016-06-03 19:28:33 +0000733 bool HadError = false;
Zachary Turner0d840742016-10-07 21:34:46 +0000734 for (auto S : ModS.symbols(&HadError)) {
735 DictScope LL(P, "");
736 if (opts::raw::DumpModuleSyms) {
737 if (auto EC = SD.dump(S)) {
738 llvm::consumeError(std::move(EC));
739 HadError = true;
740 break;
741 }
742 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000743 if (opts::raw::DumpSymRecordBytes)
Zachary Turnerc67b00c2016-09-14 23:00:16 +0000744 P.printBinaryBlock("Bytes", S.content());
Zachary Turnerd3117392016-06-03 19:28:33 +0000745 }
746 if (HadError)
747 return make_error<RawError>(
748 raw_error_code::corrupt_file,
749 "DBI stream contained corrupt symbol record");
750 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000751 if (opts::raw::DumpLineInfo) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000752 ListScope SS(P, "LineInfo");
Zachary Turnerd3117392016-06-03 19:28:33 +0000753
Zachary Turner5b6e4e02017-04-29 01:13:21 +0000754 // Inlinee Line Type Indices refer to the IPI stream.
Zachary Turnerdf1d9762017-04-29 05:30:19 +0000755 C13RawVisitor V(P, File);
Zachary Turner5b6e4e02017-04-29 01:13:21 +0000756 if (auto EC = codeview::visitModuleDebugFragments(
757 ModS.linesAndChecksums(), V))
758 return EC;
Zachary Turnerd3117392016-06-03 19:28:33 +0000759 }
760 }
761 }
762 }
763 return Error::success();
764}
765
766Error LLVMOutputStyle::dumpSectionContribs() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000767 if (!opts::raw::DumpSectionContribs)
Zachary Turnerd3117392016-06-03 19:28:33 +0000768 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000769 if (!File.hasPDBDbiStream()) {
770 P.printString("DBI Stream not present");
771 return Error::success();
772 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000773
Zachary Turnera1657a92016-06-08 17:26:39 +0000774 auto Dbi = File.getPDBDbiStream();
775 if (!Dbi)
776 return Dbi.takeError();
777
Zachary Turnerd3117392016-06-03 19:28:33 +0000778 ListScope L(P, "Section Contributions");
779 class Visitor : public ISectionContribVisitor {
780 public:
781 Visitor(ScopedPrinter &P, DbiStream &DS) : P(P), DS(DS) {}
782 void visit(const SectionContrib &SC) override {
783 DictScope D(P, "Contribution");
784 P.printNumber("ISect", SC.ISect);
785 P.printNumber("Off", SC.Off);
786 P.printNumber("Size", SC.Size);
787 P.printFlags("Characteristics", SC.Characteristics,
788 codeview::getImageSectionCharacteristicNames(),
789 COFF::SectionCharacteristics(0x00F00000));
790 {
791 DictScope DD(P, "Module");
792 P.printNumber("Index", SC.Imod);
793 auto M = DS.modules();
794 if (M.size() > SC.Imod) {
795 P.printString("Name", M[SC.Imod].Info.getModuleName());
796 }
797 }
798 P.printNumber("Data CRC", SC.DataCrc);
799 P.printNumber("Reloc CRC", SC.RelocCrc);
800 P.flush();
801 }
802 void visit(const SectionContrib2 &SC) override {
803 visit(SC.Base);
804 P.printNumber("ISect Coff", SC.ISectCoff);
805 P.flush();
806 }
807
808 private:
809 ScopedPrinter &P;
810 DbiStream &DS;
811 };
Zachary Turnera1657a92016-06-08 17:26:39 +0000812 Visitor V(P, *Dbi);
813 Dbi->visitSectionContributions(V);
Zachary Turnerd3117392016-06-03 19:28:33 +0000814 return Error::success();
815}
816
817Error LLVMOutputStyle::dumpSectionMap() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000818 if (!opts::raw::DumpSectionMap)
Zachary Turnerd3117392016-06-03 19:28:33 +0000819 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000820 if (!File.hasPDBDbiStream()) {
821 P.printString("DBI Stream not present");
822 return Error::success();
823 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000824
Zachary Turnera1657a92016-06-08 17:26:39 +0000825 auto Dbi = File.getPDBDbiStream();
826 if (!Dbi)
827 return Dbi.takeError();
828
Zachary Turnerd3117392016-06-03 19:28:33 +0000829 ListScope L(P, "Section Map");
Zachary Turnera1657a92016-06-08 17:26:39 +0000830 for (auto &M : Dbi->getSectionMap()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000831 DictScope D(P, "Entry");
832 P.printFlags("Flags", M.Flags, getOMFSegMapDescFlagNames());
Zachary Turnerd3117392016-06-03 19:28:33 +0000833 P.printNumber("Ovl", M.Ovl);
834 P.printNumber("Group", M.Group);
835 P.printNumber("Frame", M.Frame);
836 P.printNumber("SecName", M.SecName);
837 P.printNumber("ClassName", M.ClassName);
838 P.printNumber("Offset", M.Offset);
839 P.printNumber("SecByteLength", M.SecByteLength);
840 P.flush();
841 }
842 return Error::success();
843}
844
845Error LLVMOutputStyle::dumpPublicsStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000846 if (!opts::raw::DumpPublics)
Zachary Turnerd3117392016-06-03 19:28:33 +0000847 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000848 if (!File.hasPDBPublicsStream()) {
849 P.printString("Publics Stream not present");
850 return Error::success();
851 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000852
Zachary Turnera1657a92016-06-08 17:26:39 +0000853 auto Publics = File.getPDBPublicsStream();
854 if (!Publics)
855 return Publics.takeError();
Bob Haarmana5b43582016-12-05 22:44:00 +0000856 DictScope D(P, "Publics Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000857
858 auto Dbi = File.getPDBDbiStream();
859 if (!Dbi)
860 return Dbi.takeError();
861
862 P.printNumber("Stream number", Dbi->getPublicSymbolStreamIndex());
863 P.printNumber("SymHash", Publics->getSymHash());
864 P.printNumber("AddrMap", Publics->getAddrMap());
865 P.printNumber("Number of buckets", Publics->getNumBuckets());
866 P.printList("Hash Buckets", Publics->getHashBuckets());
867 P.printList("Address Map", Publics->getAddressMap());
868 P.printList("Thunk Map", Publics->getThunkMap());
869 P.printList("Section Offsets", Publics->getSectionOffsets(),
Zachary Turnerd3117392016-06-03 19:28:33 +0000870 printSectionOffset);
871 ListScope L(P, "Symbols");
Zachary Turner629cb7d2017-01-11 23:24:22 +0000872 codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
Zachary Turnerd3117392016-06-03 19:28:33 +0000873 bool HadError = false;
Zachary Turnera1657a92016-06-08 17:26:39 +0000874 for (auto S : Publics->getSymbols(&HadError)) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000875 DictScope DD(P, "");
876
Zachary Turner0d840742016-10-07 21:34:46 +0000877 if (auto EC = SD.dump(S)) {
878 HadError = true;
879 break;
880 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000881 if (opts::raw::DumpSymRecordBytes)
Zachary Turnerc67b00c2016-09-14 23:00:16 +0000882 P.printBinaryBlock("Bytes", S.content());
Zachary Turnerd3117392016-06-03 19:28:33 +0000883 }
884 if (HadError)
885 return make_error<RawError>(
886 raw_error_code::corrupt_file,
887 "Public symbol stream contained corrupt record");
888
889 return Error::success();
890}
891
892Error LLVMOutputStyle::dumpSectionHeaders() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000893 if (!opts::raw::DumpSectionHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000894 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000895 if (!File.hasPDBDbiStream()) {
896 P.printString("DBI Stream not present");
897 return Error::success();
898 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000899
Zachary Turnera1657a92016-06-08 17:26:39 +0000900 auto Dbi = File.getPDBDbiStream();
901 if (!Dbi)
902 return Dbi.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000903
904 ListScope D(P, "Section Headers");
Zachary Turnera1657a92016-06-08 17:26:39 +0000905 for (const object::coff_section &Section : Dbi->getSectionHeaders()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000906 DictScope DD(P, "");
907
908 // If a name is 8 characters long, there is no NUL character at end.
909 StringRef Name(Section.Name, strnlen(Section.Name, sizeof(Section.Name)));
910 P.printString("Name", Name);
911 P.printNumber("Virtual Size", Section.VirtualSize);
912 P.printNumber("Virtual Address", Section.VirtualAddress);
913 P.printNumber("Size of Raw Data", Section.SizeOfRawData);
914 P.printNumber("File Pointer to Raw Data", Section.PointerToRawData);
915 P.printNumber("File Pointer to Relocations", Section.PointerToRelocations);
916 P.printNumber("File Pointer to Linenumbers", Section.PointerToLinenumbers);
917 P.printNumber("Number of Relocations", Section.NumberOfRelocations);
918 P.printNumber("Number of Linenumbers", Section.NumberOfLinenumbers);
Rui Ueyama2c5384a2016-06-06 21:34:55 +0000919 P.printFlags("Characteristics", Section.Characteristics,
920 getImageSectionCharacteristicNames());
Zachary Turnerd3117392016-06-03 19:28:33 +0000921 }
922 return Error::success();
923}
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000924
925Error LLVMOutputStyle::dumpFpoStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000926 if (!opts::raw::DumpFpo)
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000927 return Error::success();
Bob Haarmana5b43582016-12-05 22:44:00 +0000928 if (!File.hasPDBDbiStream()) {
929 P.printString("DBI Stream not present");
930 return Error::success();
931 }
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000932
Zachary Turnera1657a92016-06-08 17:26:39 +0000933 auto Dbi = File.getPDBDbiStream();
934 if (!Dbi)
935 return Dbi.takeError();
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000936
937 ListScope D(P, "New FPO");
Zachary Turnera1657a92016-06-08 17:26:39 +0000938 for (const object::FpoData &Fpo : Dbi->getFpoRecords()) {
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000939 DictScope DD(P, "");
940 P.printNumber("Offset", Fpo.Offset);
941 P.printNumber("Size", Fpo.Size);
942 P.printNumber("Number of locals", Fpo.NumLocals);
943 P.printNumber("Number of params", Fpo.NumParams);
944 P.printNumber("Size of Prolog", Fpo.getPrologSize());
945 P.printNumber("Number of Saved Registers", Fpo.getNumSavedRegs());
946 P.printBoolean("Has SEH", Fpo.hasSEH());
947 P.printBoolean("Use BP", Fpo.useBP());
948 P.printNumber("Frame Pointer", Fpo.getFP());
949 }
950 return Error::success();
951}
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000952
Zachary Turner7120a472016-06-06 20:37:05 +0000953void LLVMOutputStyle::flush() { P.flush(); }