1 //===- llvm-pdbdump.cpp - Dump debug info from a PDB file -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Dumps debug information present in PDB files. This utility makes use of
11 // the Microsoft Windows SDK, so will not compile or run on non-Windows
14 //===----------------------------------------------------------------------===//
16 #include "llvm-pdbdump.h"
17 #include "LLVMOutputStyle.h"
18 #include "LinePrinter.h"
19 #include "OutputStyle.h"
20 #include "PrettyCompilandDumper.h"
21 #include "PrettyExternalSymbolDumper.h"
22 #include "PrettyFunctionDumper.h"
23 #include "PrettyTypeDumper.h"
24 #include "PrettyVariableDumper.h"
25 #include "YAMLOutputStyle.h"
27 #include "llvm/ADT/ArrayRef.h"
28 #include "llvm/ADT/BitVector.h"
29 #include "llvm/ADT/DenseMap.h"
30 #include "llvm/ADT/StringExtras.h"
31 #include "llvm/Config/config.h"
32 #include "llvm/DebugInfo/MSF/ByteStream.h"
33 #include "llvm/DebugInfo/MSF/MSFBuilder.h"
34 #include "llvm/DebugInfo/PDB/GenericError.h"
35 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
36 #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
37 #include "llvm/DebugInfo/PDB/IPDBSession.h"
38 #include "llvm/DebugInfo/PDB/PDB.h"
39 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
40 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
41 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
42 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
43 #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
44 #include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
45 #include "llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h"
46 #include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
47 #include "llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h"
48 #include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
49 #include "llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h"
50 #include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
51 #include "llvm/DebugInfo/PDB/Raw/RawError.h"
52 #include "llvm/DebugInfo/PDB/Raw/RawSession.h"
53 #include "llvm/DebugInfo/PDB/Raw/TpiStream.h"
54 #include "llvm/DebugInfo/PDB/Raw/TpiStreamBuilder.h"
55 #include "llvm/Support/COM.h"
56 #include "llvm/Support/CommandLine.h"
57 #include "llvm/Support/ConvertUTF.h"
58 #include "llvm/Support/FileOutputBuffer.h"
59 #include "llvm/Support/FileSystem.h"
60 #include "llvm/Support/Format.h"
61 #include "llvm/Support/ManagedStatic.h"
62 #include "llvm/Support/MemoryBuffer.h"
63 #include "llvm/Support/PrettyStackTrace.h"
64 #include "llvm/Support/Process.h"
65 #include "llvm/Support/Regex.h"
66 #include "llvm/Support/ScopedPrinter.h"
67 #include "llvm/Support/Signals.h"
68 #include "llvm/Support/raw_ostream.h"
71 using namespace llvm::codeview;
72 using namespace llvm::msf;
73 using namespace llvm::pdb;
77 cl::SubCommand RawSubcommand("raw", "Dump raw structure of the PDB file");
79 PrettySubcommand("pretty",
80 "Dump semantic information about types and symbols");
82 YamlToPdbSubcommand("yaml2pdb",
83 "Generate a PDB file from a YAML description");
85 PdbToYamlSubcommand("pdb2yaml",
86 "Generate a detailed YAML description of a PDB File");
88 cl::OptionCategory TypeCategory("Symbol Type Options");
89 cl::OptionCategory FilterCategory("Filtering Options");
90 cl::OptionCategory OtherOptions("Other Options");
93 cl::list<std::string> InputFilenames(cl::Positional,
94 cl::desc("<input PDB files>"),
95 cl::OneOrMore, cl::sub(PrettySubcommand));
97 cl::opt<bool> Compilands("compilands", cl::desc("Display compilands"),
98 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
99 cl::opt<bool> Symbols("symbols", cl::desc("Display symbols for each compiland"),
100 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
101 cl::opt<bool> Globals("globals", cl::desc("Dump global symbols"),
102 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
103 cl::opt<bool> Externals("externals", cl::desc("Dump external symbols"),
104 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
105 cl::opt<bool> Types("types", cl::desc("Display types"), cl::cat(TypeCategory),
106 cl::sub(PrettySubcommand));
107 cl::opt<bool> Lines("lines", cl::desc("Line tables"), cl::cat(TypeCategory),
108 cl::sub(PrettySubcommand));
110 All("all", cl::desc("Implies all other options in 'Symbol Types' category"),
111 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
113 cl::opt<uint64_t> LoadAddress(
115 cl::desc("Assume the module is loaded at the specified address"),
116 cl::cat(OtherOptions), cl::sub(PrettySubcommand));
117 cl::list<std::string> ExcludeTypes(
118 "exclude-types", cl::desc("Exclude types by regular expression"),
119 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
120 cl::list<std::string> ExcludeSymbols(
121 "exclude-symbols", cl::desc("Exclude symbols by regular expression"),
122 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
123 cl::list<std::string> ExcludeCompilands(
124 "exclude-compilands", cl::desc("Exclude compilands by regular expression"),
125 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
127 cl::list<std::string> IncludeTypes(
129 cl::desc("Include only types which match a regular expression"),
130 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
131 cl::list<std::string> IncludeSymbols(
133 cl::desc("Include only symbols which match a regular expression"),
134 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
135 cl::list<std::string> IncludeCompilands(
136 "include-compilands",
137 cl::desc("Include only compilands those which match a regular expression"),
138 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
140 cl::opt<bool> ExcludeCompilerGenerated(
141 "no-compiler-generated",
142 cl::desc("Don't show compiler generated types and symbols"),
143 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
145 ExcludeSystemLibraries("no-system-libs",
146 cl::desc("Don't show symbols from system libraries"),
147 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
148 cl::opt<bool> NoClassDefs("no-class-definitions",
149 cl::desc("Don't display full class definitions"),
150 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
151 cl::opt<bool> NoEnumDefs("no-enum-definitions",
152 cl::desc("Don't display full enum definitions"),
153 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
158 cl::OptionCategory MsfOptions("MSF Container Options");
159 cl::OptionCategory TypeOptions("Type Record Options");
160 cl::OptionCategory FileOptions("Module & File Options");
161 cl::OptionCategory SymbolOptions("Symbol Options");
162 cl::OptionCategory MiscOptions("Miscellaneous Options");
165 cl::opt<bool> DumpHeaders("headers", cl::desc("dump PDB headers"),
166 cl::cat(MsfOptions), cl::sub(RawSubcommand));
167 cl::opt<bool> DumpStreamBlocks("stream-blocks",
168 cl::desc("dump PDB stream blocks"),
169 cl::cat(MsfOptions), cl::sub(RawSubcommand));
170 cl::opt<bool> DumpStreamSummary("stream-summary",
171 cl::desc("dump summary of the PDB streams"),
172 cl::cat(MsfOptions), cl::sub(RawSubcommand));
173 cl::opt<bool> DumpPageStats(
175 cl::desc("dump allocation stats of the pages in the MSF file"),
176 cl::cat(MsfOptions), cl::sub(RawSubcommand));
178 DumpBlockRangeOpt("block-data", cl::value_desc("start[-end]"),
179 cl::desc("Dump binary data from specified range."),
180 cl::cat(MsfOptions), cl::sub(RawSubcommand));
181 llvm::Optional<BlockRange> DumpBlockRange;
184 DumpStreamData("stream-data", cl::CommaSeparated, cl::ZeroOrMore,
185 cl::desc("Dump binary data from specified streams."),
186 cl::cat(MsfOptions), cl::sub(RawSubcommand));
190 DumpTpiRecords("tpi-records",
191 cl::desc("dump CodeView type records from TPI stream"),
192 cl::cat(TypeOptions), cl::sub(RawSubcommand));
193 cl::opt<bool> DumpTpiRecordBytes(
195 cl::desc("dump CodeView type record raw bytes from TPI stream"),
196 cl::cat(TypeOptions), cl::sub(RawSubcommand));
197 cl::opt<bool> DumpTpiHash("tpi-hash", cl::desc("dump CodeView TPI hash stream"),
198 cl::cat(TypeOptions), cl::sub(RawSubcommand));
200 DumpIpiRecords("ipi-records",
201 cl::desc("dump CodeView type records from IPI stream"),
202 cl::cat(TypeOptions), cl::sub(RawSubcommand));
203 cl::opt<bool> DumpIpiRecordBytes(
205 cl::desc("dump CodeView type record raw bytes from IPI stream"),
206 cl::cat(TypeOptions), cl::sub(RawSubcommand));
208 // MODULE & FILE OPTIONS
209 cl::opt<bool> DumpModules("modules", cl::desc("dump compiland information"),
210 cl::cat(FileOptions), cl::sub(RawSubcommand));
211 cl::opt<bool> DumpModuleFiles("module-files", cl::desc("dump file information"),
212 cl::cat(FileOptions), cl::sub(RawSubcommand));
213 cl::opt<bool> DumpLineInfo("line-info",
214 cl::desc("dump file and line information"),
215 cl::cat(FileOptions), cl::sub(RawSubcommand));
218 cl::opt<bool> DumpGlobals("globals", cl::desc("dump globals stream data"),
219 cl::cat(SymbolOptions), cl::sub(RawSubcommand));
220 cl::opt<bool> DumpModuleSyms("module-syms", cl::desc("dump module symbols"),
221 cl::cat(SymbolOptions), cl::sub(RawSubcommand));
222 cl::opt<bool> DumpPublics("publics", cl::desc("dump Publics stream data"),
223 cl::cat(SymbolOptions), cl::sub(RawSubcommand));
225 DumpSymRecordBytes("sym-record-bytes",
226 cl::desc("dump CodeView symbol record raw bytes"),
227 cl::cat(SymbolOptions), cl::sub(RawSubcommand));
229 // MISCELLANEOUS OPTIONS
230 cl::opt<bool> DumpSectionContribs("section-contribs",
231 cl::desc("dump section contributions"),
232 cl::cat(MiscOptions), cl::sub(RawSubcommand));
233 cl::opt<bool> DumpSectionMap("section-map", cl::desc("dump section map"),
234 cl::cat(MiscOptions), cl::sub(RawSubcommand));
235 cl::opt<bool> DumpSectionHeaders("section-headers",
236 cl::desc("dump section headers"),
237 cl::cat(MiscOptions), cl::sub(RawSubcommand));
238 cl::opt<bool> DumpFpo("fpo", cl::desc("dump FPO records"), cl::cat(MiscOptions),
239 cl::sub(RawSubcommand));
241 cl::opt<bool> RawAll("all", cl::desc("Implies most other options."),
242 cl::cat(MiscOptions), cl::sub(RawSubcommand));
244 cl::list<std::string> InputFilenames(cl::Positional,
245 cl::desc("<input PDB files>"),
246 cl::OneOrMore, cl::sub(RawSubcommand));
251 YamlPdbOutputFile("pdb", cl::desc("the name of the PDB file to write"),
252 cl::sub(YamlToPdbSubcommand));
254 cl::list<std::string> InputFilename(cl::Positional,
255 cl::desc("<input YAML file>"), cl::Required,
256 cl::sub(YamlToPdbSubcommand));
261 NoFileHeaders("no-file-headers",
262 cl::desc("Do not dump MSF file headers (you will not be able "
263 "to generate a fresh PDB from the resulting YAML)"),
264 cl::sub(PdbToYamlSubcommand), cl::init(false));
266 cl::opt<bool> StreamMetadata(
268 cl::desc("Dump the number of streams and each stream's size"),
269 cl::sub(PdbToYamlSubcommand), cl::init(false));
270 cl::opt<bool> StreamDirectory(
272 cl::desc("Dump each stream's block map (implies -stream-metadata)"),
273 cl::sub(PdbToYamlSubcommand), cl::init(false));
274 cl::opt<bool> PdbStream("pdb-stream",
275 cl::desc("Dump the PDB Stream (Stream 1)"),
276 cl::sub(PdbToYamlSubcommand), cl::init(false));
277 cl::opt<bool> DbiStream("dbi-stream",
278 cl::desc("Dump the DBI Stream (Stream 2)"),
279 cl::sub(PdbToYamlSubcommand), cl::init(false));
281 DbiModuleInfo("dbi-module-info",
282 cl::desc("Dump DBI Module Information (implies -dbi-stream)"),
283 cl::sub(PdbToYamlSubcommand), cl::init(false));
285 cl::opt<bool> DbiModuleSyms(
287 cl::desc("Dump DBI Module Information (implies -dbi-module-info)"),
288 cl::sub(PdbToYamlSubcommand), cl::init(false));
290 cl::opt<bool> DbiModuleSourceFileInfo(
291 "dbi-module-source-info",
293 "Dump DBI Module Source File Information (implies -dbi-module-info"),
294 cl::sub(PdbToYamlSubcommand), cl::init(false));
296 cl::opt<bool> TpiStream("tpi-stream",
297 cl::desc("Dump the TPI Stream (Stream 3)"),
298 cl::sub(PdbToYamlSubcommand), cl::init(false));
300 cl::opt<bool> IpiStream("ipi-stream",
301 cl::desc("Dump the IPI Stream (Stream 5)"),
302 cl::sub(PdbToYamlSubcommand), cl::init(false));
304 cl::list<std::string> InputFilename(cl::Positional,
305 cl::desc("<input PDB file>"), cl::Required,
306 cl::sub(PdbToYamlSubcommand));
310 static ExitOnError ExitOnErr;
312 static void yamlToPdb(StringRef Path) {
313 BumpPtrAllocator Allocator;
314 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
315 MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
316 /*RequiresNullTerminator=*/false);
318 if (ErrorOrBuffer.getError()) {
319 ExitOnErr(make_error<GenericError>(generic_error_code::invalid_path, Path));
322 std::unique_ptr<MemoryBuffer> &Buffer = ErrorOrBuffer.get();
324 llvm::yaml::Input In(Buffer->getBuffer());
325 pdb::yaml::PdbObject YamlObj(Allocator);
327 if (!YamlObj.Headers.hasValue())
328 ExitOnErr(make_error<GenericError>(generic_error_code::unspecified,
329 "Yaml does not contain MSF headers"));
331 PDBFileBuilder Builder(Allocator);
333 ExitOnErr(Builder.initialize(YamlObj.Headers->SuperBlock.BlockSize));
334 // Add each of the reserved streams. We ignore stream metadata in the
335 // yaml, because we will reconstruct our own view of the streams. For
336 // example, the YAML may say that there were 20 streams in the original
337 // PDB, but maybe we only dump a subset of those 20 streams, so we will
338 // have fewer, and the ones we do have may end up with different indices
339 // than the ones in the original PDB. So we just start with a clean slate.
340 for (uint32_t I = 0; I < kSpecialStreamCount; ++I)
341 ExitOnErr(Builder.getMsfBuilder().addStream(0));
343 if (YamlObj.PdbStream.hasValue()) {
344 auto &InfoBuilder = Builder.getInfoBuilder();
345 InfoBuilder.setAge(YamlObj.PdbStream->Age);
346 InfoBuilder.setGuid(YamlObj.PdbStream->Guid);
347 InfoBuilder.setSignature(YamlObj.PdbStream->Signature);
348 InfoBuilder.setVersion(YamlObj.PdbStream->Version);
349 for (auto &NM : YamlObj.PdbStream->NamedStreams)
350 InfoBuilder.getNamedStreamsBuilder().addMapping(NM.StreamName,
354 if (YamlObj.DbiStream.hasValue()) {
355 auto &DbiBuilder = Builder.getDbiBuilder();
356 DbiBuilder.setAge(YamlObj.DbiStream->Age);
357 DbiBuilder.setBuildNumber(YamlObj.DbiStream->BuildNumber);
358 DbiBuilder.setFlags(YamlObj.DbiStream->Flags);
359 DbiBuilder.setMachineType(YamlObj.DbiStream->MachineType);
360 DbiBuilder.setPdbDllRbld(YamlObj.DbiStream->PdbDllRbld);
361 DbiBuilder.setPdbDllVersion(YamlObj.DbiStream->PdbDllVersion);
362 DbiBuilder.setVersionHeader(YamlObj.DbiStream->VerHeader);
363 for (const auto &MI : YamlObj.DbiStream->ModInfos) {
364 ExitOnErr(DbiBuilder.addModuleInfo(MI.Obj, MI.Mod));
365 for (auto S : MI.SourceFiles)
366 ExitOnErr(DbiBuilder.addModuleSourceFile(MI.Mod, S));
370 if (YamlObj.TpiStream.hasValue()) {
371 auto &TpiBuilder = Builder.getTpiBuilder();
372 TpiBuilder.setVersionHeader(YamlObj.TpiStream->Version);
373 for (const auto &R : YamlObj.TpiStream->Records)
374 TpiBuilder.addTypeRecord(R.Record);
377 if (YamlObj.IpiStream.hasValue()) {
378 auto &IpiBuilder = Builder.getIpiBuilder();
379 IpiBuilder.setVersionHeader(YamlObj.IpiStream->Version);
380 for (const auto &R : YamlObj.IpiStream->Records)
381 IpiBuilder.addTypeRecord(R.Record);
384 ExitOnErr(Builder.commit(opts::yaml2pdb::YamlPdbOutputFile));
387 static void pdb2Yaml(StringRef Path) {
388 std::unique_ptr<IPDBSession> Session;
389 ExitOnErr(loadDataForPDB(PDB_ReaderType::Raw, Path, Session));
391 RawSession *RS = static_cast<RawSession *>(Session.get());
392 PDBFile &File = RS->getPDBFile();
393 auto O = llvm::make_unique<YAMLOutputStyle>(File);
394 O = llvm::make_unique<YAMLOutputStyle>(File);
396 ExitOnErr(O->dump());
399 static void dumpRaw(StringRef Path) {
400 std::unique_ptr<IPDBSession> Session;
401 ExitOnErr(loadDataForPDB(PDB_ReaderType::Raw, Path, Session));
403 RawSession *RS = static_cast<RawSession *>(Session.get());
404 PDBFile &File = RS->getPDBFile();
405 auto O = llvm::make_unique<LLVMOutputStyle>(File);
407 ExitOnErr(O->dump());
410 static void dumpPretty(StringRef Path) {
411 std::unique_ptr<IPDBSession> Session;
413 ExitOnErr(loadDataForPDB(PDB_ReaderType::DIA, Path, Session));
415 if (opts::pretty::LoadAddress)
416 Session->setLoadAddress(opts::pretty::LoadAddress);
418 LinePrinter Printer(2, outs());
420 auto GlobalScope(Session->getGlobalScope());
421 std::string FileName(GlobalScope->getSymbolsFileName());
423 WithColor(Printer, PDB_ColorItem::None).get() << "Summary for ";
424 WithColor(Printer, PDB_ColorItem::Path).get() << FileName;
426 uint64_t FileSize = 0;
429 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Size";
430 if (!sys::fs::file_size(FileName, FileSize)) {
431 Printer << ": " << FileSize << " bytes";
433 Printer << ": (Unable to obtain file size)";
437 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Guid";
438 Printer << ": " << GlobalScope->getGuid();
441 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Age";
442 Printer << ": " << GlobalScope->getAge();
445 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Attributes";
447 if (GlobalScope->hasCTypes())
448 outs() << "HasCTypes ";
449 if (GlobalScope->hasPrivateSymbols())
450 outs() << "HasPrivateSymbols ";
453 if (opts::pretty::Compilands) {
455 WithColor(Printer, PDB_ColorItem::SectionHeader).get()
456 << "---COMPILANDS---";
458 auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
459 CompilandDumper Dumper(Printer);
460 CompilandDumpFlags options = CompilandDumper::Flags::None;
461 if (opts::pretty::Lines)
462 options = options | CompilandDumper::Flags::Lines;
463 while (auto Compiland = Compilands->getNext())
464 Dumper.start(*Compiland, options);
468 if (opts::pretty::Types) {
470 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---";
472 TypeDumper Dumper(Printer);
473 Dumper.start(*GlobalScope);
477 if (opts::pretty::Symbols) {
479 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---SYMBOLS---";
481 auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
482 CompilandDumper Dumper(Printer);
483 while (auto Compiland = Compilands->getNext())
484 Dumper.start(*Compiland, true);
488 if (opts::pretty::Globals) {
490 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---GLOBALS---";
493 FunctionDumper Dumper(Printer);
494 auto Functions = GlobalScope->findAllChildren<PDBSymbolFunc>();
495 while (auto Function = Functions->getNext()) {
497 Dumper.start(*Function, FunctionDumper::PointerType::None);
501 auto Vars = GlobalScope->findAllChildren<PDBSymbolData>();
502 VariableDumper Dumper(Printer);
503 while (auto Var = Vars->getNext())
507 auto Thunks = GlobalScope->findAllChildren<PDBSymbolThunk>();
508 CompilandDumper Dumper(Printer);
509 while (auto Thunk = Thunks->getNext())
514 if (opts::pretty::Externals) {
516 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---EXTERNALS---";
518 ExternalSymbolDumper Dumper(Printer);
519 Dumper.start(*GlobalScope);
521 if (opts::pretty::Lines) {
527 int main(int argc_, const char *argv_[]) {
528 // Print a stack trace if we signal out.
529 sys::PrintStackTraceOnErrorSignal(argv_[0]);
530 PrettyStackTraceProgram X(argc_, argv_);
532 ExitOnErr.setBanner("llvm-pdbdump: ");
534 SmallVector<const char *, 256> argv;
535 SpecificBumpPtrAllocator<char> ArgAllocator;
536 ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector(
537 argv, makeArrayRef(argv_, argc_), ArgAllocator)));
539 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
541 cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n");
542 if (!opts::raw::DumpBlockRangeOpt.empty()) {
543 llvm::Regex R("^([0-9]+)(-([0-9]+))?$");
544 llvm::SmallVector<llvm::StringRef, 2> Matches;
545 if (!R.match(opts::raw::DumpBlockRangeOpt, &Matches)) {
546 errs() << "Argument '" << opts::raw::DumpBlockRangeOpt
547 << "' invalid format.\n";
551 opts::raw::DumpBlockRange.emplace();
552 Matches[1].getAsInteger(10, opts::raw::DumpBlockRange->Min);
553 if (!Matches[3].empty()) {
554 opts::raw::DumpBlockRange->Max.emplace();
555 Matches[3].getAsInteger(10, *opts::raw::DumpBlockRange->Max);
559 if (opts::RawSubcommand && opts::raw::RawAll) {
560 opts::raw::DumpHeaders = true;
561 opts::raw::DumpModules = true;
562 opts::raw::DumpModuleFiles = true;
563 opts::raw::DumpModuleSyms = true;
564 opts::raw::DumpGlobals = true;
565 opts::raw::DumpPublics = true;
566 opts::raw::DumpSectionHeaders = true;
567 opts::raw::DumpStreamSummary = true;
568 opts::raw::DumpPageStats = true;
569 opts::raw::DumpStreamBlocks = true;
570 opts::raw::DumpTpiRecords = true;
571 opts::raw::DumpTpiHash = true;
572 opts::raw::DumpIpiRecords = true;
573 opts::raw::DumpSectionMap = true;
574 opts::raw::DumpSectionContribs = true;
575 opts::raw::DumpLineInfo = true;
576 opts::raw::DumpFpo = true;
579 llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
581 if (opts::PdbToYamlSubcommand) {
582 pdb2Yaml(opts::pdb2yaml::InputFilename.front());
583 } else if (opts::YamlToPdbSubcommand) {
584 yamlToPdb(opts::yaml2pdb::InputFilename.front());
585 } else if (opts::PrettySubcommand) {
586 if (opts::pretty::Lines)
587 opts::pretty::Compilands = true;
589 if (opts::pretty::All) {
590 opts::pretty::Compilands = true;
591 opts::pretty::Symbols = true;
592 opts::pretty::Globals = true;
593 opts::pretty::Types = true;
594 opts::pretty::Externals = true;
595 opts::pretty::Lines = true;
598 // When adding filters for excluded compilands and types, we need to
599 // remember that these are regexes. So special characters such as * and \
600 // need to be escaped in the regex. In the case of a literal \, this means
601 // it needs to be escaped again in the C++. So matching a single \ in the
602 // input requires 4 \es in the C++.
603 if (opts::pretty::ExcludeCompilerGenerated) {
604 opts::pretty::ExcludeTypes.push_back("__vc_attributes");
605 opts::pretty::ExcludeCompilands.push_back("\\* Linker \\*");
607 if (opts::pretty::ExcludeSystemLibraries) {
608 opts::pretty::ExcludeCompilands.push_back(
609 "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
610 opts::pretty::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
611 opts::pretty::ExcludeCompilands.push_back(
612 "d:\\\\th.obj.x86fre\\\\minkernel");
614 std::for_each(opts::pretty::InputFilenames.begin(),
615 opts::pretty::InputFilenames.end(), dumpPretty);
616 } else if (opts::RawSubcommand) {
617 std::for_each(opts::raw::InputFilenames.begin(),
618 opts::raw::InputFilenames.end(), dumpRaw);