blob: 2287e0d143c0f5fd65852f3239f425ef41f7d5b2 [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
12#include "llvm-pdbdump.h"
13#include "llvm/DebugInfo/CodeView/EnumTables.h"
14#include "llvm/DebugInfo/CodeView/ModuleSubstreamVisitor.h"
15#include "llvm/DebugInfo/CodeView/SymbolDumper.h"
Zachary Turnera3225b02016-07-29 20:56:36 +000016#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
17#include "llvm/DebugInfo/MSF/StreamReader.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000018#include "llvm/DebugInfo/PDB/PDBExtras.h"
19#include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
20#include "llvm/DebugInfo/PDB/Raw/EnumTables.h"
Bob Haarman653baa22016-10-21 19:43:19 +000021#include "llvm/DebugInfo/PDB/Raw/GlobalsStream.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000022#include "llvm/DebugInfo/PDB/Raw/ISectionContribVisitor.h"
23#include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
24#include "llvm/DebugInfo/PDB/Raw/ModInfo.h"
25#include "llvm/DebugInfo/PDB/Raw/ModStream.h"
26#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
27#include "llvm/DebugInfo/PDB/Raw/PublicsStream.h"
28#include "llvm/DebugInfo/PDB/Raw/RawError.h"
29#include "llvm/DebugInfo/PDB/Raw/TpiStream.h"
30#include "llvm/Object/COFF.h"
31
32#include <unordered_map>
33
34using namespace llvm;
35using namespace llvm::codeview;
Zachary Turnerbac69d32016-07-22 19:56:05 +000036using namespace llvm::msf;
Zachary Turnerd3117392016-06-03 19:28:33 +000037using namespace llvm::pdb;
38
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +000039namespace {
40struct PageStats {
41 explicit PageStats(const BitVector &FreePages)
42 : Upm(FreePages), ActualUsedPages(FreePages.size()),
43 MultiUsePages(FreePages.size()), UseAfterFreePages(FreePages.size()) {
44 const_cast<BitVector &>(Upm).flip();
45 // To calculate orphaned pages, we start with the set of pages that the
46 // MSF thinks are used. Each time we find one that actually *is* used,
47 // we unset it. Whichever bits remain set at the end are orphaned.
48 OrphanedPages = Upm;
49 }
50
51 // The inverse of the MSF File's copy of the Fpm. The basis for which we
52 // determine the allocation status of each page.
53 const BitVector Upm;
54
55 // Pages which are marked as used in the FPM and are used at least once.
56 BitVector ActualUsedPages;
57
58 // Pages which are marked as used in the FPM but are used more than once.
59 BitVector MultiUsePages;
60
61 // Pages which are marked as used in the FPM but are not used at all.
62 BitVector OrphanedPages;
63
64 // Pages which are marked free in the FPM but are used.
65 BitVector UseAfterFreePages;
66};
67}
68
69static void recordKnownUsedPage(PageStats &Stats, uint32_t UsedIndex) {
70 if (Stats.Upm.test(UsedIndex)) {
71 if (Stats.ActualUsedPages.test(UsedIndex))
72 Stats.MultiUsePages.set(UsedIndex);
73 Stats.ActualUsedPages.set(UsedIndex);
74 Stats.OrphanedPages.reset(UsedIndex);
75 } else {
76 // The MSF doesn't think this page is used, but it is.
77 Stats.UseAfterFreePages.set(UsedIndex);
78 }
79}
80
Zachary Turnerd3117392016-06-03 19:28:33 +000081static void printSectionOffset(llvm::raw_ostream &OS,
82 const SectionOffset &Off) {
83 OS << Off.Off << ", " << Off.Isect;
84}
85
86LLVMOutputStyle::LLVMOutputStyle(PDBFile &File)
Zachary Turner5e3e4bb2016-08-05 21:45:34 +000087 : File(File), P(outs()), Dumper(&P, false) {}
Zachary Turnerd3117392016-06-03 19:28:33 +000088
Zachary Turnera30bd1a2016-06-30 17:42:48 +000089Error LLVMOutputStyle::dump() {
90 if (auto EC = dumpFileHeaders())
91 return EC;
92
93 if (auto EC = dumpStreamSummary())
94 return EC;
95
Rui Ueyama7a5cdc62016-07-29 21:38:00 +000096 if (auto EC = dumpFreePageMap())
97 return EC;
98
Zachary Turnera30bd1a2016-06-30 17:42:48 +000099 if (auto EC = dumpStreamBlocks())
100 return EC;
101
Zachary Turner72c5b642016-09-09 18:17:52 +0000102 if (auto EC = dumpBlockRanges())
103 return EC;
104
105 if (auto EC = dumpStreamBytes())
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000106 return EC;
107
108 if (auto EC = dumpInfoStream())
109 return EC;
110
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000111 if (auto EC = dumpTpiStream(StreamTPI))
112 return EC;
113
114 if (auto EC = dumpTpiStream(StreamIPI))
115 return EC;
116
117 if (auto EC = dumpDbiStream())
118 return EC;
119
120 if (auto EC = dumpSectionContribs())
121 return EC;
122
123 if (auto EC = dumpSectionMap())
124 return EC;
125
Bob Haarman653baa22016-10-21 19:43:19 +0000126 if (auto EC = dumpGlobalsStream())
127 return EC;
128
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000129 if (auto EC = dumpPublicsStream())
130 return EC;
131
132 if (auto EC = dumpSectionHeaders())
133 return EC;
134
135 if (auto EC = dumpFpoStream())
136 return EC;
137
138 flush();
139
140 return Error::success();
141}
142
Zachary Turnerd3117392016-06-03 19:28:33 +0000143Error LLVMOutputStyle::dumpFileHeaders() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000144 if (!opts::raw::DumpHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000145 return Error::success();
146
147 DictScope D(P, "FileHeaders");
148 P.printNumber("BlockSize", File.getBlockSize());
Zachary Turnerb927e022016-07-15 22:17:19 +0000149 P.printNumber("FreeBlockMap", File.getFreeBlockMapBlock());
Zachary Turnerd3117392016-06-03 19:28:33 +0000150 P.printNumber("NumBlocks", File.getBlockCount());
151 P.printNumber("NumDirectoryBytes", File.getNumDirectoryBytes());
152 P.printNumber("Unknown1", File.getUnknown1());
153 P.printNumber("BlockMapAddr", File.getBlockMapIndex());
154 P.printNumber("NumDirectoryBlocks", File.getNumDirectoryBlocks());
Zachary Turnerd3117392016-06-03 19:28:33 +0000155
156 // The directory is not contiguous. Instead, the block map contains a
157 // contiguous list of block numbers whose contents, when concatenated in
158 // order, make up the directory.
159 P.printList("DirectoryBlocks", File.getDirectoryBlockArray());
160 P.printNumber("NumStreams", File.getNumStreams());
161 return Error::success();
162}
163
Zachary Turner36efbfa2016-09-09 19:00:49 +0000164void LLVMOutputStyle::discoverStreamPurposes() {
165 if (!StreamPurposes.empty())
166 return;
Zachary Turnerd3117392016-06-03 19:28:33 +0000167
Reid Kleckner11582c52016-06-17 20:38:01 +0000168 // It's OK if we fail to load some of these streams, we still attempt to print
169 // what we can.
Zachary Turnera1657a92016-06-08 17:26:39 +0000170 auto Dbi = File.getPDBDbiStream();
Zachary Turnera1657a92016-06-08 17:26:39 +0000171 auto Tpi = File.getPDBTpiStream();
Zachary Turnera1657a92016-06-08 17:26:39 +0000172 auto Ipi = File.getPDBIpiStream();
Zachary Turnera1657a92016-06-08 17:26:39 +0000173 auto Info = File.getPDBInfoStream();
Zachary Turnerd3117392016-06-03 19:28:33 +0000174
Zachary Turnerd3117392016-06-03 19:28:33 +0000175 uint32_t StreamCount = File.getNumStreams();
176 std::unordered_map<uint16_t, const ModuleInfoEx *> ModStreams;
177 std::unordered_map<uint16_t, std::string> NamedStreams;
178
Reid Kleckner11582c52016-06-17 20:38:01 +0000179 if (Dbi) {
180 for (auto &ModI : Dbi->modules()) {
181 uint16_t SN = ModI.Info.getModuleStreamIndex();
182 ModStreams[SN] = &ModI;
183 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000184 }
Reid Kleckner11582c52016-06-17 20:38:01 +0000185 if (Info) {
186 for (auto &NSE : Info->named_streams()) {
187 NamedStreams[NSE.second] = NSE.first();
188 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000189 }
190
Zachary Turner36efbfa2016-09-09 19:00:49 +0000191 StreamPurposes.resize(StreamCount);
Zachary Turnerd3117392016-06-03 19:28:33 +0000192 for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000193 std::string Value;
194 if (StreamIdx == OldMSFDirectory)
195 Value = "Old MSF Directory";
196 else if (StreamIdx == StreamPDB)
197 Value = "PDB Stream";
198 else if (StreamIdx == StreamDBI)
199 Value = "DBI Stream";
200 else if (StreamIdx == StreamTPI)
201 Value = "TPI Stream";
202 else if (StreamIdx == StreamIPI)
203 Value = "IPI Stream";
Reid Kleckner11582c52016-06-17 20:38:01 +0000204 else if (Dbi && StreamIdx == Dbi->getGlobalSymbolStreamIndex())
Zachary Turnerd3117392016-06-03 19:28:33 +0000205 Value = "Global Symbol Hash";
Reid Kleckner11582c52016-06-17 20:38:01 +0000206 else if (Dbi && StreamIdx == Dbi->getPublicSymbolStreamIndex())
Zachary Turnerd3117392016-06-03 19:28:33 +0000207 Value = "Public Symbol Hash";
Reid Kleckner11582c52016-06-17 20:38:01 +0000208 else if (Dbi && StreamIdx == Dbi->getSymRecordStreamIndex())
Zachary Turnerd3117392016-06-03 19:28:33 +0000209 Value = "Public Symbol Records";
Reid Kleckner11582c52016-06-17 20:38:01 +0000210 else if (Tpi && StreamIdx == Tpi->getTypeHashStreamIndex())
Zachary Turnerd3117392016-06-03 19:28:33 +0000211 Value = "TPI Hash";
Reid Kleckner11582c52016-06-17 20:38:01 +0000212 else if (Tpi && StreamIdx == Tpi->getTypeHashStreamAuxIndex())
Zachary Turnerd3117392016-06-03 19:28:33 +0000213 Value = "TPI Aux Hash";
Reid Kleckner11582c52016-06-17 20:38:01 +0000214 else if (Ipi && StreamIdx == Ipi->getTypeHashStreamIndex())
Zachary Turnerd3117392016-06-03 19:28:33 +0000215 Value = "IPI Hash";
Reid Kleckner11582c52016-06-17 20:38:01 +0000216 else if (Ipi && StreamIdx == Ipi->getTypeHashStreamAuxIndex())
Zachary Turnerd3117392016-06-03 19:28:33 +0000217 Value = "IPI Aux Hash";
Reid Kleckner11582c52016-06-17 20:38:01 +0000218 else if (Dbi &&
219 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Exception))
Zachary Turnerd3117392016-06-03 19:28:33 +0000220 Value = "Exception Data";
Reid Kleckner11582c52016-06-17 20:38:01 +0000221 else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Fixup))
Zachary Turnerd3117392016-06-03 19:28:33 +0000222 Value = "Fixup Data";
Reid Kleckner11582c52016-06-17 20:38:01 +0000223 else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::FPO))
Zachary Turnerd3117392016-06-03 19:28:33 +0000224 Value = "FPO Data";
Reid Kleckner11582c52016-06-17 20:38:01 +0000225 else if (Dbi &&
226 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::NewFPO))
Zachary Turnerd3117392016-06-03 19:28:33 +0000227 Value = "New FPO Data";
Reid Kleckner11582c52016-06-17 20:38:01 +0000228 else if (Dbi &&
229 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapFromSrc))
Zachary Turnerd3117392016-06-03 19:28:33 +0000230 Value = "Omap From Source Data";
Reid Kleckner11582c52016-06-17 20:38:01 +0000231 else if (Dbi &&
232 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::OmapToSrc))
Zachary Turnerd3117392016-06-03 19:28:33 +0000233 Value = "Omap To Source Data";
Reid Kleckner11582c52016-06-17 20:38:01 +0000234 else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Pdata))
Zachary Turnerd3117392016-06-03 19:28:33 +0000235 Value = "Pdata";
Reid Kleckner11582c52016-06-17 20:38:01 +0000236 else if (Dbi &&
237 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdr))
Zachary Turnerd3117392016-06-03 19:28:33 +0000238 Value = "Section Header Data";
Reid Kleckner11582c52016-06-17 20:38:01 +0000239 else if (Dbi &&
240 StreamIdx ==
241 Dbi->getDebugStreamIndex(DbgHeaderType::SectionHdrOrig))
Zachary Turnerd3117392016-06-03 19:28:33 +0000242 Value = "Section Header Original Data";
Reid Kleckner11582c52016-06-17 20:38:01 +0000243 else if (Dbi &&
244 StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::TokenRidMap))
Zachary Turnerd3117392016-06-03 19:28:33 +0000245 Value = "Token Rid Data";
Reid Kleckner11582c52016-06-17 20:38:01 +0000246 else if (Dbi && StreamIdx == Dbi->getDebugStreamIndex(DbgHeaderType::Xdata))
Zachary Turnerd3117392016-06-03 19:28:33 +0000247 Value = "Xdata";
248 else {
249 auto ModIter = ModStreams.find(StreamIdx);
250 auto NSIter = NamedStreams.find(StreamIdx);
251 if (ModIter != ModStreams.end()) {
252 Value = "Module \"";
253 Value += ModIter->second->Info.getModuleName().str();
254 Value += "\"";
255 } else if (NSIter != NamedStreams.end()) {
256 Value = "Named Stream \"";
257 Value += NSIter->second;
258 Value += "\"";
259 } else {
260 Value = "???";
261 }
262 }
Zachary Turner36efbfa2016-09-09 19:00:49 +0000263 StreamPurposes[StreamIdx] = Value;
Zachary Turnerd3117392016-06-03 19:28:33 +0000264 }
Reid Kleckner11582c52016-06-17 20:38:01 +0000265
266 // Consume errors from missing streams.
267 if (!Dbi)
268 consumeError(Dbi.takeError());
269 if (!Tpi)
270 consumeError(Tpi.takeError());
271 if (!Ipi)
272 consumeError(Ipi.takeError());
273 if (!Info)
274 consumeError(Info.takeError());
Zachary Turner36efbfa2016-09-09 19:00:49 +0000275}
276
277Error LLVMOutputStyle::dumpStreamSummary() {
278 if (!opts::raw::DumpStreamSummary)
279 return Error::success();
280
281 discoverStreamPurposes();
282
283 uint32_t StreamCount = File.getNumStreams();
284
285 ListScope L(P, "Streams");
286 for (uint16_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
287 std::string Label("Stream ");
288 Label += to_string(StreamIdx);
289
290 std::string Value = "[" + StreamPurposes[StreamIdx] + "] (";
291 Value += to_string(File.getStreamByteSize(StreamIdx));
292 Value += " bytes)";
293
294 P.printString(Label, Value);
295 }
Reid Kleckner11582c52016-06-17 20:38:01 +0000296
Zachary Turnerd3117392016-06-03 19:28:33 +0000297 P.flush();
298 return Error::success();
299}
300
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000301Error LLVMOutputStyle::dumpFreePageMap() {
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000302 if (!opts::raw::DumpPageStats)
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000303 return Error::success();
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000304
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000305 // Start with used pages instead of free pages because
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000306 // the number of free pages is far larger than used pages.
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000307 BitVector FPM = File.getMsfLayout().FreePageMap;
308
309 PageStats PS(FPM);
310
311 recordKnownUsedPage(PS, 0); // MSF Super Block
312
Zachary Turner8cf51c32016-08-03 16:53:21 +0000313 uint32_t BlocksPerSection = msf::getFpmIntervalLength(File.getMsfLayout());
314 uint32_t NumSections = msf::getNumFpmIntervals(File.getMsfLayout());
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000315 for (uint32_t I = 0; I < NumSections; ++I) {
316 uint32_t Fpm0 = 1 + BlocksPerSection * I;
317 // 2 Fpm blocks spaced at `getBlockSize()` block intervals
318 recordKnownUsedPage(PS, Fpm0);
319 recordKnownUsedPage(PS, Fpm0 + 1);
320 }
321
322 recordKnownUsedPage(PS, File.getBlockMapIndex()); // Stream Table
323
Rui Ueyama22e67382016-08-02 23:22:46 +0000324 for (auto DB : File.getDirectoryBlockArray())
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000325 recordKnownUsedPage(PS, DB);
Rui Ueyama22e67382016-08-02 23:22:46 +0000326
327 // Record pages used by streams. Note that pages for stream 0
328 // are considered being unused because that's what MSVC tools do.
329 // Stream 0 doesn't contain actual data, so it makes some sense,
330 // though it's a bit confusing to us.
331 for (auto &SE : File.getStreamMap().drop_front(1))
332 for (auto &S : SE)
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000333 recordKnownUsedPage(PS, S);
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000334
335 dumpBitVector("Msf Free Pages", FPM);
336 dumpBitVector("Orphaned Pages", PS.OrphanedPages);
337 dumpBitVector("Multiply Used Pages", PS.MultiUsePages);
338 dumpBitVector("Use After Free Pages", PS.UseAfterFreePages);
Rui Ueyama7a5cdc62016-07-29 21:38:00 +0000339 return Error::success();
340}
341
Zachary Turnerd3c7b8e2016-08-01 21:19:45 +0000342void LLVMOutputStyle::dumpBitVector(StringRef Name, const BitVector &V) {
343 std::vector<uint32_t> Vec;
344 for (uint32_t I = 0, E = V.size(); I != E; ++I)
345 if (V[I])
346 Vec.push_back(I);
347 P.printList(Name, Vec);
348}
349
Bob Haarman653baa22016-10-21 19:43:19 +0000350Error LLVMOutputStyle::dumpGlobalsStream() {
351 if (!opts::raw::DumpGlobals)
352 return Error::success();
353
354 DictScope D(P, "Globals Stream");
355 auto Globals = File.getPDBGlobalsStream();
356 if (!Globals)
357 return Globals.takeError();
358
359 auto Dbi = File.getPDBDbiStream();
360 if (!Dbi)
361 return Dbi.takeError();
362
363 P.printNumber("Stream number", Dbi->getGlobalSymbolStreamIndex());
364 P.printNumber("Number of buckets", Globals->getNumBuckets());
365 P.printList("Hash Buckets", Globals->getHashBuckets());
366
367 return Error::success();
368}
369
Zachary Turnerd3117392016-06-03 19:28:33 +0000370Error LLVMOutputStyle::dumpStreamBlocks() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000371 if (!opts::raw::DumpStreamBlocks)
Zachary Turnerd3117392016-06-03 19:28:33 +0000372 return Error::success();
373
374 ListScope L(P, "StreamBlocks");
375 uint32_t StreamCount = File.getNumStreams();
376 for (uint32_t StreamIdx = 0; StreamIdx < StreamCount; ++StreamIdx) {
377 std::string Name("Stream ");
378 Name += to_string(StreamIdx);
379 auto StreamBlocks = File.getStreamBlockList(StreamIdx);
380 P.printList(Name, StreamBlocks);
381 }
382 return Error::success();
383}
384
Zachary Turner72c5b642016-09-09 18:17:52 +0000385Error LLVMOutputStyle::dumpBlockRanges() {
386 if (!opts::raw::DumpBlockRange.hasValue())
387 return Error::success();
388 auto &R = *opts::raw::DumpBlockRange;
389 uint32_t Max = R.Max.getValueOr(R.Min);
390
391 if (Max < R.Min)
392 return make_error<StringError>(
393 "Invalid block range specified. Max < Min",
394 std::make_error_code(std::errc::bad_address));
395 if (Max >= File.getBlockCount())
396 return make_error<StringError>(
397 "Invalid block range specified. Requested block out of bounds",
398 std::make_error_code(std::errc::bad_address));
399
400 DictScope D(P, "Block Data");
401 for (uint32_t I = R.Min; I <= Max; ++I) {
402 auto ExpectedData = File.getBlockData(I, File.getBlockSize());
403 if (!ExpectedData)
404 return ExpectedData.takeError();
405 std::string Label;
406 llvm::raw_string_ostream S(Label);
407 S << "Block " << I;
408 S.flush();
409 P.printBinaryBlock(Label, *ExpectedData);
410 }
411
412 return Error::success();
413}
414
415Error LLVMOutputStyle::dumpStreamBytes() {
416 if (opts::raw::DumpStreamData.empty())
Zachary Turnerd3117392016-06-03 19:28:33 +0000417 return Error::success();
418
Zachary Turner36efbfa2016-09-09 19:00:49 +0000419 discoverStreamPurposes();
420
Zachary Turner72c5b642016-09-09 18:17:52 +0000421 DictScope D(P, "Stream Data");
422 for (uint32_t SI : opts::raw::DumpStreamData) {
423 if (SI >= File.getNumStreams())
424 return make_error<RawError>(raw_error_code::no_stream);
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000425
Zachary Turner72c5b642016-09-09 18:17:52 +0000426 auto S = MappedBlockStream::createIndexedStream(File.getMsfLayout(),
427 File.getMsfBuffer(), SI);
428 if (!S)
429 continue;
Zachary Turner36efbfa2016-09-09 19:00:49 +0000430 DictScope DD(P, "Stream");
431
432 P.printNumber("Index", SI);
433 P.printString("Type", StreamPurposes[SI]);
434 P.printNumber("Size", S->getLength());
435 auto Blocks = File.getMsfLayout().StreamMap[SI];
436 P.printList("Blocks", Blocks);
437
Zachary Turner72c5b642016-09-09 18:17:52 +0000438 StreamReader R(*S);
439 ArrayRef<uint8_t> StreamData;
440 if (auto EC = R.readBytes(StreamData, S->getLength()))
Zachary Turnerd3117392016-06-03 19:28:33 +0000441 return EC;
Zachary Turner36efbfa2016-09-09 19:00:49 +0000442 P.printBinaryBlock("Data", StreamData);
Zachary Turnerd3117392016-06-03 19:28:33 +0000443 }
444 return Error::success();
445}
446
447Error LLVMOutputStyle::dumpInfoStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000448 if (!opts::raw::DumpHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000449 return Error::success();
Zachary Turnera1657a92016-06-08 17:26:39 +0000450 auto IS = File.getPDBInfoStream();
451 if (!IS)
452 return IS.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000453
454 DictScope D(P, "PDB Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000455 P.printNumber("Version", IS->getVersion());
456 P.printHex("Signature", IS->getSignature());
457 P.printNumber("Age", IS->getAge());
458 P.printObject("Guid", IS->getGuid());
Zachary Turnerd3117392016-06-03 19:28:33 +0000459 return Error::success();
460}
461
Rui Ueyamafd97bf12016-06-03 20:48:51 +0000462static void printTypeIndexOffset(raw_ostream &OS,
463 const TypeIndexOffset &TIOff) {
464 OS << "{" << TIOff.Type.getIndex() << ", " << TIOff.Offset << "}";
465}
466
467static void dumpTpiHash(ScopedPrinter &P, TpiStream &Tpi) {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000468 if (!opts::raw::DumpTpiHash)
Rui Ueyamafd97bf12016-06-03 20:48:51 +0000469 return;
470 DictScope DD(P, "Hash");
Rui Ueyamaf14a74c2016-06-07 23:53:43 +0000471 P.printNumber("Number of Hash Buckets", Tpi.NumHashBuckets());
Rui Ueyamad8339172016-06-07 23:44:27 +0000472 P.printNumber("Hash Key Size", Tpi.getHashKeySize());
Rui Ueyamafd97bf12016-06-03 20:48:51 +0000473 P.printList("Values", Tpi.getHashValues());
474 P.printList("Type Index Offsets", Tpi.getTypeIndexOffsets(),
475 printTypeIndexOffset);
476 P.printList("Hash Adjustments", Tpi.getHashAdjustments(),
477 printTypeIndexOffset);
478}
479
Zachary Turnerd3117392016-06-03 19:28:33 +0000480Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
481 assert(StreamIdx == StreamTPI || StreamIdx == StreamIPI);
482
483 bool DumpRecordBytes = false;
484 bool DumpRecords = false;
485 StringRef Label;
486 StringRef VerLabel;
487 if (StreamIdx == StreamTPI) {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000488 DumpRecordBytes = opts::raw::DumpTpiRecordBytes;
489 DumpRecords = opts::raw::DumpTpiRecords;
Zachary Turnerd3117392016-06-03 19:28:33 +0000490 Label = "Type Info Stream (TPI)";
491 VerLabel = "TPI Version";
492 } else if (StreamIdx == StreamIPI) {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000493 DumpRecordBytes = opts::raw::DumpIpiRecordBytes;
494 DumpRecords = opts::raw::DumpIpiRecords;
Zachary Turnerd3117392016-06-03 19:28:33 +0000495 Label = "Type Info Stream (IPI)";
496 VerLabel = "IPI Version";
497 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000498 if (!DumpRecordBytes && !DumpRecords && !opts::raw::DumpModuleSyms)
Zachary Turnerd3117392016-06-03 19:28:33 +0000499 return Error::success();
500
Zachary Turnera1657a92016-06-08 17:26:39 +0000501 auto Tpi = (StreamIdx == StreamTPI) ? File.getPDBTpiStream()
502 : File.getPDBIpiStream();
503 if (!Tpi)
504 return Tpi.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000505
506 if (DumpRecords || DumpRecordBytes) {
507 DictScope D(P, Label);
508
Zachary Turnera1657a92016-06-08 17:26:39 +0000509 P.printNumber(VerLabel, Tpi->getTpiVersion());
510 P.printNumber("Record count", Tpi->NumTypeRecords());
Zachary Turnerd3117392016-06-03 19:28:33 +0000511
512 ListScope L(P, "Records");
513
514 bool HadError = false;
Zachary Turnera1657a92016-06-08 17:26:39 +0000515 for (auto &Type : Tpi->types(&HadError)) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000516 DictScope DD(P, "");
517
Zachary Turner01ee3dae2016-06-16 18:22:27 +0000518 if (DumpRecords) {
Zachary Turner5e3e4bb2016-08-05 21:45:34 +0000519 if (auto EC = Dumper.dump(Type))
Zachary Turner01ee3dae2016-06-16 18:22:27 +0000520 return EC;
521 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000522
523 if (DumpRecordBytes)
Zachary Turnerc67b00c2016-09-14 23:00:16 +0000524 P.printBinaryBlock("Bytes", Type.content());
Zachary Turnerd3117392016-06-03 19:28:33 +0000525 }
Zachary Turnera1657a92016-06-08 17:26:39 +0000526 dumpTpiHash(P, *Tpi);
Zachary Turnerd3117392016-06-03 19:28:33 +0000527 if (HadError)
528 return make_error<RawError>(raw_error_code::corrupt_file,
529 "TPI stream contained corrupt record");
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000530 } else if (opts::raw::DumpModuleSyms) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000531 // Even if the user doesn't want to dump type records, we still need to
532 // iterate them in order to build the list of types so that we can print
533 // them when dumping module symbols. So when they want to dump symbols
534 // but not types, use a null output stream.
Zachary Turner5e3e4bb2016-08-05 21:45:34 +0000535 ScopedPrinter *OldP = Dumper.getPrinter();
536 Dumper.setPrinter(nullptr);
Zachary Turnerd3117392016-06-03 19:28:33 +0000537
538 bool HadError = false;
Zachary Turner01ee3dae2016-06-16 18:22:27 +0000539 for (auto &Type : Tpi->types(&HadError)) {
Zachary Turner5e3e4bb2016-08-05 21:45:34 +0000540 if (auto EC = Dumper.dump(Type))
Zachary Turner01ee3dae2016-06-16 18:22:27 +0000541 return EC;
542 }
Zachary Turnerd3117392016-06-03 19:28:33 +0000543
Zachary Turner5e3e4bb2016-08-05 21:45:34 +0000544 Dumper.setPrinter(OldP);
Zachary Turnera1657a92016-06-08 17:26:39 +0000545 dumpTpiHash(P, *Tpi);
Zachary Turnerd3117392016-06-03 19:28:33 +0000546 if (HadError)
547 return make_error<RawError>(raw_error_code::corrupt_file,
548 "TPI stream contained corrupt record");
549 }
550 P.flush();
551 return Error::success();
552}
553
554Error LLVMOutputStyle::dumpDbiStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000555 bool DumpModules = opts::raw::DumpModules || opts::raw::DumpModuleSyms ||
556 opts::raw::DumpModuleFiles || opts::raw::DumpLineInfo;
557 if (!opts::raw::DumpHeaders && !DumpModules)
Zachary Turnerd3117392016-06-03 19:28:33 +0000558 return Error::success();
559
Zachary Turnera1657a92016-06-08 17:26:39 +0000560 auto DS = File.getPDBDbiStream();
561 if (!DS)
562 return DS.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000563
564 DictScope D(P, "DBI Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000565 P.printNumber("Dbi Version", DS->getDbiVersion());
566 P.printNumber("Age", DS->getAge());
567 P.printBoolean("Incremental Linking", DS->isIncrementallyLinked());
568 P.printBoolean("Has CTypes", DS->hasCTypes());
569 P.printBoolean("Is Stripped", DS->isStripped());
570 P.printObject("Machine Type", DS->getMachineType());
571 P.printNumber("Symbol Record Stream Index", DS->getSymRecordStreamIndex());
572 P.printNumber("Public Symbol Stream Index", DS->getPublicSymbolStreamIndex());
573 P.printNumber("Global Symbol Stream Index", DS->getGlobalSymbolStreamIndex());
Zachary Turnerd3117392016-06-03 19:28:33 +0000574
Zachary Turnera1657a92016-06-08 17:26:39 +0000575 uint16_t Major = DS->getBuildMajorVersion();
576 uint16_t Minor = DS->getBuildMinorVersion();
Zachary Turnerd3117392016-06-03 19:28:33 +0000577 P.printVersion("Toolchain Version", Major, Minor);
578
579 std::string DllName;
580 raw_string_ostream DllStream(DllName);
581 DllStream << "mspdb" << Major << Minor << ".dll version";
582 DllStream.flush();
Zachary Turnera1657a92016-06-08 17:26:39 +0000583 P.printVersion(DllName, Major, Minor, DS->getPdbDllVersion());
Zachary Turnerd3117392016-06-03 19:28:33 +0000584
585 if (DumpModules) {
586 ListScope L(P, "Modules");
Zachary Turnera1657a92016-06-08 17:26:39 +0000587 for (auto &Modi : DS->modules()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000588 DictScope DD(P);
589 P.printString("Name", Modi.Info.getModuleName().str());
590 P.printNumber("Debug Stream Index", Modi.Info.getModuleStreamIndex());
591 P.printString("Object File Name", Modi.Info.getObjFileName().str());
592 P.printNumber("Num Files", Modi.Info.getNumberOfFiles());
593 P.printNumber("Source File Name Idx", Modi.Info.getSourceFileNameIndex());
594 P.printNumber("Pdb File Name Idx", Modi.Info.getPdbFilePathNameIndex());
595 P.printNumber("Line Info Byte Size", Modi.Info.getLineInfoByteSize());
596 P.printNumber("C13 Line Info Byte Size",
597 Modi.Info.getC13LineInfoByteSize());
598 P.printNumber("Symbol Byte Size", Modi.Info.getSymbolDebugInfoByteSize());
599 P.printNumber("Type Server Index", Modi.Info.getTypeServerIndex());
600 P.printBoolean("Has EC Info", Modi.Info.hasECInfo());
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000601 if (opts::raw::DumpModuleFiles) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000602 std::string FileListName =
603 to_string(Modi.SourceFiles.size()) + " Contributing Source Files";
604 ListScope LL(P, FileListName);
605 for (auto File : Modi.SourceFiles)
606 P.printString(File.str());
607 }
608 bool HasModuleDI =
609 (Modi.Info.getModuleStreamIndex() < File.getNumStreams());
610 bool ShouldDumpSymbols =
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000611 (opts::raw::DumpModuleSyms || opts::raw::DumpSymRecordBytes);
612 if (HasModuleDI && (ShouldDumpSymbols || opts::raw::DumpLineInfo)) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000613 auto ModStreamData = MappedBlockStream::createIndexedStream(
Zachary Turnerd66889c2016-07-28 19:12:28 +0000614 File.getMsfLayout(), File.getMsfBuffer(),
615 Modi.Info.getModuleStreamIndex());
616
617 ModStream ModS(Modi.Info, std::move(ModStreamData));
Zachary Turnerd3117392016-06-03 19:28:33 +0000618 if (auto EC = ModS.reload())
619 return EC;
620
621 if (ShouldDumpSymbols) {
622 ListScope SS(P, "Symbols");
Zachary Turner5e3e4bb2016-08-05 21:45:34 +0000623 codeview::CVSymbolDumper SD(P, Dumper, nullptr, false);
Zachary Turnerd3117392016-06-03 19:28:33 +0000624 bool HadError = false;
Zachary Turner0d840742016-10-07 21:34:46 +0000625 for (auto S : ModS.symbols(&HadError)) {
626 DictScope LL(P, "");
627 if (opts::raw::DumpModuleSyms) {
628 if (auto EC = SD.dump(S)) {
629 llvm::consumeError(std::move(EC));
630 HadError = true;
631 break;
632 }
633 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000634 if (opts::raw::DumpSymRecordBytes)
Zachary Turnerc67b00c2016-09-14 23:00:16 +0000635 P.printBinaryBlock("Bytes", S.content());
Zachary Turnerd3117392016-06-03 19:28:33 +0000636 }
637 if (HadError)
638 return make_error<RawError>(
639 raw_error_code::corrupt_file,
640 "DBI stream contained corrupt symbol record");
641 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000642 if (opts::raw::DumpLineInfo) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000643 ListScope SS(P, "LineInfo");
644 bool HadError = false;
645 // Define a locally scoped visitor to print the different
646 // substream types types.
647 class RecordVisitor : public codeview::IModuleSubstreamVisitor {
648 public:
649 RecordVisitor(ScopedPrinter &P, PDBFile &F) : P(P), F(F) {}
650 Error visitUnknown(ModuleSubstreamKind Kind,
Zachary Turnerd66889c2016-07-28 19:12:28 +0000651 ReadableStreamRef Stream) override {
Zachary Turnerd3117392016-06-03 19:28:33 +0000652 DictScope DD(P, "Unknown");
653 ArrayRef<uint8_t> Data;
654 StreamReader R(Stream);
655 if (auto EC = R.readBytes(Data, R.bytesRemaining())) {
656 return make_error<RawError>(
657 raw_error_code::corrupt_file,
658 "DBI stream contained corrupt line info record");
659 }
660 P.printBinaryBlock("Data", Data);
661 return Error::success();
662 }
663 Error
Zachary Turnerd66889c2016-07-28 19:12:28 +0000664 visitFileChecksums(ReadableStreamRef Data,
Zachary Turnerd3117392016-06-03 19:28:33 +0000665 const FileChecksumArray &Checksums) override {
666 DictScope DD(P, "FileChecksums");
667 for (const auto &C : Checksums) {
668 DictScope DDD(P, "Checksum");
669 if (auto Result = getFileNameForOffset(C.FileNameOffset))
670 P.printString("FileName", Result.get());
671 else
672 return Result.takeError();
673 P.flush();
674 P.printEnum("Kind", uint8_t(C.Kind), getFileChecksumNames());
675 P.printBinaryBlock("Checksum", C.Checksum);
676 }
677 return Error::success();
678 }
679
Zachary Turnerd66889c2016-07-28 19:12:28 +0000680 Error visitLines(ReadableStreamRef Data,
681 const LineSubstreamHeader *Header,
Zachary Turnerd3117392016-06-03 19:28:33 +0000682 const LineInfoArray &Lines) override {
683 DictScope DD(P, "Lines");
684 for (const auto &L : Lines) {
685 if (auto Result = getFileNameForOffset2(L.NameIndex))
686 P.printString("FileName", Result.get());
687 else
688 return Result.takeError();
689 P.flush();
690 for (const auto &N : L.LineNumbers) {
691 DictScope DDD(P, "Line");
692 LineInfo LI(N.Flags);
693 P.printNumber("Offset", N.Offset);
694 if (LI.isAlwaysStepInto())
695 P.printString("StepInto", StringRef("Always"));
696 else if (LI.isNeverStepInto())
697 P.printString("StepInto", StringRef("Never"));
698 else
699 P.printNumber("LineNumberStart", LI.getStartLine());
700 P.printNumber("EndDelta", LI.getLineDelta());
701 P.printBoolean("IsStatement", LI.isStatement());
702 }
703 for (const auto &C : L.Columns) {
704 DictScope DDD(P, "Column");
705 P.printNumber("Start", C.StartColumn);
706 P.printNumber("End", C.EndColumn);
707 }
708 }
709 return Error::success();
710 }
711
712 private:
713 Expected<StringRef> getFileNameForOffset(uint32_t Offset) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000714 auto ST = F.getStringTable();
715 if (!ST)
716 return ST.takeError();
717
718 return ST->getStringForID(Offset);
Zachary Turnerd3117392016-06-03 19:28:33 +0000719 }
720 Expected<StringRef> getFileNameForOffset2(uint32_t Offset) {
Zachary Turnera1657a92016-06-08 17:26:39 +0000721 auto DS = F.getPDBDbiStream();
722 if (!DS)
723 return DS.takeError();
724 return DS->getFileNameForIndex(Offset);
Zachary Turnerd3117392016-06-03 19:28:33 +0000725 }
726 ScopedPrinter &P;
727 PDBFile &F;
728 };
729
730 RecordVisitor V(P, File);
731 for (const auto &L : ModS.lines(&HadError)) {
732 if (auto EC = codeview::visitModuleSubstream(L, V))
733 return EC;
734 }
735 }
736 }
737 }
738 }
739 return Error::success();
740}
741
742Error LLVMOutputStyle::dumpSectionContribs() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000743 if (!opts::raw::DumpSectionContribs)
Zachary Turnerd3117392016-06-03 19:28:33 +0000744 return Error::success();
745
Zachary Turnera1657a92016-06-08 17:26:39 +0000746 auto Dbi = File.getPDBDbiStream();
747 if (!Dbi)
748 return Dbi.takeError();
749
Zachary Turnerd3117392016-06-03 19:28:33 +0000750 ListScope L(P, "Section Contributions");
751 class Visitor : public ISectionContribVisitor {
752 public:
753 Visitor(ScopedPrinter &P, DbiStream &DS) : P(P), DS(DS) {}
754 void visit(const SectionContrib &SC) override {
755 DictScope D(P, "Contribution");
756 P.printNumber("ISect", SC.ISect);
757 P.printNumber("Off", SC.Off);
758 P.printNumber("Size", SC.Size);
759 P.printFlags("Characteristics", SC.Characteristics,
760 codeview::getImageSectionCharacteristicNames(),
761 COFF::SectionCharacteristics(0x00F00000));
762 {
763 DictScope DD(P, "Module");
764 P.printNumber("Index", SC.Imod);
765 auto M = DS.modules();
766 if (M.size() > SC.Imod) {
767 P.printString("Name", M[SC.Imod].Info.getModuleName());
768 }
769 }
770 P.printNumber("Data CRC", SC.DataCrc);
771 P.printNumber("Reloc CRC", SC.RelocCrc);
772 P.flush();
773 }
774 void visit(const SectionContrib2 &SC) override {
775 visit(SC.Base);
776 P.printNumber("ISect Coff", SC.ISectCoff);
777 P.flush();
778 }
779
780 private:
781 ScopedPrinter &P;
782 DbiStream &DS;
783 };
Zachary Turnera1657a92016-06-08 17:26:39 +0000784 Visitor V(P, *Dbi);
785 Dbi->visitSectionContributions(V);
Zachary Turnerd3117392016-06-03 19:28:33 +0000786 return Error::success();
787}
788
789Error LLVMOutputStyle::dumpSectionMap() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000790 if (!opts::raw::DumpSectionMap)
Zachary Turnerd3117392016-06-03 19:28:33 +0000791 return Error::success();
792
Zachary Turnera1657a92016-06-08 17:26:39 +0000793 auto Dbi = File.getPDBDbiStream();
794 if (!Dbi)
795 return Dbi.takeError();
796
Zachary Turnerd3117392016-06-03 19:28:33 +0000797 ListScope L(P, "Section Map");
Zachary Turnera1657a92016-06-08 17:26:39 +0000798 for (auto &M : Dbi->getSectionMap()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000799 DictScope D(P, "Entry");
800 P.printFlags("Flags", M.Flags, getOMFSegMapDescFlagNames());
Zachary Turnerd3117392016-06-03 19:28:33 +0000801 P.printNumber("Ovl", M.Ovl);
802 P.printNumber("Group", M.Group);
803 P.printNumber("Frame", M.Frame);
804 P.printNumber("SecName", M.SecName);
805 P.printNumber("ClassName", M.ClassName);
806 P.printNumber("Offset", M.Offset);
807 P.printNumber("SecByteLength", M.SecByteLength);
808 P.flush();
809 }
810 return Error::success();
811}
812
813Error LLVMOutputStyle::dumpPublicsStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000814 if (!opts::raw::DumpPublics)
Zachary Turnerd3117392016-06-03 19:28:33 +0000815 return Error::success();
816
817 DictScope D(P, "Publics Stream");
Zachary Turnera1657a92016-06-08 17:26:39 +0000818 auto Publics = File.getPDBPublicsStream();
819 if (!Publics)
820 return Publics.takeError();
821
822 auto Dbi = File.getPDBDbiStream();
823 if (!Dbi)
824 return Dbi.takeError();
825
826 P.printNumber("Stream number", Dbi->getPublicSymbolStreamIndex());
827 P.printNumber("SymHash", Publics->getSymHash());
828 P.printNumber("AddrMap", Publics->getAddrMap());
829 P.printNumber("Number of buckets", Publics->getNumBuckets());
830 P.printList("Hash Buckets", Publics->getHashBuckets());
831 P.printList("Address Map", Publics->getAddressMap());
832 P.printList("Thunk Map", Publics->getThunkMap());
833 P.printList("Section Offsets", Publics->getSectionOffsets(),
Zachary Turnerd3117392016-06-03 19:28:33 +0000834 printSectionOffset);
835 ListScope L(P, "Symbols");
Zachary Turner5e3e4bb2016-08-05 21:45:34 +0000836 codeview::CVSymbolDumper SD(P, Dumper, nullptr, false);
Zachary Turnerd3117392016-06-03 19:28:33 +0000837 bool HadError = false;
Zachary Turnera1657a92016-06-08 17:26:39 +0000838 for (auto S : Publics->getSymbols(&HadError)) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000839 DictScope DD(P, "");
840
Zachary Turner0d840742016-10-07 21:34:46 +0000841 if (auto EC = SD.dump(S)) {
842 HadError = true;
843 break;
844 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000845 if (opts::raw::DumpSymRecordBytes)
Zachary Turnerc67b00c2016-09-14 23:00:16 +0000846 P.printBinaryBlock("Bytes", S.content());
Zachary Turnerd3117392016-06-03 19:28:33 +0000847 }
848 if (HadError)
849 return make_error<RawError>(
850 raw_error_code::corrupt_file,
851 "Public symbol stream contained corrupt record");
852
853 return Error::success();
854}
855
856Error LLVMOutputStyle::dumpSectionHeaders() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000857 if (!opts::raw::DumpSectionHeaders)
Zachary Turnerd3117392016-06-03 19:28:33 +0000858 return Error::success();
859
Zachary Turnera1657a92016-06-08 17:26:39 +0000860 auto Dbi = File.getPDBDbiStream();
861 if (!Dbi)
862 return Dbi.takeError();
Zachary Turnerd3117392016-06-03 19:28:33 +0000863
864 ListScope D(P, "Section Headers");
Zachary Turnera1657a92016-06-08 17:26:39 +0000865 for (const object::coff_section &Section : Dbi->getSectionHeaders()) {
Zachary Turnerd3117392016-06-03 19:28:33 +0000866 DictScope DD(P, "");
867
868 // If a name is 8 characters long, there is no NUL character at end.
869 StringRef Name(Section.Name, strnlen(Section.Name, sizeof(Section.Name)));
870 P.printString("Name", Name);
871 P.printNumber("Virtual Size", Section.VirtualSize);
872 P.printNumber("Virtual Address", Section.VirtualAddress);
873 P.printNumber("Size of Raw Data", Section.SizeOfRawData);
874 P.printNumber("File Pointer to Raw Data", Section.PointerToRawData);
875 P.printNumber("File Pointer to Relocations", Section.PointerToRelocations);
876 P.printNumber("File Pointer to Linenumbers", Section.PointerToLinenumbers);
877 P.printNumber("Number of Relocations", Section.NumberOfRelocations);
878 P.printNumber("Number of Linenumbers", Section.NumberOfLinenumbers);
Rui Ueyama2c5384a2016-06-06 21:34:55 +0000879 P.printFlags("Characteristics", Section.Characteristics,
880 getImageSectionCharacteristicNames());
Zachary Turnerd3117392016-06-03 19:28:33 +0000881 }
882 return Error::success();
883}
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000884
885Error LLVMOutputStyle::dumpFpoStream() {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000886 if (!opts::raw::DumpFpo)
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000887 return Error::success();
888
Zachary Turnera1657a92016-06-08 17:26:39 +0000889 auto Dbi = File.getPDBDbiStream();
890 if (!Dbi)
891 return Dbi.takeError();
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000892
893 ListScope D(P, "New FPO");
Zachary Turnera1657a92016-06-08 17:26:39 +0000894 for (const object::FpoData &Fpo : Dbi->getFpoRecords()) {
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000895 DictScope DD(P, "");
896 P.printNumber("Offset", Fpo.Offset);
897 P.printNumber("Size", Fpo.Size);
898 P.printNumber("Number of locals", Fpo.NumLocals);
899 P.printNumber("Number of params", Fpo.NumParams);
900 P.printNumber("Size of Prolog", Fpo.getPrologSize());
901 P.printNumber("Number of Saved Registers", Fpo.getNumSavedRegs());
902 P.printBoolean("Has SEH", Fpo.hasSEH());
903 P.printBoolean("Use BP", Fpo.useBP());
904 P.printNumber("Frame Pointer", Fpo.getFP());
905 }
906 return Error::success();
907}
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000908
Zachary Turner7120a472016-06-06 20:37:05 +0000909void LLVMOutputStyle::flush() { P.flush(); }