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