]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r303571, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-pdbdump / llvm-pdbdump.cpp
1 //===- llvm-pdbdump.cpp - Dump debug info from a PDB file -------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Dumps debug information present in PDB files.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm-pdbdump.h"
15
16 #include "Analyze.h"
17 #include "Diff.h"
18 #include "LLVMOutputStyle.h"
19 #include "LinePrinter.h"
20 #include "OutputStyle.h"
21 #include "PrettyCompilandDumper.h"
22 #include "PrettyExternalSymbolDumper.h"
23 #include "PrettyFunctionDumper.h"
24 #include "PrettyTypeDumper.h"
25 #include "PrettyVariableDumper.h"
26 #include "YAMLOutputStyle.h"
27
28 #include "llvm/ADT/ArrayRef.h"
29 #include "llvm/ADT/BitVector.h"
30 #include "llvm/ADT/DenseMap.h"
31 #include "llvm/ADT/STLExtras.h"
32 #include "llvm/ADT/StringExtras.h"
33 #include "llvm/Config/config.h"
34 #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
35 #include "llvm/DebugInfo/CodeView/ModuleDebugFileChecksumFragment.h"
36 #include "llvm/DebugInfo/CodeView/ModuleDebugInlineeLinesFragment.h"
37 #include "llvm/DebugInfo/CodeView/ModuleDebugLineFragment.h"
38 #include "llvm/DebugInfo/CodeView/TypeStreamMerger.h"
39 #include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
40 #include "llvm/DebugInfo/MSF/MSFBuilder.h"
41 #include "llvm/DebugInfo/PDB/GenericError.h"
42 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
43 #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
44 #include "llvm/DebugInfo/PDB/IPDBSession.h"
45 #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h"
46 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
47 #include "llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h"
48 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
49 #include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h"
50 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
51 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
52 #include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
53 #include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
54 #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
55 #include "llvm/DebugInfo/PDB/Native/RawError.h"
56 #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
57 #include "llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h"
58 #include "llvm/DebugInfo/PDB/PDB.h"
59 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
60 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
61 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
62 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
63 #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
64 #include "llvm/Support/BinaryByteStream.h"
65 #include "llvm/Support/COM.h"
66 #include "llvm/Support/CommandLine.h"
67 #include "llvm/Support/ConvertUTF.h"
68 #include "llvm/Support/FileOutputBuffer.h"
69 #include "llvm/Support/FileSystem.h"
70 #include "llvm/Support/Format.h"
71 #include "llvm/Support/ManagedStatic.h"
72 #include "llvm/Support/MemoryBuffer.h"
73 #include "llvm/Support/Path.h"
74 #include "llvm/Support/PrettyStackTrace.h"
75 #include "llvm/Support/Process.h"
76 #include "llvm/Support/Regex.h"
77 #include "llvm/Support/ScopedPrinter.h"
78 #include "llvm/Support/Signals.h"
79 #include "llvm/Support/raw_ostream.h"
80
81 using namespace llvm;
82 using namespace llvm::codeview;
83 using namespace llvm::msf;
84 using namespace llvm::pdb;
85
86 namespace opts {
87
88 cl::SubCommand RawSubcommand("raw", "Dump raw structure of the PDB file");
89 cl::SubCommand
90     PrettySubcommand("pretty",
91                      "Dump semantic information about types and symbols");
92
93 cl::SubCommand DiffSubcommand("diff", "Diff the contents of 2 PDB files");
94
95 cl::SubCommand
96     YamlToPdbSubcommand("yaml2pdb",
97                         "Generate a PDB file from a YAML description");
98 cl::SubCommand
99     PdbToYamlSubcommand("pdb2yaml",
100                         "Generate a detailed YAML description of a PDB File");
101
102 cl::SubCommand
103     AnalyzeSubcommand("analyze",
104                       "Analyze various aspects of a PDB's structure");
105
106 cl::SubCommand MergeSubcommand("merge",
107                                "Merge multiple PDBs into a single PDB");
108
109 cl::OptionCategory TypeCategory("Symbol Type Options");
110 cl::OptionCategory FilterCategory("Filtering and Sorting Options");
111 cl::OptionCategory OtherOptions("Other Options");
112
113 namespace pretty {
114 cl::list<std::string> InputFilenames(cl::Positional,
115                                      cl::desc("<input PDB files>"),
116                                      cl::OneOrMore, cl::sub(PrettySubcommand));
117
118 cl::opt<bool> Compilands("compilands", cl::desc("Display compilands"),
119                          cl::cat(TypeCategory), cl::sub(PrettySubcommand));
120 cl::opt<bool> Symbols("module-syms",
121                       cl::desc("Display symbols for each compiland"),
122                       cl::cat(TypeCategory), cl::sub(PrettySubcommand));
123 cl::opt<bool> Globals("globals", cl::desc("Dump global symbols"),
124                       cl::cat(TypeCategory), cl::sub(PrettySubcommand));
125 cl::opt<bool> Externals("externals", cl::desc("Dump external symbols"),
126                         cl::cat(TypeCategory), cl::sub(PrettySubcommand));
127 cl::list<SymLevel> SymTypes(
128     "sym-types", cl::desc("Type of symbols to dump (default all)"),
129     cl::cat(TypeCategory), cl::sub(PrettySubcommand), cl::ZeroOrMore,
130     cl::values(
131         clEnumValN(SymLevel::Thunks, "thunks", "Display thunk symbols"),
132         clEnumValN(SymLevel::Data, "data", "Display data symbols"),
133         clEnumValN(SymLevel::Functions, "funcs", "Display function symbols"),
134         clEnumValN(SymLevel::All, "all", "Display all symbols (default)")));
135
136 cl::opt<bool>
137     Types("types",
138           cl::desc("Display all types (implies -classes, -enums, -typedefs)"),
139           cl::cat(TypeCategory), cl::sub(PrettySubcommand));
140 cl::opt<bool> Classes("classes", cl::desc("Display class types"),
141                       cl::cat(TypeCategory), cl::sub(PrettySubcommand));
142 cl::opt<bool> Enums("enums", cl::desc("Display enum types"),
143                     cl::cat(TypeCategory), cl::sub(PrettySubcommand));
144 cl::opt<bool> Typedefs("typedefs", cl::desc("Display typedef types"),
145                        cl::cat(TypeCategory), cl::sub(PrettySubcommand));
146 cl::opt<SymbolSortMode> SymbolOrder(
147     "symbol-order", cl::desc("symbol sort order"),
148     cl::init(SymbolSortMode::None),
149     cl::values(clEnumValN(SymbolSortMode::None, "none",
150                           "Undefined / no particular sort order"),
151                clEnumValN(SymbolSortMode::Name, "name", "Sort symbols by name"),
152                clEnumValN(SymbolSortMode::Size, "size",
153                           "Sort symbols by size")),
154     cl::cat(TypeCategory), cl::sub(PrettySubcommand));
155
156 cl::opt<ClassSortMode> ClassOrder(
157     "class-order", cl::desc("Class sort order"), cl::init(ClassSortMode::None),
158     cl::values(
159         clEnumValN(ClassSortMode::None, "none",
160                    "Undefined / no particular sort order"),
161         clEnumValN(ClassSortMode::Name, "name", "Sort classes by name"),
162         clEnumValN(ClassSortMode::Size, "size", "Sort classes by size"),
163         clEnumValN(ClassSortMode::Padding, "padding",
164                    "Sort classes by amount of padding"),
165         clEnumValN(ClassSortMode::PaddingPct, "padding-pct",
166                    "Sort classes by percentage of space consumed by padding"),
167         clEnumValN(ClassSortMode::PaddingImmediate, "padding-imm",
168                    "Sort classes by amount of immediate padding"),
169         clEnumValN(ClassSortMode::PaddingPctImmediate, "padding-pct-imm",
170                    "Sort classes by percentage of space consumed by immediate "
171                    "padding")),
172     cl::cat(TypeCategory), cl::sub(PrettySubcommand));
173
174 cl::opt<ClassDefinitionFormat> ClassFormat(
175     "class-definitions", cl::desc("Class definition format"),
176     cl::init(ClassDefinitionFormat::All),
177     cl::values(
178         clEnumValN(ClassDefinitionFormat::All, "all",
179                    "Display all class members including data, constants, "
180                    "typedefs, functions, etc"),
181         clEnumValN(ClassDefinitionFormat::Layout, "layout",
182                    "Only display members that contribute to class size."),
183         clEnumValN(ClassDefinitionFormat::None, "none",
184                    "Don't display class definitions")),
185     cl::cat(TypeCategory), cl::sub(PrettySubcommand));
186 cl::opt<uint32_t> ClassRecursionDepth(
187     "class-recurse-depth", cl::desc("Class recursion depth (0=no limit)"),
188     cl::init(0), cl::cat(TypeCategory), cl::sub(PrettySubcommand));
189
190 cl::opt<bool> Lines("lines", cl::desc("Line tables"), cl::cat(TypeCategory),
191                     cl::sub(PrettySubcommand));
192 cl::opt<bool>
193     All("all", cl::desc("Implies all other options in 'Symbol Types' category"),
194         cl::cat(TypeCategory), cl::sub(PrettySubcommand));
195
196 cl::opt<uint64_t> LoadAddress(
197     "load-address",
198     cl::desc("Assume the module is loaded at the specified address"),
199     cl::cat(OtherOptions), cl::sub(PrettySubcommand));
200 cl::opt<bool> Native("native", cl::desc("Use native PDB reader instead of DIA"),
201                      cl::cat(OtherOptions), cl::sub(PrettySubcommand));
202 cl::opt<cl::boolOrDefault>
203     ColorOutput("color-output",
204                 cl::desc("Override use of color (default = isatty)"),
205                 cl::cat(OtherOptions), cl::sub(PrettySubcommand));
206 cl::list<std::string> ExcludeTypes(
207     "exclude-types", cl::desc("Exclude types by regular expression"),
208     cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
209 cl::list<std::string> ExcludeSymbols(
210     "exclude-symbols", cl::desc("Exclude symbols by regular expression"),
211     cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
212 cl::list<std::string> ExcludeCompilands(
213     "exclude-compilands", cl::desc("Exclude compilands by regular expression"),
214     cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
215
216 cl::list<std::string> IncludeTypes(
217     "include-types",
218     cl::desc("Include only types which match a regular expression"),
219     cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
220 cl::list<std::string> IncludeSymbols(
221     "include-symbols",
222     cl::desc("Include only symbols which match a regular expression"),
223     cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
224 cl::list<std::string> IncludeCompilands(
225     "include-compilands",
226     cl::desc("Include only compilands those which match a regular expression"),
227     cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
228 cl::opt<uint32_t> SizeThreshold(
229     "min-type-size", cl::desc("Displays only those types which are greater "
230                               "than or equal to the specified size."),
231     cl::init(0), cl::cat(FilterCategory), cl::sub(PrettySubcommand));
232 cl::opt<uint32_t> PaddingThreshold(
233     "min-class-padding", cl::desc("Displays only those classes which have at "
234                                   "least the specified amount of padding."),
235     cl::init(0), cl::cat(FilterCategory), cl::sub(PrettySubcommand));
236 cl::opt<uint32_t> ImmediatePaddingThreshold(
237     "min-class-padding-imm",
238     cl::desc("Displays only those classes which have at least the specified "
239              "amount of immediate padding, ignoring padding internal to bases "
240              "and aggregates."),
241     cl::init(0), cl::cat(FilterCategory), cl::sub(PrettySubcommand));
242
243 cl::opt<bool> ExcludeCompilerGenerated(
244     "no-compiler-generated",
245     cl::desc("Don't show compiler generated types and symbols"),
246     cl::cat(FilterCategory), cl::sub(PrettySubcommand));
247 cl::opt<bool>
248     ExcludeSystemLibraries("no-system-libs",
249                            cl::desc("Don't show symbols from system libraries"),
250                            cl::cat(FilterCategory), cl::sub(PrettySubcommand));
251
252 cl::opt<bool> NoEnumDefs("no-enum-definitions",
253                          cl::desc("Don't display full enum definitions"),
254                          cl::cat(FilterCategory), cl::sub(PrettySubcommand));
255 }
256
257 namespace diff {
258 cl::opt<bool> Pedantic("pedantic",
259                        cl::desc("Finds all differences (even structural ones "
260                                 "that produce otherwise identical PDBs)"),
261                        cl::sub(DiffSubcommand));
262
263 cl::list<std::string> InputFilenames(cl::Positional,
264                                      cl::desc("<first> <second>"),
265                                      cl::OneOrMore, cl::sub(DiffSubcommand));
266 }
267
268 namespace raw {
269
270 cl::OptionCategory MsfOptions("MSF Container Options");
271 cl::OptionCategory TypeOptions("Type Record Options");
272 cl::OptionCategory FileOptions("Module & File Options");
273 cl::OptionCategory SymbolOptions("Symbol Options");
274 cl::OptionCategory MiscOptions("Miscellaneous Options");
275
276 // MSF OPTIONS
277 cl::opt<bool> DumpHeaders("headers", cl::desc("dump PDB headers"),
278                           cl::cat(MsfOptions), cl::sub(RawSubcommand));
279 cl::opt<bool> DumpStreamBlocks("stream-blocks",
280                                cl::desc("dump PDB stream blocks"),
281                                cl::cat(MsfOptions), cl::sub(RawSubcommand));
282 cl::opt<bool> DumpStreamSummary("stream-summary",
283                                 cl::desc("dump summary of the PDB streams"),
284                                 cl::cat(MsfOptions), cl::sub(RawSubcommand));
285 cl::opt<bool> DumpPageStats(
286     "page-stats",
287     cl::desc("dump allocation stats of the pages in the MSF file"),
288     cl::cat(MsfOptions), cl::sub(RawSubcommand));
289 cl::opt<std::string>
290     DumpBlockRangeOpt("block-data", cl::value_desc("start[-end]"),
291                       cl::desc("Dump binary data from specified range."),
292                       cl::cat(MsfOptions), cl::sub(RawSubcommand));
293 llvm::Optional<BlockRange> DumpBlockRange;
294
295 cl::list<std::string>
296     DumpStreamData("stream-data", cl::CommaSeparated, cl::ZeroOrMore,
297                    cl::desc("Dump binary data from specified streams.  Format "
298                             "is SN[:Start][@Size]"),
299                    cl::cat(MsfOptions), cl::sub(RawSubcommand));
300
301 // TYPE OPTIONS
302 cl::opt<bool>
303     CompactRecords("compact-records",
304                    cl::desc("Dump type and symbol records with less detail"),
305                    cl::cat(TypeOptions), cl::sub(RawSubcommand));
306
307 cl::opt<bool>
308     DumpTpiRecords("tpi-records",
309                    cl::desc("dump CodeView type records from TPI stream"),
310                    cl::cat(TypeOptions), cl::sub(RawSubcommand));
311 cl::opt<bool> DumpTpiRecordBytes(
312     "tpi-record-bytes",
313     cl::desc("dump CodeView type record raw bytes from TPI stream"),
314     cl::cat(TypeOptions), cl::sub(RawSubcommand));
315 cl::opt<bool> DumpTpiHash("tpi-hash", cl::desc("dump CodeView TPI hash stream"),
316                           cl::cat(TypeOptions), cl::sub(RawSubcommand));
317 cl::opt<bool>
318     DumpIpiRecords("ipi-records",
319                    cl::desc("dump CodeView type records from IPI stream"),
320                    cl::cat(TypeOptions), cl::sub(RawSubcommand));
321 cl::opt<bool> DumpIpiRecordBytes(
322     "ipi-record-bytes",
323     cl::desc("dump CodeView type record raw bytes from IPI stream"),
324     cl::cat(TypeOptions), cl::sub(RawSubcommand));
325
326 // MODULE & FILE OPTIONS
327 cl::opt<bool> DumpModules("modules", cl::desc("dump compiland information"),
328                           cl::cat(FileOptions), cl::sub(RawSubcommand));
329 cl::opt<bool> DumpModuleFiles("module-files", cl::desc("dump file information"),
330                               cl::cat(FileOptions), cl::sub(RawSubcommand));
331 cl::opt<bool> DumpLineInfo("line-info",
332                            cl::desc("dump file and line information"),
333                            cl::cat(FileOptions), cl::sub(RawSubcommand));
334
335 // SYMBOL OPTIONS
336 cl::opt<bool> DumpGlobals("globals", cl::desc("dump globals stream data"),
337                           cl::cat(SymbolOptions), cl::sub(RawSubcommand));
338 cl::opt<bool> DumpModuleSyms("module-syms", cl::desc("dump module symbols"),
339                              cl::cat(SymbolOptions), cl::sub(RawSubcommand));
340 cl::opt<bool> DumpPublics("publics", cl::desc("dump Publics stream data"),
341                           cl::cat(SymbolOptions), cl::sub(RawSubcommand));
342 cl::opt<bool>
343     DumpSymRecordBytes("sym-record-bytes",
344                        cl::desc("dump CodeView symbol record raw bytes"),
345                        cl::cat(SymbolOptions), cl::sub(RawSubcommand));
346
347 // MISCELLANEOUS OPTIONS
348 cl::opt<bool> DumpStringTable("string-table", cl::desc("dump PDB String Table"),
349                               cl::cat(MiscOptions), cl::sub(RawSubcommand));
350
351 cl::opt<bool> DumpSectionContribs("section-contribs",
352                                   cl::desc("dump section contributions"),
353                                   cl::cat(MiscOptions), cl::sub(RawSubcommand));
354 cl::opt<bool> DumpSectionMap("section-map", cl::desc("dump section map"),
355                              cl::cat(MiscOptions), cl::sub(RawSubcommand));
356 cl::opt<bool> DumpSectionHeaders("section-headers",
357                                  cl::desc("dump section headers"),
358                                  cl::cat(MiscOptions), cl::sub(RawSubcommand));
359 cl::opt<bool> DumpFpo("fpo", cl::desc("dump FPO records"), cl::cat(MiscOptions),
360                       cl::sub(RawSubcommand));
361
362 cl::opt<bool> RawAll("all", cl::desc("Implies most other options."),
363                      cl::cat(MiscOptions), cl::sub(RawSubcommand));
364
365 cl::list<std::string> InputFilenames(cl::Positional,
366                                      cl::desc("<input PDB files>"),
367                                      cl::OneOrMore, cl::sub(RawSubcommand));
368 }
369
370 namespace yaml2pdb {
371 cl::opt<std::string>
372     YamlPdbOutputFile("pdb", cl::desc("the name of the PDB file to write"),
373                       cl::sub(YamlToPdbSubcommand));
374
375 cl::opt<std::string> InputFilename(cl::Positional,
376                                    cl::desc("<input YAML file>"), cl::Required,
377                                    cl::sub(YamlToPdbSubcommand));
378 }
379
380 namespace pdb2yaml {
381 cl::opt<bool>
382     NoFileHeaders("no-file-headers",
383                   cl::desc("Do not dump MSF file headers (you will not be able "
384                            "to generate a fresh PDB from the resulting YAML)"),
385                   cl::sub(PdbToYamlSubcommand), cl::init(false));
386 cl::opt<bool> Minimal("minimal",
387                       cl::desc("Don't write fields with default values"),
388                       cl::sub(PdbToYamlSubcommand), cl::init(false));
389
390 cl::opt<bool> StreamMetadata(
391     "stream-metadata",
392     cl::desc("Dump the number of streams and each stream's size"),
393     cl::sub(PdbToYamlSubcommand), cl::init(false));
394 cl::opt<bool> StreamDirectory(
395     "stream-directory",
396     cl::desc("Dump each stream's block map (implies -stream-metadata)"),
397     cl::sub(PdbToYamlSubcommand), cl::init(false));
398 cl::opt<bool> PdbStream("pdb-stream",
399                         cl::desc("Dump the PDB Stream (Stream 1)"),
400                         cl::sub(PdbToYamlSubcommand), cl::init(false));
401
402 cl::opt<bool> StringTable("string-table", cl::desc("Dump the PDB String Table"),
403                           cl::sub(PdbToYamlSubcommand), cl::init(false));
404
405 cl::opt<bool> DbiStream("dbi-stream",
406                         cl::desc("Dump the DBI Stream (Stream 2)"),
407                         cl::sub(PdbToYamlSubcommand), cl::init(false));
408 cl::opt<bool>
409     DbiModuleInfo("dbi-module-info",
410                   cl::desc("Dump DBI Module Information (implies -dbi-stream)"),
411                   cl::sub(PdbToYamlSubcommand), cl::init(false));
412
413 cl::opt<bool> DbiModuleSyms(
414     "dbi-module-syms",
415     cl::desc("Dump DBI Module Information (implies -dbi-module-info)"),
416     cl::sub(PdbToYamlSubcommand), cl::init(false));
417
418 cl::opt<bool> DbiModuleSourceFileInfo(
419     "dbi-module-source-info",
420     cl::desc(
421         "Dump DBI Module Source File Information (implies -dbi-module-info)"),
422     cl::sub(PdbToYamlSubcommand), cl::init(false));
423
424 cl::opt<bool>
425     DbiModuleSourceLineInfo("dbi-module-lines",
426                             cl::desc("Dump DBI Module Source Line Information "
427                                      "(implies -dbi-module-source-info)"),
428                             cl::sub(PdbToYamlSubcommand), cl::init(false));
429
430 cl::opt<bool> TpiStream("tpi-stream",
431                         cl::desc("Dump the TPI Stream (Stream 3)"),
432                         cl::sub(PdbToYamlSubcommand), cl::init(false));
433
434 cl::opt<bool> IpiStream("ipi-stream",
435                         cl::desc("Dump the IPI Stream (Stream 5)"),
436                         cl::sub(PdbToYamlSubcommand), cl::init(false));
437
438 cl::list<std::string> InputFilename(cl::Positional,
439                                     cl::desc("<input PDB file>"), cl::Required,
440                                     cl::sub(PdbToYamlSubcommand));
441 }
442
443 namespace analyze {
444 cl::opt<bool> StringTable("hash-collisions", cl::desc("Find hash collisions"),
445                           cl::sub(AnalyzeSubcommand), cl::init(false));
446 cl::list<std::string> InputFilename(cl::Positional,
447                                     cl::desc("<input PDB file>"), cl::Required,
448                                     cl::sub(AnalyzeSubcommand));
449 }
450
451 namespace merge {
452 cl::list<std::string> InputFilenames(cl::Positional,
453                                      cl::desc("<input PDB files>"),
454                                      cl::OneOrMore, cl::sub(MergeSubcommand));
455 cl::opt<std::string>
456     PdbOutputFile("pdb", cl::desc("the name of the PDB file to write"),
457                   cl::sub(MergeSubcommand));
458 }
459 }
460
461 static ExitOnError ExitOnErr;
462
463 static void yamlToPdb(StringRef Path) {
464   BumpPtrAllocator Allocator;
465   ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
466       MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
467                                    /*RequiresNullTerminator=*/false);
468
469   if (ErrorOrBuffer.getError()) {
470     ExitOnErr(make_error<GenericError>(generic_error_code::invalid_path, Path));
471   }
472
473   std::unique_ptr<MemoryBuffer> &Buffer = ErrorOrBuffer.get();
474
475   llvm::yaml::Input In(Buffer->getBuffer());
476   pdb::yaml::PdbObject YamlObj(Allocator);
477   In >> YamlObj;
478
479   PDBFileBuilder Builder(Allocator);
480
481   uint32_t BlockSize = 4096;
482   if (YamlObj.Headers.hasValue())
483     BlockSize = YamlObj.Headers->SuperBlock.BlockSize;
484   ExitOnErr(Builder.initialize(BlockSize));
485   // Add each of the reserved streams.  We ignore stream metadata in the
486   // yaml, because we will reconstruct our own view of the streams.  For
487   // example, the YAML may say that there were 20 streams in the original
488   // PDB, but maybe we only dump a subset of those 20 streams, so we will
489   // have fewer, and the ones we do have may end up with different indices
490   // than the ones in the original PDB.  So we just start with a clean slate.
491   for (uint32_t I = 0; I < kSpecialStreamCount; ++I)
492     ExitOnErr(Builder.getMsfBuilder().addStream(0));
493
494   if (YamlObj.StringTable.hasValue()) {
495     auto &Strings = Builder.getStringTableBuilder();
496     for (auto S : *YamlObj.StringTable)
497       Strings.insert(S);
498   }
499
500   pdb::yaml::PdbInfoStream DefaultInfoStream;
501   pdb::yaml::PdbDbiStream DefaultDbiStream;
502   pdb::yaml::PdbTpiStream DefaultTpiStream;
503
504   const auto &Info = YamlObj.PdbStream.getValueOr(DefaultInfoStream);
505
506   auto &InfoBuilder = Builder.getInfoBuilder();
507   InfoBuilder.setAge(Info.Age);
508   InfoBuilder.setGuid(Info.Guid);
509   InfoBuilder.setSignature(Info.Signature);
510   InfoBuilder.setVersion(Info.Version);
511   for (auto F : Info.Features)
512     InfoBuilder.addFeature(F);
513
514   auto &Strings = Builder.getStringTableBuilder().getStrings();
515
516   const auto &Dbi = YamlObj.DbiStream.getValueOr(DefaultDbiStream);
517   auto &DbiBuilder = Builder.getDbiBuilder();
518   DbiBuilder.setAge(Dbi.Age);
519   DbiBuilder.setBuildNumber(Dbi.BuildNumber);
520   DbiBuilder.setFlags(Dbi.Flags);
521   DbiBuilder.setMachineType(Dbi.MachineType);
522   DbiBuilder.setPdbDllRbld(Dbi.PdbDllRbld);
523   DbiBuilder.setPdbDllVersion(Dbi.PdbDllVersion);
524   DbiBuilder.setVersionHeader(Dbi.VerHeader);
525   for (const auto &MI : Dbi.ModInfos) {
526     auto &ModiBuilder = ExitOnErr(DbiBuilder.addModuleInfo(MI.Mod));
527
528     for (auto S : MI.SourceFiles)
529       ExitOnErr(DbiBuilder.addModuleSourceFile(MI.Mod, S));
530     if (MI.Modi.hasValue()) {
531       const auto &ModiStream = *MI.Modi;
532       ModiBuilder.setObjFileName(MI.Obj);
533       for (auto Symbol : ModiStream.Symbols)
534         ModiBuilder.addSymbol(Symbol.Record);
535     }
536     if (MI.FileLineInfo.hasValue()) {
537       const auto &FLI = *MI.FileLineInfo;
538
539       // File Checksums must be emitted before line information, because line
540       // info records use offsets into the checksum buffer to reference a file's
541       // source file name.
542       auto Checksums =
543           llvm::make_unique<ModuleDebugFileChecksumFragment>(Strings);
544       auto &ChecksumRef = *Checksums;
545       if (!FLI.FileChecksums.empty()) {
546         for (auto &FC : FLI.FileChecksums)
547           Checksums->addChecksum(FC.FileName, FC.Kind, FC.ChecksumBytes.Bytes);
548       }
549       ModiBuilder.setC13FileChecksums(std::move(Checksums));
550
551       for (const auto &Fragment : FLI.LineFragments) {
552         auto Lines =
553             llvm::make_unique<ModuleDebugLineFragment>(ChecksumRef, Strings);
554         Lines->setCodeSize(Fragment.CodeSize);
555         Lines->setRelocationAddress(Fragment.RelocSegment,
556                                     Fragment.RelocOffset);
557         Lines->setFlags(Fragment.Flags);
558         for (const auto &LC : Fragment.Blocks) {
559           Lines->createBlock(LC.FileName);
560           if (Lines->hasColumnInfo()) {
561             for (const auto &Item : zip(LC.Lines, LC.Columns)) {
562               auto &L = std::get<0>(Item);
563               auto &C = std::get<1>(Item);
564               uint32_t LE = L.LineStart + L.EndDelta;
565               Lines->addLineAndColumnInfo(
566                   L.Offset, LineInfo(L.LineStart, LE, L.IsStatement),
567                   C.StartColumn, C.EndColumn);
568             }
569           } else {
570             for (const auto &L : LC.Lines) {
571               uint32_t LE = L.LineStart + L.EndDelta;
572               Lines->addLineInfo(L.Offset,
573                                  LineInfo(L.LineStart, LE, L.IsStatement));
574             }
575           }
576         }
577         ModiBuilder.addC13Fragment(std::move(Lines));
578       }
579
580       for (const auto &Inlinee : FLI.Inlinees) {
581         auto Inlinees = llvm::make_unique<ModuleDebugInlineeLineFragment>(
582             ChecksumRef, Inlinee.HasExtraFiles);
583         for (const auto &Site : Inlinee.Sites) {
584           Inlinees->addInlineSite(Site.Inlinee, Site.FileName,
585                                   Site.SourceLineNum);
586           if (!Inlinee.HasExtraFiles)
587             continue;
588
589           for (auto EF : Site.ExtraFiles) {
590             Inlinees->addExtraFile(EF);
591           }
592         }
593         ModiBuilder.addC13Fragment(std::move(Inlinees));
594       }
595     }
596   }
597
598   auto &TpiBuilder = Builder.getTpiBuilder();
599   const auto &Tpi = YamlObj.TpiStream.getValueOr(DefaultTpiStream);
600   TpiBuilder.setVersionHeader(Tpi.Version);
601   for (const auto &R : Tpi.Records)
602     TpiBuilder.addTypeRecord(R.Record.data(), R.Record.Hash);
603
604   const auto &Ipi = YamlObj.IpiStream.getValueOr(DefaultTpiStream);
605   auto &IpiBuilder = Builder.getIpiBuilder();
606   IpiBuilder.setVersionHeader(Ipi.Version);
607   for (const auto &R : Ipi.Records)
608     TpiBuilder.addTypeRecord(R.Record.data(), R.Record.Hash);
609
610   ExitOnErr(Builder.commit(opts::yaml2pdb::YamlPdbOutputFile));
611 }
612
613 static PDBFile &loadPDB(StringRef Path, std::unique_ptr<IPDBSession> &Session) {
614   ExitOnErr(loadDataForPDB(PDB_ReaderType::Native, Path, Session));
615
616   NativeSession *NS = static_cast<NativeSession *>(Session.get());
617   return NS->getPDBFile();
618 }
619
620 static void pdb2Yaml(StringRef Path) {
621   std::unique_ptr<IPDBSession> Session;
622   auto &File = loadPDB(Path, Session);
623
624   auto O = llvm::make_unique<YAMLOutputStyle>(File);
625   O = llvm::make_unique<YAMLOutputStyle>(File);
626
627   ExitOnErr(O->dump());
628 }
629
630 static void dumpRaw(StringRef Path) {
631   std::unique_ptr<IPDBSession> Session;
632   auto &File = loadPDB(Path, Session);
633
634   auto O = llvm::make_unique<LLVMOutputStyle>(File);
635
636   ExitOnErr(O->dump());
637 }
638
639 static void dumpAnalysis(StringRef Path) {
640   std::unique_ptr<IPDBSession> Session;
641   auto &File = loadPDB(Path, Session);
642   auto O = llvm::make_unique<AnalysisStyle>(File);
643
644   ExitOnErr(O->dump());
645 }
646
647 static void diff(StringRef Path1, StringRef Path2) {
648   std::unique_ptr<IPDBSession> Session1;
649   std::unique_ptr<IPDBSession> Session2;
650
651   auto &File1 = loadPDB(Path1, Session1);
652   auto &File2 = loadPDB(Path2, Session2);
653
654   auto O = llvm::make_unique<DiffStyle>(File1, File2);
655
656   ExitOnErr(O->dump());
657 }
658
659 bool opts::pretty::shouldDumpSymLevel(SymLevel Search) {
660   if (SymTypes.empty())
661     return true;
662   if (llvm::find(SymTypes, Search) != SymTypes.end())
663     return true;
664   if (llvm::find(SymTypes, SymLevel::All) != SymTypes.end())
665     return true;
666   return false;
667 }
668
669 uint32_t llvm::pdb::getTypeLength(const PDBSymbolData &Symbol) {
670   auto SymbolType = Symbol.getType();
671   const IPDBRawSymbol &RawType = SymbolType->getRawSymbol();
672
673   return RawType.getLength();
674 }
675
676 bool opts::pretty::compareFunctionSymbols(
677     const std::unique_ptr<PDBSymbolFunc> &F1,
678     const std::unique_ptr<PDBSymbolFunc> &F2) {
679   assert(opts::pretty::SymbolOrder != opts::pretty::SymbolSortMode::None);
680
681   if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::Name)
682     return F1->getName() < F2->getName();
683
684   // Note that we intentionally sort in descending order on length, since
685   // long functions are more interesting than short functions.
686   return F1->getLength() > F2->getLength();
687 }
688
689 bool opts::pretty::compareDataSymbols(
690     const std::unique_ptr<PDBSymbolData> &F1,
691     const std::unique_ptr<PDBSymbolData> &F2) {
692   assert(opts::pretty::SymbolOrder != opts::pretty::SymbolSortMode::None);
693
694   if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::Name)
695     return F1->getName() < F2->getName();
696
697   // Note that we intentionally sort in descending order on length, since
698   // large types are more interesting than short ones.
699   return getTypeLength(*F1) > getTypeLength(*F2);
700 }
701
702 static void dumpPretty(StringRef Path) {
703   std::unique_ptr<IPDBSession> Session;
704
705   const auto ReaderType =
706       opts::pretty::Native ? PDB_ReaderType::Native : PDB_ReaderType::DIA;
707   ExitOnErr(loadDataForPDB(ReaderType, Path, Session));
708
709   if (opts::pretty::LoadAddress)
710     Session->setLoadAddress(opts::pretty::LoadAddress);
711
712   auto &Stream = outs();
713   const bool UseColor = opts::pretty::ColorOutput == cl::BOU_UNSET
714                             ? Stream.has_colors()
715                             : opts::pretty::ColorOutput == cl::BOU_TRUE;
716   LinePrinter Printer(2, UseColor, Stream);
717
718   auto GlobalScope(Session->getGlobalScope());
719   std::string FileName(GlobalScope->getSymbolsFileName());
720
721   WithColor(Printer, PDB_ColorItem::None).get() << "Summary for ";
722   WithColor(Printer, PDB_ColorItem::Path).get() << FileName;
723   Printer.Indent();
724   uint64_t FileSize = 0;
725
726   Printer.NewLine();
727   WithColor(Printer, PDB_ColorItem::Identifier).get() << "Size";
728   if (!sys::fs::file_size(FileName, FileSize)) {
729     Printer << ": " << FileSize << " bytes";
730   } else {
731     Printer << ": (Unable to obtain file size)";
732   }
733
734   Printer.NewLine();
735   WithColor(Printer, PDB_ColorItem::Identifier).get() << "Guid";
736   Printer << ": " << GlobalScope->getGuid();
737
738   Printer.NewLine();
739   WithColor(Printer, PDB_ColorItem::Identifier).get() << "Age";
740   Printer << ": " << GlobalScope->getAge();
741
742   Printer.NewLine();
743   WithColor(Printer, PDB_ColorItem::Identifier).get() << "Attributes";
744   Printer << ": ";
745   if (GlobalScope->hasCTypes())
746     outs() << "HasCTypes ";
747   if (GlobalScope->hasPrivateSymbols())
748     outs() << "HasPrivateSymbols ";
749   Printer.Unindent();
750
751   if (opts::pretty::Compilands) {
752     Printer.NewLine();
753     WithColor(Printer, PDB_ColorItem::SectionHeader).get()
754         << "---COMPILANDS---";
755     Printer.Indent();
756     auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
757     CompilandDumper Dumper(Printer);
758     CompilandDumpFlags options = CompilandDumper::Flags::None;
759     if (opts::pretty::Lines)
760       options = options | CompilandDumper::Flags::Lines;
761     while (auto Compiland = Compilands->getNext())
762       Dumper.start(*Compiland, options);
763     Printer.Unindent();
764   }
765
766   if (opts::pretty::Classes || opts::pretty::Enums || opts::pretty::Typedefs) {
767     Printer.NewLine();
768     WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---";
769     Printer.Indent();
770     TypeDumper Dumper(Printer);
771     Dumper.start(*GlobalScope);
772     Printer.Unindent();
773   }
774
775   if (opts::pretty::Symbols) {
776     Printer.NewLine();
777     WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---SYMBOLS---";
778     Printer.Indent();
779     auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
780     CompilandDumper Dumper(Printer);
781     while (auto Compiland = Compilands->getNext())
782       Dumper.start(*Compiland, true);
783     Printer.Unindent();
784   }
785
786   if (opts::pretty::Globals) {
787     Printer.NewLine();
788     WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---GLOBALS---";
789     Printer.Indent();
790     if (shouldDumpSymLevel(opts::pretty::SymLevel::Functions)) {
791       FunctionDumper Dumper(Printer);
792       auto Functions = GlobalScope->findAllChildren<PDBSymbolFunc>();
793       if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
794         while (auto Function = Functions->getNext()) {
795           Printer.NewLine();
796           Dumper.start(*Function, FunctionDumper::PointerType::None);
797         }
798       } else {
799         std::vector<std::unique_ptr<PDBSymbolFunc>> Funcs;
800         while (auto Func = Functions->getNext())
801           Funcs.push_back(std::move(Func));
802         std::sort(Funcs.begin(), Funcs.end(),
803                   opts::pretty::compareFunctionSymbols);
804         for (const auto &Func : Funcs) {
805           Printer.NewLine();
806           Dumper.start(*Func, FunctionDumper::PointerType::None);
807         }
808       }
809     }
810     if (shouldDumpSymLevel(opts::pretty::SymLevel::Data)) {
811       auto Vars = GlobalScope->findAllChildren<PDBSymbolData>();
812       VariableDumper Dumper(Printer);
813       if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
814         while (auto Var = Vars->getNext())
815           Dumper.start(*Var);
816       } else {
817         std::vector<std::unique_ptr<PDBSymbolData>> Datas;
818         while (auto Var = Vars->getNext())
819           Datas.push_back(std::move(Var));
820         std::sort(Datas.begin(), Datas.end(), opts::pretty::compareDataSymbols);
821         for (const auto &Var : Datas)
822           Dumper.start(*Var);
823       }
824     }
825     if (shouldDumpSymLevel(opts::pretty::SymLevel::Thunks)) {
826       auto Thunks = GlobalScope->findAllChildren<PDBSymbolThunk>();
827       CompilandDumper Dumper(Printer);
828       while (auto Thunk = Thunks->getNext())
829         Dumper.dump(*Thunk);
830     }
831     Printer.Unindent();
832   }
833   if (opts::pretty::Externals) {
834     Printer.NewLine();
835     WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---EXTERNALS---";
836     Printer.Indent();
837     ExternalSymbolDumper Dumper(Printer);
838     Dumper.start(*GlobalScope);
839   }
840   if (opts::pretty::Lines) {
841     Printer.NewLine();
842   }
843   outs().flush();
844 }
845
846 static void mergePdbs() {
847   BumpPtrAllocator Allocator;
848   TypeTableBuilder MergedTpi(Allocator);
849   TypeTableBuilder MergedIpi(Allocator);
850
851   // Create a Tpi and Ipi type table with all types from all input files.
852   for (const auto &Path : opts::merge::InputFilenames) {
853     std::unique_ptr<IPDBSession> Session;
854     auto &File = loadPDB(Path, Session);
855     SmallVector<TypeIndex, 128> SourceToDest;
856     if (File.hasPDBTpiStream()) {
857       SourceToDest.clear();
858       auto &Tpi = ExitOnErr(File.getPDBTpiStream());
859       ExitOnErr(codeview::mergeTypeStreams(MergedIpi, MergedTpi, SourceToDest,
860                                            nullptr, Tpi.typeArray()));
861     }
862     if (File.hasPDBIpiStream()) {
863       SourceToDest.clear();
864       auto &Ipi = ExitOnErr(File.getPDBIpiStream());
865       ExitOnErr(codeview::mergeTypeStreams(MergedIpi, MergedTpi, SourceToDest,
866                                            nullptr, Ipi.typeArray()));
867     }
868   }
869
870   // Then write the PDB.
871   PDBFileBuilder Builder(Allocator);
872   ExitOnErr(Builder.initialize(4096));
873   // Add each of the reserved streams.  We might not put any data in them,
874   // but at least they have to be present.
875   for (uint32_t I = 0; I < kSpecialStreamCount; ++I)
876     ExitOnErr(Builder.getMsfBuilder().addStream(0));
877
878   auto &DestTpi = Builder.getTpiBuilder();
879   auto &DestIpi = Builder.getIpiBuilder();
880   MergedTpi.ForEachRecord(
881       [&DestTpi](TypeIndex TI, MutableArrayRef<uint8_t> Data) {
882         DestTpi.addTypeRecord(Data, None);
883       });
884   MergedIpi.ForEachRecord(
885       [&DestIpi](TypeIndex TI, MutableArrayRef<uint8_t> Data) {
886         DestIpi.addTypeRecord(Data, None);
887       });
888
889   SmallString<64> OutFile(opts::merge::PdbOutputFile);
890   if (OutFile.empty()) {
891     OutFile = opts::merge::InputFilenames[0];
892     llvm::sys::path::replace_extension(OutFile, "merged.pdb");
893   }
894   ExitOnErr(Builder.commit(OutFile));
895 }
896
897 int main(int argc_, const char *argv_[]) {
898   // Print a stack trace if we signal out.
899   sys::PrintStackTraceOnErrorSignal(argv_[0]);
900   PrettyStackTraceProgram X(argc_, argv_);
901
902   ExitOnErr.setBanner("llvm-pdbdump: ");
903
904   SmallVector<const char *, 256> argv;
905   SpecificBumpPtrAllocator<char> ArgAllocator;
906   ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector(
907       argv, makeArrayRef(argv_, argc_), ArgAllocator)));
908
909   llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
910
911   cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n");
912   if (!opts::raw::DumpBlockRangeOpt.empty()) {
913     llvm::Regex R("^([0-9]+)(-([0-9]+))?$");
914     llvm::SmallVector<llvm::StringRef, 2> Matches;
915     if (!R.match(opts::raw::DumpBlockRangeOpt, &Matches)) {
916       errs() << "Argument '" << opts::raw::DumpBlockRangeOpt
917              << "' invalid format.\n";
918       errs().flush();
919       exit(1);
920     }
921     opts::raw::DumpBlockRange.emplace();
922     Matches[1].getAsInteger(10, opts::raw::DumpBlockRange->Min);
923     if (!Matches[3].empty()) {
924       opts::raw::DumpBlockRange->Max.emplace();
925       Matches[3].getAsInteger(10, *opts::raw::DumpBlockRange->Max);
926     }
927   }
928
929   if (opts::RawSubcommand) {
930     if (opts::raw::RawAll) {
931       opts::raw::DumpHeaders = true;
932       opts::raw::DumpModules = true;
933       opts::raw::DumpModuleFiles = true;
934       opts::raw::DumpModuleSyms = true;
935       opts::raw::DumpGlobals = true;
936       opts::raw::DumpPublics = true;
937       opts::raw::DumpSectionHeaders = true;
938       opts::raw::DumpStreamSummary = true;
939       opts::raw::DumpPageStats = true;
940       opts::raw::DumpStreamBlocks = true;
941       opts::raw::DumpTpiRecords = true;
942       opts::raw::DumpTpiHash = true;
943       opts::raw::DumpIpiRecords = true;
944       opts::raw::DumpSectionMap = true;
945       opts::raw::DumpSectionContribs = true;
946       opts::raw::DumpLineInfo = true;
947       opts::raw::DumpFpo = true;
948       opts::raw::DumpStringTable = true;
949     }
950
951     if (opts::raw::CompactRecords &&
952         (opts::raw::DumpTpiRecordBytes || opts::raw::DumpIpiRecordBytes)) {
953       errs() << "-compact-records is incompatible with -tpi-record-bytes and "
954                 "-ipi-record-bytes.\n";
955       exit(1);
956     }
957   }
958
959   llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
960
961   if (opts::PdbToYamlSubcommand) {
962     pdb2Yaml(opts::pdb2yaml::InputFilename.front());
963   } else if (opts::YamlToPdbSubcommand) {
964     if (opts::yaml2pdb::YamlPdbOutputFile.empty()) {
965       SmallString<16> OutputFilename(opts::yaml2pdb::InputFilename.getValue());
966       sys::path::replace_extension(OutputFilename, ".pdb");
967       opts::yaml2pdb::YamlPdbOutputFile = OutputFilename.str();
968     }
969     yamlToPdb(opts::yaml2pdb::InputFilename);
970   } else if (opts::AnalyzeSubcommand) {
971     dumpAnalysis(opts::analyze::InputFilename.front());
972   } else if (opts::PrettySubcommand) {
973     if (opts::pretty::Lines)
974       opts::pretty::Compilands = true;
975
976     if (opts::pretty::All) {
977       opts::pretty::Compilands = true;
978       opts::pretty::Symbols = true;
979       opts::pretty::Globals = true;
980       opts::pretty::Types = true;
981       opts::pretty::Externals = true;
982       opts::pretty::Lines = true;
983     }
984
985     if (opts::pretty::Types) {
986       opts::pretty::Classes = true;
987       opts::pretty::Typedefs = true;
988       opts::pretty::Enums = true;
989     }
990
991     // When adding filters for excluded compilands and types, we need to
992     // remember that these are regexes.  So special characters such as * and \
993     // need to be escaped in the regex.  In the case of a literal \, this means
994     // it needs to be escaped again in the C++.  So matching a single \ in the
995     // input requires 4 \es in the C++.
996     if (opts::pretty::ExcludeCompilerGenerated) {
997       opts::pretty::ExcludeTypes.push_back("__vc_attributes");
998       opts::pretty::ExcludeCompilands.push_back("\\* Linker \\*");
999     }
1000     if (opts::pretty::ExcludeSystemLibraries) {
1001       opts::pretty::ExcludeCompilands.push_back(
1002           "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
1003       opts::pretty::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
1004       opts::pretty::ExcludeCompilands.push_back(
1005           "d:\\\\th.obj.x86fre\\\\minkernel");
1006     }
1007     std::for_each(opts::pretty::InputFilenames.begin(),
1008                   opts::pretty::InputFilenames.end(), dumpPretty);
1009   } else if (opts::RawSubcommand) {
1010     std::for_each(opts::raw::InputFilenames.begin(),
1011                   opts::raw::InputFilenames.end(), dumpRaw);
1012   } else if (opts::DiffSubcommand) {
1013     if (opts::diff::InputFilenames.size() != 2) {
1014       errs() << "diff subcommand expects exactly 2 arguments.\n";
1015       exit(1);
1016     }
1017     diff(opts::diff::InputFilenames[0], opts::diff::InputFilenames[1]);
1018   } else if (opts::MergeSubcommand) {
1019     if (opts::merge::InputFilenames.size() < 2) {
1020       errs() << "merge subcommand requires at least 2 input files.\n";
1021       exit(1);
1022     }
1023     mergePdbs();
1024   }
1025
1026   outs().flush();
1027   return 0;
1028 }