1*9880d681SAndroid Build Coastguard Worker //===- llvm-pdbdump.cpp - Dump debug info from a PDB file -------*- C++ -*-===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // Dumps debug information present in PDB files. This utility makes use of
11*9880d681SAndroid Build Coastguard Worker // the Microsoft Windows SDK, so will not compile or run on non-Windows
12*9880d681SAndroid Build Coastguard Worker // platforms.
13*9880d681SAndroid Build Coastguard Worker //
14*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
15*9880d681SAndroid Build Coastguard Worker
16*9880d681SAndroid Build Coastguard Worker #include "llvm-pdbdump.h"
17*9880d681SAndroid Build Coastguard Worker #include "CompilandDumper.h"
18*9880d681SAndroid Build Coastguard Worker #include "ExternalSymbolDumper.h"
19*9880d681SAndroid Build Coastguard Worker #include "FunctionDumper.h"
20*9880d681SAndroid Build Coastguard Worker #include "LLVMOutputStyle.h"
21*9880d681SAndroid Build Coastguard Worker #include "LinePrinter.h"
22*9880d681SAndroid Build Coastguard Worker #include "OutputStyle.h"
23*9880d681SAndroid Build Coastguard Worker #include "TypeDumper.h"
24*9880d681SAndroid Build Coastguard Worker #include "VariableDumper.h"
25*9880d681SAndroid Build Coastguard Worker #include "YAMLOutputStyle.h"
26*9880d681SAndroid Build Coastguard Worker
27*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/ArrayRef.h"
28*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/BitVector.h"
29*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/DenseMap.h"
30*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/StringExtras.h"
31*9880d681SAndroid Build Coastguard Worker #include "llvm/Config/config.h"
32*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/CodeView/ByteStream.h"
33*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/GenericError.h"
34*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
35*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
36*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/IPDBSession.h"
37*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/PDB.h"
38*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
39*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
40*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
41*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
42*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
43*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
44*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h"
45*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
46*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h"
47*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
48*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h"
49*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
50*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/RawError.h"
51*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/RawSession.h"
52*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/COM.h"
53*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/CommandLine.h"
54*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/ConvertUTF.h"
55*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/FileOutputBuffer.h"
56*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/FileSystem.h"
57*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Format.h"
58*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/ManagedStatic.h"
59*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/MemoryBuffer.h"
60*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/PrettyStackTrace.h"
61*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Process.h"
62*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/ScopedPrinter.h"
63*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Signals.h"
64*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/raw_ostream.h"
65*9880d681SAndroid Build Coastguard Worker
66*9880d681SAndroid Build Coastguard Worker using namespace llvm;
67*9880d681SAndroid Build Coastguard Worker using namespace llvm::codeview;
68*9880d681SAndroid Build Coastguard Worker using namespace llvm::pdb;
69*9880d681SAndroid Build Coastguard Worker
70*9880d681SAndroid Build Coastguard Worker namespace {
71*9880d681SAndroid Build Coastguard Worker // A simple adapter that acts like a ByteStream but holds ownership over
72*9880d681SAndroid Build Coastguard Worker // and underlying FileOutputBuffer.
73*9880d681SAndroid Build Coastguard Worker class FileBufferByteStream : public ByteStream<true> {
74*9880d681SAndroid Build Coastguard Worker public:
FileBufferByteStream(std::unique_ptr<FileOutputBuffer> Buffer)75*9880d681SAndroid Build Coastguard Worker FileBufferByteStream(std::unique_ptr<FileOutputBuffer> Buffer)
76*9880d681SAndroid Build Coastguard Worker : ByteStream(MutableArrayRef<uint8_t>(Buffer->getBufferStart(),
77*9880d681SAndroid Build Coastguard Worker Buffer->getBufferEnd())),
78*9880d681SAndroid Build Coastguard Worker FileBuffer(std::move(Buffer)) {}
79*9880d681SAndroid Build Coastguard Worker
commit() const80*9880d681SAndroid Build Coastguard Worker Error commit() const override {
81*9880d681SAndroid Build Coastguard Worker if (FileBuffer->commit())
82*9880d681SAndroid Build Coastguard Worker return llvm::make_error<RawError>(raw_error_code::not_writable);
83*9880d681SAndroid Build Coastguard Worker return Error::success();
84*9880d681SAndroid Build Coastguard Worker }
85*9880d681SAndroid Build Coastguard Worker
86*9880d681SAndroid Build Coastguard Worker private:
87*9880d681SAndroid Build Coastguard Worker std::unique_ptr<FileOutputBuffer> FileBuffer;
88*9880d681SAndroid Build Coastguard Worker };
89*9880d681SAndroid Build Coastguard Worker }
90*9880d681SAndroid Build Coastguard Worker
91*9880d681SAndroid Build Coastguard Worker namespace opts {
92*9880d681SAndroid Build Coastguard Worker
93*9880d681SAndroid Build Coastguard Worker cl::SubCommand RawSubcommand("raw", "Dump raw structure of the PDB file");
94*9880d681SAndroid Build Coastguard Worker cl::SubCommand
95*9880d681SAndroid Build Coastguard Worker PrettySubcommand("pretty",
96*9880d681SAndroid Build Coastguard Worker "Dump semantic information about types and symbols");
97*9880d681SAndroid Build Coastguard Worker cl::SubCommand
98*9880d681SAndroid Build Coastguard Worker YamlToPdbSubcommand("yaml2pdb",
99*9880d681SAndroid Build Coastguard Worker "Generate a PDB file from a YAML description");
100*9880d681SAndroid Build Coastguard Worker cl::SubCommand
101*9880d681SAndroid Build Coastguard Worker PdbToYamlSubcommand("pdb2yaml",
102*9880d681SAndroid Build Coastguard Worker "Generate a detailed YAML description of a PDB File");
103*9880d681SAndroid Build Coastguard Worker
104*9880d681SAndroid Build Coastguard Worker cl::OptionCategory TypeCategory("Symbol Type Options");
105*9880d681SAndroid Build Coastguard Worker cl::OptionCategory FilterCategory("Filtering Options");
106*9880d681SAndroid Build Coastguard Worker cl::OptionCategory OtherOptions("Other Options");
107*9880d681SAndroid Build Coastguard Worker
108*9880d681SAndroid Build Coastguard Worker namespace pretty {
109*9880d681SAndroid Build Coastguard Worker cl::list<std::string> InputFilenames(cl::Positional,
110*9880d681SAndroid Build Coastguard Worker cl::desc("<input PDB files>"),
111*9880d681SAndroid Build Coastguard Worker cl::OneOrMore, cl::sub(PrettySubcommand));
112*9880d681SAndroid Build Coastguard Worker
113*9880d681SAndroid Build Coastguard Worker cl::opt<bool> Compilands("compilands", cl::desc("Display compilands"),
114*9880d681SAndroid Build Coastguard Worker cl::cat(TypeCategory), cl::sub(PrettySubcommand));
115*9880d681SAndroid Build Coastguard Worker cl::opt<bool> Symbols("symbols", cl::desc("Display symbols for each compiland"),
116*9880d681SAndroid Build Coastguard Worker cl::cat(TypeCategory), cl::sub(PrettySubcommand));
117*9880d681SAndroid Build Coastguard Worker cl::opt<bool> Globals("globals", cl::desc("Dump global symbols"),
118*9880d681SAndroid Build Coastguard Worker cl::cat(TypeCategory), cl::sub(PrettySubcommand));
119*9880d681SAndroid Build Coastguard Worker cl::opt<bool> Externals("externals", cl::desc("Dump external symbols"),
120*9880d681SAndroid Build Coastguard Worker cl::cat(TypeCategory), cl::sub(PrettySubcommand));
121*9880d681SAndroid Build Coastguard Worker cl::opt<bool> Types("types", cl::desc("Display types"), cl::cat(TypeCategory),
122*9880d681SAndroid Build Coastguard Worker cl::sub(PrettySubcommand));
123*9880d681SAndroid Build Coastguard Worker cl::opt<bool> Lines("lines", cl::desc("Line tables"), cl::cat(TypeCategory),
124*9880d681SAndroid Build Coastguard Worker cl::sub(PrettySubcommand));
125*9880d681SAndroid Build Coastguard Worker cl::opt<bool>
126*9880d681SAndroid Build Coastguard Worker All("all", cl::desc("Implies all other options in 'Symbol Types' category"),
127*9880d681SAndroid Build Coastguard Worker cl::cat(TypeCategory), cl::sub(PrettySubcommand));
128*9880d681SAndroid Build Coastguard Worker
129*9880d681SAndroid Build Coastguard Worker cl::opt<uint64_t> LoadAddress(
130*9880d681SAndroid Build Coastguard Worker "load-address",
131*9880d681SAndroid Build Coastguard Worker cl::desc("Assume the module is loaded at the specified address"),
132*9880d681SAndroid Build Coastguard Worker cl::cat(OtherOptions), cl::sub(PrettySubcommand));
133*9880d681SAndroid Build Coastguard Worker cl::list<std::string> ExcludeTypes(
134*9880d681SAndroid Build Coastguard Worker "exclude-types", cl::desc("Exclude types by regular expression"),
135*9880d681SAndroid Build Coastguard Worker cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
136*9880d681SAndroid Build Coastguard Worker cl::list<std::string> ExcludeSymbols(
137*9880d681SAndroid Build Coastguard Worker "exclude-symbols", cl::desc("Exclude symbols by regular expression"),
138*9880d681SAndroid Build Coastguard Worker cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
139*9880d681SAndroid Build Coastguard Worker cl::list<std::string> ExcludeCompilands(
140*9880d681SAndroid Build Coastguard Worker "exclude-compilands", cl::desc("Exclude compilands by regular expression"),
141*9880d681SAndroid Build Coastguard Worker cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
142*9880d681SAndroid Build Coastguard Worker
143*9880d681SAndroid Build Coastguard Worker cl::list<std::string> IncludeTypes(
144*9880d681SAndroid Build Coastguard Worker "include-types",
145*9880d681SAndroid Build Coastguard Worker cl::desc("Include only types which match a regular expression"),
146*9880d681SAndroid Build Coastguard Worker cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
147*9880d681SAndroid Build Coastguard Worker cl::list<std::string> IncludeSymbols(
148*9880d681SAndroid Build Coastguard Worker "include-symbols",
149*9880d681SAndroid Build Coastguard Worker cl::desc("Include only symbols which match a regular expression"),
150*9880d681SAndroid Build Coastguard Worker cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
151*9880d681SAndroid Build Coastguard Worker cl::list<std::string> IncludeCompilands(
152*9880d681SAndroid Build Coastguard Worker "include-compilands",
153*9880d681SAndroid Build Coastguard Worker cl::desc("Include only compilands those which match a regular expression"),
154*9880d681SAndroid Build Coastguard Worker cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
155*9880d681SAndroid Build Coastguard Worker
156*9880d681SAndroid Build Coastguard Worker cl::opt<bool> ExcludeCompilerGenerated(
157*9880d681SAndroid Build Coastguard Worker "no-compiler-generated",
158*9880d681SAndroid Build Coastguard Worker cl::desc("Don't show compiler generated types and symbols"),
159*9880d681SAndroid Build Coastguard Worker cl::cat(FilterCategory), cl::sub(PrettySubcommand));
160*9880d681SAndroid Build Coastguard Worker cl::opt<bool>
161*9880d681SAndroid Build Coastguard Worker ExcludeSystemLibraries("no-system-libs",
162*9880d681SAndroid Build Coastguard Worker cl::desc("Don't show symbols from system libraries"),
163*9880d681SAndroid Build Coastguard Worker cl::cat(FilterCategory), cl::sub(PrettySubcommand));
164*9880d681SAndroid Build Coastguard Worker cl::opt<bool> NoClassDefs("no-class-definitions",
165*9880d681SAndroid Build Coastguard Worker cl::desc("Don't display full class definitions"),
166*9880d681SAndroid Build Coastguard Worker cl::cat(FilterCategory), cl::sub(PrettySubcommand));
167*9880d681SAndroid Build Coastguard Worker cl::opt<bool> NoEnumDefs("no-enum-definitions",
168*9880d681SAndroid Build Coastguard Worker cl::desc("Don't display full enum definitions"),
169*9880d681SAndroid Build Coastguard Worker cl::cat(FilterCategory), cl::sub(PrettySubcommand));
170*9880d681SAndroid Build Coastguard Worker }
171*9880d681SAndroid Build Coastguard Worker
172*9880d681SAndroid Build Coastguard Worker namespace raw {
173*9880d681SAndroid Build Coastguard Worker
174*9880d681SAndroid Build Coastguard Worker cl::OptionCategory MsfOptions("MSF Container Options");
175*9880d681SAndroid Build Coastguard Worker cl::OptionCategory TypeOptions("Type Record Options");
176*9880d681SAndroid Build Coastguard Worker cl::OptionCategory FileOptions("Module & File Options");
177*9880d681SAndroid Build Coastguard Worker cl::OptionCategory SymbolOptions("Symbol Options");
178*9880d681SAndroid Build Coastguard Worker cl::OptionCategory MiscOptions("Miscellaneous Options");
179*9880d681SAndroid Build Coastguard Worker
180*9880d681SAndroid Build Coastguard Worker // MSF OPTIONS
181*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DumpHeaders("headers", cl::desc("dump PDB headers"),
182*9880d681SAndroid Build Coastguard Worker cl::cat(MsfOptions), cl::sub(RawSubcommand));
183*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DumpStreamBlocks("stream-blocks",
184*9880d681SAndroid Build Coastguard Worker cl::desc("dump PDB stream blocks"),
185*9880d681SAndroid Build Coastguard Worker cl::cat(MsfOptions), cl::sub(RawSubcommand));
186*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DumpStreamSummary("stream-summary",
187*9880d681SAndroid Build Coastguard Worker cl::desc("dump summary of the PDB streams"),
188*9880d681SAndroid Build Coastguard Worker cl::cat(MsfOptions), cl::sub(RawSubcommand));
189*9880d681SAndroid Build Coastguard Worker
190*9880d681SAndroid Build Coastguard Worker // TYPE OPTIONS
191*9880d681SAndroid Build Coastguard Worker cl::opt<bool>
192*9880d681SAndroid Build Coastguard Worker DumpTpiRecords("tpi-records",
193*9880d681SAndroid Build Coastguard Worker cl::desc("dump CodeView type records from TPI stream"),
194*9880d681SAndroid Build Coastguard Worker cl::cat(TypeOptions), cl::sub(RawSubcommand));
195*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DumpTpiRecordBytes(
196*9880d681SAndroid Build Coastguard Worker "tpi-record-bytes",
197*9880d681SAndroid Build Coastguard Worker cl::desc("dump CodeView type record raw bytes from TPI stream"),
198*9880d681SAndroid Build Coastguard Worker cl::cat(TypeOptions), cl::sub(RawSubcommand));
199*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DumpTpiHash("tpi-hash", cl::desc("dump CodeView TPI hash stream"),
200*9880d681SAndroid Build Coastguard Worker cl::cat(TypeOptions), cl::sub(RawSubcommand));
201*9880d681SAndroid Build Coastguard Worker cl::opt<bool>
202*9880d681SAndroid Build Coastguard Worker DumpIpiRecords("ipi-records",
203*9880d681SAndroid Build Coastguard Worker cl::desc("dump CodeView type records from IPI stream"),
204*9880d681SAndroid Build Coastguard Worker cl::cat(TypeOptions), cl::sub(RawSubcommand));
205*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DumpIpiRecordBytes(
206*9880d681SAndroid Build Coastguard Worker "ipi-record-bytes",
207*9880d681SAndroid Build Coastguard Worker cl::desc("dump CodeView type record raw bytes from IPI stream"),
208*9880d681SAndroid Build Coastguard Worker cl::cat(TypeOptions), cl::sub(RawSubcommand));
209*9880d681SAndroid Build Coastguard Worker
210*9880d681SAndroid Build Coastguard Worker // MODULE & FILE OPTIONS
211*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DumpModules("modules", cl::desc("dump compiland information"),
212*9880d681SAndroid Build Coastguard Worker cl::cat(FileOptions), cl::sub(RawSubcommand));
213*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DumpModuleFiles("module-files", cl::desc("dump file information"),
214*9880d681SAndroid Build Coastguard Worker cl::cat(FileOptions), cl::sub(RawSubcommand));
215*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DumpLineInfo("line-info",
216*9880d681SAndroid Build Coastguard Worker cl::desc("dump file and line information"),
217*9880d681SAndroid Build Coastguard Worker cl::cat(FileOptions), cl::sub(RawSubcommand));
218*9880d681SAndroid Build Coastguard Worker
219*9880d681SAndroid Build Coastguard Worker // SYMBOL OPTIONS
220*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DumpModuleSyms("module-syms", cl::desc("dump module symbols"),
221*9880d681SAndroid Build Coastguard Worker cl::cat(SymbolOptions), cl::sub(RawSubcommand));
222*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DumpPublics("publics", cl::desc("dump Publics stream data"),
223*9880d681SAndroid Build Coastguard Worker cl::cat(SymbolOptions), cl::sub(RawSubcommand));
224*9880d681SAndroid Build Coastguard Worker cl::opt<bool>
225*9880d681SAndroid Build Coastguard Worker DumpSymRecordBytes("sym-record-bytes",
226*9880d681SAndroid Build Coastguard Worker cl::desc("dump CodeView symbol record raw bytes"),
227*9880d681SAndroid Build Coastguard Worker cl::cat(SymbolOptions), cl::sub(RawSubcommand));
228*9880d681SAndroid Build Coastguard Worker
229*9880d681SAndroid Build Coastguard Worker // MISCELLANEOUS OPTIONS
230*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DumpSectionContribs("section-contribs",
231*9880d681SAndroid Build Coastguard Worker cl::desc("dump section contributions"),
232*9880d681SAndroid Build Coastguard Worker cl::cat(MiscOptions), cl::sub(RawSubcommand));
233*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DumpSectionMap("section-map", cl::desc("dump section map"),
234*9880d681SAndroid Build Coastguard Worker cl::cat(MiscOptions), cl::sub(RawSubcommand));
235*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DumpSectionHeaders("section-headers",
236*9880d681SAndroid Build Coastguard Worker cl::desc("dump section headers"),
237*9880d681SAndroid Build Coastguard Worker cl::cat(MiscOptions), cl::sub(RawSubcommand));
238*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DumpFpo("fpo", cl::desc("dump FPO records"), cl::cat(MiscOptions),
239*9880d681SAndroid Build Coastguard Worker cl::sub(RawSubcommand));
240*9880d681SAndroid Build Coastguard Worker
241*9880d681SAndroid Build Coastguard Worker cl::opt<std::string> DumpStreamDataIdx("stream", cl::desc("dump stream data"),
242*9880d681SAndroid Build Coastguard Worker cl::cat(MiscOptions),
243*9880d681SAndroid Build Coastguard Worker cl::sub(RawSubcommand));
244*9880d681SAndroid Build Coastguard Worker cl::opt<std::string> DumpStreamDataName("stream-name",
245*9880d681SAndroid Build Coastguard Worker cl::desc("dump stream data"),
246*9880d681SAndroid Build Coastguard Worker cl::cat(MiscOptions),
247*9880d681SAndroid Build Coastguard Worker cl::sub(RawSubcommand));
248*9880d681SAndroid Build Coastguard Worker
249*9880d681SAndroid Build Coastguard Worker cl::opt<bool> RawAll("all", cl::desc("Implies most other options."),
250*9880d681SAndroid Build Coastguard Worker cl::cat(MiscOptions), cl::sub(RawSubcommand));
251*9880d681SAndroid Build Coastguard Worker
252*9880d681SAndroid Build Coastguard Worker cl::list<std::string> InputFilenames(cl::Positional,
253*9880d681SAndroid Build Coastguard Worker cl::desc("<input PDB files>"),
254*9880d681SAndroid Build Coastguard Worker cl::OneOrMore, cl::sub(RawSubcommand));
255*9880d681SAndroid Build Coastguard Worker }
256*9880d681SAndroid Build Coastguard Worker
257*9880d681SAndroid Build Coastguard Worker namespace yaml2pdb {
258*9880d681SAndroid Build Coastguard Worker cl::opt<std::string>
259*9880d681SAndroid Build Coastguard Worker YamlPdbOutputFile("pdb", cl::desc("the name of the PDB file to write"),
260*9880d681SAndroid Build Coastguard Worker cl::sub(YamlToPdbSubcommand));
261*9880d681SAndroid Build Coastguard Worker
262*9880d681SAndroid Build Coastguard Worker cl::list<std::string> InputFilename(cl::Positional,
263*9880d681SAndroid Build Coastguard Worker cl::desc("<input YAML file>"), cl::Required,
264*9880d681SAndroid Build Coastguard Worker cl::sub(YamlToPdbSubcommand));
265*9880d681SAndroid Build Coastguard Worker }
266*9880d681SAndroid Build Coastguard Worker
267*9880d681SAndroid Build Coastguard Worker namespace pdb2yaml {
268*9880d681SAndroid Build Coastguard Worker cl::opt<bool>
269*9880d681SAndroid Build Coastguard Worker NoFileHeaders("no-file-headers",
270*9880d681SAndroid Build Coastguard Worker cl::desc("Do not dump MSF file headers (you will not be able "
271*9880d681SAndroid Build Coastguard Worker "to generate a fresh PDB from the resulting YAML)"),
272*9880d681SAndroid Build Coastguard Worker cl::sub(PdbToYamlSubcommand), cl::init(false));
273*9880d681SAndroid Build Coastguard Worker
274*9880d681SAndroid Build Coastguard Worker cl::opt<bool> StreamMetadata(
275*9880d681SAndroid Build Coastguard Worker "stream-metadata",
276*9880d681SAndroid Build Coastguard Worker cl::desc("Dump the number of streams and each stream's size"),
277*9880d681SAndroid Build Coastguard Worker cl::sub(PdbToYamlSubcommand), cl::init(false));
278*9880d681SAndroid Build Coastguard Worker cl::opt<bool> StreamDirectory(
279*9880d681SAndroid Build Coastguard Worker "stream-directory",
280*9880d681SAndroid Build Coastguard Worker cl::desc("Dump each stream's block map (implies -stream-metadata)"),
281*9880d681SAndroid Build Coastguard Worker cl::sub(PdbToYamlSubcommand), cl::init(false));
282*9880d681SAndroid Build Coastguard Worker cl::opt<bool> PdbStream(
283*9880d681SAndroid Build Coastguard Worker "pdb-stream",
284*9880d681SAndroid Build Coastguard Worker cl::desc("Dump the PDB Stream (Stream 1) (implies -stream-metadata)"),
285*9880d681SAndroid Build Coastguard Worker cl::sub(PdbToYamlSubcommand), cl::init(false));
286*9880d681SAndroid Build Coastguard Worker cl::opt<bool> DbiStream(
287*9880d681SAndroid Build Coastguard Worker "dbi-stream",
288*9880d681SAndroid Build Coastguard Worker cl::desc("Dump the DBI Stream (Stream 2) (implies -stream-metadata)"),
289*9880d681SAndroid Build Coastguard Worker cl::sub(PdbToYamlSubcommand), cl::init(false));
290*9880d681SAndroid Build Coastguard Worker
291*9880d681SAndroid Build Coastguard Worker cl::list<std::string> InputFilename(cl::Positional,
292*9880d681SAndroid Build Coastguard Worker cl::desc("<input PDB file>"), cl::Required,
293*9880d681SAndroid Build Coastguard Worker cl::sub(PdbToYamlSubcommand));
294*9880d681SAndroid Build Coastguard Worker }
295*9880d681SAndroid Build Coastguard Worker }
296*9880d681SAndroid Build Coastguard Worker
297*9880d681SAndroid Build Coastguard Worker static ExitOnError ExitOnErr;
298*9880d681SAndroid Build Coastguard Worker
yamlToPdb(StringRef Path)299*9880d681SAndroid Build Coastguard Worker static void yamlToPdb(StringRef Path) {
300*9880d681SAndroid Build Coastguard Worker ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
301*9880d681SAndroid Build Coastguard Worker MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
302*9880d681SAndroid Build Coastguard Worker /*RequiresNullTerminator=*/false);
303*9880d681SAndroid Build Coastguard Worker
304*9880d681SAndroid Build Coastguard Worker if (ErrorOrBuffer.getError()) {
305*9880d681SAndroid Build Coastguard Worker ExitOnErr(make_error<GenericError>(generic_error_code::invalid_path, Path));
306*9880d681SAndroid Build Coastguard Worker }
307*9880d681SAndroid Build Coastguard Worker
308*9880d681SAndroid Build Coastguard Worker std::unique_ptr<MemoryBuffer> &Buffer = ErrorOrBuffer.get();
309*9880d681SAndroid Build Coastguard Worker
310*9880d681SAndroid Build Coastguard Worker llvm::yaml::Input In(Buffer->getBuffer());
311*9880d681SAndroid Build Coastguard Worker pdb::yaml::PdbObject YamlObj;
312*9880d681SAndroid Build Coastguard Worker In >> YamlObj;
313*9880d681SAndroid Build Coastguard Worker if (!YamlObj.Headers.hasValue())
314*9880d681SAndroid Build Coastguard Worker ExitOnErr(make_error<GenericError>(generic_error_code::unspecified,
315*9880d681SAndroid Build Coastguard Worker "Yaml does not contain MSF headers"));
316*9880d681SAndroid Build Coastguard Worker
317*9880d681SAndroid Build Coastguard Worker auto OutFileOrError = FileOutputBuffer::create(
318*9880d681SAndroid Build Coastguard Worker opts::yaml2pdb::YamlPdbOutputFile, YamlObj.Headers->FileSize);
319*9880d681SAndroid Build Coastguard Worker if (OutFileOrError.getError())
320*9880d681SAndroid Build Coastguard Worker ExitOnErr(make_error<GenericError>(generic_error_code::invalid_path,
321*9880d681SAndroid Build Coastguard Worker opts::yaml2pdb::YamlPdbOutputFile));
322*9880d681SAndroid Build Coastguard Worker
323*9880d681SAndroid Build Coastguard Worker auto FileByteStream =
324*9880d681SAndroid Build Coastguard Worker llvm::make_unique<FileBufferByteStream>(std::move(*OutFileOrError));
325*9880d681SAndroid Build Coastguard Worker PDBFileBuilder Builder(std::move(FileByteStream));
326*9880d681SAndroid Build Coastguard Worker
327*9880d681SAndroid Build Coastguard Worker ExitOnErr(Builder.setSuperBlock(YamlObj.Headers->SuperBlock));
328*9880d681SAndroid Build Coastguard Worker if (YamlObj.StreamSizes.hasValue()) {
329*9880d681SAndroid Build Coastguard Worker Builder.setStreamSizes(YamlObj.StreamSizes.getValue());
330*9880d681SAndroid Build Coastguard Worker }
331*9880d681SAndroid Build Coastguard Worker Builder.setDirectoryBlocks(YamlObj.Headers->DirectoryBlocks);
332*9880d681SAndroid Build Coastguard Worker
333*9880d681SAndroid Build Coastguard Worker if (YamlObj.StreamMap.hasValue()) {
334*9880d681SAndroid Build Coastguard Worker std::vector<ArrayRef<support::ulittle32_t>> StreamMap;
335*9880d681SAndroid Build Coastguard Worker for (auto &E : YamlObj.StreamMap.getValue()) {
336*9880d681SAndroid Build Coastguard Worker StreamMap.push_back(E.Blocks);
337*9880d681SAndroid Build Coastguard Worker }
338*9880d681SAndroid Build Coastguard Worker Builder.setStreamMap(StreamMap);
339*9880d681SAndroid Build Coastguard Worker } else {
340*9880d681SAndroid Build Coastguard Worker ExitOnErr(Builder.generateSimpleStreamMap());
341*9880d681SAndroid Build Coastguard Worker }
342*9880d681SAndroid Build Coastguard Worker
343*9880d681SAndroid Build Coastguard Worker if (YamlObj.PdbStream.hasValue()) {
344*9880d681SAndroid Build Coastguard Worker auto &InfoBuilder = Builder.getInfoBuilder();
345*9880d681SAndroid Build Coastguard Worker InfoBuilder.setAge(YamlObj.PdbStream->Age);
346*9880d681SAndroid Build Coastguard Worker InfoBuilder.setGuid(YamlObj.PdbStream->Guid);
347*9880d681SAndroid Build Coastguard Worker InfoBuilder.setSignature(YamlObj.PdbStream->Signature);
348*9880d681SAndroid Build Coastguard Worker InfoBuilder.setVersion(YamlObj.PdbStream->Version);
349*9880d681SAndroid Build Coastguard Worker }
350*9880d681SAndroid Build Coastguard Worker
351*9880d681SAndroid Build Coastguard Worker if (YamlObj.DbiStream.hasValue()) {
352*9880d681SAndroid Build Coastguard Worker auto &DbiBuilder = Builder.getDbiBuilder();
353*9880d681SAndroid Build Coastguard Worker DbiBuilder.setAge(YamlObj.DbiStream->Age);
354*9880d681SAndroid Build Coastguard Worker DbiBuilder.setBuildNumber(YamlObj.DbiStream->BuildNumber);
355*9880d681SAndroid Build Coastguard Worker DbiBuilder.setFlags(YamlObj.DbiStream->Flags);
356*9880d681SAndroid Build Coastguard Worker DbiBuilder.setMachineType(YamlObj.DbiStream->MachineType);
357*9880d681SAndroid Build Coastguard Worker DbiBuilder.setPdbDllRbld(YamlObj.DbiStream->PdbDllRbld);
358*9880d681SAndroid Build Coastguard Worker DbiBuilder.setPdbDllVersion(YamlObj.DbiStream->PdbDllVersion);
359*9880d681SAndroid Build Coastguard Worker DbiBuilder.setVersionHeader(YamlObj.DbiStream->VerHeader);
360*9880d681SAndroid Build Coastguard Worker }
361*9880d681SAndroid Build Coastguard Worker
362*9880d681SAndroid Build Coastguard Worker auto Pdb = Builder.build();
363*9880d681SAndroid Build Coastguard Worker ExitOnErr(Pdb.takeError());
364*9880d681SAndroid Build Coastguard Worker
365*9880d681SAndroid Build Coastguard Worker auto &PdbFile = *Pdb;
366*9880d681SAndroid Build Coastguard Worker ExitOnErr(PdbFile->commit());
367*9880d681SAndroid Build Coastguard Worker }
368*9880d681SAndroid Build Coastguard Worker
pdb2Yaml(StringRef Path)369*9880d681SAndroid Build Coastguard Worker static void pdb2Yaml(StringRef Path) {
370*9880d681SAndroid Build Coastguard Worker std::unique_ptr<IPDBSession> Session;
371*9880d681SAndroid Build Coastguard Worker ExitOnErr(loadDataForPDB(PDB_ReaderType::Raw, Path, Session));
372*9880d681SAndroid Build Coastguard Worker
373*9880d681SAndroid Build Coastguard Worker RawSession *RS = static_cast<RawSession *>(Session.get());
374*9880d681SAndroid Build Coastguard Worker PDBFile &File = RS->getPDBFile();
375*9880d681SAndroid Build Coastguard Worker auto O = llvm::make_unique<YAMLOutputStyle>(File);
376*9880d681SAndroid Build Coastguard Worker O = llvm::make_unique<YAMLOutputStyle>(File);
377*9880d681SAndroid Build Coastguard Worker
378*9880d681SAndroid Build Coastguard Worker ExitOnErr(O->dump());
379*9880d681SAndroid Build Coastguard Worker }
380*9880d681SAndroid Build Coastguard Worker
dumpRaw(StringRef Path)381*9880d681SAndroid Build Coastguard Worker static void dumpRaw(StringRef Path) {
382*9880d681SAndroid Build Coastguard Worker std::unique_ptr<IPDBSession> Session;
383*9880d681SAndroid Build Coastguard Worker ExitOnErr(loadDataForPDB(PDB_ReaderType::Raw, Path, Session));
384*9880d681SAndroid Build Coastguard Worker
385*9880d681SAndroid Build Coastguard Worker RawSession *RS = static_cast<RawSession *>(Session.get());
386*9880d681SAndroid Build Coastguard Worker PDBFile &File = RS->getPDBFile();
387*9880d681SAndroid Build Coastguard Worker auto O = llvm::make_unique<LLVMOutputStyle>(File);
388*9880d681SAndroid Build Coastguard Worker
389*9880d681SAndroid Build Coastguard Worker ExitOnErr(O->dump());
390*9880d681SAndroid Build Coastguard Worker }
391*9880d681SAndroid Build Coastguard Worker
dumpPretty(StringRef Path)392*9880d681SAndroid Build Coastguard Worker static void dumpPretty(StringRef Path) {
393*9880d681SAndroid Build Coastguard Worker std::unique_ptr<IPDBSession> Session;
394*9880d681SAndroid Build Coastguard Worker
395*9880d681SAndroid Build Coastguard Worker ExitOnErr(loadDataForPDB(PDB_ReaderType::DIA, Path, Session));
396*9880d681SAndroid Build Coastguard Worker
397*9880d681SAndroid Build Coastguard Worker if (opts::pretty::LoadAddress)
398*9880d681SAndroid Build Coastguard Worker Session->setLoadAddress(opts::pretty::LoadAddress);
399*9880d681SAndroid Build Coastguard Worker
400*9880d681SAndroid Build Coastguard Worker LinePrinter Printer(2, outs());
401*9880d681SAndroid Build Coastguard Worker
402*9880d681SAndroid Build Coastguard Worker auto GlobalScope(Session->getGlobalScope());
403*9880d681SAndroid Build Coastguard Worker std::string FileName(GlobalScope->getSymbolsFileName());
404*9880d681SAndroid Build Coastguard Worker
405*9880d681SAndroid Build Coastguard Worker WithColor(Printer, PDB_ColorItem::None).get() << "Summary for ";
406*9880d681SAndroid Build Coastguard Worker WithColor(Printer, PDB_ColorItem::Path).get() << FileName;
407*9880d681SAndroid Build Coastguard Worker Printer.Indent();
408*9880d681SAndroid Build Coastguard Worker uint64_t FileSize = 0;
409*9880d681SAndroid Build Coastguard Worker
410*9880d681SAndroid Build Coastguard Worker Printer.NewLine();
411*9880d681SAndroid Build Coastguard Worker WithColor(Printer, PDB_ColorItem::Identifier).get() << "Size";
412*9880d681SAndroid Build Coastguard Worker if (!sys::fs::file_size(FileName, FileSize)) {
413*9880d681SAndroid Build Coastguard Worker Printer << ": " << FileSize << " bytes";
414*9880d681SAndroid Build Coastguard Worker } else {
415*9880d681SAndroid Build Coastguard Worker Printer << ": (Unable to obtain file size)";
416*9880d681SAndroid Build Coastguard Worker }
417*9880d681SAndroid Build Coastguard Worker
418*9880d681SAndroid Build Coastguard Worker Printer.NewLine();
419*9880d681SAndroid Build Coastguard Worker WithColor(Printer, PDB_ColorItem::Identifier).get() << "Guid";
420*9880d681SAndroid Build Coastguard Worker Printer << ": " << GlobalScope->getGuid();
421*9880d681SAndroid Build Coastguard Worker
422*9880d681SAndroid Build Coastguard Worker Printer.NewLine();
423*9880d681SAndroid Build Coastguard Worker WithColor(Printer, PDB_ColorItem::Identifier).get() << "Age";
424*9880d681SAndroid Build Coastguard Worker Printer << ": " << GlobalScope->getAge();
425*9880d681SAndroid Build Coastguard Worker
426*9880d681SAndroid Build Coastguard Worker Printer.NewLine();
427*9880d681SAndroid Build Coastguard Worker WithColor(Printer, PDB_ColorItem::Identifier).get() << "Attributes";
428*9880d681SAndroid Build Coastguard Worker Printer << ": ";
429*9880d681SAndroid Build Coastguard Worker if (GlobalScope->hasCTypes())
430*9880d681SAndroid Build Coastguard Worker outs() << "HasCTypes ";
431*9880d681SAndroid Build Coastguard Worker if (GlobalScope->hasPrivateSymbols())
432*9880d681SAndroid Build Coastguard Worker outs() << "HasPrivateSymbols ";
433*9880d681SAndroid Build Coastguard Worker Printer.Unindent();
434*9880d681SAndroid Build Coastguard Worker
435*9880d681SAndroid Build Coastguard Worker if (opts::pretty::Compilands) {
436*9880d681SAndroid Build Coastguard Worker Printer.NewLine();
437*9880d681SAndroid Build Coastguard Worker WithColor(Printer, PDB_ColorItem::SectionHeader).get()
438*9880d681SAndroid Build Coastguard Worker << "---COMPILANDS---";
439*9880d681SAndroid Build Coastguard Worker Printer.Indent();
440*9880d681SAndroid Build Coastguard Worker auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
441*9880d681SAndroid Build Coastguard Worker CompilandDumper Dumper(Printer);
442*9880d681SAndroid Build Coastguard Worker CompilandDumpFlags options = CompilandDumper::Flags::None;
443*9880d681SAndroid Build Coastguard Worker if (opts::pretty::Lines)
444*9880d681SAndroid Build Coastguard Worker options = options | CompilandDumper::Flags::Lines;
445*9880d681SAndroid Build Coastguard Worker while (auto Compiland = Compilands->getNext())
446*9880d681SAndroid Build Coastguard Worker Dumper.start(*Compiland, options);
447*9880d681SAndroid Build Coastguard Worker Printer.Unindent();
448*9880d681SAndroid Build Coastguard Worker }
449*9880d681SAndroid Build Coastguard Worker
450*9880d681SAndroid Build Coastguard Worker if (opts::pretty::Types) {
451*9880d681SAndroid Build Coastguard Worker Printer.NewLine();
452*9880d681SAndroid Build Coastguard Worker WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---";
453*9880d681SAndroid Build Coastguard Worker Printer.Indent();
454*9880d681SAndroid Build Coastguard Worker TypeDumper Dumper(Printer);
455*9880d681SAndroid Build Coastguard Worker Dumper.start(*GlobalScope);
456*9880d681SAndroid Build Coastguard Worker Printer.Unindent();
457*9880d681SAndroid Build Coastguard Worker }
458*9880d681SAndroid Build Coastguard Worker
459*9880d681SAndroid Build Coastguard Worker if (opts::pretty::Symbols) {
460*9880d681SAndroid Build Coastguard Worker Printer.NewLine();
461*9880d681SAndroid Build Coastguard Worker WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---SYMBOLS---";
462*9880d681SAndroid Build Coastguard Worker Printer.Indent();
463*9880d681SAndroid Build Coastguard Worker auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
464*9880d681SAndroid Build Coastguard Worker CompilandDumper Dumper(Printer);
465*9880d681SAndroid Build Coastguard Worker while (auto Compiland = Compilands->getNext())
466*9880d681SAndroid Build Coastguard Worker Dumper.start(*Compiland, true);
467*9880d681SAndroid Build Coastguard Worker Printer.Unindent();
468*9880d681SAndroid Build Coastguard Worker }
469*9880d681SAndroid Build Coastguard Worker
470*9880d681SAndroid Build Coastguard Worker if (opts::pretty::Globals) {
471*9880d681SAndroid Build Coastguard Worker Printer.NewLine();
472*9880d681SAndroid Build Coastguard Worker WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---GLOBALS---";
473*9880d681SAndroid Build Coastguard Worker Printer.Indent();
474*9880d681SAndroid Build Coastguard Worker {
475*9880d681SAndroid Build Coastguard Worker FunctionDumper Dumper(Printer);
476*9880d681SAndroid Build Coastguard Worker auto Functions = GlobalScope->findAllChildren<PDBSymbolFunc>();
477*9880d681SAndroid Build Coastguard Worker while (auto Function = Functions->getNext()) {
478*9880d681SAndroid Build Coastguard Worker Printer.NewLine();
479*9880d681SAndroid Build Coastguard Worker Dumper.start(*Function, FunctionDumper::PointerType::None);
480*9880d681SAndroid Build Coastguard Worker }
481*9880d681SAndroid Build Coastguard Worker }
482*9880d681SAndroid Build Coastguard Worker {
483*9880d681SAndroid Build Coastguard Worker auto Vars = GlobalScope->findAllChildren<PDBSymbolData>();
484*9880d681SAndroid Build Coastguard Worker VariableDumper Dumper(Printer);
485*9880d681SAndroid Build Coastguard Worker while (auto Var = Vars->getNext())
486*9880d681SAndroid Build Coastguard Worker Dumper.start(*Var);
487*9880d681SAndroid Build Coastguard Worker }
488*9880d681SAndroid Build Coastguard Worker {
489*9880d681SAndroid Build Coastguard Worker auto Thunks = GlobalScope->findAllChildren<PDBSymbolThunk>();
490*9880d681SAndroid Build Coastguard Worker CompilandDumper Dumper(Printer);
491*9880d681SAndroid Build Coastguard Worker while (auto Thunk = Thunks->getNext())
492*9880d681SAndroid Build Coastguard Worker Dumper.dump(*Thunk);
493*9880d681SAndroid Build Coastguard Worker }
494*9880d681SAndroid Build Coastguard Worker Printer.Unindent();
495*9880d681SAndroid Build Coastguard Worker }
496*9880d681SAndroid Build Coastguard Worker if (opts::pretty::Externals) {
497*9880d681SAndroid Build Coastguard Worker Printer.NewLine();
498*9880d681SAndroid Build Coastguard Worker WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---EXTERNALS---";
499*9880d681SAndroid Build Coastguard Worker Printer.Indent();
500*9880d681SAndroid Build Coastguard Worker ExternalSymbolDumper Dumper(Printer);
501*9880d681SAndroid Build Coastguard Worker Dumper.start(*GlobalScope);
502*9880d681SAndroid Build Coastguard Worker }
503*9880d681SAndroid Build Coastguard Worker if (opts::pretty::Lines) {
504*9880d681SAndroid Build Coastguard Worker Printer.NewLine();
505*9880d681SAndroid Build Coastguard Worker }
506*9880d681SAndroid Build Coastguard Worker outs().flush();
507*9880d681SAndroid Build Coastguard Worker }
508*9880d681SAndroid Build Coastguard Worker
main(int argc_,const char * argv_[])509*9880d681SAndroid Build Coastguard Worker int main(int argc_, const char *argv_[]) {
510*9880d681SAndroid Build Coastguard Worker // Print a stack trace if we signal out.
511*9880d681SAndroid Build Coastguard Worker sys::PrintStackTraceOnErrorSignal(argv_[0]);
512*9880d681SAndroid Build Coastguard Worker PrettyStackTraceProgram X(argc_, argv_);
513*9880d681SAndroid Build Coastguard Worker
514*9880d681SAndroid Build Coastguard Worker ExitOnErr.setBanner("llvm-pdbdump: ");
515*9880d681SAndroid Build Coastguard Worker
516*9880d681SAndroid Build Coastguard Worker SmallVector<const char *, 256> argv;
517*9880d681SAndroid Build Coastguard Worker SpecificBumpPtrAllocator<char> ArgAllocator;
518*9880d681SAndroid Build Coastguard Worker ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector(
519*9880d681SAndroid Build Coastguard Worker argv, makeArrayRef(argv_, argc_), ArgAllocator)));
520*9880d681SAndroid Build Coastguard Worker
521*9880d681SAndroid Build Coastguard Worker llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
522*9880d681SAndroid Build Coastguard Worker
523*9880d681SAndroid Build Coastguard Worker cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n");
524*9880d681SAndroid Build Coastguard Worker
525*9880d681SAndroid Build Coastguard Worker // These options are shared by two subcommands.
526*9880d681SAndroid Build Coastguard Worker if ((opts::PdbToYamlSubcommand || opts::RawSubcommand) && opts::raw::RawAll) {
527*9880d681SAndroid Build Coastguard Worker opts::raw::DumpHeaders = true;
528*9880d681SAndroid Build Coastguard Worker opts::raw::DumpModules = true;
529*9880d681SAndroid Build Coastguard Worker opts::raw::DumpModuleFiles = true;
530*9880d681SAndroid Build Coastguard Worker opts::raw::DumpModuleSyms = true;
531*9880d681SAndroid Build Coastguard Worker opts::raw::DumpPublics = true;
532*9880d681SAndroid Build Coastguard Worker opts::raw::DumpSectionHeaders = true;
533*9880d681SAndroid Build Coastguard Worker opts::raw::DumpStreamSummary = true;
534*9880d681SAndroid Build Coastguard Worker opts::raw::DumpStreamBlocks = true;
535*9880d681SAndroid Build Coastguard Worker opts::raw::DumpTpiRecords = true;
536*9880d681SAndroid Build Coastguard Worker opts::raw::DumpTpiHash = true;
537*9880d681SAndroid Build Coastguard Worker opts::raw::DumpIpiRecords = true;
538*9880d681SAndroid Build Coastguard Worker opts::raw::DumpSectionMap = true;
539*9880d681SAndroid Build Coastguard Worker opts::raw::DumpSectionContribs = true;
540*9880d681SAndroid Build Coastguard Worker opts::raw::DumpLineInfo = true;
541*9880d681SAndroid Build Coastguard Worker opts::raw::DumpFpo = true;
542*9880d681SAndroid Build Coastguard Worker }
543*9880d681SAndroid Build Coastguard Worker
544*9880d681SAndroid Build Coastguard Worker llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
545*9880d681SAndroid Build Coastguard Worker
546*9880d681SAndroid Build Coastguard Worker if (opts::PdbToYamlSubcommand) {
547*9880d681SAndroid Build Coastguard Worker pdb2Yaml(opts::pdb2yaml::InputFilename.front());
548*9880d681SAndroid Build Coastguard Worker } else if (opts::YamlToPdbSubcommand) {
549*9880d681SAndroid Build Coastguard Worker yamlToPdb(opts::yaml2pdb::InputFilename.front());
550*9880d681SAndroid Build Coastguard Worker } else if (opts::PrettySubcommand) {
551*9880d681SAndroid Build Coastguard Worker if (opts::pretty::Lines)
552*9880d681SAndroid Build Coastguard Worker opts::pretty::Compilands = true;
553*9880d681SAndroid Build Coastguard Worker
554*9880d681SAndroid Build Coastguard Worker if (opts::pretty::All) {
555*9880d681SAndroid Build Coastguard Worker opts::pretty::Compilands = true;
556*9880d681SAndroid Build Coastguard Worker opts::pretty::Symbols = true;
557*9880d681SAndroid Build Coastguard Worker opts::pretty::Globals = true;
558*9880d681SAndroid Build Coastguard Worker opts::pretty::Types = true;
559*9880d681SAndroid Build Coastguard Worker opts::pretty::Externals = true;
560*9880d681SAndroid Build Coastguard Worker opts::pretty::Lines = true;
561*9880d681SAndroid Build Coastguard Worker }
562*9880d681SAndroid Build Coastguard Worker
563*9880d681SAndroid Build Coastguard Worker // When adding filters for excluded compilands and types, we need to
564*9880d681SAndroid Build Coastguard Worker // remember
565*9880d681SAndroid Build Coastguard Worker // that these are regexes. So special characters such as * and \ need to be
566*9880d681SAndroid Build Coastguard Worker // escaped in the regex. In the case of a literal \, this means it needs to
567*9880d681SAndroid Build Coastguard Worker // be escaped again in the C++. So matching a single \ in the input
568*9880d681SAndroid Build Coastguard Worker // requires
569*9880d681SAndroid Build Coastguard Worker // 4 \es in the C++.
570*9880d681SAndroid Build Coastguard Worker if (opts::pretty::ExcludeCompilerGenerated) {
571*9880d681SAndroid Build Coastguard Worker opts::pretty::ExcludeTypes.push_back("__vc_attributes");
572*9880d681SAndroid Build Coastguard Worker opts::pretty::ExcludeCompilands.push_back("\\* Linker \\*");
573*9880d681SAndroid Build Coastguard Worker }
574*9880d681SAndroid Build Coastguard Worker if (opts::pretty::ExcludeSystemLibraries) {
575*9880d681SAndroid Build Coastguard Worker opts::pretty::ExcludeCompilands.push_back(
576*9880d681SAndroid Build Coastguard Worker "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
577*9880d681SAndroid Build Coastguard Worker opts::pretty::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
578*9880d681SAndroid Build Coastguard Worker opts::pretty::ExcludeCompilands.push_back(
579*9880d681SAndroid Build Coastguard Worker "d:\\\\th.obj.x86fre\\\\minkernel");
580*9880d681SAndroid Build Coastguard Worker }
581*9880d681SAndroid Build Coastguard Worker std::for_each(opts::pretty::InputFilenames.begin(),
582*9880d681SAndroid Build Coastguard Worker opts::pretty::InputFilenames.end(), dumpPretty);
583*9880d681SAndroid Build Coastguard Worker } else if (opts::RawSubcommand) {
584*9880d681SAndroid Build Coastguard Worker std::for_each(opts::raw::InputFilenames.begin(),
585*9880d681SAndroid Build Coastguard Worker opts::raw::InputFilenames.end(), dumpRaw);
586*9880d681SAndroid Build Coastguard Worker }
587*9880d681SAndroid Build Coastguard Worker
588*9880d681SAndroid Build Coastguard Worker outs().flush();
589*9880d681SAndroid Build Coastguard Worker return 0;
590*9880d681SAndroid Build Coastguard Worker }
591