1 //===- DumpOutputStyle.cpp ------------------------------------ *- C++ --*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "DumpOutputStyle.h"
11 #include "FormatUtil.h"
12 #include "InputFile.h"
13 #include "MinimalSymbolDumper.h"
14 #include "MinimalTypeDumper.h"
15 #include "StreamUtil.h"
16 #include "TypeReferenceTracker.h"
17 #include "llvm-pdbutil.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/DebugInfo/CodeView/CVSymbolVisitor.h"
21 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
22 #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
23 #include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h"
24 #include "llvm/DebugInfo/CodeView/DebugCrossImpSubsection.h"
25 #include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h"
26 #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
27 #include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
28 #include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
29 #include "llvm/DebugInfo/CodeView/DebugSymbolsSubsection.h"
30 #include "llvm/DebugInfo/CodeView/Formatters.h"
31 #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
32 #include "llvm/DebugInfo/CodeView/Line.h"
33 #include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
34 #include "llvm/DebugInfo/CodeView/SymbolVisitorCallbackPipeline.h"
35 #include "llvm/DebugInfo/CodeView/SymbolVisitorCallbacks.h"
36 #include "llvm/DebugInfo/CodeView/TypeHashing.h"
37 #include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h"
38 #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
39 #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
40 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
41 #include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
42 #include "llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h"
43 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
44 #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
45 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
46 #include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
47 #include "llvm/DebugInfo/PDB/Native/RawError.h"
48 #include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
49 #include "llvm/DebugInfo/PDB/Native/TpiHashing.h"
50 #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
51 #include "llvm/Object/COFF.h"
52 #include "llvm/Support/BinaryStreamReader.h"
53 #include "llvm/Support/FormatAdapters.h"
54 #include "llvm/Support/FormatVariadic.h"
59 using namespace llvm::codeview
;
60 using namespace llvm::msf
;
61 using namespace llvm::pdb
;
63 DumpOutputStyle::DumpOutputStyle(InputFile
&File
)
64 : File(File
), P(2, false, outs()) {
65 if (opts::dump::DumpTypeRefStats
)
66 RefTracker
.reset(new TypeReferenceTracker(File
));
69 DumpOutputStyle::~DumpOutputStyle() {}
71 PDBFile
&DumpOutputStyle::getPdb() { return File
.pdb(); }
72 object::COFFObjectFile
&DumpOutputStyle::getObj() { return File
.obj(); }
74 void DumpOutputStyle::printStreamNotValidForObj() {
75 AutoIndent
Indent(P
, 4);
76 P
.formatLine("Dumping this stream is not valid for object files");
79 void DumpOutputStyle::printStreamNotPresent(StringRef StreamName
) {
80 AutoIndent
Indent(P
, 4);
81 P
.formatLine("{0} stream not present", StreamName
);
84 Error
DumpOutputStyle::dump() {
85 // Walk symbols & globals if we are supposed to mark types referenced.
86 if (opts::dump::DumpTypeRefStats
)
89 if (opts::dump::DumpSummary
) {
90 if (auto EC
= dumpFileSummary())
95 if (opts::dump::DumpStreams
) {
96 if (auto EC
= dumpStreamSummary())
101 if (opts::dump::DumpSymbolStats
) {
102 if (auto EC
= dumpSymbolStats())
107 if (opts::dump::DumpUdtStats
) {
108 if (auto EC
= dumpUdtStats())
113 if (opts::dump::DumpTypeStats
|| opts::dump::DumpIDStats
) {
114 if (auto EC
= dumpTypeStats())
119 if (opts::dump::DumpNamedStreams
) {
120 if (auto EC
= dumpNamedStreams())
125 if (opts::dump::DumpStringTable
|| opts::dump::DumpStringTableDetails
) {
126 if (auto EC
= dumpStringTable())
131 if (opts::dump::DumpModules
) {
132 if (auto EC
= dumpModules())
136 if (opts::dump::DumpModuleFiles
) {
137 if (auto EC
= dumpModuleFiles())
141 if (opts::dump::DumpLines
) {
142 if (auto EC
= dumpLines())
146 if (opts::dump::DumpInlineeLines
) {
147 if (auto EC
= dumpInlineeLines())
151 if (opts::dump::DumpXmi
) {
152 if (auto EC
= dumpXmi())
156 if (opts::dump::DumpXme
) {
157 if (auto EC
= dumpXme())
161 if (opts::dump::DumpFpo
) {
162 if (auto EC
= dumpFpo())
167 if (opts::dump::DumpTypes
|| !opts::dump::DumpTypeIndex
.empty() ||
168 opts::dump::DumpTypeExtras
)
169 if (auto EC
= dumpTypesFromObjectFile())
172 if (opts::dump::DumpTypes
|| !opts::dump::DumpTypeIndex
.empty() ||
173 opts::dump::DumpTypeExtras
) {
174 if (auto EC
= dumpTpiStream(StreamTPI
))
178 if (opts::dump::DumpIds
|| !opts::dump::DumpIdIndex
.empty() ||
179 opts::dump::DumpIdExtras
) {
180 if (auto EC
= dumpTpiStream(StreamIPI
))
185 if (opts::dump::DumpGSIRecords
) {
186 if (auto EC
= dumpGSIRecords())
190 if (opts::dump::DumpGlobals
) {
191 if (auto EC
= dumpGlobals())
195 if (opts::dump::DumpPublics
) {
196 if (auto EC
= dumpPublics())
200 if (opts::dump::DumpSymbols
) {
201 auto EC
= File
.isPdb() ? dumpModuleSymsForPdb() : dumpModuleSymsForObj();
206 if (opts::dump::DumpTypeRefStats
) {
207 if (auto EC
= dumpTypeRefStats())
211 if (opts::dump::DumpSectionHeaders
) {
212 if (auto EC
= dumpSectionHeaders())
216 if (opts::dump::DumpSectionContribs
) {
217 if (auto EC
= dumpSectionContribs())
221 if (opts::dump::DumpSectionMap
) {
222 if (auto EC
= dumpSectionMap())
228 return Error::success();
231 static void printHeader(LinePrinter
&P
, const Twine
&S
) {
233 P
.formatLine("{0,=60}", S
);
234 P
.formatLine("{0}", fmt_repeat('=', 60));
237 Error
DumpOutputStyle::dumpFileSummary() {
238 printHeader(P
, "Summary");
241 printStreamNotValidForObj();
242 return Error::success();
245 AutoIndent
Indent(P
);
246 ExitOnError
Err("Invalid PDB Format: ");
248 P
.formatLine("Block Size: {0}", getPdb().getBlockSize());
249 P
.formatLine("Number of blocks: {0}", getPdb().getBlockCount());
250 P
.formatLine("Number of streams: {0}", getPdb().getNumStreams());
252 auto &PS
= Err(getPdb().getPDBInfoStream());
253 P
.formatLine("Signature: {0}", PS
.getSignature());
254 P
.formatLine("Age: {0}", PS
.getAge());
255 P
.formatLine("GUID: {0}", fmt_guid(PS
.getGuid().Guid
));
256 P
.formatLine("Features: {0:x+}", static_cast<uint32_t>(PS
.getFeatures()));
257 P
.formatLine("Has Debug Info: {0}", getPdb().hasPDBDbiStream());
258 P
.formatLine("Has Types: {0}", getPdb().hasPDBTpiStream());
259 P
.formatLine("Has IDs: {0}", getPdb().hasPDBIpiStream());
260 P
.formatLine("Has Globals: {0}", getPdb().hasPDBGlobalsStream());
261 P
.formatLine("Has Publics: {0}", getPdb().hasPDBPublicsStream());
262 if (getPdb().hasPDBDbiStream()) {
263 auto &DBI
= Err(getPdb().getPDBDbiStream());
264 P
.formatLine("Is incrementally linked: {0}", DBI
.isIncrementallyLinked());
265 P
.formatLine("Has conflicting types: {0}", DBI
.hasCTypes());
266 P
.formatLine("Is stripped: {0}", DBI
.isStripped());
269 return Error::success();
272 static StatCollection
getSymbolStats(const SymbolGroup
&SG
,
273 StatCollection
&CumulativeStats
) {
274 StatCollection Stats
;
275 if (SG
.getFile().isPdb() && SG
.hasDebugStream()) {
276 // For PDB files, all symbols are packed into one stream.
277 for (const auto &S
: SG
.getPdbModuleStream().symbols(nullptr)) {
278 Stats
.update(S
.kind(), S
.length());
279 CumulativeStats
.update(S
.kind(), S
.length());
284 for (const auto &SS
: SG
.getDebugSubsections()) {
285 // For object files, all symbols are spread across multiple Symbol
286 // subsections of a given .debug$S section.
287 if (SS
.kind() != DebugSubsectionKind::Symbols
)
289 DebugSymbolsSubsectionRef Symbols
;
290 BinaryStreamReader
Reader(SS
.getRecordData());
291 cantFail(Symbols
.initialize(Reader
));
292 for (const auto &S
: Symbols
) {
293 Stats
.update(S
.kind(), S
.length());
294 CumulativeStats
.update(S
.kind(), S
.length());
300 static StatCollection
getChunkStats(const SymbolGroup
&SG
,
301 StatCollection
&CumulativeStats
) {
302 StatCollection Stats
;
303 for (const auto &Chunk
: SG
.getDebugSubsections()) {
304 Stats
.update(uint32_t(Chunk
.kind()), Chunk
.getRecordLength());
305 CumulativeStats
.update(uint32_t(Chunk
.kind()), Chunk
.getRecordLength());
310 static inline std::string
formatModuleDetailKind(DebugSubsectionKind K
) {
311 return formatChunkKind(K
, false);
314 static inline std::string
formatModuleDetailKind(SymbolKind K
) {
315 return formatSymbolKind(K
);
318 // Get the stats sorted by size, descending.
319 std::vector
<StatCollection::KindAndStat
>
320 StatCollection::getStatsSortedBySize() const {
321 std::vector
<KindAndStat
> SortedStats(Individual
.begin(), Individual
.end());
322 llvm::stable_sort(SortedStats
,
323 [](const KindAndStat
&LHS
, const KindAndStat
&RHS
) {
324 return LHS
.second
.Size
> RHS
.second
.Size
;
329 template <typename Kind
>
330 static void printModuleDetailStats(LinePrinter
&P
, StringRef Label
,
331 const StatCollection
&Stats
) {
333 P
.formatLine(" {0}", Label
);
334 AutoIndent
Indent(P
);
335 P
.formatLine("{0,40}: {1,7} entries ({2,12:N} bytes)", "Total",
336 Stats
.Totals
.Count
, Stats
.Totals
.Size
);
337 P
.formatLine("{0}", fmt_repeat('-', 74));
339 for (const auto &K
: Stats
.getStatsSortedBySize()) {
340 std::string KindName
= formatModuleDetailKind(Kind(K
.first
));
341 P
.formatLine("{0,40}: {1,7} entries ({2,12:N} bytes)", KindName
,
342 K
.second
.Count
, K
.second
.Size
);
346 static bool isMyCode(const SymbolGroup
&Group
) {
347 if (Group
.getFile().isObj())
350 StringRef Name
= Group
.name();
351 if (Name
.startswith("Import:"))
353 if (Name
.endswith_insensitive(".dll"))
355 if (Name
.equals_insensitive("* linker *"))
357 if (Name
.startswith_insensitive("f:\\binaries\\Intermediate\\vctools"))
359 if (Name
.startswith_insensitive("f:\\dd\\vctools\\crt"))
364 static bool shouldDumpSymbolGroup(uint32_t Idx
, const SymbolGroup
&Group
) {
365 if (opts::dump::JustMyCode
&& !isMyCode(Group
))
368 // If the arg was not specified on the command line, always dump all modules.
369 if (opts::dump::DumpModi
.getNumOccurrences() == 0)
372 // Otherwise, only dump if this is the same module specified.
373 return (opts::dump::DumpModi
== Idx
);
376 Error
DumpOutputStyle::dumpStreamSummary() {
377 printHeader(P
, "Streams");
380 printStreamNotValidForObj();
381 return Error::success();
384 AutoIndent
Indent(P
);
386 if (StreamPurposes
.empty())
387 discoverStreamPurposes(getPdb(), StreamPurposes
);
389 uint32_t StreamCount
= getPdb().getNumStreams();
390 uint32_t MaxStreamSize
= getPdb().getMaxStreamSize();
392 for (uint16_t StreamIdx
= 0; StreamIdx
< StreamCount
; ++StreamIdx
) {
394 "Stream {0} ({1} bytes): [{2}]",
395 fmt_align(StreamIdx
, AlignStyle::Right
, NumDigits(StreamCount
)),
396 fmt_align(getPdb().getStreamByteSize(StreamIdx
), AlignStyle::Right
,
397 NumDigits(MaxStreamSize
)),
398 StreamPurposes
[StreamIdx
].getLongName());
400 if (opts::dump::DumpStreamBlocks
) {
401 auto Blocks
= getPdb().getStreamBlockList(StreamIdx
);
402 std::vector
<uint32_t> BV(Blocks
.begin(), Blocks
.end());
403 P
.formatLine(" {0} Blocks: [{1}]",
404 fmt_repeat(' ', NumDigits(StreamCount
)),
405 make_range(BV
.begin(), BV
.end()));
409 return Error::success();
412 static Expected
<ModuleDebugStreamRef
> getModuleDebugStream(PDBFile
&File
,
414 ExitOnError
Err("Unexpected error: ");
416 auto &Dbi
= Err(File
.getPDBDbiStream());
417 const auto &Modules
= Dbi
.modules();
418 auto Modi
= Modules
.getModuleDescriptor(Index
);
420 uint16_t ModiStream
= Modi
.getModuleStreamIndex();
421 if (ModiStream
== kInvalidStreamIndex
)
422 return make_error
<RawError
>(raw_error_code::no_stream
,
423 "Module stream not present");
425 auto ModStreamData
= File
.createIndexedStream(ModiStream
);
427 ModuleDebugStreamRef
ModS(Modi
, std::move(ModStreamData
));
428 if (auto EC
= ModS
.reload())
429 return make_error
<RawError
>(raw_error_code::corrupt_file
,
430 "Invalid module stream");
432 return std::move(ModS
);
435 template <typename CallbackT
>
437 iterateOneModule(InputFile
&File
, const Optional
<PrintScope
> &HeaderScope
,
438 const SymbolGroup
&SG
, uint32_t Modi
, CallbackT Callback
) {
440 HeaderScope
->P
.formatLine(
441 "Mod {0:4} | `{1}`: ",
442 fmt_align(Modi
, AlignStyle::Right
, HeaderScope
->LabelWidth
), SG
.name());
445 AutoIndent
Indent(HeaderScope
);
449 template <typename CallbackT
>
450 static void iterateSymbolGroups(InputFile
&Input
,
451 const Optional
<PrintScope
> &HeaderScope
,
452 CallbackT Callback
) {
453 AutoIndent
Indent(HeaderScope
);
455 ExitOnError
Err("Unexpected error processing modules: ");
457 if (opts::dump::DumpModi
.getNumOccurrences() > 0) {
458 assert(opts::dump::DumpModi
.getNumOccurrences() == 1);
459 uint32_t Modi
= opts::dump::DumpModi
;
460 SymbolGroup
SG(&Input
, Modi
);
461 iterateOneModule(Input
, withLabelWidth(HeaderScope
, NumDigits(Modi
)), SG
,
468 for (const auto &SG
: Input
.symbol_groups()) {
469 if (shouldDumpSymbolGroup(I
, SG
))
470 iterateOneModule(Input
, withLabelWidth(HeaderScope
, NumDigits(I
)), SG
, I
,
477 template <typename SubsectionT
>
478 static void iterateModuleSubsections(
479 InputFile
&File
, const Optional
<PrintScope
> &HeaderScope
,
480 llvm::function_ref
<void(uint32_t, const SymbolGroup
&, SubsectionT
&)>
483 iterateSymbolGroups(File
, HeaderScope
,
484 [&](uint32_t Modi
, const SymbolGroup
&SG
) {
485 for (const auto &SS
: SG
.getDebugSubsections()) {
486 SubsectionT Subsection
;
488 if (SS
.kind() != Subsection
.kind())
491 BinaryStreamReader
Reader(SS
.getRecordData());
492 if (auto EC
= Subsection
.initialize(Reader
))
494 Callback(Modi
, SG
, Subsection
);
499 static Expected
<std::pair
<std::unique_ptr
<MappedBlockStream
>,
500 ArrayRef
<llvm::object::coff_section
>>>
501 loadSectionHeaders(PDBFile
&File
, DbgHeaderType Type
) {
502 if (!File
.hasPDBDbiStream())
503 return make_error
<StringError
>(
504 "Section headers require a DBI Stream, which could not be loaded",
505 inconvertibleErrorCode());
507 auto &Dbi
= cantFail(File
.getPDBDbiStream());
508 uint32_t SI
= Dbi
.getDebugStreamIndex(Type
);
510 if (SI
== kInvalidStreamIndex
)
511 return make_error
<StringError
>(
512 "PDB does not contain the requested image section header type",
513 inconvertibleErrorCode());
515 auto Stream
= File
.createIndexedStream(SI
);
517 return make_error
<StringError
>("Could not load the required stream data",
518 inconvertibleErrorCode());
520 ArrayRef
<object::coff_section
> Headers
;
521 if (Stream
->getLength() % sizeof(object::coff_section
) != 0)
522 return make_error
<StringError
>(
523 "Section header array size is not a multiple of section header size",
524 inconvertibleErrorCode());
526 uint32_t NumHeaders
= Stream
->getLength() / sizeof(object::coff_section
);
527 BinaryStreamReader
Reader(*Stream
);
528 cantFail(Reader
.readArray(Headers
, NumHeaders
));
529 return std::make_pair(std::move(Stream
), Headers
);
532 static std::vector
<std::string
> getSectionNames(PDBFile
&File
) {
533 auto ExpectedHeaders
= loadSectionHeaders(File
, DbgHeaderType::SectionHdr
);
534 if (!ExpectedHeaders
)
537 std::unique_ptr
<MappedBlockStream
> Stream
;
538 ArrayRef
<object::coff_section
> Headers
;
539 std::tie(Stream
, Headers
) = std::move(*ExpectedHeaders
);
540 std::vector
<std::string
> Names
;
541 for (const auto &H
: Headers
)
542 Names
.push_back(H
.Name
);
546 static void dumpSectionContrib(LinePrinter
&P
, const SectionContrib
&SC
,
547 ArrayRef
<std::string
> SectionNames
,
548 uint32_t FieldWidth
) {
549 std::string NameInsert
;
550 if (SC
.ISect
> 0 && SC
.ISect
<= SectionNames
.size()) {
551 StringRef SectionName
= SectionNames
[SC
.ISect
- 1];
552 NameInsert
= formatv("[{0}]", SectionName
).str();
554 NameInsert
= "[???]";
555 P
.formatLine("SC{5} | mod = {2}, {0}, size = {1}, data crc = {3}, reloc "
557 formatSegmentOffset(SC
.ISect
, SC
.Off
), fmtle(SC
.Size
),
558 fmtle(SC
.Imod
), fmtle(SC
.DataCrc
), fmtle(SC
.RelocCrc
),
559 fmt_align(NameInsert
, AlignStyle::Left
, FieldWidth
+ 2));
560 AutoIndent
Indent(P
, FieldWidth
+ 2);
562 formatSectionCharacteristics(P
.getIndentLevel() + 6,
563 SC
.Characteristics
, 3, " | "));
566 static void dumpSectionContrib(LinePrinter
&P
, const SectionContrib2
&SC
,
567 ArrayRef
<std::string
> SectionNames
,
568 uint32_t FieldWidth
) {
569 P
.formatLine("SC2[{6}] | mod = {2}, {0}, size = {1}, data crc = {3}, reloc "
570 "crc = {4}, coff section = {5}",
571 formatSegmentOffset(SC
.Base
.ISect
, SC
.Base
.Off
),
572 fmtle(SC
.Base
.Size
), fmtle(SC
.Base
.Imod
), fmtle(SC
.Base
.DataCrc
),
573 fmtle(SC
.Base
.RelocCrc
), fmtle(SC
.ISectCoff
));
575 formatSectionCharacteristics(P
.getIndentLevel() + 6,
576 SC
.Base
.Characteristics
, 3, " | "));
579 Error
DumpOutputStyle::dumpModules() {
580 printHeader(P
, "Modules");
583 printStreamNotValidForObj();
584 return Error::success();
587 if (!getPdb().hasPDBDbiStream()) {
588 printStreamNotPresent("DBI");
589 return Error::success();
592 AutoIndent
Indent(P
);
593 ExitOnError
Err("Unexpected error processing modules: ");
595 auto &Stream
= Err(getPdb().getPDBDbiStream());
597 const DbiModuleList
&Modules
= Stream
.modules();
599 File
, PrintScope
{P
, 11}, [&](uint32_t Modi
, const SymbolGroup
&Strings
) {
600 auto Desc
= Modules
.getModuleDescriptor(Modi
);
601 if (opts::dump::DumpSectionContribs
) {
602 std::vector
<std::string
> Sections
= getSectionNames(getPdb());
603 dumpSectionContrib(P
, Desc
.getSectionContrib(), Sections
, 0);
605 P
.formatLine("Obj: `{0}`: ", Desc
.getObjFileName());
606 P
.formatLine("debug stream: {0}, # files: {1}, has ec info: {2}",
607 Desc
.getModuleStreamIndex(), Desc
.getNumberOfFiles(),
609 StringRef PdbFilePath
=
610 Err(Stream
.getECName(Desc
.getPdbFilePathNameIndex()));
611 StringRef SrcFilePath
=
612 Err(Stream
.getECName(Desc
.getSourceFileNameIndex()));
613 P
.formatLine("pdb file ni: {0} `{1}`, src file ni: {2} `{3}`",
614 Desc
.getPdbFilePathNameIndex(), PdbFilePath
,
615 Desc
.getSourceFileNameIndex(), SrcFilePath
);
617 return Error::success();
620 Error
DumpOutputStyle::dumpModuleFiles() {
621 printHeader(P
, "Files");
624 printStreamNotValidForObj();
625 return Error::success();
628 if (!getPdb().hasPDBDbiStream()) {
629 printStreamNotPresent("DBI");
630 return Error::success();
633 ExitOnError
Err("Unexpected error processing modules: ");
635 iterateSymbolGroups(File
, PrintScope
{P
, 11},
636 [this, &Err
](uint32_t Modi
, const SymbolGroup
&Strings
) {
637 auto &Stream
= Err(getPdb().getPDBDbiStream());
639 const DbiModuleList
&Modules
= Stream
.modules();
640 for (const auto &F
: Modules
.source_files(Modi
)) {
641 Strings
.formatFromFileName(P
, F
);
644 return Error::success();
647 Error
DumpOutputStyle::dumpSymbolStats() {
648 printHeader(P
, "Module Stats");
650 if (File
.isPdb() && !getPdb().hasPDBDbiStream()) {
651 printStreamNotPresent("DBI");
652 return Error::success();
655 ExitOnError
Err("Unexpected error processing modules: ");
657 StatCollection SymStats
;
658 StatCollection ChunkStats
;
660 Optional
<PrintScope
> Scope
;
664 iterateSymbolGroups(File
, Scope
, [&](uint32_t Modi
, const SymbolGroup
&SG
) {
665 StatCollection SS
= getSymbolStats(SG
, SymStats
);
666 StatCollection CS
= getChunkStats(SG
, ChunkStats
);
668 if (SG
.getFile().isPdb()) {
669 AutoIndent
Indent(P
);
670 auto Modules
= cantFail(File
.pdb().getPDBDbiStream()).modules();
671 uint32_t ModCount
= Modules
.getModuleCount();
672 DbiModuleDescriptor Desc
= Modules
.getModuleDescriptor(Modi
);
673 uint32_t StreamIdx
= Desc
.getModuleStreamIndex();
675 if (StreamIdx
== kInvalidStreamIndex
) {
676 P
.formatLine("Mod {0} (debug info not present): [{1}]",
677 fmt_align(Modi
, AlignStyle::Right
, NumDigits(ModCount
)),
678 Desc
.getModuleName());
681 P
.formatLine("Stream {0}, {1} bytes", StreamIdx
,
682 getPdb().getStreamByteSize(StreamIdx
));
684 printModuleDetailStats
<SymbolKind
>(P
, "Symbols", SS
);
685 printModuleDetailStats
<DebugSubsectionKind
>(P
, "Chunks", CS
);
689 if (SymStats
.Totals
.Count
> 0) {
690 P
.printLine(" Summary |");
691 AutoIndent
Indent(P
, 4);
692 printModuleDetailStats
<SymbolKind
>(P
, "Symbols", SymStats
);
693 printModuleDetailStats
<DebugSubsectionKind
>(P
, "Chunks", ChunkStats
);
696 return Error::success();
699 Error
DumpOutputStyle::dumpTypeStats() {
700 printHeader(P
, "Type Record Stats");
702 // Iterate the types, categorize by kind, accumulate size stats.
703 StatCollection TypeStats
;
704 LazyRandomTypeCollection
&Types
=
705 opts::dump::DumpTypeStats
? File
.types() : File
.ids();
706 for (Optional
<TypeIndex
> TI
= Types
.getFirst(); TI
; TI
= Types
.getNext(*TI
)) {
707 CVType Type
= Types
.getType(*TI
);
708 TypeStats
.update(uint32_t(Type
.kind()), Type
.length());
712 P
.formatLine(" Types");
713 AutoIndent
Indent(P
);
714 P
.formatLine("{0,16}: {1,7} entries ({2,12:N} bytes, {3,7} avg)", "Total",
715 TypeStats
.Totals
.Count
, TypeStats
.Totals
.Size
,
716 (double)TypeStats
.Totals
.Size
/ TypeStats
.Totals
.Count
);
717 P
.formatLine("{0}", fmt_repeat('-', 74));
719 for (const auto &K
: TypeStats
.getStatsSortedBySize()) {
720 P
.formatLine("{0,16}: {1,7} entries ({2,12:N} bytes, {3,7} avg)",
721 formatTypeLeafKind(TypeLeafKind(K
.first
)), K
.second
.Count
,
722 K
.second
.Size
, (double)K
.second
.Size
/ K
.second
.Count
);
724 return Error::success();
727 static bool isValidNamespaceIdentifier(StringRef S
) {
731 if (std::isdigit(S
[0]))
734 return llvm::all_of(S
, [](char C
) { return std::isalnum(C
); });
738 constexpr uint32_t kNoneUdtKind
= 0;
739 constexpr uint32_t kSimpleUdtKind
= 1;
740 constexpr uint32_t kUnknownUdtKind
= 2;
743 static std::string
getUdtStatLabel(uint32_t Kind
) {
744 if (Kind
== kNoneUdtKind
)
745 return "<none type>";
747 if (Kind
== kSimpleUdtKind
)
748 return "<simple type>";
750 if (Kind
== kUnknownUdtKind
)
751 return "<unknown type>";
753 return formatTypeLeafKind(static_cast<TypeLeafKind
>(Kind
));
756 static uint32_t getLongestTypeLeafName(const StatCollection
&Stats
) {
758 for (const auto &Stat
: Stats
.Individual
) {
759 std::string Label
= getUdtStatLabel(Stat
.first
);
760 L
= std::max(L
, Label
.size());
762 return static_cast<uint32_t>(L
);
765 Error
DumpOutputStyle::dumpUdtStats() {
766 printHeader(P
, "S_UDT Record Stats");
768 if (File
.isPdb() && !getPdb().hasPDBGlobalsStream()) {
769 printStreamNotPresent("Globals");
770 return Error::success();
773 StatCollection UdtStats
;
774 StatCollection UdtTargetStats
;
775 AutoIndent
Indent(P
, 4);
777 auto &TpiTypes
= File
.types();
779 StringMap
<StatCollection::Stat
> NamespacedStats
;
781 size_t LongestNamespace
= 0;
782 auto HandleOneSymbol
= [&](const CVSymbol
&Sym
) {
783 if (Sym
.kind() != SymbolKind::S_UDT
)
785 UdtStats
.update(SymbolKind::S_UDT
, Sym
.length());
787 UDTSym UDT
= cantFail(SymbolDeserializer::deserializeAs
<UDTSym
>(Sym
));
790 uint32_t RecordSize
= 0;
792 if (UDT
.Type
.isNoneType())
794 else if (UDT
.Type
.isSimple())
795 Kind
= kSimpleUdtKind
;
796 else if (Optional
<CVType
> T
= TpiTypes
.tryGetType(UDT
.Type
)) {
798 RecordSize
= T
->length();
800 Kind
= kUnknownUdtKind
;
802 UdtTargetStats
.update(Kind
, RecordSize
);
804 size_t Pos
= UDT
.Name
.find("::");
805 if (Pos
== StringRef::npos
)
808 StringRef Scope
= UDT
.Name
.take_front(Pos
);
809 if (Scope
.empty() || !isValidNamespaceIdentifier(Scope
))
812 LongestNamespace
= std::max(LongestNamespace
, Scope
.size());
813 NamespacedStats
[Scope
].update(RecordSize
);
819 auto &SymbolRecords
= cantFail(getPdb().getPDBSymbolStream());
820 auto ExpGlobals
= getPdb().getPDBGlobalsStream();
822 return ExpGlobals
.takeError();
824 for (uint32_t PubSymOff
: ExpGlobals
->getGlobalsTable()) {
825 CVSymbol Sym
= SymbolRecords
.readRecord(PubSymOff
);
826 HandleOneSymbol(Sym
);
829 for (const auto &Sec
: File
.symbol_groups()) {
830 for (const auto &SS
: Sec
.getDebugSubsections()) {
831 if (SS
.kind() != DebugSubsectionKind::Symbols
)
834 DebugSymbolsSubsectionRef Symbols
;
835 BinaryStreamReader
Reader(SS
.getRecordData());
836 cantFail(Symbols
.initialize(Reader
));
837 for (const auto &S
: Symbols
)
843 LongestNamespace
+= StringRef(" namespace ''").size();
844 size_t LongestTypeLeafKind
= getLongestTypeLeafName(UdtTargetStats
);
845 size_t FieldWidth
= std::max(LongestNamespace
, LongestTypeLeafKind
);
847 // Compute the max number of digits for count and size fields, including comma
849 StringRef
CountHeader("Count");
850 StringRef
SizeHeader("Size");
851 size_t CD
= NumDigits(UdtStats
.Totals
.Count
);
853 CD
= std::max(CD
, CountHeader
.size());
855 size_t SD
= NumDigits(UdtStats
.Totals
.Size
);
857 SD
= std::max(SD
, SizeHeader
.size());
859 uint32_t TableWidth
= FieldWidth
+ 3 + CD
+ 2 + SD
+ 1;
861 P
.formatLine("{0} | {1} {2}",
862 fmt_align("Record Kind", AlignStyle::Right
, FieldWidth
),
863 fmt_align(CountHeader
, AlignStyle::Right
, CD
),
864 fmt_align(SizeHeader
, AlignStyle::Right
, SD
));
866 P
.formatLine("{0}", fmt_repeat('-', TableWidth
));
867 for (const auto &Stat
: UdtTargetStats
.getStatsSortedBySize()) {
868 std::string Label
= getUdtStatLabel(Stat
.first
);
869 P
.formatLine("{0} | {1:N} {2:N}",
870 fmt_align(Label
, AlignStyle::Right
, FieldWidth
),
871 fmt_align(Stat
.second
.Count
, AlignStyle::Right
, CD
),
872 fmt_align(Stat
.second
.Size
, AlignStyle::Right
, SD
));
874 P
.formatLine("{0}", fmt_repeat('-', TableWidth
));
875 P
.formatLine("{0} | {1:N} {2:N}",
876 fmt_align("Total (S_UDT)", AlignStyle::Right
, FieldWidth
),
877 fmt_align(UdtStats
.Totals
.Count
, AlignStyle::Right
, CD
),
878 fmt_align(UdtStats
.Totals
.Size
, AlignStyle::Right
, SD
));
879 P
.formatLine("{0}", fmt_repeat('-', TableWidth
));
882 StatCollection::Stat Stat
;
885 // Print namespace stats in descending order of size.
886 std::vector
<StrAndStat
> NamespacedStatsSorted
;
887 for (const auto &Stat
: NamespacedStats
)
888 NamespacedStatsSorted
.push_back({Stat
.getKey(), Stat
.second
});
889 llvm::stable_sort(NamespacedStatsSorted
,
890 [](const StrAndStat
&L
, const StrAndStat
&R
) {
891 return L
.Stat
.Size
> R
.Stat
.Size
;
893 for (const auto &Stat
: NamespacedStatsSorted
) {
894 std::string Label
= std::string(formatv("namespace '{0}'", Stat
.Key
));
895 P
.formatLine("{0} | {1:N} {2:N}",
896 fmt_align(Label
, AlignStyle::Right
, FieldWidth
),
897 fmt_align(Stat
.Stat
.Count
, AlignStyle::Right
, CD
),
898 fmt_align(Stat
.Stat
.Size
, AlignStyle::Right
, SD
));
900 return Error::success();
903 static void typesetLinesAndColumns(LinePrinter
&P
, uint32_t Start
,
904 const LineColumnEntry
&E
) {
905 const uint32_t kMaxCharsPerLineNumber
= 4; // 4 digit line number
906 uint32_t MinColumnWidth
= kMaxCharsPerLineNumber
+ 5;
908 // Let's try to keep it under 100 characters
909 constexpr uint32_t kMaxRowLength
= 100;
910 // At least 3 spaces between columns.
911 uint32_t ColumnsPerRow
= kMaxRowLength
/ (MinColumnWidth
+ 3);
912 uint32_t ItemsLeft
= E
.LineNumbers
.size();
913 auto LineIter
= E
.LineNumbers
.begin();
914 while (ItemsLeft
!= 0) {
915 uint32_t RowColumns
= std::min(ItemsLeft
, ColumnsPerRow
);
916 for (uint32_t I
= 0; I
< RowColumns
; ++I
) {
917 LineInfo
Line(LineIter
->Flags
);
919 if (Line
.isAlwaysStepInto())
921 else if (Line
.isNeverStepInto())
924 LineStr
= utostr(Line
.getStartLine());
925 char Statement
= Line
.isStatement() ? ' ' : '!';
926 P
.format("{0} {1:X-} {2} ",
927 fmt_align(LineStr
, AlignStyle::Right
, kMaxCharsPerLineNumber
),
928 fmt_align(Start
+ LineIter
->Offset
, AlignStyle::Right
, 8, '0'),
937 Error
DumpOutputStyle::dumpLines() {
938 printHeader(P
, "Lines");
940 if (File
.isPdb() && !getPdb().hasPDBDbiStream()) {
941 printStreamNotPresent("DBI");
942 return Error::success();
945 uint32_t LastModi
= UINT32_MAX
;
946 uint32_t LastNameIndex
= UINT32_MAX
;
947 iterateModuleSubsections
<DebugLinesSubsectionRef
>(
948 File
, PrintScope
{P
, 4},
949 [this, &LastModi
, &LastNameIndex
](uint32_t Modi
,
950 const SymbolGroup
&Strings
,
951 DebugLinesSubsectionRef
&Lines
) {
952 uint16_t Segment
= Lines
.header()->RelocSegment
;
953 uint32_t Begin
= Lines
.header()->RelocOffset
;
954 uint32_t End
= Begin
+ Lines
.header()->CodeSize
;
955 for (const auto &Block
: Lines
) {
956 if (LastModi
!= Modi
|| LastNameIndex
!= Block
.NameIndex
) {
958 LastNameIndex
= Block
.NameIndex
;
959 Strings
.formatFromChecksumsOffset(P
, Block
.NameIndex
);
962 AutoIndent
Indent(P
, 2);
963 P
.formatLine("{0:X-4}:{1:X-8}-{2:X-8}, ", Segment
, Begin
, End
);
964 uint32_t Count
= Block
.LineNumbers
.size();
965 if (Lines
.hasColumnInfo())
966 P
.format("line/column/addr entries = {0}", Count
);
968 P
.format("line/addr entries = {0}", Count
);
971 typesetLinesAndColumns(P
, Begin
, Block
);
975 return Error::success();
978 Error
DumpOutputStyle::dumpInlineeLines() {
979 printHeader(P
, "Inlinee Lines");
981 if (File
.isPdb() && !getPdb().hasPDBDbiStream()) {
982 printStreamNotPresent("DBI");
983 return Error::success();
986 iterateModuleSubsections
<DebugInlineeLinesSubsectionRef
>(
987 File
, PrintScope
{P
, 2},
988 [this](uint32_t Modi
, const SymbolGroup
&Strings
,
989 DebugInlineeLinesSubsectionRef
&Lines
) {
990 P
.formatLine("{0,+8} | {1,+5} | {2}", "Inlinee", "Line", "Source File");
991 for (const auto &Entry
: Lines
) {
992 P
.formatLine("{0,+8} | {1,+5} | ", Entry
.Header
->Inlinee
,
993 fmtle(Entry
.Header
->SourceLineNum
));
994 Strings
.formatFromChecksumsOffset(P
, Entry
.Header
->FileID
, true);
995 for (const auto &ExtraFileID
: Entry
.ExtraFiles
) {
997 Strings
.formatFromChecksumsOffset(P
, ExtraFileID
, true);
1003 return Error::success();
1006 Error
DumpOutputStyle::dumpXmi() {
1007 printHeader(P
, "Cross Module Imports");
1009 if (File
.isPdb() && !getPdb().hasPDBDbiStream()) {
1010 printStreamNotPresent("DBI");
1011 return Error::success();
1014 iterateModuleSubsections
<DebugCrossModuleImportsSubsectionRef
>(
1015 File
, PrintScope
{P
, 2},
1016 [this](uint32_t Modi
, const SymbolGroup
&Strings
,
1017 DebugCrossModuleImportsSubsectionRef
&Imports
) {
1018 P
.formatLine("{0,=32} | {1}", "Imported Module", "Type IDs");
1020 for (const auto &Xmi
: Imports
) {
1021 auto ExpectedModule
=
1022 Strings
.getNameFromStringTable(Xmi
.Header
->ModuleNameOffset
);
1024 SmallString
<32> ModuleStorage
;
1025 if (!ExpectedModule
) {
1026 Module
= "(unknown module)";
1027 consumeError(ExpectedModule
.takeError());
1029 Module
= *ExpectedModule
;
1030 if (Module
.size() > 32) {
1031 ModuleStorage
= "...";
1032 ModuleStorage
+= Module
.take_back(32 - 3);
1033 Module
= ModuleStorage
;
1035 std::vector
<std::string
> TIs
;
1036 for (const auto I
: Xmi
.Imports
)
1037 TIs
.push_back(std::string(formatv("{0,+10:X+}", fmtle(I
))));
1038 std::string Result
=
1039 typesetItemList(TIs
, P
.getIndentLevel() + 35, 12, " ");
1040 P
.formatLine("{0,+32} | {1}", Module
, Result
);
1044 return Error::success();
1047 Error
DumpOutputStyle::dumpXme() {
1048 printHeader(P
, "Cross Module Exports");
1050 if (File
.isPdb() && !getPdb().hasPDBDbiStream()) {
1051 printStreamNotPresent("DBI");
1052 return Error::success();
1055 iterateModuleSubsections
<DebugCrossModuleExportsSubsectionRef
>(
1056 File
, PrintScope
{P
, 2},
1057 [this](uint32_t Modi
, const SymbolGroup
&Strings
,
1058 DebugCrossModuleExportsSubsectionRef
&Exports
) {
1059 P
.formatLine("{0,-10} | {1}", "Local ID", "Global ID");
1060 for (const auto &Export
: Exports
) {
1061 P
.formatLine("{0,+10:X+} | {1}", TypeIndex(Export
.Local
),
1062 TypeIndex(Export
.Global
));
1066 return Error::success();
1069 std::string
formatFrameType(object::frame_type FT
) {
1071 case object::frame_type::Fpo
:
1073 case object::frame_type::NonFpo
:
1075 case object::frame_type::Trap
:
1077 case object::frame_type::Tss
:
1083 Error
DumpOutputStyle::dumpOldFpo(PDBFile
&File
) {
1084 printHeader(P
, "Old FPO Data");
1086 ExitOnError
Err("Error dumping old fpo data:");
1087 auto &Dbi
= Err(File
.getPDBDbiStream());
1089 if (!Dbi
.hasOldFpoRecords()) {
1090 printStreamNotPresent("FPO");
1091 return Error::success();
1094 const FixedStreamArray
<object::FpoData
>& Records
= Dbi
.getOldFpoRecords();
1096 P
.printLine(" RVA | Code | Locals | Params | Prolog | Saved Regs | Use "
1097 "BP | Has SEH | Frame Type");
1099 for (const object::FpoData
&FD
: Records
) {
1100 P
.formatLine("{0:X-8} | {1,4} | {2,6} | {3,6} | {4,6} | {5,10} | {6,6} | "
1102 uint32_t(FD
.Offset
), uint32_t(FD
.Size
), uint32_t(FD
.NumLocals
),
1103 uint32_t(FD
.NumParams
), FD
.getPrologSize(),
1104 FD
.getNumSavedRegs(), FD
.useBP(), FD
.hasSEH(),
1105 formatFrameType(FD
.getFP()));
1107 return Error::success();
1110 Error
DumpOutputStyle::dumpNewFpo(PDBFile
&File
) {
1111 printHeader(P
, "New FPO Data");
1113 ExitOnError
Err("Error dumping new fpo data:");
1114 auto &Dbi
= Err(File
.getPDBDbiStream());
1116 if (!Dbi
.hasNewFpoRecords()) {
1117 printStreamNotPresent("New FPO");
1118 return Error::success();
1121 const DebugFrameDataSubsectionRef
& FDS
= Dbi
.getNewFpoRecords();
1123 P
.printLine(" RVA | Code | Locals | Params | Stack | Prolog | Saved Regs "
1124 "| Has SEH | Has C++EH | Start | Program");
1125 for (const FrameData
&FD
: FDS
) {
1126 bool IsFuncStart
= FD
.Flags
& FrameData::IsFunctionStart
;
1127 bool HasEH
= FD
.Flags
& FrameData::HasEH
;
1128 bool HasSEH
= FD
.Flags
& FrameData::HasSEH
;
1130 auto &StringTable
= Err(File
.getStringTable());
1132 auto Program
= Err(StringTable
.getStringForID(FD
.FrameFunc
));
1133 P
.formatLine("{0:X-8} | {1,4} | {2,6} | {3,6} | {4,5} | {5,6} | {6,10} | "
1134 "{7,7} | {8,9} | {9,5} | {10}",
1135 uint32_t(FD
.RvaStart
), uint32_t(FD
.CodeSize
),
1136 uint32_t(FD
.LocalSize
), uint32_t(FD
.ParamsSize
),
1137 uint32_t(FD
.MaxStackSize
), uint16_t(FD
.PrologSize
),
1138 uint16_t(FD
.SavedRegsSize
), HasSEH
, HasEH
, IsFuncStart
,
1141 return Error::success();
1144 Error
DumpOutputStyle::dumpFpo() {
1145 if (!File
.isPdb()) {
1146 printStreamNotValidForObj();
1147 return Error::success();
1150 PDBFile
&File
= getPdb();
1151 if (!File
.hasPDBDbiStream()) {
1152 printStreamNotPresent("DBI");
1153 return Error::success();
1156 if (auto EC
= dumpOldFpo(File
))
1158 if (auto EC
= dumpNewFpo(File
))
1160 return Error::success();
1163 Error
DumpOutputStyle::dumpStringTableFromPdb() {
1164 AutoIndent
Indent(P
);
1165 auto IS
= getPdb().getStringTable();
1167 P
.formatLine("Not present in file");
1168 consumeError(IS
.takeError());
1169 return Error::success();
1172 if (opts::dump::DumpStringTable
) {
1173 if (IS
->name_ids().empty())
1174 P
.formatLine("Empty");
1177 std::max_element(IS
->name_ids().begin(), IS
->name_ids().end());
1178 uint32_t Digits
= NumDigits(*MaxID
);
1180 P
.formatLine("{0} | {1}", fmt_align("ID", AlignStyle::Right
, Digits
),
1183 std::vector
<uint32_t> SortedIDs(IS
->name_ids().begin(),
1184 IS
->name_ids().end());
1185 llvm::sort(SortedIDs
);
1186 for (uint32_t I
: SortedIDs
) {
1187 auto ES
= IS
->getStringForID(I
);
1188 llvm::SmallString
<32> Str
;
1190 consumeError(ES
.takeError());
1191 Str
= "Error reading string";
1192 } else if (!ES
->empty()) {
1199 P
.formatLine("{0} | {1}", fmt_align(I
, AlignStyle::Right
, Digits
),
1205 if (opts::dump::DumpStringTableDetails
) {
1208 P
.printLine("String Table Header:");
1209 AutoIndent
Indent(P
);
1210 P
.formatLine("Signature: {0}", IS
->getSignature());
1211 P
.formatLine("Hash Version: {0}", IS
->getHashVersion());
1212 P
.formatLine("Name Buffer Size: {0}", IS
->getByteSize());
1216 BinaryStreamRef NameBuffer
= IS
->getStringTable().getBuffer();
1217 ArrayRef
<uint8_t> Contents
;
1218 cantFail(NameBuffer
.readBytes(0, NameBuffer
.getLength(), Contents
));
1219 P
.formatBinary("Name Buffer", Contents
, 0);
1222 P
.printLine("Hash Table:");
1223 AutoIndent
Indent(P
);
1224 P
.formatLine("Bucket Count: {0}", IS
->name_ids().size());
1225 for (const auto &Entry
: enumerate(IS
->name_ids()))
1226 P
.formatLine("Bucket[{0}] : {1}", Entry
.index(),
1227 uint32_t(Entry
.value()));
1228 P
.formatLine("Name Count: {0}", IS
->getNameCount());
1231 return Error::success();
1234 Error
DumpOutputStyle::dumpStringTableFromObj() {
1235 iterateModuleSubsections
<DebugStringTableSubsectionRef
>(
1236 File
, PrintScope
{P
, 4},
1237 [&](uint32_t Modi
, const SymbolGroup
&Strings
,
1238 DebugStringTableSubsectionRef
&Strings2
) {
1239 BinaryStreamRef StringTableBuffer
= Strings2
.getBuffer();
1240 BinaryStreamReader
Reader(StringTableBuffer
);
1241 while (Reader
.bytesRemaining() > 0) {
1243 uint32_t Offset
= Reader
.getOffset();
1244 cantFail(Reader
.readCString(Str
));
1248 P
.formatLine("{0} | {1}", fmt_align(Offset
, AlignStyle::Right
, 4),
1252 return Error::success();
1255 Error
DumpOutputStyle::dumpNamedStreams() {
1256 printHeader(P
, "Named Streams");
1259 printStreamNotValidForObj();
1260 return Error::success();
1263 AutoIndent
Indent(P
);
1264 ExitOnError
Err("Invalid PDB File: ");
1266 auto &IS
= Err(File
.pdb().getPDBInfoStream());
1267 const NamedStreamMap
&NS
= IS
.getNamedStreams();
1268 for (const auto &Entry
: NS
.entries()) {
1269 P
.printLine(Entry
.getKey());
1270 AutoIndent
Indent2(P
, 2);
1271 P
.formatLine("Index: {0}", Entry
.getValue());
1272 P
.formatLine("Size in bytes: {0}",
1273 File
.pdb().getStreamByteSize(Entry
.getValue()));
1276 return Error::success();
1279 Error
DumpOutputStyle::dumpStringTable() {
1280 printHeader(P
, "String Table");
1283 return dumpStringTableFromPdb();
1285 return dumpStringTableFromObj();
1288 static void buildDepSet(LazyRandomTypeCollection
&Types
,
1289 ArrayRef
<TypeIndex
> Indices
,
1290 std::map
<TypeIndex
, CVType
> &DepSet
) {
1291 SmallVector
<TypeIndex
, 4> DepList
;
1292 for (const auto &I
: Indices
) {
1294 if (DepSet
.find(TI
) != DepSet
.end() || TI
.isSimple() || TI
.isNoneType())
1297 CVType Type
= Types
.getType(TI
);
1299 codeview::discoverTypeIndices(Type
, DepList
);
1300 buildDepSet(Types
, DepList
, DepSet
);
1305 dumpFullTypeStream(LinePrinter
&Printer
, LazyRandomTypeCollection
&Types
,
1306 TypeReferenceTracker
*RefTracker
, uint32_t NumTypeRecords
,
1307 uint32_t NumHashBuckets
,
1308 FixedStreamArray
<support::ulittle32_t
> HashValues
,
1309 TpiStream
*Stream
, bool Bytes
, bool Extras
) {
1311 Printer
.formatLine("Showing {0:N} records", NumTypeRecords
);
1312 uint32_t Width
= NumDigits(TypeIndex::FirstNonSimpleIndex
+ NumTypeRecords
);
1314 MinimalTypeDumpVisitor
V(Printer
, Width
+ 2, Bytes
, Extras
, Types
, RefTracker
,
1315 NumHashBuckets
, HashValues
, Stream
);
1317 if (auto EC
= codeview::visitTypeStream(Types
, V
)) {
1318 Printer
.formatLine("An error occurred dumping type records: {0}",
1319 toString(std::move(EC
)));
1323 static void dumpPartialTypeStream(LinePrinter
&Printer
,
1324 LazyRandomTypeCollection
&Types
,
1325 TypeReferenceTracker
*RefTracker
,
1326 TpiStream
&Stream
, ArrayRef
<TypeIndex
> TiList
,
1327 bool Bytes
, bool Extras
, bool Deps
) {
1329 NumDigits(TypeIndex::FirstNonSimpleIndex
+ Stream
.getNumTypeRecords());
1331 MinimalTypeDumpVisitor
V(Printer
, Width
+ 2, Bytes
, Extras
, Types
, RefTracker
,
1332 Stream
.getNumHashBuckets(), Stream
.getHashValues(),
1335 if (opts::dump::DumpTypeDependents
) {
1336 // If we need to dump all dependents, then iterate each index and find
1337 // all dependents, adding them to a map ordered by TypeIndex.
1338 std::map
<TypeIndex
, CVType
> DepSet
;
1339 buildDepSet(Types
, TiList
, DepSet
);
1342 "Showing {0:N} records and their dependents ({1:N} records total)",
1343 TiList
.size(), DepSet
.size());
1345 for (auto &Dep
: DepSet
) {
1346 if (auto EC
= codeview::visitTypeRecord(Dep
.second
, Dep
.first
, V
))
1347 Printer
.formatLine("An error occurred dumping type record {0}: {1}",
1348 Dep
.first
, toString(std::move(EC
)));
1351 Printer
.formatLine("Showing {0:N} records.", TiList
.size());
1353 for (const auto &I
: TiList
) {
1355 CVType Type
= Types
.getType(TI
);
1356 if (auto EC
= codeview::visitTypeRecord(Type
, TI
, V
))
1357 Printer
.formatLine("An error occurred dumping type record {0}: {1}", TI
,
1358 toString(std::move(EC
)));
1363 Error
DumpOutputStyle::dumpTypesFromObjectFile() {
1364 LazyRandomTypeCollection
Types(100);
1366 for (const auto &S
: getObj().sections()) {
1367 Expected
<StringRef
> NameOrErr
= S
.getName();
1369 return NameOrErr
.takeError();
1370 StringRef SectionName
= *NameOrErr
;
1372 // .debug$T is a standard CodeView type section, while .debug$P is the same
1373 // format but used for MSVC precompiled header object files.
1374 if (SectionName
== ".debug$T")
1375 printHeader(P
, "Types (.debug$T)");
1376 else if (SectionName
== ".debug$P")
1377 printHeader(P
, "Precompiled Types (.debug$P)");
1381 Expected
<StringRef
> ContentsOrErr
= S
.getContents();
1383 return ContentsOrErr
.takeError();
1386 BinaryStreamReader
Reader(*ContentsOrErr
, llvm::support::little
);
1387 if (auto EC
= Reader
.readInteger(Magic
))
1389 if (Magic
!= COFF::DEBUG_SECTION_MAGIC
)
1390 return make_error
<StringError
>("Invalid CodeView debug section.",
1391 inconvertibleErrorCode());
1393 Types
.reset(Reader
, 100);
1395 if (opts::dump::DumpTypes
) {
1396 dumpFullTypeStream(P
, Types
, RefTracker
.get(), 0, 0, {}, nullptr,
1397 opts::dump::DumpTypeData
, false);
1398 } else if (opts::dump::DumpTypeExtras
) {
1399 auto LocalHashes
= LocallyHashedType::hashTypeCollection(Types
);
1400 auto GlobalHashes
= GloballyHashedType::hashTypeCollection(Types
);
1401 assert(LocalHashes
.size() == GlobalHashes
.size());
1403 P
.formatLine("Local / Global hashes:");
1404 TypeIndex
TI(TypeIndex::FirstNonSimpleIndex
);
1405 for (auto H
: zip(LocalHashes
, GlobalHashes
)) {
1406 AutoIndent
Indent2(P
);
1407 LocallyHashedType
&L
= std::get
<0>(H
);
1408 GloballyHashedType
&G
= std::get
<1>(H
);
1410 P
.formatLine("TI: {0}, LocalHash: {1:X}, GlobalHash: {2}", TI
, L
, G
);
1418 return Error::success();
1421 Error
DumpOutputStyle::dumpTpiStream(uint32_t StreamIdx
) {
1422 assert(StreamIdx
== StreamTPI
|| StreamIdx
== StreamIPI
);
1424 if (StreamIdx
== StreamTPI
) {
1425 printHeader(P
, "Types (TPI Stream)");
1426 } else if (StreamIdx
== StreamIPI
) {
1427 printHeader(P
, "Types (IPI Stream)");
1430 assert(!File
.isObj());
1432 bool Present
= false;
1433 bool DumpTypes
= false;
1434 bool DumpBytes
= false;
1435 bool DumpExtras
= false;
1436 std::vector
<uint32_t> Indices
;
1437 if (StreamIdx
== StreamTPI
) {
1438 Present
= getPdb().hasPDBTpiStream();
1439 DumpTypes
= opts::dump::DumpTypes
;
1440 DumpBytes
= opts::dump::DumpTypeData
;
1441 DumpExtras
= opts::dump::DumpTypeExtras
;
1442 Indices
.assign(opts::dump::DumpTypeIndex
.begin(),
1443 opts::dump::DumpTypeIndex
.end());
1444 } else if (StreamIdx
== StreamIPI
) {
1445 Present
= getPdb().hasPDBIpiStream();
1446 DumpTypes
= opts::dump::DumpIds
;
1447 DumpBytes
= opts::dump::DumpIdData
;
1448 DumpExtras
= opts::dump::DumpIdExtras
;
1449 Indices
.assign(opts::dump::DumpIdIndex
.begin(),
1450 opts::dump::DumpIdIndex
.end());
1454 printStreamNotPresent(StreamIdx
== StreamTPI
? "TPI" : "IPI");
1455 return Error::success();
1458 AutoIndent
Indent(P
);
1459 ExitOnError
Err("Unexpected error processing types: ");
1461 auto &Stream
= Err((StreamIdx
== StreamTPI
) ? getPdb().getPDBTpiStream()
1462 : getPdb().getPDBIpiStream());
1464 auto &Types
= (StreamIdx
== StreamTPI
) ? File
.types() : File
.ids();
1466 // Only emit notes about referenced/unreferenced for types.
1467 TypeReferenceTracker
*MaybeTracker
=
1468 (StreamIdx
== StreamTPI
) ? RefTracker
.get() : nullptr;
1470 // Enable resolving forward decls.
1471 Stream
.buildHashMap();
1473 if (DumpTypes
|| !Indices
.empty()) {
1474 if (Indices
.empty())
1475 dumpFullTypeStream(P
, Types
, MaybeTracker
, Stream
.getNumTypeRecords(),
1476 Stream
.getNumHashBuckets(), Stream
.getHashValues(),
1477 &Stream
, DumpBytes
, DumpExtras
);
1479 std::vector
<TypeIndex
> TiList(Indices
.begin(), Indices
.end());
1480 dumpPartialTypeStream(P
, Types
, MaybeTracker
, Stream
, TiList
, DumpBytes
,
1481 DumpExtras
, opts::dump::DumpTypeDependents
);
1488 P
.formatLine("Header Version: {0}",
1489 static_cast<uint32_t>(Stream
.getTpiVersion()));
1490 P
.formatLine("Hash Stream Index: {0}", Stream
.getTypeHashStreamIndex());
1491 P
.formatLine("Aux Hash Stream Index: {0}",
1492 Stream
.getTypeHashStreamAuxIndex());
1493 P
.formatLine("Hash Key Size: {0}", Stream
.getHashKeySize());
1494 P
.formatLine("Num Hash Buckets: {0}", Stream
.getNumHashBuckets());
1496 auto IndexOffsets
= Stream
.getTypeIndexOffsets();
1497 P
.formatLine("Type Index Offsets:");
1498 for (const auto &IO
: IndexOffsets
) {
1499 AutoIndent
Indent2(P
);
1500 P
.formatLine("TI: {0}, Offset: {1}", IO
.Type
, fmtle(IO
.Offset
));
1503 if (getPdb().hasPDBStringTable()) {
1505 P
.formatLine("Hash Adjusters:");
1506 auto &Adjusters
= Stream
.getHashAdjusters();
1507 auto &Strings
= Err(getPdb().getStringTable());
1508 for (const auto &A
: Adjusters
) {
1509 AutoIndent
Indent2(P
);
1510 auto ExpectedStr
= Strings
.getStringForID(A
.first
);
1511 TypeIndex
TI(A
.second
);
1513 P
.formatLine("`{0}` -> {1}", *ExpectedStr
, TI
);
1515 P
.formatLine("unknown str id ({0}) -> {1}", A
.first
, TI
);
1516 consumeError(ExpectedStr
.takeError());
1521 return Error::success();
1524 Error
DumpOutputStyle::dumpModuleSymsForObj() {
1525 printHeader(P
, "Symbols");
1527 AutoIndent
Indent(P
);
1529 ExitOnError
Err("Unexpected error processing symbols: ");
1531 auto &Types
= File
.types();
1533 SymbolVisitorCallbackPipeline Pipeline
;
1534 SymbolDeserializer
Deserializer(nullptr, CodeViewContainer::ObjectFile
);
1535 MinimalSymbolDumper
Dumper(P
, opts::dump::DumpSymRecordBytes
, Types
, Types
);
1537 Pipeline
.addCallbackToPipeline(Deserializer
);
1538 Pipeline
.addCallbackToPipeline(Dumper
);
1539 CVSymbolVisitor
Visitor(Pipeline
);
1541 std::unique_ptr
<llvm::Error
> SymbolError
;
1543 iterateModuleSubsections
<DebugSymbolsSubsectionRef
>(
1544 File
, PrintScope
{P
, 2},
1545 [&](uint32_t Modi
, const SymbolGroup
&Strings
,
1546 DebugSymbolsSubsectionRef
&Symbols
) {
1547 Dumper
.setSymbolGroup(&Strings
);
1548 for (auto Symbol
: Symbols
) {
1549 if (auto EC
= Visitor
.visitSymbolRecord(Symbol
)) {
1550 SymbolError
= std::make_unique
<Error
>(std::move(EC
));
1557 return std::move(*SymbolError
);
1559 return Error::success();
1562 Error
DumpOutputStyle::dumpModuleSymsForPdb() {
1563 printHeader(P
, "Symbols");
1565 if (File
.isPdb() && !getPdb().hasPDBDbiStream()) {
1566 printStreamNotPresent("DBI");
1567 return Error::success();
1570 AutoIndent
Indent(P
);
1571 ExitOnError
Err("Unexpected error processing symbols: ");
1573 auto &Ids
= File
.ids();
1574 auto &Types
= File
.types();
1576 iterateSymbolGroups(
1577 File
, PrintScope
{P
, 2}, [&](uint32_t I
, const SymbolGroup
&Strings
) {
1578 auto ExpectedModS
= getModuleDebugStream(File
.pdb(), I
);
1579 if (!ExpectedModS
) {
1580 P
.formatLine("Error loading module stream {0}. {1}", I
,
1581 toString(ExpectedModS
.takeError()));
1585 ModuleDebugStreamRef
&ModS
= *ExpectedModS
;
1587 SymbolVisitorCallbackPipeline Pipeline
;
1588 SymbolDeserializer
Deserializer(nullptr, CodeViewContainer::Pdb
);
1589 MinimalSymbolDumper
Dumper(P
, opts::dump::DumpSymRecordBytes
, Strings
,
1592 Pipeline
.addCallbackToPipeline(Deserializer
);
1593 Pipeline
.addCallbackToPipeline(Dumper
);
1594 CVSymbolVisitor
Visitor(Pipeline
);
1595 auto SS
= ModS
.getSymbolsSubstream();
1597 Visitor
.visitSymbolStream(ModS
.getSymbolArray(), SS
.Offset
)) {
1598 P
.formatLine("Error while processing symbol records. {0}",
1599 toString(std::move(EC
)));
1603 return Error::success();
1606 Error
DumpOutputStyle::dumpTypeRefStats() {
1607 printHeader(P
, "Type Reference Statistics");
1608 AutoIndent
Indent(P
);
1610 // Sum the byte size of all type records, and the size and count of all
1611 // referenced records.
1612 size_t TotalRecs
= File
.types().size();
1614 size_t TotalBytes
= 0;
1615 size_t RefBytes
= 0;
1616 auto &Types
= File
.types();
1617 for (Optional
<TypeIndex
> TI
= Types
.getFirst(); TI
; TI
= Types
.getNext(*TI
)) {
1618 CVType Type
= File
.types().getType(*TI
);
1619 TotalBytes
+= Type
.length();
1620 if (RefTracker
->isTypeReferenced(*TI
)) {
1622 RefBytes
+= Type
.length();
1626 P
.formatLine("Records referenced: {0:N} / {1:N} {2:P}", RefRecs
, TotalRecs
,
1627 (double)RefRecs
/ TotalRecs
);
1628 P
.formatLine("Bytes referenced: {0:N} / {1:N} {2:P}", RefBytes
, TotalBytes
,
1629 (double)RefBytes
/ TotalBytes
);
1631 return Error::success();
1634 Error
DumpOutputStyle::dumpGSIRecords() {
1635 printHeader(P
, "GSI Records");
1638 printStreamNotValidForObj();
1639 return Error::success();
1642 if (!getPdb().hasPDBSymbolStream()) {
1643 printStreamNotPresent("GSI Common Symbol");
1644 return Error::success();
1647 AutoIndent
Indent(P
);
1649 auto &Records
= cantFail(getPdb().getPDBSymbolStream());
1650 auto &Types
= File
.types();
1651 auto &Ids
= File
.ids();
1653 P
.printLine("Records");
1654 SymbolVisitorCallbackPipeline Pipeline
;
1655 SymbolDeserializer
Deserializer(nullptr, CodeViewContainer::Pdb
);
1656 MinimalSymbolDumper
Dumper(P
, opts::dump::DumpSymRecordBytes
, Ids
, Types
);
1658 Pipeline
.addCallbackToPipeline(Deserializer
);
1659 Pipeline
.addCallbackToPipeline(Dumper
);
1660 CVSymbolVisitor
Visitor(Pipeline
);
1662 BinaryStreamRef SymStream
= Records
.getSymbolArray().getUnderlyingStream();
1663 if (auto E
= Visitor
.visitSymbolStream(Records
.getSymbolArray(), 0))
1665 return Error::success();
1668 Error
DumpOutputStyle::dumpGlobals() {
1669 printHeader(P
, "Global Symbols");
1672 printStreamNotValidForObj();
1673 return Error::success();
1676 if (!getPdb().hasPDBGlobalsStream()) {
1677 printStreamNotPresent("Globals");
1678 return Error::success();
1681 AutoIndent
Indent(P
);
1682 ExitOnError
Err("Error dumping globals stream: ");
1683 auto &Globals
= Err(getPdb().getPDBGlobalsStream());
1685 if (opts::dump::DumpGlobalNames
.empty()) {
1686 const GSIHashTable
&Table
= Globals
.getGlobalsTable();
1687 Err(dumpSymbolsFromGSI(Table
, opts::dump::DumpGlobalExtras
));
1689 SymbolStream
&SymRecords
= cantFail(getPdb().getPDBSymbolStream());
1690 auto &Types
= File
.types();
1691 auto &Ids
= File
.ids();
1693 SymbolVisitorCallbackPipeline Pipeline
;
1694 SymbolDeserializer
Deserializer(nullptr, CodeViewContainer::Pdb
);
1695 MinimalSymbolDumper
Dumper(P
, opts::dump::DumpSymRecordBytes
, Ids
, Types
);
1697 Pipeline
.addCallbackToPipeline(Deserializer
);
1698 Pipeline
.addCallbackToPipeline(Dumper
);
1699 CVSymbolVisitor
Visitor(Pipeline
);
1701 using ResultEntryType
= std::pair
<uint32_t, CVSymbol
>;
1702 for (StringRef Name
: opts::dump::DumpGlobalNames
) {
1703 AutoIndent
Indent(P
);
1704 P
.formatLine("Global Name `{0}`", Name
);
1705 std::vector
<ResultEntryType
> Results
=
1706 Globals
.findRecordsByName(Name
, SymRecords
);
1707 if (Results
.empty()) {
1708 AutoIndent
Indent(P
);
1709 P
.printLine("(no matching records found)");
1713 for (ResultEntryType Result
: Results
) {
1714 if (auto E
= Visitor
.visitSymbolRecord(Result
.second
, Result
.first
))
1719 return Error::success();
1722 Error
DumpOutputStyle::dumpPublics() {
1723 printHeader(P
, "Public Symbols");
1726 printStreamNotValidForObj();
1727 return Error::success();
1730 if (!getPdb().hasPDBPublicsStream()) {
1731 printStreamNotPresent("Publics");
1732 return Error::success();
1735 AutoIndent
Indent(P
);
1736 ExitOnError
Err("Error dumping publics stream: ");
1737 auto &Publics
= Err(getPdb().getPDBPublicsStream());
1739 const GSIHashTable
&PublicsTable
= Publics
.getPublicsTable();
1740 if (opts::dump::DumpPublicExtras
) {
1741 P
.printLine("Publics Header");
1742 AutoIndent
Indent(P
);
1743 P
.formatLine("sym hash = {0}, thunk table addr = {1}", Publics
.getSymHash(),
1744 formatSegmentOffset(Publics
.getThunkTableSection(),
1745 Publics
.getThunkTableOffset()));
1747 Err(dumpSymbolsFromGSI(PublicsTable
, opts::dump::DumpPublicExtras
));
1749 // Skip the rest if we aren't dumping extras.
1750 if (!opts::dump::DumpPublicExtras
)
1751 return Error::success();
1753 P
.formatLine("Address Map");
1755 // These are offsets into the publics stream sorted by secidx:secrel.
1756 AutoIndent
Indent2(P
);
1757 for (uint32_t Addr
: Publics
.getAddressMap())
1758 P
.formatLine("off = {0}", Addr
);
1761 // The thunk map is optional debug info used for ILT thunks.
1762 if (!Publics
.getThunkMap().empty()) {
1763 P
.formatLine("Thunk Map");
1764 AutoIndent
Indent2(P
);
1765 for (uint32_t Addr
: Publics
.getThunkMap())
1766 P
.formatLine("{0:x8}", Addr
);
1769 // The section offsets table appears to be empty when incremental linking
1771 if (!Publics
.getSectionOffsets().empty()) {
1772 P
.formatLine("Section Offsets");
1773 AutoIndent
Indent2(P
);
1774 for (const SectionOffset
&SO
: Publics
.getSectionOffsets())
1775 P
.formatLine("{0:x4}:{1:x8}", uint16_t(SO
.Isect
), uint32_t(SO
.Off
));
1778 return Error::success();
1781 Error
DumpOutputStyle::dumpSymbolsFromGSI(const GSIHashTable
&Table
,
1783 auto ExpectedSyms
= getPdb().getPDBSymbolStream();
1785 return ExpectedSyms
.takeError();
1786 auto &Types
= File
.types();
1787 auto &Ids
= File
.ids();
1790 P
.printLine("GSI Header");
1791 AutoIndent
Indent(P
);
1792 P
.formatLine("sig = {0:X}, hdr = {1:X}, hr size = {2}, num buckets = {3}",
1793 Table
.getVerSignature(), Table
.getVerHeader(),
1794 Table
.getHashRecordSize(), Table
.getNumBuckets());
1798 P
.printLine("Records");
1799 SymbolVisitorCallbackPipeline Pipeline
;
1800 SymbolDeserializer
Deserializer(nullptr, CodeViewContainer::Pdb
);
1801 MinimalSymbolDumper
Dumper(P
, opts::dump::DumpSymRecordBytes
, Ids
, Types
);
1803 Pipeline
.addCallbackToPipeline(Deserializer
);
1804 Pipeline
.addCallbackToPipeline(Dumper
);
1805 CVSymbolVisitor
Visitor(Pipeline
);
1808 BinaryStreamRef SymStream
=
1809 ExpectedSyms
->getSymbolArray().getUnderlyingStream();
1810 for (uint32_t PubSymOff
: Table
) {
1811 Expected
<CVSymbol
> Sym
= readSymbolFromStream(SymStream
, PubSymOff
);
1813 return Sym
.takeError();
1814 if (auto E
= Visitor
.visitSymbolRecord(*Sym
, PubSymOff
))
1819 // Return early if we aren't dumping public hash table and address map info.
1821 P
.formatLine("Hash Entries");
1823 AutoIndent
Indent2(P
);
1824 for (const PSHashRecord
&HR
: Table
.HashRecords
)
1825 P
.formatLine("off = {0}, refcnt = {1}", uint32_t(HR
.Off
),
1829 P
.formatLine("Hash Buckets");
1831 AutoIndent
Indent2(P
);
1832 for (uint32_t Hash
: Table
.HashBuckets
)
1833 P
.formatLine("{0:x8}", Hash
);
1837 return Error::success();
1840 static std::string
formatSegMapDescriptorFlag(uint32_t IndentLevel
,
1841 OMFSegDescFlags Flags
) {
1842 std::vector
<std::string
> Opts
;
1843 if (Flags
== OMFSegDescFlags::None
)
1846 PUSH_FLAG(OMFSegDescFlags
, Read
, Flags
, "read");
1847 PUSH_FLAG(OMFSegDescFlags
, Write
, Flags
, "write");
1848 PUSH_FLAG(OMFSegDescFlags
, Execute
, Flags
, "execute");
1849 PUSH_FLAG(OMFSegDescFlags
, AddressIs32Bit
, Flags
, "32 bit addr");
1850 PUSH_FLAG(OMFSegDescFlags
, IsSelector
, Flags
, "selector");
1851 PUSH_FLAG(OMFSegDescFlags
, IsAbsoluteAddress
, Flags
, "absolute addr");
1852 PUSH_FLAG(OMFSegDescFlags
, IsGroup
, Flags
, "group");
1853 return typesetItemList(Opts
, IndentLevel
, 4, " | ");
1856 Error
DumpOutputStyle::dumpSectionHeaders() {
1857 dumpSectionHeaders("Section Headers", DbgHeaderType::SectionHdr
);
1858 dumpSectionHeaders("Original Section Headers", DbgHeaderType::SectionHdrOrig
);
1859 return Error::success();
1862 void DumpOutputStyle::dumpSectionHeaders(StringRef Label
, DbgHeaderType Type
) {
1863 printHeader(P
, Label
);
1866 printStreamNotValidForObj();
1870 if (!getPdb().hasPDBDbiStream()) {
1871 printStreamNotPresent("DBI");
1875 AutoIndent
Indent(P
);
1876 ExitOnError
Err("Error dumping section headers: ");
1877 std::unique_ptr
<MappedBlockStream
> Stream
;
1878 ArrayRef
<object::coff_section
> Headers
;
1879 auto ExpectedHeaders
= loadSectionHeaders(getPdb(), Type
);
1880 if (!ExpectedHeaders
) {
1881 P
.printLine(toString(ExpectedHeaders
.takeError()));
1884 std::tie(Stream
, Headers
) = std::move(*ExpectedHeaders
);
1887 for (const auto &Header
: Headers
) {
1889 P
.formatLine("SECTION HEADER #{0}", I
);
1890 P
.formatLine("{0,8} name", Header
.Name
);
1891 P
.formatLine("{0,8:X-} virtual size", uint32_t(Header
.VirtualSize
));
1892 P
.formatLine("{0,8:X-} virtual address", uint32_t(Header
.VirtualAddress
));
1893 P
.formatLine("{0,8:X-} size of raw data", uint32_t(Header
.SizeOfRawData
));
1894 P
.formatLine("{0,8:X-} file pointer to raw data",
1895 uint32_t(Header
.PointerToRawData
));
1896 P
.formatLine("{0,8:X-} file pointer to relocation table",
1897 uint32_t(Header
.PointerToRelocations
));
1898 P
.formatLine("{0,8:X-} file pointer to line numbers",
1899 uint32_t(Header
.PointerToLinenumbers
));
1900 P
.formatLine("{0,8:X-} number of relocations",
1901 uint32_t(Header
.NumberOfRelocations
));
1902 P
.formatLine("{0,8:X-} number of line numbers",
1903 uint32_t(Header
.NumberOfLinenumbers
));
1904 P
.formatLine("{0,8:X-} flags", uint32_t(Header
.Characteristics
));
1905 AutoIndent
IndentMore(P
, 9);
1906 P
.formatLine("{0}", formatSectionCharacteristics(
1907 P
.getIndentLevel(), Header
.Characteristics
, 1, ""));
1912 Error
DumpOutputStyle::dumpSectionContribs() {
1913 printHeader(P
, "Section Contributions");
1916 printStreamNotValidForObj();
1917 return Error::success();
1920 if (!getPdb().hasPDBDbiStream()) {
1921 printStreamNotPresent("DBI");
1922 return Error::success();
1925 AutoIndent
Indent(P
);
1926 ExitOnError
Err("Error dumping section contributions: ");
1928 auto &Dbi
= Err(getPdb().getPDBDbiStream());
1930 class Visitor
: public ISectionContribVisitor
{
1932 Visitor(LinePrinter
&P
, ArrayRef
<std::string
> Names
) : P(P
), Names(Names
) {
1933 auto Max
= std::max_element(
1934 Names
.begin(), Names
.end(),
1935 [](StringRef S1
, StringRef S2
) { return S1
.size() < S2
.size(); });
1936 MaxNameLen
= (Max
== Names
.end() ? 0 : Max
->size());
1938 void visit(const SectionContrib
&SC
) override
{
1939 dumpSectionContrib(P
, SC
, Names
, MaxNameLen
);
1941 void visit(const SectionContrib2
&SC
) override
{
1942 dumpSectionContrib(P
, SC
, Names
, MaxNameLen
);
1947 uint32_t MaxNameLen
;
1948 ArrayRef
<std::string
> Names
;
1951 std::vector
<std::string
> Names
= getSectionNames(getPdb());
1952 Visitor
V(P
, makeArrayRef(Names
));
1953 Dbi
.visitSectionContributions(V
);
1954 return Error::success();
1957 Error
DumpOutputStyle::dumpSectionMap() {
1958 printHeader(P
, "Section Map");
1961 printStreamNotValidForObj();
1962 return Error::success();
1965 if (!getPdb().hasPDBDbiStream()) {
1966 printStreamNotPresent("DBI");
1967 return Error::success();
1970 AutoIndent
Indent(P
);
1971 ExitOnError
Err("Error dumping section map: ");
1973 auto &Dbi
= Err(getPdb().getPDBDbiStream());
1976 for (auto &M
: Dbi
.getSectionMap()) {
1978 "Section {0:4} | ovl = {1}, group = {2}, frame = {3}, name = {4}", I
,
1979 fmtle(M
.Ovl
), fmtle(M
.Group
), fmtle(M
.Frame
), fmtle(M
.SecName
));
1980 P
.formatLine(" class = {0}, offset = {1}, size = {2}",
1981 fmtle(M
.ClassName
), fmtle(M
.Offset
), fmtle(M
.SecByteLength
));
1982 P
.formatLine(" flags = {0}",
1983 formatSegMapDescriptorFlag(
1984 P
.getIndentLevel() + 13,
1985 static_cast<OMFSegDescFlags
>(uint16_t(M
.Flags
))));
1988 return Error::success();