llvm-project
1638 строк · 65.9 Кб
1//===- llvm-pdbutil.cpp - Dump debug info from a PDB file -------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// Dumps debug information present in PDB files.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm-pdbutil.h"
14
15#include "BytesOutputStyle.h"
16#include "DumpOutputStyle.h"
17#include "ExplainOutputStyle.h"
18#include "OutputStyle.h"
19#include "PrettyClassDefinitionDumper.h"
20#include "PrettyCompilandDumper.h"
21#include "PrettyEnumDumper.h"
22#include "PrettyExternalSymbolDumper.h"
23#include "PrettyFunctionDumper.h"
24#include "PrettyTypeDumper.h"
25#include "PrettyTypedefDumper.h"
26#include "PrettyVariableDumper.h"
27#include "YAMLOutputStyle.h"
28
29#include "llvm/ADT/ArrayRef.h"
30#include "llvm/ADT/STLExtras.h"
31#include "llvm/ADT/StringExtras.h"
32#include "llvm/BinaryFormat/Magic.h"
33#include "llvm/Config/config.h"
34#include "llvm/DebugInfo/CodeView/AppendingTypeTableBuilder.h"
35#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
36#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
37#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
38#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
39#include "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h"
40#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
41#include "llvm/DebugInfo/CodeView/TypeStreamMerger.h"
42#include "llvm/DebugInfo/MSF/MSFBuilder.h"
43#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
44#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
45#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
46#include "llvm/DebugInfo/PDB/IPDBInjectedSource.h"
47#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
48#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
49#include "llvm/DebugInfo/PDB/IPDBSession.h"
50#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h"
51#include "llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h"
52#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
53#include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h"
54#include "llvm/DebugInfo/PDB/Native/InputFile.h"
55#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
56#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
57#include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
58#include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
59#include "llvm/DebugInfo/PDB/Native/RawConstants.h"
60#include "llvm/DebugInfo/PDB/Native/RawError.h"
61#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
62#include "llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h"
63#include "llvm/DebugInfo/PDB/PDB.h"
64#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
65#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
66#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
67#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
68#include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
69#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
70#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
71#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
72#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
73#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
74#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
75#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
76#include "llvm/Support/BinaryByteStream.h"
77#include "llvm/Support/COM.h"
78#include "llvm/Support/CommandLine.h"
79#include "llvm/Support/ConvertUTF.h"
80#include "llvm/Support/FileOutputBuffer.h"
81#include "llvm/Support/FileSystem.h"
82#include "llvm/Support/Format.h"
83#include "llvm/Support/InitLLVM.h"
84#include "llvm/Support/LineIterator.h"
85#include "llvm/Support/MemoryBuffer.h"
86#include "llvm/Support/Path.h"
87#include "llvm/Support/PrettyStackTrace.h"
88#include "llvm/Support/Process.h"
89#include "llvm/Support/Regex.h"
90#include "llvm/Support/ScopedPrinter.h"
91#include "llvm/Support/Signals.h"
92#include "llvm/Support/raw_ostream.h"
93
94using namespace llvm;
95using namespace llvm::codeview;
96using namespace llvm::msf;
97using namespace llvm::pdb;
98
99namespace opts {
100
101cl::SubCommand DumpSubcommand("dump", "Dump MSF and CodeView debug info");
102cl::SubCommand BytesSubcommand("bytes", "Dump raw bytes from the PDB file");
103
104cl::SubCommand DiaDumpSubcommand("diadump",
105"Dump debug information using a DIA-like API");
106
107cl::SubCommand
108PrettySubcommand("pretty",
109"Dump semantic information about types and symbols");
110
111cl::SubCommand
112YamlToPdbSubcommand("yaml2pdb",
113"Generate a PDB file from a YAML description");
114cl::SubCommand
115PdbToYamlSubcommand("pdb2yaml",
116"Generate a detailed YAML description of a PDB File");
117
118cl::SubCommand MergeSubcommand("merge",
119"Merge multiple PDBs into a single PDB");
120
121cl::SubCommand ExplainSubcommand("explain",
122"Explain the meaning of a file offset");
123
124cl::SubCommand ExportSubcommand("export",
125"Write binary data from a stream to a file");
126
127cl::OptionCategory TypeCategory("Symbol Type Options");
128cl::OptionCategory FilterCategory("Filtering and Sorting Options");
129cl::OptionCategory OtherOptions("Other Options");
130
131cl::ValuesClass ChunkValues = cl::values(
132clEnumValN(ModuleSubsection::CrossScopeExports, "cme",
133"Cross module exports (DEBUG_S_CROSSSCOPEEXPORTS subsection)"),
134clEnumValN(ModuleSubsection::CrossScopeImports, "cmi",
135"Cross module imports (DEBUG_S_CROSSSCOPEIMPORTS subsection)"),
136clEnumValN(ModuleSubsection::FileChecksums, "fc",
137"File checksums (DEBUG_S_CHECKSUMS subsection)"),
138clEnumValN(ModuleSubsection::InlineeLines, "ilines",
139"Inlinee lines (DEBUG_S_INLINEELINES subsection)"),
140clEnumValN(ModuleSubsection::Lines, "lines",
141"Lines (DEBUG_S_LINES subsection)"),
142clEnumValN(ModuleSubsection::StringTable, "strings",
143"String Table (DEBUG_S_STRINGTABLE subsection) (not "
144"typically present in PDB file)"),
145clEnumValN(ModuleSubsection::FrameData, "frames",
146"Frame Data (DEBUG_S_FRAMEDATA subsection)"),
147clEnumValN(ModuleSubsection::Symbols, "symbols",
148"Symbols (DEBUG_S_SYMBOLS subsection) (not typically "
149"present in PDB file)"),
150clEnumValN(ModuleSubsection::CoffSymbolRVAs, "rvas",
151"COFF Symbol RVAs (DEBUG_S_COFF_SYMBOL_RVA subsection)"),
152clEnumValN(ModuleSubsection::Unknown, "unknown",
153"Any subsection not covered by another option"),
154clEnumValN(ModuleSubsection::All, "all", "All known subsections"));
155
156namespace diadump {
157cl::list<std::string> InputFilenames(cl::Positional,
158cl::desc("<input PDB files>"),
159cl::OneOrMore, cl::sub(DiaDumpSubcommand));
160
161cl::opt<bool> Native("native", cl::desc("Use native PDB reader instead of DIA"),
162cl::sub(DiaDumpSubcommand));
163
164static cl::opt<bool>
165ShowClassHierarchy("hierarchy", cl::desc("Show lexical and class parents"),
166cl::sub(DiaDumpSubcommand));
167static cl::opt<bool> NoSymIndexIds(
168"no-ids",
169cl::desc("Don't show any SymIndexId fields (overrides -hierarchy)"),
170cl::sub(DiaDumpSubcommand));
171
172static cl::opt<bool>
173Recurse("recurse",
174cl::desc("When dumping a SymIndexId, dump the full details of the "
175"corresponding record"),
176cl::sub(DiaDumpSubcommand));
177
178static cl::opt<bool> Enums("enums", cl::desc("Dump enum types"),
179cl::sub(DiaDumpSubcommand));
180static cl::opt<bool> Pointers("pointers", cl::desc("Dump enum types"),
181cl::sub(DiaDumpSubcommand));
182static cl::opt<bool> UDTs("udts", cl::desc("Dump udt types"),
183cl::sub(DiaDumpSubcommand));
184static cl::opt<bool> Compilands("compilands",
185cl::desc("Dump compiland information"),
186cl::sub(DiaDumpSubcommand));
187static cl::opt<bool> Funcsigs("funcsigs",
188cl::desc("Dump function signature information"),
189cl::sub(DiaDumpSubcommand));
190static cl::opt<bool> Arrays("arrays", cl::desc("Dump array types"),
191cl::sub(DiaDumpSubcommand));
192static cl::opt<bool> VTShapes("vtshapes", cl::desc("Dump virtual table shapes"),
193cl::sub(DiaDumpSubcommand));
194static cl::opt<bool> Typedefs("typedefs", cl::desc("Dump typedefs"),
195cl::sub(DiaDumpSubcommand));
196} // namespace diadump
197
198FilterOptions Filters;
199
200namespace pretty {
201cl::list<std::string> InputFilenames(cl::Positional,
202cl::desc("<input PDB files>"),
203cl::OneOrMore, cl::sub(PrettySubcommand));
204
205cl::opt<bool> InjectedSources("injected-sources",
206cl::desc("Display injected sources"),
207cl::cat(OtherOptions), cl::sub(PrettySubcommand));
208cl::opt<bool> ShowInjectedSourceContent(
209"injected-source-content",
210cl::desc("When displaying an injected source, display the file content"),
211cl::cat(OtherOptions), cl::sub(PrettySubcommand));
212
213cl::list<std::string> WithName(
214"with-name",
215cl::desc("Display any symbol or type with the specified exact name"),
216cl::cat(TypeCategory), cl::sub(PrettySubcommand));
217
218cl::opt<bool> Compilands("compilands", cl::desc("Display compilands"),
219cl::cat(TypeCategory), cl::sub(PrettySubcommand));
220cl::opt<bool> Symbols("module-syms",
221cl::desc("Display symbols for each compiland"),
222cl::cat(TypeCategory), cl::sub(PrettySubcommand));
223cl::opt<bool> Globals("globals", cl::desc("Dump global symbols"),
224cl::cat(TypeCategory), cl::sub(PrettySubcommand));
225cl::opt<bool> Externals("externals", cl::desc("Dump external symbols"),
226cl::cat(TypeCategory), cl::sub(PrettySubcommand));
227cl::list<SymLevel> SymTypes(
228"sym-types", cl::desc("Type of symbols to dump (default all)"),
229cl::cat(TypeCategory), cl::sub(PrettySubcommand),
230cl::values(
231clEnumValN(SymLevel::Thunks, "thunks", "Display thunk symbols"),
232clEnumValN(SymLevel::Data, "data", "Display data symbols"),
233clEnumValN(SymLevel::Functions, "funcs", "Display function symbols"),
234clEnumValN(SymLevel::All, "all", "Display all symbols (default)")));
235
236cl::opt<bool>
237Types("types",
238cl::desc("Display all types (implies -classes, -enums, -typedefs)"),
239cl::cat(TypeCategory), cl::sub(PrettySubcommand));
240cl::opt<bool> Classes("classes", cl::desc("Display class types"),
241cl::cat(TypeCategory), cl::sub(PrettySubcommand));
242cl::opt<bool> Enums("enums", cl::desc("Display enum types"),
243cl::cat(TypeCategory), cl::sub(PrettySubcommand));
244cl::opt<bool> Typedefs("typedefs", cl::desc("Display typedef types"),
245cl::cat(TypeCategory), cl::sub(PrettySubcommand));
246cl::opt<bool> Funcsigs("funcsigs", cl::desc("Display function signatures"),
247cl::cat(TypeCategory), cl::sub(PrettySubcommand));
248cl::opt<bool> Pointers("pointers", cl::desc("Display pointer types"),
249cl::cat(TypeCategory), cl::sub(PrettySubcommand));
250cl::opt<bool> Arrays("arrays", cl::desc("Display arrays"),
251cl::cat(TypeCategory), cl::sub(PrettySubcommand));
252cl::opt<bool> VTShapes("vtshapes", cl::desc("Display vftable shapes"),
253cl::cat(TypeCategory), cl::sub(PrettySubcommand));
254
255cl::opt<SymbolSortMode> SymbolOrder(
256"symbol-order", cl::desc("symbol sort order"),
257cl::init(SymbolSortMode::None),
258cl::values(clEnumValN(SymbolSortMode::None, "none",
259"Undefined / no particular sort order"),
260clEnumValN(SymbolSortMode::Name, "name", "Sort symbols by name"),
261clEnumValN(SymbolSortMode::Size, "size",
262"Sort symbols by size")),
263cl::cat(TypeCategory), cl::sub(PrettySubcommand));
264
265cl::opt<ClassSortMode> ClassOrder(
266"class-order", cl::desc("Class sort order"), cl::init(ClassSortMode::None),
267cl::values(
268clEnumValN(ClassSortMode::None, "none",
269"Undefined / no particular sort order"),
270clEnumValN(ClassSortMode::Name, "name", "Sort classes by name"),
271clEnumValN(ClassSortMode::Size, "size", "Sort classes by size"),
272clEnumValN(ClassSortMode::Padding, "padding",
273"Sort classes by amount of padding"),
274clEnumValN(ClassSortMode::PaddingPct, "padding-pct",
275"Sort classes by percentage of space consumed by padding"),
276clEnumValN(ClassSortMode::PaddingImmediate, "padding-imm",
277"Sort classes by amount of immediate padding"),
278clEnumValN(ClassSortMode::PaddingPctImmediate, "padding-pct-imm",
279"Sort classes by percentage of space consumed by immediate "
280"padding")),
281cl::cat(TypeCategory), cl::sub(PrettySubcommand));
282
283cl::opt<ClassDefinitionFormat> ClassFormat(
284"class-definitions", cl::desc("Class definition format"),
285cl::init(ClassDefinitionFormat::All),
286cl::values(
287clEnumValN(ClassDefinitionFormat::All, "all",
288"Display all class members including data, constants, "
289"typedefs, functions, etc"),
290clEnumValN(ClassDefinitionFormat::Layout, "layout",
291"Only display members that contribute to class size."),
292clEnumValN(ClassDefinitionFormat::None, "none",
293"Don't display class definitions")),
294cl::cat(TypeCategory), cl::sub(PrettySubcommand));
295cl::opt<uint32_t> ClassRecursionDepth(
296"class-recurse-depth", cl::desc("Class recursion depth (0=no limit)"),
297cl::init(0), cl::cat(TypeCategory), cl::sub(PrettySubcommand));
298
299cl::opt<bool> Lines("lines", cl::desc("Line tables"), cl::cat(TypeCategory),
300cl::sub(PrettySubcommand));
301cl::opt<bool>
302All("all", cl::desc("Implies all other options in 'Symbol Types' category"),
303cl::cat(TypeCategory), cl::sub(PrettySubcommand));
304
305cl::opt<uint64_t> LoadAddress(
306"load-address",
307cl::desc("Assume the module is loaded at the specified address"),
308cl::cat(OtherOptions), cl::sub(PrettySubcommand));
309cl::opt<bool> Native("native", cl::desc("Use native PDB reader instead of DIA"),
310cl::cat(OtherOptions), cl::sub(PrettySubcommand));
311cl::opt<cl::boolOrDefault>
312ColorOutput("color-output",
313cl::desc("Override use of color (default = isatty)"),
314cl::cat(OtherOptions), cl::sub(PrettySubcommand));
315cl::list<std::string>
316ExcludeTypes("exclude-types",
317cl::desc("Exclude types by regular expression"),
318cl::cat(FilterCategory), cl::sub(PrettySubcommand));
319cl::list<std::string>
320ExcludeSymbols("exclude-symbols",
321cl::desc("Exclude symbols by regular expression"),
322cl::cat(FilterCategory), cl::sub(PrettySubcommand));
323cl::list<std::string>
324ExcludeCompilands("exclude-compilands",
325cl::desc("Exclude compilands by regular expression"),
326cl::cat(FilterCategory), cl::sub(PrettySubcommand));
327
328cl::list<std::string> IncludeTypes(
329"include-types",
330cl::desc("Include only types which match a regular expression"),
331cl::cat(FilterCategory), cl::sub(PrettySubcommand));
332cl::list<std::string> IncludeSymbols(
333"include-symbols",
334cl::desc("Include only symbols which match a regular expression"),
335cl::cat(FilterCategory), cl::sub(PrettySubcommand));
336cl::list<std::string> IncludeCompilands(
337"include-compilands",
338cl::desc("Include only compilands those which match a regular expression"),
339cl::cat(FilterCategory), cl::sub(PrettySubcommand));
340cl::opt<uint32_t> SizeThreshold(
341"min-type-size", cl::desc("Displays only those types which are greater "
342"than or equal to the specified size."),
343cl::init(0), cl::cat(FilterCategory), cl::sub(PrettySubcommand));
344cl::opt<uint32_t> PaddingThreshold(
345"min-class-padding", cl::desc("Displays only those classes which have at "
346"least the specified amount of padding."),
347cl::init(0), cl::cat(FilterCategory), cl::sub(PrettySubcommand));
348cl::opt<uint32_t> ImmediatePaddingThreshold(
349"min-class-padding-imm",
350cl::desc("Displays only those classes which have at least the specified "
351"amount of immediate padding, ignoring padding internal to bases "
352"and aggregates."),
353cl::init(0), cl::cat(FilterCategory), cl::sub(PrettySubcommand));
354
355cl::opt<bool> ExcludeCompilerGenerated(
356"no-compiler-generated",
357cl::desc("Don't show compiler generated types and symbols"),
358cl::cat(FilterCategory), cl::sub(PrettySubcommand));
359cl::opt<bool>
360ExcludeSystemLibraries("no-system-libs",
361cl::desc("Don't show symbols from system libraries"),
362cl::cat(FilterCategory), cl::sub(PrettySubcommand));
363
364cl::opt<bool> NoEnumDefs("no-enum-definitions",
365cl::desc("Don't display full enum definitions"),
366cl::cat(FilterCategory), cl::sub(PrettySubcommand));
367}
368
369cl::OptionCategory FileOptions("Module & File Options");
370
371namespace bytes {
372cl::OptionCategory MsfBytes("MSF File Options");
373cl::OptionCategory DbiBytes("Dbi Stream Options");
374cl::OptionCategory PdbBytes("PDB Stream Options");
375cl::OptionCategory Types("Type Options");
376cl::OptionCategory ModuleCategory("Module Options");
377
378std::optional<NumberRange> DumpBlockRange;
379std::optional<NumberRange> DumpByteRange;
380
381cl::opt<std::string> DumpBlockRangeOpt(
382"block-range", cl::value_desc("start[-end]"),
383cl::desc("Dump binary data from specified range of blocks."),
384cl::sub(BytesSubcommand), cl::cat(MsfBytes));
385
386cl::opt<std::string>
387DumpByteRangeOpt("byte-range", cl::value_desc("start[-end]"),
388cl::desc("Dump binary data from specified range of bytes"),
389cl::sub(BytesSubcommand), cl::cat(MsfBytes));
390
391cl::list<std::string>
392DumpStreamData("stream-data", cl::CommaSeparated,
393cl::desc("Dump binary data from specified streams. Format "
394"is SN[:Start][@Size]"),
395cl::sub(BytesSubcommand), cl::cat(MsfBytes));
396
397cl::opt<bool> NameMap("name-map", cl::desc("Dump bytes of PDB Name Map"),
398cl::sub(BytesSubcommand), cl::cat(PdbBytes));
399cl::opt<bool> Fpm("fpm", cl::desc("Dump free page map"),
400cl::sub(BytesSubcommand), cl::cat(MsfBytes));
401
402cl::opt<bool> SectionContributions("sc", cl::desc("Dump section contributions"),
403cl::sub(BytesSubcommand), cl::cat(DbiBytes));
404cl::opt<bool> SectionMap("sm", cl::desc("Dump section map"),
405cl::sub(BytesSubcommand), cl::cat(DbiBytes));
406cl::opt<bool> ModuleInfos("modi", cl::desc("Dump module info"),
407cl::sub(BytesSubcommand), cl::cat(DbiBytes));
408cl::opt<bool> FileInfo("files", cl::desc("Dump source file info"),
409cl::sub(BytesSubcommand), cl::cat(DbiBytes));
410cl::opt<bool> TypeServerMap("type-server", cl::desc("Dump type server map"),
411cl::sub(BytesSubcommand), cl::cat(DbiBytes));
412cl::opt<bool> ECData("ec", cl::desc("Dump edit and continue map"),
413cl::sub(BytesSubcommand), cl::cat(DbiBytes));
414
415cl::list<uint32_t> TypeIndex(
416"type", cl::desc("Dump the type record with the given type index"),
417cl::CommaSeparated, cl::sub(BytesSubcommand), cl::cat(TypeCategory));
418cl::list<uint32_t>
419IdIndex("id", cl::desc("Dump the id record with the given type index"),
420cl::CommaSeparated, cl::sub(BytesSubcommand),
421cl::cat(TypeCategory));
422
423cl::opt<uint32_t> ModuleIndex(
424"mod",
425cl::desc(
426"Limit options in the Modules category to the specified module index"),
427cl::Optional, cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
428cl::opt<bool> ModuleSyms("syms", cl::desc("Dump symbol record substream"),
429cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
430cl::opt<bool> ModuleC11("c11-chunks", cl::Hidden,
431cl::desc("Dump C11 CodeView debug chunks"),
432cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
433cl::opt<bool> ModuleC13("chunks",
434cl::desc("Dump C13 CodeView debug chunk subsection"),
435cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
436cl::opt<bool> SplitChunks(
437"split-chunks",
438cl::desc(
439"When dumping debug chunks, show a different section for each chunk"),
440cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
441cl::list<std::string> InputFilenames(cl::Positional,
442cl::desc("<input PDB files>"),
443cl::OneOrMore, cl::sub(BytesSubcommand));
444
445} // namespace bytes
446
447namespace dump {
448
449cl::OptionCategory MsfOptions("MSF Container Options");
450cl::OptionCategory TypeOptions("Type Record Options");
451cl::OptionCategory SymbolOptions("Symbol Options");
452cl::OptionCategory MiscOptions("Miscellaneous Options");
453
454// MSF OPTIONS
455cl::opt<bool> DumpSummary("summary", cl::desc("dump file summary"),
456cl::cat(MsfOptions), cl::sub(DumpSubcommand));
457cl::opt<bool> DumpStreams("streams",
458cl::desc("dump summary of the PDB streams"),
459cl::cat(MsfOptions), cl::sub(DumpSubcommand));
460cl::opt<bool> DumpStreamBlocks(
461"stream-blocks",
462cl::desc("Add block information to the output of -streams"),
463cl::cat(MsfOptions), cl::sub(DumpSubcommand));
464cl::opt<bool> DumpSymbolStats(
465"sym-stats",
466cl::desc("Dump a detailed breakdown of symbol usage/size for each module"),
467cl::cat(MsfOptions), cl::sub(DumpSubcommand));
468cl::opt<bool> DumpTypeStats(
469"type-stats",
470cl::desc("Dump a detailed breakdown of type usage/size"),
471cl::cat(MsfOptions), cl::sub(DumpSubcommand));
472cl::opt<bool> DumpIDStats(
473"id-stats",
474cl::desc("Dump a detailed breakdown of IPI types usage/size"),
475cl::cat(MsfOptions), cl::sub(DumpSubcommand));
476cl::opt<bool> DumpUdtStats(
477"udt-stats",
478cl::desc("Dump a detailed breakdown of S_UDT record usage / stats"),
479cl::cat(MsfOptions), cl::sub(DumpSubcommand));
480
481// TYPE OPTIONS
482cl::opt<bool> DumpTypes("types",
483cl::desc("dump CodeView type records from TPI stream"),
484cl::cat(TypeOptions), cl::sub(DumpSubcommand));
485cl::opt<bool> DumpTypeData(
486"type-data",
487cl::desc("dump CodeView type record raw bytes from TPI stream"),
488cl::cat(TypeOptions), cl::sub(DumpSubcommand));
489cl::opt<bool>
490DumpTypeRefStats("type-ref-stats",
491cl::desc("dump statistics on the number and size of types "
492"transitively referenced by symbol records"),
493cl::cat(TypeOptions), cl::sub(DumpSubcommand));
494
495cl::opt<bool> DumpTypeExtras("type-extras",
496cl::desc("dump type hashes and index offsets"),
497cl::cat(TypeOptions), cl::sub(DumpSubcommand));
498
499cl::opt<bool> DontResolveForwardRefs(
500"dont-resolve-forward-refs",
501cl::desc("When dumping type records for classes, unions, enums, and "
502"structs, don't try to resolve forward references"),
503cl::cat(TypeOptions), cl::sub(DumpSubcommand));
504
505cl::list<uint32_t> DumpTypeIndex(
506"type-index", cl::CommaSeparated,
507cl::desc("only dump types with the specified hexadecimal type index"),
508cl::cat(TypeOptions), cl::sub(DumpSubcommand));
509
510cl::opt<bool> DumpIds("ids",
511cl::desc("dump CodeView type records from IPI stream"),
512cl::cat(TypeOptions), cl::sub(DumpSubcommand));
513cl::opt<bool>
514DumpIdData("id-data",
515cl::desc("dump CodeView type record raw bytes from IPI stream"),
516cl::cat(TypeOptions), cl::sub(DumpSubcommand));
517
518cl::opt<bool> DumpIdExtras("id-extras",
519cl::desc("dump id hashes and index offsets"),
520cl::cat(TypeOptions), cl::sub(DumpSubcommand));
521cl::list<uint32_t> DumpIdIndex(
522"id-index", cl::CommaSeparated,
523cl::desc("only dump ids with the specified hexadecimal type index"),
524cl::cat(TypeOptions), cl::sub(DumpSubcommand));
525
526cl::opt<bool> DumpTypeDependents(
527"dependents",
528cl::desc("In conjunection with -type-index and -id-index, dumps the entire "
529"dependency graph for the specified index instead of "
530"just the single record with the specified index"),
531cl::cat(TypeOptions), cl::sub(DumpSubcommand));
532
533// SYMBOL OPTIONS
534cl::opt<bool> DumpGlobals("globals", cl::desc("dump Globals symbol records"),
535cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
536cl::opt<bool> DumpGlobalExtras("global-extras", cl::desc("dump Globals hashes"),
537cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
538cl::list<std::string> DumpGlobalNames(
539"global-name",
540cl::desc(
541"With -globals, only dump globals whose name matches the given value"),
542cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
543cl::opt<bool> DumpPublics("publics", cl::desc("dump Publics stream data"),
544cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
545cl::opt<bool> DumpPublicExtras("public-extras",
546cl::desc("dump Publics hashes and address maps"),
547cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
548cl::opt<bool>
549DumpGSIRecords("gsi-records",
550cl::desc("dump public / global common record stream"),
551cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
552cl::opt<bool> DumpSymbols("symbols", cl::desc("dump module symbols"),
553cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
554
555cl::opt<bool>
556DumpSymRecordBytes("sym-data",
557cl::desc("dump CodeView symbol record raw bytes"),
558cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
559
560cl::opt<bool> DumpFpo("fpo", cl::desc("dump FPO records"),
561cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
562
563cl::opt<uint32_t> DumpSymbolOffset(
564"symbol-offset", cl::Optional,
565cl::desc("only dump symbol record with the specified symbol offset"),
566cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
567cl::opt<bool> DumpParents("show-parents",
568cl::desc("dump the symbols record's all parents."),
569cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
570cl::opt<uint32_t>
571DumpParentDepth("parent-recurse-depth", cl::Optional, cl::init(-1U),
572cl::desc("only recurse to a depth of N when displaying "
573"parents of a symbol record."),
574cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
575cl::opt<bool> DumpChildren("show-children",
576cl::desc("dump the symbols record's all children."),
577cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
578cl::opt<uint32_t>
579DumpChildrenDepth("children-recurse-depth", cl::Optional, cl::init(-1U),
580cl::desc("only recurse to a depth of N when displaying "
581"children of a symbol record."),
582cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
583
584// MODULE & FILE OPTIONS
585cl::opt<bool> DumpModules("modules", cl::desc("dump compiland information"),
586cl::cat(FileOptions), cl::sub(DumpSubcommand));
587cl::opt<bool> DumpModuleFiles(
588"files",
589cl::desc("Dump the source files that contribute to each module's."),
590cl::cat(FileOptions), cl::sub(DumpSubcommand));
591cl::opt<bool> DumpLines(
592"l",
593cl::desc("dump source file/line information (DEBUG_S_LINES subsection)"),
594cl::cat(FileOptions), cl::sub(DumpSubcommand));
595cl::opt<bool> DumpInlineeLines(
596"il",
597cl::desc("dump inlinee line information (DEBUG_S_INLINEELINES subsection)"),
598cl::cat(FileOptions), cl::sub(DumpSubcommand));
599cl::opt<bool> DumpXmi(
600"xmi",
601cl::desc(
602"dump cross module imports (DEBUG_S_CROSSSCOPEIMPORTS subsection)"),
603cl::cat(FileOptions), cl::sub(DumpSubcommand));
604cl::opt<bool> DumpXme(
605"xme",
606cl::desc(
607"dump cross module exports (DEBUG_S_CROSSSCOPEEXPORTS subsection)"),
608cl::cat(FileOptions), cl::sub(DumpSubcommand));
609cl::opt<uint32_t> DumpModi("modi", cl::Optional,
610cl::desc("For all options that iterate over "
611"modules, limit to the specified module"),
612cl::cat(FileOptions), cl::sub(DumpSubcommand));
613cl::opt<bool> JustMyCode("jmc", cl::Optional,
614cl::desc("For all options that iterate over modules, "
615"ignore modules from system libraries"),
616cl::cat(FileOptions), cl::sub(DumpSubcommand));
617
618// MISCELLANEOUS OPTIONS
619cl::opt<bool> DumpNamedStreams("named-streams",
620cl::desc("dump PDB named stream table"),
621cl::cat(MiscOptions), cl::sub(DumpSubcommand));
622
623cl::opt<bool> DumpStringTable("string-table", cl::desc("dump PDB String Table"),
624cl::cat(MiscOptions), cl::sub(DumpSubcommand));
625cl::opt<bool> DumpStringTableDetails("string-table-details",
626cl::desc("dump PDB String Table Details"),
627cl::cat(MiscOptions),
628cl::sub(DumpSubcommand));
629
630cl::opt<bool> DumpSectionContribs("section-contribs",
631cl::desc("dump section contributions"),
632cl::cat(MiscOptions),
633cl::sub(DumpSubcommand));
634cl::opt<bool> DumpSectionMap("section-map", cl::desc("dump section map"),
635cl::cat(MiscOptions), cl::sub(DumpSubcommand));
636cl::opt<bool> DumpSectionHeaders("section-headers",
637cl::desc("Dump image section headers"),
638cl::cat(MiscOptions), cl::sub(DumpSubcommand));
639
640cl::opt<bool> RawAll("all", cl::desc("Implies most other options."),
641cl::cat(MiscOptions), cl::sub(DumpSubcommand));
642
643cl::list<std::string> InputFilenames(cl::Positional,
644cl::desc("<input PDB files>"),
645cl::OneOrMore, cl::sub(DumpSubcommand));
646}
647
648namespace yaml2pdb {
649cl::opt<std::string>
650YamlPdbOutputFile("pdb", cl::desc("the name of the PDB file to write"),
651cl::sub(YamlToPdbSubcommand));
652
653cl::opt<std::string> InputFilename(cl::Positional,
654cl::desc("<input YAML file>"), cl::Required,
655cl::sub(YamlToPdbSubcommand));
656}
657
658namespace pdb2yaml {
659cl::opt<bool> All("all",
660cl::desc("Dump everything we know how to dump."),
661cl::sub(PdbToYamlSubcommand), cl::init(false));
662cl::opt<bool> NoFileHeaders("no-file-headers",
663cl::desc("Do not dump MSF file headers"),
664cl::sub(PdbToYamlSubcommand), cl::init(false));
665cl::opt<bool> Minimal("minimal",
666cl::desc("Don't write fields with default values"),
667cl::sub(PdbToYamlSubcommand), cl::init(false));
668
669cl::opt<bool> StreamMetadata(
670"stream-metadata",
671cl::desc("Dump the number of streams and each stream's size"),
672cl::sub(PdbToYamlSubcommand), cl::init(false));
673cl::opt<bool> StreamDirectory(
674"stream-directory",
675cl::desc("Dump each stream's block map (implies -stream-metadata)"),
676cl::sub(PdbToYamlSubcommand), cl::init(false));
677cl::opt<bool> PdbStream("pdb-stream",
678cl::desc("Dump the PDB Stream (Stream 1)"),
679cl::sub(PdbToYamlSubcommand), cl::init(false));
680
681cl::opt<bool> StringTable("string-table", cl::desc("Dump the PDB String Table"),
682cl::sub(PdbToYamlSubcommand), cl::init(false));
683
684cl::opt<bool> DbiStream("dbi-stream",
685cl::desc("Dump the DBI Stream Headers (Stream 2)"),
686cl::sub(PdbToYamlSubcommand), cl::init(false));
687
688cl::opt<bool> TpiStream("tpi-stream",
689cl::desc("Dump the TPI Stream (Stream 3)"),
690cl::sub(PdbToYamlSubcommand), cl::init(false));
691
692cl::opt<bool> IpiStream("ipi-stream",
693cl::desc("Dump the IPI Stream (Stream 5)"),
694cl::sub(PdbToYamlSubcommand), cl::init(false));
695
696cl::opt<bool> PublicsStream("publics-stream",
697cl::desc("Dump the Publics Stream"),
698cl::sub(PdbToYamlSubcommand), cl::init(false));
699
700// MODULE & FILE OPTIONS
701cl::opt<bool> DumpModules("modules", cl::desc("dump compiland information"),
702cl::cat(FileOptions), cl::sub(PdbToYamlSubcommand));
703cl::opt<bool> DumpModuleFiles("module-files", cl::desc("dump file information"),
704cl::cat(FileOptions),
705cl::sub(PdbToYamlSubcommand));
706cl::list<ModuleSubsection> DumpModuleSubsections(
707"subsections", cl::CommaSeparated,
708cl::desc("dump subsections from each module's debug stream"), ChunkValues,
709cl::cat(FileOptions), cl::sub(PdbToYamlSubcommand));
710cl::opt<bool> DumpModuleSyms("module-syms", cl::desc("dump module symbols"),
711cl::cat(FileOptions),
712cl::sub(PdbToYamlSubcommand));
713
714cl::list<std::string> InputFilename(cl::Positional,
715cl::desc("<input PDB file>"), cl::Required,
716cl::sub(PdbToYamlSubcommand));
717} // namespace pdb2yaml
718
719namespace merge {
720cl::list<std::string> InputFilenames(cl::Positional,
721cl::desc("<input PDB files>"),
722cl::OneOrMore, cl::sub(MergeSubcommand));
723cl::opt<std::string>
724PdbOutputFile("pdb", cl::desc("the name of the PDB file to write"),
725cl::sub(MergeSubcommand));
726}
727
728namespace explain {
729cl::list<std::string> InputFilename(cl::Positional,
730cl::desc("<input PDB file>"), cl::Required,
731cl::sub(ExplainSubcommand));
732
733cl::list<uint64_t> Offsets("offset", cl::desc("The file offset to explain"),
734cl::sub(ExplainSubcommand), cl::OneOrMore);
735
736cl::opt<InputFileType> InputType(
737"input-type", cl::desc("Specify how to interpret the input file"),
738cl::init(InputFileType::PDBFile), cl::Optional, cl::sub(ExplainSubcommand),
739cl::values(clEnumValN(InputFileType::PDBFile, "pdb-file",
740"Treat input as a PDB file (default)"),
741clEnumValN(InputFileType::PDBStream, "pdb-stream",
742"Treat input as raw contents of PDB stream"),
743clEnumValN(InputFileType::DBIStream, "dbi-stream",
744"Treat input as raw contents of DBI stream"),
745clEnumValN(InputFileType::Names, "names-stream",
746"Treat input as raw contents of /names named stream"),
747clEnumValN(InputFileType::ModuleStream, "mod-stream",
748"Treat input as raw contents of a module stream")));
749} // namespace explain
750
751namespace exportstream {
752cl::list<std::string> InputFilename(cl::Positional,
753cl::desc("<input PDB file>"), cl::Required,
754cl::sub(ExportSubcommand));
755cl::opt<std::string> OutputFile("out",
756cl::desc("The file to write the stream to"),
757cl::Required, cl::sub(ExportSubcommand));
758cl::opt<std::string>
759Stream("stream", cl::Required,
760cl::desc("The index or name of the stream whose contents to export"),
761cl::sub(ExportSubcommand));
762cl::opt<bool> ForceName("name",
763cl::desc("Force the interpretation of -stream as a "
764"string, even if it is a valid integer"),
765cl::sub(ExportSubcommand), cl::Optional,
766cl::init(false));
767} // namespace exportstream
768}
769
770static ExitOnError ExitOnErr;
771
772static void yamlToPdb(StringRef Path) {
773BumpPtrAllocator Allocator;
774ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
775MemoryBuffer::getFileOrSTDIN(Path, /*IsText=*/false,
776/*RequiresNullTerminator=*/false);
777
778if (ErrorOrBuffer.getError()) {
779ExitOnErr(createFileError(Path, errorCodeToError(ErrorOrBuffer.getError())));
780}
781
782std::unique_ptr<MemoryBuffer> &Buffer = ErrorOrBuffer.get();
783
784llvm::yaml::Input In(Buffer->getBuffer());
785pdb::yaml::PdbObject YamlObj(Allocator);
786In >> YamlObj;
787
788PDBFileBuilder Builder(Allocator);
789
790uint32_t BlockSize = 4096;
791if (YamlObj.Headers)
792BlockSize = YamlObj.Headers->SuperBlock.BlockSize;
793ExitOnErr(Builder.initialize(BlockSize));
794// Add each of the reserved streams. We ignore stream metadata in the
795// yaml, because we will reconstruct our own view of the streams. For
796// example, the YAML may say that there were 20 streams in the original
797// PDB, but maybe we only dump a subset of those 20 streams, so we will
798// have fewer, and the ones we do have may end up with different indices
799// than the ones in the original PDB. So we just start with a clean slate.
800for (uint32_t I = 0; I < kSpecialStreamCount; ++I)
801ExitOnErr(Builder.getMsfBuilder().addStream(0));
802
803StringsAndChecksums Strings;
804Strings.setStrings(std::make_shared<DebugStringTableSubsection>());
805
806if (YamlObj.StringTable) {
807for (auto S : *YamlObj.StringTable)
808Strings.strings()->insert(S);
809}
810
811pdb::yaml::PdbInfoStream DefaultInfoStream;
812pdb::yaml::PdbDbiStream DefaultDbiStream;
813pdb::yaml::PdbTpiStream DefaultTpiStream;
814pdb::yaml::PdbTpiStream DefaultIpiStream;
815
816const auto &Info = YamlObj.PdbStream.value_or(DefaultInfoStream);
817
818auto &InfoBuilder = Builder.getInfoBuilder();
819InfoBuilder.setAge(Info.Age);
820InfoBuilder.setGuid(Info.Guid);
821InfoBuilder.setSignature(Info.Signature);
822InfoBuilder.setVersion(Info.Version);
823for (auto F : Info.Features)
824InfoBuilder.addFeature(F);
825
826const auto &Dbi = YamlObj.DbiStream.value_or(DefaultDbiStream);
827auto &DbiBuilder = Builder.getDbiBuilder();
828DbiBuilder.setAge(Dbi.Age);
829DbiBuilder.setBuildNumber(Dbi.BuildNumber);
830DbiBuilder.setFlags(Dbi.Flags);
831DbiBuilder.setMachineType(Dbi.MachineType);
832DbiBuilder.setPdbDllRbld(Dbi.PdbDllRbld);
833DbiBuilder.setPdbDllVersion(Dbi.PdbDllVersion);
834DbiBuilder.setVersionHeader(Dbi.VerHeader);
835for (const auto &MI : Dbi.ModInfos) {
836auto &ModiBuilder = ExitOnErr(DbiBuilder.addModuleInfo(MI.Mod));
837ModiBuilder.setObjFileName(MI.Obj);
838
839for (auto S : MI.SourceFiles)
840ExitOnErr(DbiBuilder.addModuleSourceFile(ModiBuilder, S));
841if (MI.Modi) {
842const auto &ModiStream = *MI.Modi;
843for (const auto &Symbol : ModiStream.Symbols) {
844ModiBuilder.addSymbol(
845Symbol.toCodeViewSymbol(Allocator, CodeViewContainer::Pdb));
846}
847}
848
849// Each module has its own checksum subsection, so scan for it every time.
850Strings.setChecksums(nullptr);
851CodeViewYAML::initializeStringsAndChecksums(MI.Subsections, Strings);
852
853auto CodeViewSubsections = ExitOnErr(CodeViewYAML::toCodeViewSubsectionList(
854Allocator, MI.Subsections, Strings));
855for (auto &SS : CodeViewSubsections) {
856ModiBuilder.addDebugSubsection(SS);
857}
858}
859
860auto &TpiBuilder = Builder.getTpiBuilder();
861const auto &Tpi = YamlObj.TpiStream.value_or(DefaultTpiStream);
862TpiBuilder.setVersionHeader(Tpi.Version);
863AppendingTypeTableBuilder TS(Allocator);
864for (const auto &R : Tpi.Records) {
865CVType Type = R.toCodeViewRecord(TS);
866TpiBuilder.addTypeRecord(Type.RecordData, std::nullopt);
867}
868
869const auto &Ipi = YamlObj.IpiStream.value_or(DefaultIpiStream);
870auto &IpiBuilder = Builder.getIpiBuilder();
871IpiBuilder.setVersionHeader(Ipi.Version);
872for (const auto &R : Ipi.Records) {
873CVType Type = R.toCodeViewRecord(TS);
874IpiBuilder.addTypeRecord(Type.RecordData, std::nullopt);
875}
876
877Builder.getStringTableBuilder().setStrings(*Strings.strings());
878
879codeview::GUID IgnoredOutGuid;
880ExitOnErr(Builder.commit(opts::yaml2pdb::YamlPdbOutputFile, &IgnoredOutGuid));
881}
882
883static PDBFile &loadPDB(StringRef Path, std::unique_ptr<IPDBSession> &Session) {
884ExitOnErr(loadDataForPDB(PDB_ReaderType::Native, Path, Session));
885
886NativeSession *NS = static_cast<NativeSession *>(Session.get());
887return NS->getPDBFile();
888}
889
890static void pdb2Yaml(StringRef Path) {
891std::unique_ptr<IPDBSession> Session;
892auto &File = loadPDB(Path, Session);
893
894auto O = std::make_unique<YAMLOutputStyle>(File);
895
896ExitOnErr(O->dump());
897}
898
899static void dumpRaw(StringRef Path) {
900InputFile IF = ExitOnErr(InputFile::open(Path));
901
902auto O = std::make_unique<DumpOutputStyle>(IF);
903ExitOnErr(O->dump());
904}
905
906static void dumpBytes(StringRef Path) {
907std::unique_ptr<IPDBSession> Session;
908auto &File = loadPDB(Path, Session);
909
910auto O = std::make_unique<BytesOutputStyle>(File);
911
912ExitOnErr(O->dump());
913}
914
915bool opts::pretty::shouldDumpSymLevel(SymLevel Search) {
916if (SymTypes.empty())
917return true;
918if (llvm::is_contained(SymTypes, Search))
919return true;
920if (llvm::is_contained(SymTypes, SymLevel::All))
921return true;
922return false;
923}
924
925uint32_t llvm::pdb::getTypeLength(const PDBSymbolData &Symbol) {
926auto SymbolType = Symbol.getType();
927const IPDBRawSymbol &RawType = SymbolType->getRawSymbol();
928
929return RawType.getLength();
930}
931
932bool opts::pretty::compareFunctionSymbols(
933const std::unique_ptr<PDBSymbolFunc> &F1,
934const std::unique_ptr<PDBSymbolFunc> &F2) {
935assert(opts::pretty::SymbolOrder != opts::pretty::SymbolSortMode::None);
936
937if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::Name)
938return F1->getName() < F2->getName();
939
940// Note that we intentionally sort in descending order on length, since
941// long functions are more interesting than short functions.
942return F1->getLength() > F2->getLength();
943}
944
945bool opts::pretty::compareDataSymbols(
946const std::unique_ptr<PDBSymbolData> &F1,
947const std::unique_ptr<PDBSymbolData> &F2) {
948assert(opts::pretty::SymbolOrder != opts::pretty::SymbolSortMode::None);
949
950if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::Name)
951return F1->getName() < F2->getName();
952
953// Note that we intentionally sort in descending order on length, since
954// large types are more interesting than short ones.
955return getTypeLength(*F1) > getTypeLength(*F2);
956}
957
958static std::string stringOr(std::string Str, std::string IfEmpty) {
959return (Str.empty()) ? IfEmpty : Str;
960}
961
962static void dumpInjectedSources(LinePrinter &Printer, IPDBSession &Session) {
963auto Sources = Session.getInjectedSources();
964if (!Sources || !Sources->getChildCount()) {
965Printer.printLine("There are no injected sources.");
966return;
967}
968
969while (auto IS = Sources->getNext()) {
970Printer.NewLine();
971std::string File = stringOr(IS->getFileName(), "<null>");
972uint64_t Size = IS->getCodeByteSize();
973std::string Obj = stringOr(IS->getObjectFileName(), "<null>");
974std::string VFName = stringOr(IS->getVirtualFileName(), "<null>");
975uint32_t CRC = IS->getCrc32();
976
977WithColor(Printer, PDB_ColorItem::Path).get() << File;
978Printer << " (";
979WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Size;
980Printer << " bytes): ";
981WithColor(Printer, PDB_ColorItem::Keyword).get() << "obj";
982Printer << "=";
983WithColor(Printer, PDB_ColorItem::Path).get() << Obj;
984Printer << ", ";
985WithColor(Printer, PDB_ColorItem::Keyword).get() << "vname";
986Printer << "=";
987WithColor(Printer, PDB_ColorItem::Path).get() << VFName;
988Printer << ", ";
989WithColor(Printer, PDB_ColorItem::Keyword).get() << "crc";
990Printer << "=";
991WithColor(Printer, PDB_ColorItem::LiteralValue).get() << CRC;
992Printer << ", ";
993WithColor(Printer, PDB_ColorItem::Keyword).get() << "compression";
994Printer << "=";
995dumpPDBSourceCompression(
996WithColor(Printer, PDB_ColorItem::LiteralValue).get(),
997IS->getCompression());
998
999if (!opts::pretty::ShowInjectedSourceContent)
1000continue;
1001
1002// Set the indent level to 0 when printing file content.
1003int Indent = Printer.getIndentLevel();
1004Printer.Unindent(Indent);
1005
1006if (IS->getCompression() == PDB_SourceCompression::None)
1007Printer.printLine(IS->getCode());
1008else
1009Printer.formatBinary("Compressed data",
1010arrayRefFromStringRef(IS->getCode()),
1011/*StartOffset=*/0);
1012
1013// Re-indent back to the original level.
1014Printer.Indent(Indent);
1015}
1016}
1017
1018template <typename OuterT, typename ChildT>
1019void diaDumpChildren(PDBSymbol &Outer, PdbSymbolIdField Ids,
1020PdbSymbolIdField Recurse) {
1021OuterT *ConcreteOuter = dyn_cast<OuterT>(&Outer);
1022if (!ConcreteOuter)
1023return;
1024
1025auto Children = ConcreteOuter->template findAllChildren<ChildT>();
1026while (auto Child = Children->getNext()) {
1027outs() << " {";
1028Child->defaultDump(outs(), 4, Ids, Recurse);
1029outs() << "\n }\n";
1030}
1031}
1032
1033static void dumpDia(StringRef Path) {
1034std::unique_ptr<IPDBSession> Session;
1035
1036const auto ReaderType =
1037opts::diadump::Native ? PDB_ReaderType::Native : PDB_ReaderType::DIA;
1038ExitOnErr(loadDataForPDB(ReaderType, Path, Session));
1039
1040auto GlobalScope = Session->getGlobalScope();
1041
1042std::vector<PDB_SymType> SymTypes;
1043
1044if (opts::diadump::Compilands)
1045SymTypes.push_back(PDB_SymType::Compiland);
1046if (opts::diadump::Enums)
1047SymTypes.push_back(PDB_SymType::Enum);
1048if (opts::diadump::Pointers)
1049SymTypes.push_back(PDB_SymType::PointerType);
1050if (opts::diadump::UDTs)
1051SymTypes.push_back(PDB_SymType::UDT);
1052if (opts::diadump::Funcsigs)
1053SymTypes.push_back(PDB_SymType::FunctionSig);
1054if (opts::diadump::Arrays)
1055SymTypes.push_back(PDB_SymType::ArrayType);
1056if (opts::diadump::VTShapes)
1057SymTypes.push_back(PDB_SymType::VTableShape);
1058if (opts::diadump::Typedefs)
1059SymTypes.push_back(PDB_SymType::Typedef);
1060PdbSymbolIdField Ids = opts::diadump::NoSymIndexIds ? PdbSymbolIdField::None
1061: PdbSymbolIdField::All;
1062
1063PdbSymbolIdField Recurse = PdbSymbolIdField::None;
1064if (opts::diadump::Recurse)
1065Recurse = PdbSymbolIdField::All;
1066if (!opts::diadump::ShowClassHierarchy)
1067Ids &= ~(PdbSymbolIdField::ClassParent | PdbSymbolIdField::LexicalParent);
1068
1069for (PDB_SymType ST : SymTypes) {
1070auto Children = GlobalScope->findAllChildren(ST);
1071while (auto Child = Children->getNext()) {
1072outs() << "{";
1073Child->defaultDump(outs(), 2, Ids, Recurse);
1074
1075diaDumpChildren<PDBSymbolTypeEnum, PDBSymbolData>(*Child, Ids, Recurse);
1076outs() << "\n}\n";
1077}
1078}
1079}
1080
1081static void dumpPretty(StringRef Path) {
1082std::unique_ptr<IPDBSession> Session;
1083
1084const auto ReaderType =
1085opts::pretty::Native ? PDB_ReaderType::Native : PDB_ReaderType::DIA;
1086ExitOnErr(loadDataForPDB(ReaderType, Path, Session));
1087
1088if (opts::pretty::LoadAddress)
1089Session->setLoadAddress(opts::pretty::LoadAddress);
1090
1091auto &Stream = outs();
1092const bool UseColor = opts::pretty::ColorOutput == cl::BOU_UNSET
1093? Stream.has_colors()
1094: opts::pretty::ColorOutput == cl::BOU_TRUE;
1095LinePrinter Printer(2, UseColor, Stream, opts::Filters);
1096
1097auto GlobalScope(Session->getGlobalScope());
1098if (!GlobalScope)
1099return;
1100std::string FileName(GlobalScope->getSymbolsFileName());
1101
1102WithColor(Printer, PDB_ColorItem::None).get() << "Summary for ";
1103WithColor(Printer, PDB_ColorItem::Path).get() << FileName;
1104Printer.Indent();
1105uint64_t FileSize = 0;
1106
1107Printer.NewLine();
1108WithColor(Printer, PDB_ColorItem::Identifier).get() << "Size";
1109if (!sys::fs::file_size(FileName, FileSize)) {
1110Printer << ": " << FileSize << " bytes";
1111} else {
1112Printer << ": (Unable to obtain file size)";
1113}
1114
1115Printer.NewLine();
1116WithColor(Printer, PDB_ColorItem::Identifier).get() << "Guid";
1117Printer << ": " << GlobalScope->getGuid();
1118
1119Printer.NewLine();
1120WithColor(Printer, PDB_ColorItem::Identifier).get() << "Age";
1121Printer << ": " << GlobalScope->getAge();
1122
1123Printer.NewLine();
1124WithColor(Printer, PDB_ColorItem::Identifier).get() << "Attributes";
1125Printer << ": ";
1126if (GlobalScope->hasCTypes())
1127outs() << "HasCTypes ";
1128if (GlobalScope->hasPrivateSymbols())
1129outs() << "HasPrivateSymbols ";
1130Printer.Unindent();
1131
1132if (!opts::pretty::WithName.empty()) {
1133Printer.NewLine();
1134WithColor(Printer, PDB_ColorItem::SectionHeader).get()
1135<< "---SYMBOLS & TYPES BY NAME---";
1136
1137for (StringRef Name : opts::pretty::WithName) {
1138auto Symbols = GlobalScope->findChildren(
1139PDB_SymType::None, Name, PDB_NameSearchFlags::NS_CaseSensitive);
1140if (!Symbols || Symbols->getChildCount() == 0) {
1141Printer.formatLine("[not found] - {0}", Name);
1142continue;
1143}
1144Printer.formatLine("[{0} occurrences] - {1}", Symbols->getChildCount(),
1145Name);
1146
1147AutoIndent Indent(Printer);
1148Printer.NewLine();
1149
1150while (auto Symbol = Symbols->getNext()) {
1151switch (Symbol->getSymTag()) {
1152case PDB_SymType::Typedef: {
1153TypedefDumper TD(Printer);
1154std::unique_ptr<PDBSymbolTypeTypedef> T =
1155llvm::unique_dyn_cast<PDBSymbolTypeTypedef>(std::move(Symbol));
1156TD.start(*T);
1157break;
1158}
1159case PDB_SymType::Enum: {
1160EnumDumper ED(Printer);
1161std::unique_ptr<PDBSymbolTypeEnum> E =
1162llvm::unique_dyn_cast<PDBSymbolTypeEnum>(std::move(Symbol));
1163ED.start(*E);
1164break;
1165}
1166case PDB_SymType::UDT: {
1167ClassDefinitionDumper CD(Printer);
1168std::unique_ptr<PDBSymbolTypeUDT> C =
1169llvm::unique_dyn_cast<PDBSymbolTypeUDT>(std::move(Symbol));
1170CD.start(*C);
1171break;
1172}
1173case PDB_SymType::BaseClass:
1174case PDB_SymType::Friend: {
1175TypeDumper TD(Printer);
1176Symbol->dump(TD);
1177break;
1178}
1179case PDB_SymType::Function: {
1180FunctionDumper FD(Printer);
1181std::unique_ptr<PDBSymbolFunc> F =
1182llvm::unique_dyn_cast<PDBSymbolFunc>(std::move(Symbol));
1183FD.start(*F, FunctionDumper::PointerType::None);
1184break;
1185}
1186case PDB_SymType::Data: {
1187VariableDumper VD(Printer);
1188std::unique_ptr<PDBSymbolData> D =
1189llvm::unique_dyn_cast<PDBSymbolData>(std::move(Symbol));
1190VD.start(*D);
1191break;
1192}
1193case PDB_SymType::PublicSymbol: {
1194ExternalSymbolDumper ED(Printer);
1195std::unique_ptr<PDBSymbolPublicSymbol> PS =
1196llvm::unique_dyn_cast<PDBSymbolPublicSymbol>(std::move(Symbol));
1197ED.dump(*PS);
1198break;
1199}
1200default:
1201llvm_unreachable("Unexpected symbol tag!");
1202}
1203}
1204}
1205llvm::outs().flush();
1206}
1207
1208if (opts::pretty::Compilands) {
1209Printer.NewLine();
1210WithColor(Printer, PDB_ColorItem::SectionHeader).get()
1211<< "---COMPILANDS---";
1212auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
1213
1214if (Compilands) {
1215Printer.Indent();
1216CompilandDumper Dumper(Printer);
1217CompilandDumpFlags options = CompilandDumper::Flags::None;
1218if (opts::pretty::Lines)
1219options = options | CompilandDumper::Flags::Lines;
1220while (auto Compiland = Compilands->getNext())
1221Dumper.start(*Compiland, options);
1222Printer.Unindent();
1223}
1224}
1225
1226if (opts::pretty::Classes || opts::pretty::Enums || opts::pretty::Typedefs ||
1227opts::pretty::Funcsigs || opts::pretty::Pointers ||
1228opts::pretty::Arrays || opts::pretty::VTShapes) {
1229Printer.NewLine();
1230WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---";
1231Printer.Indent();
1232TypeDumper Dumper(Printer);
1233Dumper.start(*GlobalScope);
1234Printer.Unindent();
1235}
1236
1237if (opts::pretty::Symbols) {
1238Printer.NewLine();
1239WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---SYMBOLS---";
1240if (auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>()) {
1241Printer.Indent();
1242CompilandDumper Dumper(Printer);
1243while (auto Compiland = Compilands->getNext())
1244Dumper.start(*Compiland, true);
1245Printer.Unindent();
1246}
1247}
1248
1249if (opts::pretty::Globals) {
1250Printer.NewLine();
1251WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---GLOBALS---";
1252Printer.Indent();
1253if (shouldDumpSymLevel(opts::pretty::SymLevel::Functions)) {
1254if (auto Functions = GlobalScope->findAllChildren<PDBSymbolFunc>()) {
1255FunctionDumper Dumper(Printer);
1256if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
1257while (auto Function = Functions->getNext()) {
1258Printer.NewLine();
1259Dumper.start(*Function, FunctionDumper::PointerType::None);
1260}
1261} else {
1262std::vector<std::unique_ptr<PDBSymbolFunc>> Funcs;
1263while (auto Func = Functions->getNext())
1264Funcs.push_back(std::move(Func));
1265llvm::sort(Funcs, opts::pretty::compareFunctionSymbols);
1266for (const auto &Func : Funcs) {
1267Printer.NewLine();
1268Dumper.start(*Func, FunctionDumper::PointerType::None);
1269}
1270}
1271}
1272}
1273if (shouldDumpSymLevel(opts::pretty::SymLevel::Data)) {
1274if (auto Vars = GlobalScope->findAllChildren<PDBSymbolData>()) {
1275VariableDumper Dumper(Printer);
1276if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
1277while (auto Var = Vars->getNext())
1278Dumper.start(*Var);
1279} else {
1280std::vector<std::unique_ptr<PDBSymbolData>> Datas;
1281while (auto Var = Vars->getNext())
1282Datas.push_back(std::move(Var));
1283llvm::sort(Datas, opts::pretty::compareDataSymbols);
1284for (const auto &Var : Datas)
1285Dumper.start(*Var);
1286}
1287}
1288}
1289if (shouldDumpSymLevel(opts::pretty::SymLevel::Thunks)) {
1290if (auto Thunks = GlobalScope->findAllChildren<PDBSymbolThunk>()) {
1291CompilandDumper Dumper(Printer);
1292while (auto Thunk = Thunks->getNext())
1293Dumper.dump(*Thunk);
1294}
1295}
1296Printer.Unindent();
1297}
1298if (opts::pretty::Externals) {
1299Printer.NewLine();
1300WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---EXTERNALS---";
1301Printer.Indent();
1302ExternalSymbolDumper Dumper(Printer);
1303Dumper.start(*GlobalScope);
1304}
1305if (opts::pretty::Lines) {
1306Printer.NewLine();
1307}
1308if (opts::pretty::InjectedSources) {
1309Printer.NewLine();
1310WithColor(Printer, PDB_ColorItem::SectionHeader).get()
1311<< "---INJECTED SOURCES---";
1312AutoIndent Indent1(Printer);
1313dumpInjectedSources(Printer, *Session);
1314}
1315
1316Printer.NewLine();
1317outs().flush();
1318}
1319
1320static void mergePdbs() {
1321BumpPtrAllocator Allocator;
1322MergingTypeTableBuilder MergedTpi(Allocator);
1323MergingTypeTableBuilder MergedIpi(Allocator);
1324
1325// Create a Tpi and Ipi type table with all types from all input files.
1326for (const auto &Path : opts::merge::InputFilenames) {
1327std::unique_ptr<IPDBSession> Session;
1328auto &File = loadPDB(Path, Session);
1329SmallVector<TypeIndex, 128> TypeMap;
1330SmallVector<TypeIndex, 128> IdMap;
1331if (File.hasPDBTpiStream()) {
1332auto &Tpi = ExitOnErr(File.getPDBTpiStream());
1333ExitOnErr(
1334codeview::mergeTypeRecords(MergedTpi, TypeMap, Tpi.typeArray()));
1335}
1336if (File.hasPDBIpiStream()) {
1337auto &Ipi = ExitOnErr(File.getPDBIpiStream());
1338ExitOnErr(codeview::mergeIdRecords(MergedIpi, TypeMap, IdMap,
1339Ipi.typeArray()));
1340}
1341}
1342
1343// Then write the PDB.
1344PDBFileBuilder Builder(Allocator);
1345ExitOnErr(Builder.initialize(4096));
1346// Add each of the reserved streams. We might not put any data in them,
1347// but at least they have to be present.
1348for (uint32_t I = 0; I < kSpecialStreamCount; ++I)
1349ExitOnErr(Builder.getMsfBuilder().addStream(0));
1350
1351auto &DestTpi = Builder.getTpiBuilder();
1352auto &DestIpi = Builder.getIpiBuilder();
1353MergedTpi.ForEachRecord([&DestTpi](TypeIndex TI, const CVType &Type) {
1354DestTpi.addTypeRecord(Type.RecordData, std::nullopt);
1355});
1356MergedIpi.ForEachRecord([&DestIpi](TypeIndex TI, const CVType &Type) {
1357DestIpi.addTypeRecord(Type.RecordData, std::nullopt);
1358});
1359Builder.getInfoBuilder().addFeature(PdbRaw_FeatureSig::VC140);
1360
1361SmallString<64> OutFile(opts::merge::PdbOutputFile);
1362if (OutFile.empty()) {
1363OutFile = opts::merge::InputFilenames[0];
1364llvm::sys::path::replace_extension(OutFile, "merged.pdb");
1365}
1366
1367codeview::GUID IgnoredOutGuid;
1368ExitOnErr(Builder.commit(OutFile, &IgnoredOutGuid));
1369}
1370
1371static void explain() {
1372std::unique_ptr<IPDBSession> Session;
1373InputFile IF =
1374ExitOnErr(InputFile::open(opts::explain::InputFilename.front(), true));
1375
1376for (uint64_t Off : opts::explain::Offsets) {
1377auto O = std::make_unique<ExplainOutputStyle>(IF, Off);
1378
1379ExitOnErr(O->dump());
1380}
1381}
1382
1383static void exportStream() {
1384std::unique_ptr<IPDBSession> Session;
1385PDBFile &File = loadPDB(opts::exportstream::InputFilename.front(), Session);
1386
1387std::unique_ptr<MappedBlockStream> SourceStream;
1388uint32_t Index = 0;
1389bool Success = false;
1390std::string OutFileName = opts::exportstream::OutputFile;
1391
1392if (!opts::exportstream::ForceName) {
1393// First try to parse it as an integer, if it fails fall back to treating it
1394// as a named stream.
1395if (to_integer(opts::exportstream::Stream, Index)) {
1396if (Index >= File.getNumStreams()) {
1397errs() << "Error: " << Index << " is not a valid stream index.\n";
1398exit(1);
1399}
1400Success = true;
1401outs() << "Dumping contents of stream index " << Index << " to file "
1402<< OutFileName << ".\n";
1403}
1404}
1405
1406if (!Success) {
1407InfoStream &IS = cantFail(File.getPDBInfoStream());
1408Index = ExitOnErr(IS.getNamedStreamIndex(opts::exportstream::Stream));
1409outs() << "Dumping contents of stream '" << opts::exportstream::Stream
1410<< "' (index " << Index << ") to file " << OutFileName << ".\n";
1411}
1412
1413SourceStream = File.createIndexedStream(Index);
1414auto OutFile = ExitOnErr(
1415FileOutputBuffer::create(OutFileName, SourceStream->getLength()));
1416FileBufferByteStream DestStream(std::move(OutFile), llvm::endianness::little);
1417BinaryStreamWriter Writer(DestStream);
1418ExitOnErr(Writer.writeStreamRef(*SourceStream));
1419ExitOnErr(DestStream.commit());
1420}
1421
1422static bool parseRange(StringRef Str,
1423std::optional<opts::bytes::NumberRange> &Parsed) {
1424if (Str.empty())
1425return true;
1426
1427llvm::Regex R("^([^-]+)(-([^-]+))?$");
1428llvm::SmallVector<llvm::StringRef, 2> Matches;
1429if (!R.match(Str, &Matches))
1430return false;
1431
1432Parsed.emplace();
1433if (!to_integer(Matches[1], Parsed->Min))
1434return false;
1435
1436if (!Matches[3].empty()) {
1437Parsed->Max.emplace();
1438if (!to_integer(Matches[3], *Parsed->Max))
1439return false;
1440}
1441return true;
1442}
1443
1444static void simplifyChunkList(llvm::cl::list<opts::ModuleSubsection> &Chunks) {
1445// If this list contains "All" plus some other stuff, remove the other stuff
1446// and just keep "All" in the list.
1447if (!llvm::is_contained(Chunks, opts::ModuleSubsection::All))
1448return;
1449Chunks.reset();
1450Chunks.push_back(opts::ModuleSubsection::All);
1451}
1452
1453int main(int Argc, const char **Argv) {
1454InitLLVM X(Argc, Argv);
1455ExitOnErr.setBanner("llvm-pdbutil: ");
1456
1457cl::HideUnrelatedOptions(
1458{&opts::TypeCategory, &opts::FilterCategory, &opts::OtherOptions});
1459cl::ParseCommandLineOptions(Argc, Argv, "LLVM PDB Dumper\n");
1460
1461if (opts::BytesSubcommand) {
1462if (!parseRange(opts::bytes::DumpBlockRangeOpt,
1463opts::bytes::DumpBlockRange)) {
1464errs() << "Argument '" << opts::bytes::DumpBlockRangeOpt
1465<< "' invalid format.\n";
1466errs().flush();
1467exit(1);
1468}
1469if (!parseRange(opts::bytes::DumpByteRangeOpt,
1470opts::bytes::DumpByteRange)) {
1471errs() << "Argument '" << opts::bytes::DumpByteRangeOpt
1472<< "' invalid format.\n";
1473errs().flush();
1474exit(1);
1475}
1476}
1477
1478if (opts::DumpSubcommand) {
1479if (opts::dump::RawAll) {
1480opts::dump::DumpGlobals = true;
1481opts::dump::DumpFpo = true;
1482opts::dump::DumpInlineeLines = true;
1483opts::dump::DumpIds = true;
1484opts::dump::DumpIdExtras = true;
1485opts::dump::DumpLines = true;
1486opts::dump::DumpModules = true;
1487opts::dump::DumpModuleFiles = true;
1488opts::dump::DumpPublics = true;
1489opts::dump::DumpSectionContribs = true;
1490opts::dump::DumpSectionHeaders = true;
1491opts::dump::DumpSectionMap = true;
1492opts::dump::DumpStreams = true;
1493opts::dump::DumpStreamBlocks = true;
1494opts::dump::DumpStringTable = true;
1495opts::dump::DumpStringTableDetails = true;
1496opts::dump::DumpSummary = true;
1497opts::dump::DumpSymbols = true;
1498opts::dump::DumpSymbolStats = true;
1499opts::dump::DumpTypes = true;
1500opts::dump::DumpTypeExtras = true;
1501opts::dump::DumpUdtStats = true;
1502opts::dump::DumpXme = true;
1503opts::dump::DumpXmi = true;
1504}
1505}
1506if (opts::PdbToYamlSubcommand) {
1507if (opts::pdb2yaml::All) {
1508opts::pdb2yaml::StreamMetadata = true;
1509opts::pdb2yaml::StreamDirectory = true;
1510opts::pdb2yaml::PdbStream = true;
1511opts::pdb2yaml::StringTable = true;
1512opts::pdb2yaml::DbiStream = true;
1513opts::pdb2yaml::TpiStream = true;
1514opts::pdb2yaml::IpiStream = true;
1515opts::pdb2yaml::PublicsStream = true;
1516opts::pdb2yaml::DumpModules = true;
1517opts::pdb2yaml::DumpModuleFiles = true;
1518opts::pdb2yaml::DumpModuleSyms = true;
1519opts::pdb2yaml::DumpModuleSubsections.push_back(
1520opts::ModuleSubsection::All);
1521}
1522simplifyChunkList(opts::pdb2yaml::DumpModuleSubsections);
1523
1524if (opts::pdb2yaml::DumpModuleSyms || opts::pdb2yaml::DumpModuleFiles)
1525opts::pdb2yaml::DumpModules = true;
1526
1527if (opts::pdb2yaml::DumpModules)
1528opts::pdb2yaml::DbiStream = true;
1529}
1530
1531llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
1532
1533// Initialize the filters for LinePrinter.
1534auto propagate = [&](auto &Target, auto &Reference) {
1535for (std::string &Option : Reference)
1536Target.push_back(Option);
1537};
1538
1539propagate(opts::Filters.ExcludeTypes, opts::pretty::ExcludeTypes);
1540propagate(opts::Filters.ExcludeTypes, opts::pretty::ExcludeTypes);
1541propagate(opts::Filters.ExcludeSymbols, opts::pretty::ExcludeSymbols);
1542propagate(opts::Filters.ExcludeCompilands, opts::pretty::ExcludeCompilands);
1543propagate(opts::Filters.IncludeTypes, opts::pretty::IncludeTypes);
1544propagate(opts::Filters.IncludeSymbols, opts::pretty::IncludeSymbols);
1545propagate(opts::Filters.IncludeCompilands, opts::pretty::IncludeCompilands);
1546opts::Filters.PaddingThreshold = opts::pretty::PaddingThreshold;
1547opts::Filters.SizeThreshold = opts::pretty::SizeThreshold;
1548opts::Filters.JustMyCode = opts::dump::JustMyCode;
1549if (opts::dump::DumpModi.getNumOccurrences() > 0) {
1550if (opts::dump::DumpModi.getNumOccurrences() != 1) {
1551errs() << "argument '-modi' specified more than once.\n";
1552errs().flush();
1553exit(1);
1554}
1555opts::Filters.DumpModi = opts::dump::DumpModi;
1556}
1557if (opts::dump::DumpSymbolOffset) {
1558if (opts::dump::DumpModi.getNumOccurrences() != 1) {
1559errs()
1560<< "need to specify argument '-modi' when using '-symbol-offset'.\n";
1561errs().flush();
1562exit(1);
1563}
1564opts::Filters.SymbolOffset = opts::dump::DumpSymbolOffset;
1565if (opts::dump::DumpParents)
1566opts::Filters.ParentRecurseDepth = opts::dump::DumpParentDepth;
1567if (opts::dump::DumpChildren)
1568opts::Filters.ChildrenRecurseDepth = opts::dump::DumpChildrenDepth;
1569}
1570
1571if (opts::PdbToYamlSubcommand) {
1572pdb2Yaml(opts::pdb2yaml::InputFilename.front());
1573} else if (opts::YamlToPdbSubcommand) {
1574if (opts::yaml2pdb::YamlPdbOutputFile.empty()) {
1575SmallString<16> OutputFilename(opts::yaml2pdb::InputFilename.getValue());
1576sys::path::replace_extension(OutputFilename, ".pdb");
1577opts::yaml2pdb::YamlPdbOutputFile = std::string(OutputFilename);
1578}
1579yamlToPdb(opts::yaml2pdb::InputFilename);
1580} else if (opts::DiaDumpSubcommand) {
1581llvm::for_each(opts::diadump::InputFilenames, dumpDia);
1582} else if (opts::PrettySubcommand) {
1583if (opts::pretty::Lines)
1584opts::pretty::Compilands = true;
1585
1586if (opts::pretty::All) {
1587opts::pretty::Compilands = true;
1588opts::pretty::Symbols = true;
1589opts::pretty::Globals = true;
1590opts::pretty::Types = true;
1591opts::pretty::Externals = true;
1592opts::pretty::Lines = true;
1593}
1594
1595if (opts::pretty::Types) {
1596opts::pretty::Classes = true;
1597opts::pretty::Typedefs = true;
1598opts::pretty::Enums = true;
1599opts::pretty::Pointers = true;
1600opts::pretty::Funcsigs = true;
1601}
1602
1603// When adding filters for excluded compilands and types, we need to
1604// remember that these are regexes. So special characters such as * and \
1605// need to be escaped in the regex. In the case of a literal \, this means
1606// it needs to be escaped again in the C++. So matching a single \ in the
1607// input requires 4 \es in the C++.
1608if (opts::pretty::ExcludeCompilerGenerated) {
1609opts::Filters.ExcludeTypes.push_back("__vc_attributes");
1610opts::Filters.ExcludeCompilands.push_back("\\* Linker \\*");
1611}
1612if (opts::pretty::ExcludeSystemLibraries) {
1613opts::Filters.ExcludeCompilands.push_back(
1614"f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
1615opts::Filters.ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
1616opts::Filters.ExcludeCompilands.push_back(
1617"d:\\\\th.obj.x86fre\\\\minkernel");
1618}
1619llvm::for_each(opts::pretty::InputFilenames, dumpPretty);
1620} else if (opts::DumpSubcommand) {
1621llvm::for_each(opts::dump::InputFilenames, dumpRaw);
1622} else if (opts::BytesSubcommand) {
1623llvm::for_each(opts::bytes::InputFilenames, dumpBytes);
1624} else if (opts::MergeSubcommand) {
1625if (opts::merge::InputFilenames.size() < 2) {
1626errs() << "merge subcommand requires at least 2 input files.\n";
1627exit(1);
1628}
1629mergePdbs();
1630} else if (opts::ExplainSubcommand) {
1631explain();
1632} else if (opts::ExportSubcommand) {
1633exportStream();
1634}
1635
1636outs().flush();
1637return 0;
1638}
1639