blob: 7c34cc6dc07c48bea827ac1aa8d92d8f6b62cdde [file] [log] [blame]
Zachary Turnerbd336e42017-06-09 20:46:17 +00001//===- llvm-pdbutil.cpp - Dump debug info from a PDB file -------*- C++ -*-===//
Zachary Turnerfcb14ad2015-01-27 20:46:21 +00002//
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//
Zachary Turner6ac232c2017-03-13 23:28:25 +000010// Dumps debug information present in PDB files.
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000011//
12//===----------------------------------------------------------------------===//
13
Zachary Turnerbd336e42017-06-09 20:46:17 +000014#include "llvm-pdbutil.h"
Zachary Turnerd50c0132017-02-01 18:30:22 +000015
16#include "Analyze.h"
Zachary Turner99402032017-06-22 20:58:11 +000017#include "BytesOutputStyle.h"
Zachary Turner7df69952017-06-22 20:57:39 +000018#include "DumpOutputStyle.h"
Zachary Turnerea40f402018-03-29 16:28:20 +000019#include "ExplainOutputStyle.h"
Zachary Turnerabb17cc2017-09-01 20:06:56 +000020#include "InputFile.h"
Zachary Turner2d11c202015-02-27 09:15:59 +000021#include "LinePrinter.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000022#include "OutputStyle.h"
Zachary Turner648bebd2018-07-06 21:01:42 +000023#include "PrettyClassDefinitionDumper.h"
Zachary Turnera9054dd2017-01-11 00:35:43 +000024#include "PrettyCompilandDumper.h"
Zachary Turner648bebd2018-07-06 21:01:42 +000025#include "PrettyEnumDumper.h"
Zachary Turnera9054dd2017-01-11 00:35:43 +000026#include "PrettyExternalSymbolDumper.h"
27#include "PrettyFunctionDumper.h"
28#include "PrettyTypeDumper.h"
Zachary Turner648bebd2018-07-06 21:01:42 +000029#include "PrettyTypedefDumper.h"
Zachary Turnera9054dd2017-01-11 00:35:43 +000030#include "PrettyVariableDumper.h"
Zachary Turner7120a472016-06-06 20:37:05 +000031#include "YAMLOutputStyle.h"
Zachary Turner9a818ad2015-02-22 22:03:38 +000032
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000033#include "llvm/ADT/ArrayRef.h"
David Majnemer6e081262015-10-15 01:27:19 +000034#include "llvm/ADT/BitVector.h"
35#include "llvm/ADT/DenseMap.h"
Zachary Turner8a2ebfb2017-05-01 23:27:42 +000036#include "llvm/ADT/STLExtras.h"
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000037#include "llvm/ADT/StringExtras.h"
Zachary Turnerabb17cc2017-09-01 20:06:56 +000038#include "llvm/BinaryFormat/Magic.h"
Zachary Turner8d7fa9b2015-02-10 22:47:14 +000039#include "llvm/Config/config.h"
Zachary Turnerca6dbf12017-11-30 18:39:50 +000040#include "llvm/DebugInfo/CodeView/AppendingTypeTableBuilder.h"
Zachary Turner8c099fe2017-05-30 16:36:15 +000041#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
42#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
43#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
Zachary Turner526f4f22017-05-19 19:26:58 +000044#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
Zachary Turnerca6dbf12017-11-30 18:39:50 +000045#include "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h"
Zachary Turnera8cfc292017-06-14 15:59:27 +000046#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
Zachary Turner8fb441a2017-05-18 23:03:41 +000047#include "llvm/DebugInfo/CodeView/TypeStreamMerger.h"
Zachary Turnera3225b02016-07-29 20:56:36 +000048#include "llvm/DebugInfo/MSF/MSFBuilder.h"
Zachary Turnera5549172015-02-10 22:43:25 +000049#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
Zachary Turner679aead2018-03-13 17:46:06 +000050#include "llvm/DebugInfo/PDB/IPDBInjectedSource.h"
Zachary Turnera5549172015-02-10 22:43:25 +000051#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
Chandler Carruth71f308a2015-02-13 09:09:03 +000052#include "llvm/DebugInfo/PDB/IPDBSession.h"
Zachary Turner67c56012017-04-27 16:11:19 +000053#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000054#include "llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h"
Zachary Turnerd11328a2018-04-02 18:35:21 +000055#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000056#include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h"
57#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
58#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
59#include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
Zachary Turnere204a6c2017-05-02 18:00:13 +000060#include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000061#include "llvm/DebugInfo/PDB/Native/RawConstants.h"
62#include "llvm/DebugInfo/PDB/Native/RawError.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000063#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
64#include "llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h"
Chandler Carruth71f308a2015-02-13 09:09:03 +000065#include "llvm/DebugInfo/PDB/PDB.h"
Zachary Turnera5549172015-02-10 22:43:25 +000066#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
Zachary Turnerdb18f5c2015-02-27 09:15:18 +000067#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
Chandler Carruth71f308a2015-02-13 09:09:03 +000068#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
Zachary Turnerdb18f5c2015-02-27 09:15:18 +000069#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
Zachary Turner648bebd2018-07-06 21:01:42 +000070#include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
Zachary Turnerdb18f5c2015-02-27 09:15:18 +000071#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
Zachary Turner648bebd2018-07-06 21:01:42 +000072#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
73#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
74#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
Zachary Turnerd9dc2822017-03-02 20:52:51 +000075#include "llvm/Support/BinaryByteStream.h"
Zachary Turner93839cb2016-06-02 05:07:49 +000076#include "llvm/Support/COM.h"
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000077#include "llvm/Support/CommandLine.h"
78#include "llvm/Support/ConvertUTF.h"
Zachary Turner1dc9fd32016-06-14 20:48:36 +000079#include "llvm/Support/FileOutputBuffer.h"
Zachary Turner9a818ad2015-02-22 22:03:38 +000080#include "llvm/Support/FileSystem.h"
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000081#include "llvm/Support/Format.h"
Rui Ueyama197194b2018-04-13 18:26:06 +000082#include "llvm/Support/InitLLVM.h"
Zachary Turnerd1de2f42017-08-21 14:53:25 +000083#include "llvm/Support/LineIterator.h"
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000084#include "llvm/Support/ManagedStatic.h"
David Majnemer6e081262015-10-15 01:27:19 +000085#include "llvm/Support/MemoryBuffer.h"
Bob Haarmande33a6372017-05-17 20:46:48 +000086#include "llvm/Support/Path.h"
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000087#include "llvm/Support/PrettyStackTrace.h"
Chandler Carruth71f308a2015-02-13 09:09:03 +000088#include "llvm/Support/Process.h"
Zachary Turner72c5b642016-09-09 18:17:52 +000089#include "llvm/Support/Regex.h"
Reid Klecknerb0345262016-05-04 16:09:04 +000090#include "llvm/Support/ScopedPrinter.h"
Daniel Sandersd41718e2016-04-22 12:04:42 +000091#include "llvm/Support/Signals.h"
Zachary Turner0a43efe2016-04-25 17:38:08 +000092#include "llvm/Support/raw_ostream.h"
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000093
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000094using namespace llvm;
Zachary Turnera96cce62016-06-03 03:25:59 +000095using namespace llvm::codeview;
Zachary Turnerbac69d32016-07-22 19:56:05 +000096using namespace llvm::msf;
Zachary Turner2f09b502016-04-29 17:28:47 +000097using namespace llvm::pdb;
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000098
99namespace opts {
Zachary Turnerc0acf682015-02-15 20:27:53 +0000100
Zachary Turner7df69952017-06-22 20:57:39 +0000101cl::SubCommand DumpSubcommand("dump", "Dump MSF and CodeView debug info");
Zachary Turner99402032017-06-22 20:58:11 +0000102cl::SubCommand BytesSubcommand("bytes", "Dump raw bytes from the PDB file");
103
Zachary Turnerda4b63a2018-09-07 23:21:33 +0000104cl::SubCommand DiaDumpSubcommand("diadump",
105 "Dump debug information using a DIA-like API");
106
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000107cl::SubCommand
108 PrettySubcommand("pretty",
109 "Dump semantic information about types and symbols");
Zachary Turner6ac232c2017-03-13 23:28:25 +0000110
Zachary Turnerab58ae82016-06-30 17:43:00 +0000111cl::SubCommand
112 YamlToPdbSubcommand("yaml2pdb",
113 "Generate a PDB file from a YAML description");
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000114cl::SubCommand
115 PdbToYamlSubcommand("pdb2yaml",
116 "Generate a detailed YAML description of a PDB File");
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000117
Zachary Turnerd50c0132017-02-01 18:30:22 +0000118cl::SubCommand
119 AnalyzeSubcommand("analyze",
120 "Analyze various aspects of a PDB's structure");
121
Zachary Turner8fb441a2017-05-18 23:03:41 +0000122cl::SubCommand MergeSubcommand("merge",
123 "Merge multiple PDBs into a single PDB");
124
Zachary Turnerea40f402018-03-29 16:28:20 +0000125cl::SubCommand ExplainSubcommand("explain",
126 "Explain the meaning of a file offset");
127
Zachary Turnerd11328a2018-04-02 18:35:21 +0000128cl::SubCommand ExportSubcommand("export",
129 "Write binary data from a stream to a file");
130
Zachary Turner7797c722015-03-02 04:39:56 +0000131cl::OptionCategory TypeCategory("Symbol Type Options");
Zachary Turnerc883a8c2017-04-12 23:18:21 +0000132cl::OptionCategory FilterCategory("Filtering and Sorting Options");
Zachary Turnere5cb2692015-05-01 20:24:26 +0000133cl::OptionCategory OtherOptions("Other Options");
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000134
Zachary Turnere79b07e2017-06-26 17:22:36 +0000135cl::ValuesClass ChunkValues = cl::values(
136 clEnumValN(ModuleSubsection::CrossScopeExports, "cme",
137 "Cross module exports (DEBUG_S_CROSSSCOPEEXPORTS subsection)"),
138 clEnumValN(ModuleSubsection::CrossScopeImports, "cmi",
139 "Cross module imports (DEBUG_S_CROSSSCOPEIMPORTS subsection)"),
140 clEnumValN(ModuleSubsection::FileChecksums, "fc",
141 "File checksums (DEBUG_S_CHECKSUMS subsection)"),
142 clEnumValN(ModuleSubsection::InlineeLines, "ilines",
143 "Inlinee lines (DEBUG_S_INLINEELINES subsection)"),
144 clEnumValN(ModuleSubsection::Lines, "lines",
145 "Lines (DEBUG_S_LINES subsection)"),
146 clEnumValN(ModuleSubsection::StringTable, "strings",
147 "String Table (DEBUG_S_STRINGTABLE subsection) (not "
148 "typically present in PDB file)"),
149 clEnumValN(ModuleSubsection::FrameData, "frames",
150 "Frame Data (DEBUG_S_FRAMEDATA subsection)"),
151 clEnumValN(ModuleSubsection::Symbols, "symbols",
152 "Symbols (DEBUG_S_SYMBOLS subsection) (not typically "
153 "present in PDB file)"),
154 clEnumValN(ModuleSubsection::CoffSymbolRVAs, "rvas",
155 "COFF Symbol RVAs (DEBUG_S_COFF_SYMBOL_RVA subsection)"),
156 clEnumValN(ModuleSubsection::Unknown, "unknown",
157 "Any subsection not covered by another option"),
158 clEnumValN(ModuleSubsection::All, "all", "All known subsections"));
159
Zachary Turnerda4b63a2018-09-07 23:21:33 +0000160namespace diadump {
161cl::list<std::string> InputFilenames(cl::Positional,
162 cl::desc("<input PDB files>"),
163 cl::OneOrMore, cl::sub(DiaDumpSubcommand));
164
165cl::opt<bool> Native("native", cl::desc("Use native PDB reader instead of DIA"),
166 cl::sub(DiaDumpSubcommand));
167
168static cl::opt<bool> Enums("enums", cl::desc("Dump enum types"),
169 cl::sub(DiaDumpSubcommand));
170static cl::opt<bool> Pointers("pointers", cl::desc("Dump enum types"),
171 cl::sub(DiaDumpSubcommand));
172static cl::opt<bool> Compilands("compilands",
173 cl::desc("Dump compiland information"),
174 cl::sub(DiaDumpSubcommand));
175} // namespace diadump
176
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000177namespace pretty {
178cl::list<std::string> InputFilenames(cl::Positional,
179 cl::desc("<input PDB files>"),
180 cl::OneOrMore, cl::sub(PrettySubcommand));
Zachary Turner7797c722015-03-02 04:39:56 +0000181
Zachary Turner679aead2018-03-13 17:46:06 +0000182cl::opt<bool> InjectedSources("injected-sources",
183 cl::desc("Display injected sources"),
184 cl::cat(OtherOptions), cl::sub(PrettySubcommand));
185cl::opt<bool> ShowInjectedSourceContent(
186 "injected-source-content",
187 cl::desc("When displaying an injected source, display the file content"),
188 cl::cat(OtherOptions), cl::sub(PrettySubcommand));
189
Zachary Turner648bebd2018-07-06 21:01:42 +0000190cl::list<std::string> WithName(
191 "with-name",
192 cl::desc("Display any symbol or type with the specified exact name"),
193 cl::cat(TypeCategory), cl::ZeroOrMore, cl::sub(PrettySubcommand));
194
Zachary Turner7797c722015-03-02 04:39:56 +0000195cl::opt<bool> Compilands("compilands", cl::desc("Display compilands"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000196 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turner0683be22017-05-14 01:13:40 +0000197cl::opt<bool> Symbols("module-syms",
198 cl::desc("Display symbols for each compiland"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000199 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turner7797c722015-03-02 04:39:56 +0000200cl::opt<bool> Globals("globals", cl::desc("Dump global symbols"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000201 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turnere5cb2692015-05-01 20:24:26 +0000202cl::opt<bool> Externals("externals", cl::desc("Dump external symbols"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000203 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turner0683be22017-05-14 01:13:40 +0000204cl::list<SymLevel> SymTypes(
205 "sym-types", cl::desc("Type of symbols to dump (default all)"),
206 cl::cat(TypeCategory), cl::sub(PrettySubcommand), cl::ZeroOrMore,
207 cl::values(
208 clEnumValN(SymLevel::Thunks, "thunks", "Display thunk symbols"),
209 clEnumValN(SymLevel::Data, "data", "Display data symbols"),
210 clEnumValN(SymLevel::Functions, "funcs", "Display function symbols"),
211 clEnumValN(SymLevel::All, "all", "Display all symbols (default)")));
212
Zachary Turner63230a4e2017-04-06 23:43:12 +0000213cl::opt<bool>
214 Types("types",
215 cl::desc("Display all types (implies -classes, -enums, -typedefs)"),
216 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
217cl::opt<bool> Classes("classes", cl::desc("Display class types"),
218 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
219cl::opt<bool> Enums("enums", cl::desc("Display enum types"),
220 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
221cl::opt<bool> Typedefs("typedefs", cl::desc("Display typedef types"),
222 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turner0683be22017-05-14 01:13:40 +0000223cl::opt<SymbolSortMode> SymbolOrder(
224 "symbol-order", cl::desc("symbol sort order"),
225 cl::init(SymbolSortMode::None),
226 cl::values(clEnumValN(SymbolSortMode::None, "none",
227 "Undefined / no particular sort order"),
228 clEnumValN(SymbolSortMode::Name, "name", "Sort symbols by name"),
229 clEnumValN(SymbolSortMode::Size, "size",
230 "Sort symbols by size")),
231 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
232
Zachary Turner4dc4f012017-04-13 21:11:00 +0000233cl::opt<ClassSortMode> ClassOrder(
234 "class-order", cl::desc("Class sort order"), cl::init(ClassSortMode::None),
Zachary Turner16901642017-04-24 17:47:24 +0000235 cl::values(
236 clEnumValN(ClassSortMode::None, "none",
237 "Undefined / no particular sort order"),
238 clEnumValN(ClassSortMode::Name, "name", "Sort classes by name"),
239 clEnumValN(ClassSortMode::Size, "size", "Sort classes by size"),
240 clEnumValN(ClassSortMode::Padding, "padding",
241 "Sort classes by amount of padding"),
242 clEnumValN(ClassSortMode::PaddingPct, "padding-pct",
Zachary Turnerda307b62017-04-25 20:22:29 +0000243 "Sort classes by percentage of space consumed by padding"),
244 clEnumValN(ClassSortMode::PaddingImmediate, "padding-imm",
245 "Sort classes by amount of immediate padding"),
246 clEnumValN(ClassSortMode::PaddingPctImmediate, "padding-pct-imm",
247 "Sort classes by percentage of space consumed by immediate "
248 "padding")),
Zachary Turner4dc4f012017-04-13 21:11:00 +0000249 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
250
Zachary Turnerc883a8c2017-04-12 23:18:21 +0000251cl::opt<ClassDefinitionFormat> ClassFormat(
252 "class-definitions", cl::desc("Class definition format"),
Zachary Turnerda949c12017-04-24 17:47:52 +0000253 cl::init(ClassDefinitionFormat::All),
Zachary Turnerc883a8c2017-04-12 23:18:21 +0000254 cl::values(
Zachary Turnerda949c12017-04-24 17:47:52 +0000255 clEnumValN(ClassDefinitionFormat::All, "all",
Zachary Turner9e7dda32017-04-12 23:18:51 +0000256 "Display all class members including data, constants, "
Zachary Turner4dc4f012017-04-13 21:11:00 +0000257 "typedefs, functions, etc"),
Zachary Turnerda949c12017-04-24 17:47:52 +0000258 clEnumValN(ClassDefinitionFormat::Layout, "layout",
Zachary Turnerc883a8c2017-04-12 23:18:21 +0000259 "Only display members that contribute to class size."),
260 clEnumValN(ClassDefinitionFormat::None, "none",
261 "Don't display class definitions")),
262 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turnerda949c12017-04-24 17:47:52 +0000263cl::opt<uint32_t> ClassRecursionDepth(
264 "class-recurse-depth", cl::desc("Class recursion depth (0=no limit)"),
265 cl::init(0), cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turner63230a4e2017-04-06 23:43:12 +0000266
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000267cl::opt<bool> Lines("lines", cl::desc("Line tables"), cl::cat(TypeCategory),
268 cl::sub(PrettySubcommand));
Zachary Turner7797c722015-03-02 04:39:56 +0000269cl::opt<bool>
Zachary Turner7797c722015-03-02 04:39:56 +0000270 All("all", cl::desc("Implies all other options in 'Symbol Types' category"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000271 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turnerf5abda22015-03-01 06:49:49 +0000272
Zachary Turnere5cb2692015-05-01 20:24:26 +0000273cl::opt<uint64_t> LoadAddress(
274 "load-address",
275 cl::desc("Assume the module is loaded at the specified address"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000276 cl::cat(OtherOptions), cl::sub(PrettySubcommand));
Adrian McCarthy65d26882017-03-15 20:17:58 +0000277cl::opt<bool> Native("native", cl::desc("Use native PDB reader instead of DIA"),
Adrian McCarthy1aa207d2017-03-23 15:28:15 +0000278 cl::cat(OtherOptions), cl::sub(PrettySubcommand));
279cl::opt<cl::boolOrDefault>
280 ColorOutput("color-output",
281 cl::desc("Override use of color (default = isatty)"),
282 cl::cat(OtherOptions), cl::sub(PrettySubcommand));
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000283cl::list<std::string> ExcludeTypes(
284 "exclude-types", cl::desc("Exclude types by regular expression"),
285 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
286cl::list<std::string> ExcludeSymbols(
287 "exclude-symbols", cl::desc("Exclude symbols by regular expression"),
288 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
289cl::list<std::string> ExcludeCompilands(
290 "exclude-compilands", cl::desc("Exclude compilands by regular expression"),
291 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner4dddcc62015-09-29 19:49:06 +0000292
293cl::list<std::string> IncludeTypes(
294 "include-types",
295 cl::desc("Include only types which match a regular expression"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000296 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner4dddcc62015-09-29 19:49:06 +0000297cl::list<std::string> IncludeSymbols(
298 "include-symbols",
299 cl::desc("Include only symbols which match a regular expression"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000300 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner4dddcc62015-09-29 19:49:06 +0000301cl::list<std::string> IncludeCompilands(
302 "include-compilands",
303 cl::desc("Include only compilands those which match a regular expression"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000304 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner4dc4f012017-04-13 21:11:00 +0000305cl::opt<uint32_t> SizeThreshold(
306 "min-type-size", cl::desc("Displays only those types which are greater "
307 "than or equal to the specified size."),
308 cl::init(0), cl::cat(FilterCategory), cl::sub(PrettySubcommand));
309cl::opt<uint32_t> PaddingThreshold(
310 "min-class-padding", cl::desc("Displays only those classes which have at "
311 "least the specified amount of padding."),
312 cl::init(0), cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turnerda307b62017-04-25 20:22:29 +0000313cl::opt<uint32_t> ImmediatePaddingThreshold(
314 "min-class-padding-imm",
315 cl::desc("Displays only those classes which have at least the specified "
316 "amount of immediate padding, ignoring padding internal to bases "
317 "and aggregates."),
318 cl::init(0), cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner4dddcc62015-09-29 19:49:06 +0000319
Zachary Turner7797c722015-03-02 04:39:56 +0000320cl::opt<bool> ExcludeCompilerGenerated(
321 "no-compiler-generated",
322 cl::desc("Don't show compiler generated types and symbols"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000323 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner7797c722015-03-02 04:39:56 +0000324cl::opt<bool>
325 ExcludeSystemLibraries("no-system-libs",
326 cl::desc("Don't show symbols from system libraries"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000327 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner10169b62017-04-06 23:43:39 +0000328
Zachary Turner65323652015-03-04 06:09:53 +0000329cl::opt<bool> NoEnumDefs("no-enum-definitions",
330 cl::desc("Don't display full enum definitions"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000331 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
332}
333
Zachary Turner63055452017-06-15 22:24:24 +0000334cl::OptionCategory FileOptions("Module & File Options");
335
Zachary Turner99402032017-06-22 20:58:11 +0000336namespace bytes {
Zachary Turnerdd739682017-06-23 21:11:54 +0000337cl::OptionCategory MsfBytes("MSF File Options");
338cl::OptionCategory DbiBytes("Dbi Stream Options");
339cl::OptionCategory PdbBytes("PDB Stream Options");
Zachary Turnerc2f5b4b2017-06-23 21:50:54 +0000340cl::OptionCategory Types("Type Options");
Zachary Turnerfa332822017-06-23 23:08:57 +0000341cl::OptionCategory ModuleCategory("Module Options");
Zachary Turnerdd739682017-06-23 21:11:54 +0000342
Zachary Turner6b124f22017-06-23 19:54:44 +0000343llvm::Optional<NumberRange> DumpBlockRange;
344llvm::Optional<NumberRange> DumpByteRange;
345
346cl::opt<std::string> DumpBlockRangeOpt(
347 "block-range", cl::value_desc("start[-end]"),
348 cl::desc("Dump binary data from specified range of blocks."),
Zachary Turnerdd739682017-06-23 21:11:54 +0000349 cl::sub(BytesSubcommand), cl::cat(MsfBytes));
Zachary Turner99402032017-06-22 20:58:11 +0000350
351cl::opt<std::string>
Zachary Turner6b124f22017-06-23 19:54:44 +0000352 DumpByteRangeOpt("byte-range", cl::value_desc("start[-end]"),
353 cl::desc("Dump binary data from specified range of bytes"),
Zachary Turnerdd739682017-06-23 21:11:54 +0000354 cl::sub(BytesSubcommand), cl::cat(MsfBytes));
Zachary Turner99402032017-06-22 20:58:11 +0000355
356cl::list<std::string>
357 DumpStreamData("stream-data", cl::CommaSeparated, cl::ZeroOrMore,
358 cl::desc("Dump binary data from specified streams. Format "
359 "is SN[:Start][@Size]"),
Zachary Turnerdd739682017-06-23 21:11:54 +0000360 cl::sub(BytesSubcommand), cl::cat(MsfBytes));
Zachary Turner99402032017-06-22 20:58:11 +0000361
Zachary Turner6c3e41b2017-06-23 20:18:38 +0000362cl::opt<bool> NameMap("name-map", cl::desc("Dump bytes of PDB Name Map"),
Zachary Turnerdd739682017-06-23 21:11:54 +0000363 cl::sub(BytesSubcommand), cl::cat(PdbBytes));
Zachary Turnerc3d8eec2017-08-02 22:25:52 +0000364cl::opt<bool> Fpm("fpm", cl::desc("Dump free page map"),
365 cl::sub(BytesSubcommand), cl::cat(MsfBytes));
Zachary Turnerdd739682017-06-23 21:11:54 +0000366
367cl::opt<bool> SectionContributions("sc", cl::desc("Dump section contributions"),
368 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
369cl::opt<bool> SectionMap("sm", cl::desc("Dump section map"),
370 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
371cl::opt<bool> ModuleInfos("modi", cl::desc("Dump module info"),
372 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
373cl::opt<bool> FileInfo("files", cl::desc("Dump source file info"),
374 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
375cl::opt<bool> TypeServerMap("type-server", cl::desc("Dump type server map"),
376 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
377cl::opt<bool> ECData("ec", cl::desc("Dump edit and continue map"),
378 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
Zachary Turner6c3e41b2017-06-23 20:18:38 +0000379
Zachary Turnerc2f5b4b2017-06-23 21:50:54 +0000380cl::list<uint32_t>
381 TypeIndex("type",
382 cl::desc("Dump the type record with the given type index"),
383 cl::ZeroOrMore, cl::CommaSeparated, cl::sub(BytesSubcommand),
384 cl::cat(TypeCategory));
385cl::list<uint32_t>
386 IdIndex("id", cl::desc("Dump the id record with the given type index"),
387 cl::ZeroOrMore, cl::CommaSeparated, cl::sub(BytesSubcommand),
388 cl::cat(TypeCategory));
389
Zachary Turnerfa332822017-06-23 23:08:57 +0000390cl::opt<uint32_t> ModuleIndex(
391 "mod",
392 cl::desc(
393 "Limit options in the Modules category to the specified module index"),
394 cl::Optional, cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
395cl::opt<bool> ModuleSyms("syms", cl::desc("Dump symbol record substream"),
396 cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
397cl::opt<bool> ModuleC11("c11-chunks", cl::Hidden,
398 cl::desc("Dump C11 CodeView debug chunks"),
399 cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
Zachary Turnere79b07e2017-06-26 17:22:36 +0000400cl::opt<bool> ModuleC13("chunks",
401 cl::desc("Dump C13 CodeView debug chunk subsection"),
Zachary Turnerfa332822017-06-23 23:08:57 +0000402 cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
Zachary Turnere79b07e2017-06-26 17:22:36 +0000403cl::opt<bool> SplitChunks(
404 "split-chunks",
405 cl::desc(
406 "When dumping debug chunks, show a different section for each chunk"),
407 cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
Zachary Turner99402032017-06-22 20:58:11 +0000408cl::list<std::string> InputFilenames(cl::Positional,
409 cl::desc("<input PDB files>"),
410 cl::OneOrMore, cl::sub(BytesSubcommand));
411
412} // namespace bytes
413
Zachary Turner7df69952017-06-22 20:57:39 +0000414namespace dump {
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000415
416cl::OptionCategory MsfOptions("MSF Container Options");
417cl::OptionCategory TypeOptions("Type Record Options");
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000418cl::OptionCategory SymbolOptions("Symbol Options");
419cl::OptionCategory MiscOptions("Miscellaneous Options");
420
421// MSF OPTIONS
Zachary Turner63055452017-06-15 22:24:24 +0000422cl::opt<bool> DumpSummary("summary", cl::desc("dump file summary"),
Zachary Turner7df69952017-06-22 20:57:39 +0000423 cl::cat(MsfOptions), cl::sub(DumpSubcommand));
Zachary Turner63055452017-06-15 22:24:24 +0000424cl::opt<bool> DumpStreams("streams",
425 cl::desc("dump summary of the PDB streams"),
Zachary Turner7df69952017-06-22 20:57:39 +0000426 cl::cat(MsfOptions), cl::sub(DumpSubcommand));
Zachary Turner5f098522017-06-23 20:28:14 +0000427cl::opt<bool> DumpStreamBlocks(
428 "stream-blocks",
429 cl::desc("Add block information to the output of -streams"),
430 cl::cat(MsfOptions), cl::sub(DumpSubcommand));
Zachary Turner99c69822017-08-31 20:43:22 +0000431cl::opt<bool> DumpSymbolStats(
432 "sym-stats",
433 cl::desc("Dump a detailed breakdown of symbol usage/size for each module"),
434 cl::cat(MsfOptions), cl::sub(DumpSubcommand));
435
436cl::opt<bool> DumpUdtStats(
437 "udt-stats",
438 cl::desc("Dump a detailed breakdown of S_UDT record usage / stats"),
439 cl::cat(MsfOptions), cl::sub(DumpSubcommand));
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000440
441// TYPE OPTIONS
Zachary Turner63055452017-06-15 22:24:24 +0000442cl::opt<bool> DumpTypes("types",
443 cl::desc("dump CodeView type records from TPI stream"),
Zachary Turner7df69952017-06-22 20:57:39 +0000444 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turner63055452017-06-15 22:24:24 +0000445cl::opt<bool> DumpTypeData(
446 "type-data",
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000447 cl::desc("dump CodeView type record raw bytes from TPI stream"),
Zachary Turner7df69952017-06-22 20:57:39 +0000448 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turner63055452017-06-15 22:24:24 +0000449
Zachary Turnerf8a2e042017-06-15 23:04:42 +0000450cl::opt<bool> DumpTypeExtras("type-extras",
451 cl::desc("dump type hashes and index offsets"),
Zachary Turner7df69952017-06-22 20:57:39 +0000452 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turner63055452017-06-15 22:24:24 +0000453
Zachary Turner59224cb2017-06-16 23:42:15 +0000454cl::list<uint32_t> DumpTypeIndex(
Zachary Turnereae44df2017-07-05 18:43:25 +0000455 "type-index", cl::ZeroOrMore, cl::CommaSeparated,
Zachary Turner59224cb2017-06-16 23:42:15 +0000456 cl::desc("only dump types with the specified hexadecimal type index"),
Zachary Turner7df69952017-06-22 20:57:39 +0000457 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turner59224cb2017-06-16 23:42:15 +0000458
Zachary Turner63055452017-06-15 22:24:24 +0000459cl::opt<bool> DumpIds("ids",
460 cl::desc("dump CodeView type records from IPI stream"),
Zachary Turner7df69952017-06-22 20:57:39 +0000461 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000462cl::opt<bool>
Zachary Turner63055452017-06-15 22:24:24 +0000463 DumpIdData("id-data",
464 cl::desc("dump CodeView type record raw bytes from IPI stream"),
Zachary Turner7df69952017-06-22 20:57:39 +0000465 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000466
Zachary Turnerf8a2e042017-06-15 23:04:42 +0000467cl::opt<bool> DumpIdExtras("id-extras",
468 cl::desc("dump id hashes and index offsets"),
Zachary Turner7df69952017-06-22 20:57:39 +0000469 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turner59224cb2017-06-16 23:42:15 +0000470cl::list<uint32_t> DumpIdIndex(
Zachary Turnereae44df2017-07-05 18:43:25 +0000471 "id-index", cl::ZeroOrMore, cl::CommaSeparated,
Zachary Turner59224cb2017-06-16 23:42:15 +0000472 cl::desc("only dump ids with the specified hexadecimal type index"),
Zachary Turner7df69952017-06-22 20:57:39 +0000473 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turnerf8a2e042017-06-15 23:04:42 +0000474
Zachary Turner02a26772017-06-30 18:15:47 +0000475cl::opt<bool> DumpTypeDependents(
476 "dependents",
477 cl::desc("In conjunection with -type-index and -id-index, dumps the entire "
478 "dependency graph for the specified index instead of "
479 "just the single record with the specified index"),
480 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
481
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000482// SYMBOL OPTIONS
Reid Kleckner14d90fd2017-07-26 00:40:36 +0000483cl::opt<bool> DumpGlobals("globals", cl::desc("dump Globals symbol records"),
484 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
485cl::opt<bool> DumpGlobalExtras("global-extras", cl::desc("dump Globals hashes"),
486 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000487cl::opt<bool> DumpPublics("publics", cl::desc("dump Publics stream data"),
Zachary Turner7df69952017-06-22 20:57:39 +0000488 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
Reid Kleckner686f1212017-07-21 18:28:55 +0000489cl::opt<bool> DumpPublicExtras("public-extras",
490 cl::desc("dump Publics hashes and address maps"),
491 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
Zachary Turner457cc342018-07-06 02:59:25 +0000492cl::opt<bool>
493 DumpGSIRecords("gsi-records",
494 cl::desc("dump public / global common record stream"),
495 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
Zachary Turner63055452017-06-15 22:24:24 +0000496cl::opt<bool> DumpSymbols("symbols", cl::desc("dump module symbols"),
Zachary Turner7df69952017-06-22 20:57:39 +0000497 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
Zachary Turner63055452017-06-15 22:24:24 +0000498
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000499cl::opt<bool>
Zachary Turner63055452017-06-15 22:24:24 +0000500 DumpSymRecordBytes("sym-data",
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000501 cl::desc("dump CodeView symbol record raw bytes"),
Zachary Turner7df69952017-06-22 20:57:39 +0000502 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000503
Zachary Turner42e7cc1b2018-09-11 22:35:01 +0000504cl::opt<bool> DumpFpo("fpo", cl::desc("dump FPO records"),
505 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
506
Zachary Turner63055452017-06-15 22:24:24 +0000507// MODULE & FILE OPTIONS
508cl::opt<bool> DumpModules("modules", cl::desc("dump compiland information"),
Zachary Turner7df69952017-06-22 20:57:39 +0000509 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turner63055452017-06-15 22:24:24 +0000510cl::opt<bool> DumpModuleFiles(
511 "files",
Zachary Turner4e950642017-06-15 23:56:19 +0000512 cl::desc("Dump the source files that contribute to each module's."),
Zachary Turner7df69952017-06-22 20:57:39 +0000513 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turner4e950642017-06-15 23:56:19 +0000514cl::opt<bool> DumpLines(
515 "l",
516 cl::desc("dump source file/line information (DEBUG_S_LINES subsection)"),
Zachary Turner7df69952017-06-22 20:57:39 +0000517 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turner4e950642017-06-15 23:56:19 +0000518cl::opt<bool> DumpInlineeLines(
519 "il",
520 cl::desc("dump inlinee line information (DEBUG_S_INLINEELINES subsection)"),
Zachary Turner7df69952017-06-22 20:57:39 +0000521 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turner47d9a562017-06-16 00:04:24 +0000522cl::opt<bool> DumpXmi(
523 "xmi",
524 cl::desc(
525 "dump cross module imports (DEBUG_S_CROSSSCOPEIMPORTS subsection)"),
Zachary Turner7df69952017-06-22 20:57:39 +0000526 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turner47d9a562017-06-16 00:04:24 +0000527cl::opt<bool> DumpXme(
528 "xme",
529 cl::desc(
530 "dump cross module exports (DEBUG_S_CROSSSCOPEEXPORTS subsection)"),
Zachary Turner7df69952017-06-22 20:57:39 +0000531 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turner58699362017-08-03 23:11:52 +0000532cl::opt<uint32_t> DumpModi("modi", cl::Optional,
533 cl::desc("For all options that iterate over "
534 "modules, limit to the specified module"),
535 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turnerd1de2f42017-08-21 14:53:25 +0000536cl::opt<bool> JustMyCode("jmc", cl::Optional,
537 cl::desc("For all options that iterate over modules, "
538 "ignore modules from system libraries"),
539 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turner63055452017-06-15 22:24:24 +0000540
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000541// MISCELLANEOUS OPTIONS
Zachary Turnera6fb5362018-03-23 18:43:39 +0000542cl::opt<bool> DumpNamedStreams("named-streams",
543 cl::desc("dump PDB named stream table"),
544 cl::cat(MiscOptions), cl::sub(DumpSubcommand));
545
Zachary Turner760ad4d2017-01-20 22:42:09 +0000546cl::opt<bool> DumpStringTable("string-table", cl::desc("dump PDB String Table"),
Zachary Turner7df69952017-06-22 20:57:39 +0000547 cl::cat(MiscOptions), cl::sub(DumpSubcommand));
Zachary Turnera6fb5362018-03-23 18:43:39 +0000548cl::opt<bool> DumpStringTableDetails("string-table-details",
549 cl::desc("dump PDB String Table Details"),
550 cl::cat(MiscOptions),
551 cl::sub(DumpSubcommand));
Zachary Turner760ad4d2017-01-20 22:42:09 +0000552
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000553cl::opt<bool> DumpSectionContribs("section-contribs",
554 cl::desc("dump section contributions"),
Zachary Turner7df69952017-06-22 20:57:39 +0000555 cl::cat(MiscOptions),
556 cl::sub(DumpSubcommand));
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000557cl::opt<bool> DumpSectionMap("section-map", cl::desc("dump section map"),
Zachary Turner7df69952017-06-22 20:57:39 +0000558 cl::cat(MiscOptions), cl::sub(DumpSubcommand));
Zachary Turnerfb1cd502017-08-04 20:02:38 +0000559cl::opt<bool> DumpSectionHeaders("section-headers",
560 cl::desc("Dump image section headers"),
561 cl::cat(MiscOptions), cl::sub(DumpSubcommand));
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000562
Zachary Turnerab58ae82016-06-30 17:43:00 +0000563cl::opt<bool> RawAll("all", cl::desc("Implies most other options."),
Zachary Turner7df69952017-06-22 20:57:39 +0000564 cl::cat(MiscOptions), cl::sub(DumpSubcommand));
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000565
566cl::list<std::string> InputFilenames(cl::Positional,
567 cl::desc("<input PDB files>"),
Zachary Turner7df69952017-06-22 20:57:39 +0000568 cl::OneOrMore, cl::sub(DumpSubcommand));
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000569}
570
571namespace yaml2pdb {
572cl::opt<std::string>
573 YamlPdbOutputFile("pdb", cl::desc("the name of the PDB file to write"),
574 cl::sub(YamlToPdbSubcommand));
575
Bob Haarmande33a6372017-05-17 20:46:48 +0000576cl::opt<std::string> InputFilename(cl::Positional,
577 cl::desc("<input YAML file>"), cl::Required,
578 cl::sub(YamlToPdbSubcommand));
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000579}
580
581namespace pdb2yaml {
Bob Haarman69fd2b72017-05-26 23:46:20 +0000582cl::opt<bool> All("all",
583 cl::desc("Dump everything we know how to dump."),
584 cl::sub(PdbToYamlSubcommand), cl::init(false));
Zachary Turner3eedd162017-06-08 23:39:33 +0000585cl::opt<bool> NoFileHeaders("no-file-headers",
586 cl::desc("Do not dump MSF file headers"),
587 cl::sub(PdbToYamlSubcommand), cl::init(false));
Zachary Turnerea4e6072017-03-15 22:18:53 +0000588cl::opt<bool> Minimal("minimal",
589 cl::desc("Don't write fields with default values"),
590 cl::sub(PdbToYamlSubcommand), cl::init(false));
Zachary Turnerf6b93822016-07-11 21:45:09 +0000591
Zachary Turnerab58ae82016-06-30 17:43:00 +0000592cl::opt<bool> StreamMetadata(
593 "stream-metadata",
594 cl::desc("Dump the number of streams and each stream's size"),
Zachary Turnerf6b93822016-07-11 21:45:09 +0000595 cl::sub(PdbToYamlSubcommand), cl::init(false));
Zachary Turnerab58ae82016-06-30 17:43:00 +0000596cl::opt<bool> StreamDirectory(
597 "stream-directory",
598 cl::desc("Dump each stream's block map (implies -stream-metadata)"),
Zachary Turnerf6b93822016-07-11 21:45:09 +0000599 cl::sub(PdbToYamlSubcommand), cl::init(false));
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000600cl::opt<bool> PdbStream("pdb-stream",
601 cl::desc("Dump the PDB Stream (Stream 1)"),
602 cl::sub(PdbToYamlSubcommand), cl::init(false));
Zachary Turner760ad4d2017-01-20 22:42:09 +0000603
604cl::opt<bool> StringTable("string-table", cl::desc("Dump the PDB String Table"),
605 cl::sub(PdbToYamlSubcommand), cl::init(false));
606
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000607cl::opt<bool> DbiStream("dbi-stream",
Zachary Turner3eedd162017-06-08 23:39:33 +0000608 cl::desc("Dump the DBI Stream Headers (Stream 2)"),
Zachary Turnerfaa554b2016-07-15 22:16:56 +0000609 cl::sub(PdbToYamlSubcommand), cl::init(false));
Zachary Turneree3b9c22017-04-25 20:22:02 +0000610
Zachary Turnerac5763e2016-08-18 16:49:29 +0000611cl::opt<bool> TpiStream("tpi-stream",
612 cl::desc("Dump the TPI Stream (Stream 3)"),
613 cl::sub(PdbToYamlSubcommand), cl::init(false));
614
Zachary Turnerde9ba152016-09-15 18:22:31 +0000615cl::opt<bool> IpiStream("ipi-stream",
616 cl::desc("Dump the IPI Stream (Stream 5)"),
617 cl::sub(PdbToYamlSubcommand), cl::init(false));
618
Zachary Turner3eedd162017-06-08 23:39:33 +0000619// MODULE & FILE OPTIONS
620cl::opt<bool> DumpModules("modules", cl::desc("dump compiland information"),
Zachary Turner63055452017-06-15 22:24:24 +0000621 cl::cat(FileOptions), cl::sub(PdbToYamlSubcommand));
Zachary Turner3eedd162017-06-08 23:39:33 +0000622cl::opt<bool> DumpModuleFiles("module-files", cl::desc("dump file information"),
Zachary Turner63055452017-06-15 22:24:24 +0000623 cl::cat(FileOptions),
Zachary Turner3eedd162017-06-08 23:39:33 +0000624 cl::sub(PdbToYamlSubcommand));
625cl::list<ModuleSubsection> DumpModuleSubsections(
626 "subsections", cl::ZeroOrMore, cl::CommaSeparated,
Zachary Turnere79b07e2017-06-26 17:22:36 +0000627 cl::desc("dump subsections from each module's debug stream"), ChunkValues,
Zachary Turner63055452017-06-15 22:24:24 +0000628 cl::cat(FileOptions), cl::sub(PdbToYamlSubcommand));
Zachary Turner3eedd162017-06-08 23:39:33 +0000629cl::opt<bool> DumpModuleSyms("module-syms", cl::desc("dump module symbols"),
Zachary Turner63055452017-06-15 22:24:24 +0000630 cl::cat(FileOptions),
Zachary Turner3eedd162017-06-08 23:39:33 +0000631 cl::sub(PdbToYamlSubcommand));
Zachary Turner63055452017-06-15 22:24:24 +0000632
633cl::list<std::string> InputFilename(cl::Positional,
634 cl::desc("<input PDB file>"), cl::Required,
635 cl::sub(PdbToYamlSubcommand));
636} // namespace pdb2yaml
Zachary Turner3eedd162017-06-08 23:39:33 +0000637
Zachary Turnerd50c0132017-02-01 18:30:22 +0000638namespace analyze {
639cl::opt<bool> StringTable("hash-collisions", cl::desc("Find hash collisions"),
640 cl::sub(AnalyzeSubcommand), cl::init(false));
641cl::list<std::string> InputFilename(cl::Positional,
642 cl::desc("<input PDB file>"), cl::Required,
643 cl::sub(AnalyzeSubcommand));
644}
Zachary Turner8fb441a2017-05-18 23:03:41 +0000645
646namespace merge {
647cl::list<std::string> InputFilenames(cl::Positional,
648 cl::desc("<input PDB files>"),
649 cl::OneOrMore, cl::sub(MergeSubcommand));
650cl::opt<std::string>
651 PdbOutputFile("pdb", cl::desc("the name of the PDB file to write"),
652 cl::sub(MergeSubcommand));
653}
Zachary Turnerea40f402018-03-29 16:28:20 +0000654
655namespace explain {
656cl::list<std::string> InputFilename(cl::Positional,
657 cl::desc("<input PDB file>"), cl::Required,
658 cl::sub(ExplainSubcommand));
659
Zachary Turnerd5cf5cf2018-03-30 17:16:50 +0000660cl::list<uint64_t> Offsets("offset", cl::desc("The file offset to explain"),
661 cl::sub(ExplainSubcommand), cl::OneOrMore);
Zachary Turner15b2bdf2018-04-04 17:29:09 +0000662
663cl::opt<InputFileType> InputType(
664 "input-type", cl::desc("Specify how to interpret the input file"),
665 cl::init(InputFileType::PDBFile), cl::Optional, cl::sub(ExplainSubcommand),
666 cl::values(clEnumValN(InputFileType::PDBFile, "pdb-file",
667 "Treat input as a PDB file (default)"),
668 clEnumValN(InputFileType::PDBStream, "pdb-stream",
669 "Treat input as raw contents of PDB stream"),
670 clEnumValN(InputFileType::DBIStream, "dbi-stream",
671 "Treat input as raw contents of DBI stream"),
672 clEnumValN(InputFileType::Names, "names-stream",
673 "Treat input as raw contents of /names named stream"),
674 clEnumValN(InputFileType::ModuleStream, "mod-stream",
675 "Treat input as raw contents of a module stream")));
Zachary Turnerea40f402018-03-29 16:28:20 +0000676} // namespace explain
Zachary Turnerd11328a2018-04-02 18:35:21 +0000677
678namespace exportstream {
679cl::list<std::string> InputFilename(cl::Positional,
680 cl::desc("<input PDB file>"), cl::Required,
681 cl::sub(ExportSubcommand));
682cl::opt<std::string> OutputFile("out",
683 cl::desc("The file to write the stream to"),
684 cl::Required, cl::sub(ExportSubcommand));
685cl::opt<std::string>
686 Stream("stream", cl::Required,
687 cl::desc("The index or name of the stream whose contents to export"),
688 cl::sub(ExportSubcommand));
689cl::opt<bool> ForceName("name",
690 cl::desc("Force the interpretation of -stream as a "
691 "string, even if it is a valid integer"),
692 cl::sub(ExportSubcommand), cl::Optional,
693 cl::init(false));
694} // namespace exportstream
Zachary Turner49693b42015-01-28 01:22:33 +0000695}
696
David Majnemerc165c882016-05-28 18:25:15 +0000697static ExitOnError ExitOnErr;
698
Zachary Turner1dc9fd32016-06-14 20:48:36 +0000699static void yamlToPdb(StringRef Path) {
Zachary Turnere109dc62016-07-22 19:56:26 +0000700 BumpPtrAllocator Allocator;
Zachary Turner1dc9fd32016-06-14 20:48:36 +0000701 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
702 MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
703 /*RequiresNullTerminator=*/false);
704
705 if (ErrorOrBuffer.getError()) {
Alexandre Ganea6a7efef2018-08-31 17:41:58 +0000706 ExitOnErr(createFileError(Path, errorCodeToError(ErrorOrBuffer.getError())));
Zachary Turner1dc9fd32016-06-14 20:48:36 +0000707 }
708
709 std::unique_ptr<MemoryBuffer> &Buffer = ErrorOrBuffer.get();
710
711 llvm::yaml::Input In(Buffer->getBuffer());
Zachary Turnerc6d54da2016-09-09 17:46:17 +0000712 pdb::yaml::PdbObject YamlObj(Allocator);
Zachary Turner1dc9fd32016-06-14 20:48:36 +0000713 In >> YamlObj;
714
Zachary Turnere109dc62016-07-22 19:56:26 +0000715 PDBFileBuilder Builder(Allocator);
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000716
Zachary Turnerea4e6072017-03-15 22:18:53 +0000717 uint32_t BlockSize = 4096;
718 if (YamlObj.Headers.hasValue())
719 BlockSize = YamlObj.Headers->SuperBlock.BlockSize;
720 ExitOnErr(Builder.initialize(BlockSize));
Zachary Turner620961d2016-09-14 23:00:02 +0000721 // Add each of the reserved streams. We ignore stream metadata in the
722 // yaml, because we will reconstruct our own view of the streams. For
723 // example, the YAML may say that there were 20 streams in the original
724 // PDB, but maybe we only dump a subset of those 20 streams, so we will
725 // have fewer, and the ones we do have may end up with different indices
726 // than the ones in the original PDB. So we just start with a clean slate.
727 for (uint32_t I = 0; I < kSpecialStreamCount; ++I)
728 ExitOnErr(Builder.getMsfBuilder().addStream(0));
Zachary Turner8848a7a2016-07-06 18:05:57 +0000729
Zachary Turnera8cfc292017-06-14 15:59:27 +0000730 StringsAndChecksums Strings;
731 Strings.setStrings(std::make_shared<DebugStringTableSubsection>());
732
Zachary Turner760ad4d2017-01-20 22:42:09 +0000733 if (YamlObj.StringTable.hasValue()) {
Zachary Turner760ad4d2017-01-20 22:42:09 +0000734 for (auto S : *YamlObj.StringTable)
Zachary Turnera8cfc292017-06-14 15:59:27 +0000735 Strings.strings()->insert(S);
Zachary Turner760ad4d2017-01-20 22:42:09 +0000736 }
737
Zachary Turnerea4e6072017-03-15 22:18:53 +0000738 pdb::yaml::PdbInfoStream DefaultInfoStream;
739 pdb::yaml::PdbDbiStream DefaultDbiStream;
740 pdb::yaml::PdbTpiStream DefaultTpiStream;
Zachary Turnerd4136e92017-05-22 21:07:43 +0000741 pdb::yaml::PdbTpiStream DefaultIpiStream;
Zachary Turner1dc9fd32016-06-14 20:48:36 +0000742
Zachary Turnerea4e6072017-03-15 22:18:53 +0000743 const auto &Info = YamlObj.PdbStream.getValueOr(DefaultInfoStream);
744
745 auto &InfoBuilder = Builder.getInfoBuilder();
746 InfoBuilder.setAge(Info.Age);
747 InfoBuilder.setGuid(Info.Guid);
748 InfoBuilder.setSignature(Info.Signature);
749 InfoBuilder.setVersion(Info.Version);
Zachary Turner05d5e612017-03-16 20:19:11 +0000750 for (auto F : Info.Features)
751 InfoBuilder.addFeature(F);
Zachary Turnerea4e6072017-03-15 22:18:53 +0000752
753 const auto &Dbi = YamlObj.DbiStream.getValueOr(DefaultDbiStream);
754 auto &DbiBuilder = Builder.getDbiBuilder();
755 DbiBuilder.setAge(Dbi.Age);
756 DbiBuilder.setBuildNumber(Dbi.BuildNumber);
757 DbiBuilder.setFlags(Dbi.Flags);
758 DbiBuilder.setMachineType(Dbi.MachineType);
759 DbiBuilder.setPdbDllRbld(Dbi.PdbDllRbld);
760 DbiBuilder.setPdbDllVersion(Dbi.PdbDllVersion);
761 DbiBuilder.setVersionHeader(Dbi.VerHeader);
762 for (const auto &MI : Dbi.ModInfos) {
Zachary Turner05d5e612017-03-16 20:19:11 +0000763 auto &ModiBuilder = ExitOnErr(DbiBuilder.addModuleInfo(MI.Mod));
Bob Haarmanea91faf2017-05-25 18:04:17 +0000764 ModiBuilder.setObjFileName(MI.Obj);
Zachary Turnerea4e6072017-03-15 22:18:53 +0000765
766 for (auto S : MI.SourceFiles)
Peter Collingbourne9e26e972017-09-07 20:39:46 +0000767 ExitOnErr(DbiBuilder.addModuleSourceFile(ModiBuilder, S));
Zachary Turnerea4e6072017-03-15 22:18:53 +0000768 if (MI.Modi.hasValue()) {
769 const auto &ModiStream = *MI.Modi;
Zachary Turnerebd3ae82017-06-01 21:52:41 +0000770 for (auto Symbol : ModiStream.Symbols) {
771 ModiBuilder.addSymbol(
772 Symbol.toCodeViewSymbol(Allocator, CodeViewContainer::Pdb));
773 }
Zachary Turnerd218c262016-07-22 15:46:37 +0000774 }
Zachary Turner8a2ebfb2017-05-01 23:27:42 +0000775
Zachary Turnera8cfc292017-06-14 15:59:27 +0000776 // Each module has its own checksum subsection, so scan for it every time.
777 Strings.setChecksums(nullptr);
778 CodeViewYAML::initializeStringsAndChecksums(MI.Subsections, Strings);
779
Zachary Turnerdeb39132017-06-09 00:28:08 +0000780 auto CodeViewSubsections = ExitOnErr(CodeViewYAML::toCodeViewSubsectionList(
781 Allocator, MI.Subsections, Strings));
Zachary Turner92dcdda2017-06-02 19:49:14 +0000782 for (auto &SS : CodeViewSubsections) {
Zachary Turnera8cfc292017-06-14 15:59:27 +0000783 ModiBuilder.addDebugSubsection(SS);
Zachary Turner8a2ebfb2017-05-01 23:27:42 +0000784 }
Zachary Turnerdbeaea72016-07-11 21:45:26 +0000785 }
786
Zachary Turnerea4e6072017-03-15 22:18:53 +0000787 auto &TpiBuilder = Builder.getTpiBuilder();
788 const auto &Tpi = YamlObj.TpiStream.getValueOr(DefaultTpiStream);
789 TpiBuilder.setVersionHeader(Tpi.Version);
Zachary Turnerca6dbf12017-11-30 18:39:50 +0000790 AppendingTypeTableBuilder TS(Allocator);
Zachary Turnerd4273832017-05-30 21:53:05 +0000791 for (const auto &R : Tpi.Records) {
Zachary Turner6900de12017-11-28 18:33:17 +0000792 CVType Type = R.toCodeViewRecord(TS);
Zachary Turnerd4273832017-05-30 21:53:05 +0000793 TpiBuilder.addTypeRecord(Type.RecordData, None);
794 }
Zachary Turnerc6d54da2016-09-09 17:46:17 +0000795
Zachary Turnerd4136e92017-05-22 21:07:43 +0000796 const auto &Ipi = YamlObj.IpiStream.getValueOr(DefaultIpiStream);
Zachary Turnerea4e6072017-03-15 22:18:53 +0000797 auto &IpiBuilder = Builder.getIpiBuilder();
798 IpiBuilder.setVersionHeader(Ipi.Version);
Zachary Turnerd4273832017-05-30 21:53:05 +0000799 for (const auto &R : Ipi.Records) {
Zachary Turner6900de12017-11-28 18:33:17 +0000800 CVType Type = R.toCodeViewRecord(TS);
Zachary Turnerd4273832017-05-30 21:53:05 +0000801 IpiBuilder.addTypeRecord(Type.RecordData, None);
802 }
Zachary Turnerde9ba152016-09-15 18:22:31 +0000803
Zachary Turnera8cfc292017-06-14 15:59:27 +0000804 Builder.getStringTableBuilder().setStrings(*Strings.strings());
805
Rui Ueyamafc22cef2016-09-30 20:34:44 +0000806 ExitOnErr(Builder.commit(opts::yaml2pdb::YamlPdbOutputFile));
Zachary Turner1dc9fd32016-06-14 20:48:36 +0000807}
808
Zachary Turner6ac232c2017-03-13 23:28:25 +0000809static PDBFile &loadPDB(StringRef Path, std::unique_ptr<IPDBSession> &Session) {
Adrian McCarthy8f713192017-01-27 00:01:55 +0000810 ExitOnErr(loadDataForPDB(PDB_ReaderType::Native, Path, Session));
Zachary Turner8848a7a2016-07-06 18:05:57 +0000811
Zachary Turner6ac232c2017-03-13 23:28:25 +0000812 NativeSession *NS = static_cast<NativeSession *>(Session.get());
813 return NS->getPDBFile();
814}
815
816static void pdb2Yaml(StringRef Path) {
817 std::unique_ptr<IPDBSession> Session;
818 auto &File = loadPDB(Path, Session);
819
Zachary Turner8848a7a2016-07-06 18:05:57 +0000820 auto O = llvm::make_unique<YAMLOutputStyle>(File);
821 O = llvm::make_unique<YAMLOutputStyle>(File);
822
823 ExitOnErr(O->dump());
824}
825
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000826static void dumpRaw(StringRef Path) {
Zachary Turnerabb17cc2017-09-01 20:06:56 +0000827 InputFile IF = ExitOnErr(InputFile::open(Path));
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000828
Zachary Turnerabb17cc2017-09-01 20:06:56 +0000829 auto O = llvm::make_unique<DumpOutputStyle>(IF);
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000830 ExitOnErr(O->dump());
831}
832
Zachary Turner99402032017-06-22 20:58:11 +0000833static void dumpBytes(StringRef Path) {
834 std::unique_ptr<IPDBSession> Session;
835 auto &File = loadPDB(Path, Session);
836
837 auto O = llvm::make_unique<BytesOutputStyle>(File);
838
839 ExitOnErr(O->dump());
840}
841
Zachary Turnerd50c0132017-02-01 18:30:22 +0000842static void dumpAnalysis(StringRef Path) {
843 std::unique_ptr<IPDBSession> Session;
Zachary Turner6ac232c2017-03-13 23:28:25 +0000844 auto &File = loadPDB(Path, Session);
Zachary Turnerd50c0132017-02-01 18:30:22 +0000845 auto O = llvm::make_unique<AnalysisStyle>(File);
846
847 ExitOnErr(O->dump());
848}
849
Zachary Turner0683be22017-05-14 01:13:40 +0000850bool opts::pretty::shouldDumpSymLevel(SymLevel Search) {
851 if (SymTypes.empty())
852 return true;
853 if (llvm::find(SymTypes, Search) != SymTypes.end())
854 return true;
855 if (llvm::find(SymTypes, SymLevel::All) != SymTypes.end())
856 return true;
857 return false;
858}
859
860uint32_t llvm::pdb::getTypeLength(const PDBSymbolData &Symbol) {
861 auto SymbolType = Symbol.getType();
862 const IPDBRawSymbol &RawType = SymbolType->getRawSymbol();
863
864 return RawType.getLength();
865}
866
867bool opts::pretty::compareFunctionSymbols(
868 const std::unique_ptr<PDBSymbolFunc> &F1,
869 const std::unique_ptr<PDBSymbolFunc> &F2) {
870 assert(opts::pretty::SymbolOrder != opts::pretty::SymbolSortMode::None);
871
872 if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::Name)
873 return F1->getName() < F2->getName();
874
875 // Note that we intentionally sort in descending order on length, since
876 // long functions are more interesting than short functions.
877 return F1->getLength() > F2->getLength();
878}
879
880bool opts::pretty::compareDataSymbols(
881 const std::unique_ptr<PDBSymbolData> &F1,
882 const std::unique_ptr<PDBSymbolData> &F2) {
883 assert(opts::pretty::SymbolOrder != opts::pretty::SymbolSortMode::None);
884
885 if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::Name)
886 return F1->getName() < F2->getName();
887
888 // Note that we intentionally sort in descending order on length, since
889 // large types are more interesting than short ones.
890 return getTypeLength(*F1) > getTypeLength(*F2);
891}
892
Zachary Turner679aead2018-03-13 17:46:06 +0000893static std::string stringOr(std::string Str, std::string IfEmpty) {
894 return (Str.empty()) ? IfEmpty : Str;
895}
896
897static void dumpInjectedSources(LinePrinter &Printer, IPDBSession &Session) {
898 auto Sources = Session.getInjectedSources();
899 if (0 == Sources->getChildCount()) {
900 Printer.printLine("There are no injected sources.");
901 return;
902 }
903
904 while (auto IS = Sources->getNext()) {
905 Printer.NewLine();
906 std::string File = stringOr(IS->getFileName(), "<null>");
907 uint64_t Size = IS->getCodeByteSize();
908 std::string Obj = stringOr(IS->getObjectFileName(), "<null>");
909 std::string VFName = stringOr(IS->getVirtualFileName(), "<null>");
910 uint32_t CRC = IS->getCrc32();
911
912 std::string CompressionStr;
913 llvm::raw_string_ostream Stream(CompressionStr);
914 Stream << IS->getCompression();
915 WithColor(Printer, PDB_ColorItem::Path).get() << File;
916 Printer << " (";
917 WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Size;
918 Printer << " bytes): ";
919 WithColor(Printer, PDB_ColorItem::Keyword).get() << "obj";
920 Printer << "=";
921 WithColor(Printer, PDB_ColorItem::Path).get() << Obj;
922 Printer << ", ";
923 WithColor(Printer, PDB_ColorItem::Keyword).get() << "vname";
924 Printer << "=";
925 WithColor(Printer, PDB_ColorItem::Path).get() << VFName;
926 Printer << ", ";
927 WithColor(Printer, PDB_ColorItem::Keyword).get() << "crc";
928 Printer << "=";
929 WithColor(Printer, PDB_ColorItem::LiteralValue).get() << CRC;
930 Printer << ", ";
931 WithColor(Printer, PDB_ColorItem::Keyword).get() << "compression";
932 Printer << "=";
933 WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Stream.str();
934
935 if (!opts::pretty::ShowInjectedSourceContent)
936 continue;
937
938 // Set the indent level to 0 when printing file content.
939 int Indent = Printer.getIndentLevel();
940 Printer.Unindent(Indent);
941
942 Printer.printLine(IS->getCode());
943
944 // Re-indent back to the original level.
945 Printer.Indent(Indent);
946 }
947}
948
Zachary Turnerda4b63a2018-09-07 23:21:33 +0000949static void dumpDia(StringRef Path) {
950 std::unique_ptr<IPDBSession> Session;
951
952 const auto ReaderType =
953 opts::diadump::Native ? PDB_ReaderType::Native : PDB_ReaderType::DIA;
954 ExitOnErr(loadDataForPDB(ReaderType, Path, Session));
955
956 auto GlobalScope = Session->getGlobalScope();
957
958 std::vector<PDB_SymType> SymTypes;
959
960 if (opts::diadump::Compilands)
961 SymTypes.push_back(PDB_SymType::Compiland);
962 if (opts::diadump::Enums)
963 SymTypes.push_back(PDB_SymType::Enum);
964 if (opts::diadump::Pointers)
965 SymTypes.push_back(PDB_SymType::PointerType);
966
967 for (PDB_SymType ST : SymTypes) {
968 auto Children = GlobalScope->findAllChildren(ST);
969 while (auto Child = Children->getNext()) {
970 outs() << "{";
971 Child->defaultDump(outs(), 2);
972 outs() << "\n}\n";
973 }
974 }
975}
976
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000977static void dumpPretty(StringRef Path) {
978 std::unique_ptr<IPDBSession> Session;
David Majnemer1573b242016-04-28 23:47:27 +0000979
Adrian McCarthy65d26882017-03-15 20:17:58 +0000980 const auto ReaderType =
981 opts::pretty::Native ? PDB_ReaderType::Native : PDB_ReaderType::DIA;
982 ExitOnErr(loadDataForPDB(ReaderType, Path, Session));
David Majnemer1573b242016-04-28 23:47:27 +0000983
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000984 if (opts::pretty::LoadAddress)
985 Session->setLoadAddress(opts::pretty::LoadAddress);
Zachary Turner7058dfc2015-01-27 22:40:14 +0000986
Adrian McCarthy1aa207d2017-03-23 15:28:15 +0000987 auto &Stream = outs();
988 const bool UseColor = opts::pretty::ColorOutput == cl::BOU_UNSET
989 ? Stream.has_colors()
990 : opts::pretty::ColorOutput == cl::BOU_TRUE;
991 LinePrinter Printer(2, UseColor, Stream);
Zachary Turner2d11c202015-02-27 09:15:59 +0000992
Zachary Turnera5549172015-02-10 22:43:25 +0000993 auto GlobalScope(Session->getGlobalScope());
Aaron Smitha27b5e92018-03-07 02:23:08 +0000994 if (!GlobalScope)
995 return;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000996 std::string FileName(GlobalScope->getSymbolsFileName());
997
Zachary Turner2d11c202015-02-27 09:15:59 +0000998 WithColor(Printer, PDB_ColorItem::None).get() << "Summary for ";
999 WithColor(Printer, PDB_ColorItem::Path).get() << FileName;
1000 Printer.Indent();
Zachary Turner9a818ad2015-02-22 22:03:38 +00001001 uint64_t FileSize = 0;
Zachary Turner9a818ad2015-02-22 22:03:38 +00001002
Zachary Turner2d11c202015-02-27 09:15:59 +00001003 Printer.NewLine();
1004 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Size";
David Majnemer6e081262015-10-15 01:27:19 +00001005 if (!sys::fs::file_size(FileName, FileSize)) {
Zachary Turner2d11c202015-02-27 09:15:59 +00001006 Printer << ": " << FileSize << " bytes";
1007 } else {
1008 Printer << ": (Unable to obtain file size)";
1009 }
1010
1011 Printer.NewLine();
1012 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Guid";
1013 Printer << ": " << GlobalScope->getGuid();
1014
1015 Printer.NewLine();
1016 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Age";
1017 Printer << ": " << GlobalScope->getAge();
1018
1019 Printer.NewLine();
1020 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Attributes";
1021 Printer << ": ";
Zachary Turner9a818ad2015-02-22 22:03:38 +00001022 if (GlobalScope->hasCTypes())
1023 outs() << "HasCTypes ";
1024 if (GlobalScope->hasPrivateSymbols())
1025 outs() << "HasPrivateSymbols ";
Zachary Turner2d11c202015-02-27 09:15:59 +00001026 Printer.Unindent();
Zachary Turner9a818ad2015-02-22 22:03:38 +00001027
Zachary Turner648bebd2018-07-06 21:01:42 +00001028 if (!opts::pretty::WithName.empty()) {
1029 Printer.NewLine();
1030 WithColor(Printer, PDB_ColorItem::SectionHeader).get()
1031 << "---SYMBOLS & TYPES BY NAME---";
1032
1033 for (StringRef Name : opts::pretty::WithName) {
1034 auto Symbols = GlobalScope->findChildren(
1035 PDB_SymType::None, Name, PDB_NameSearchFlags::NS_CaseSensitive);
1036 if (!Symbols || Symbols->getChildCount() == 0) {
1037 Printer.formatLine("[not found] - {0}", Name);
1038 continue;
1039 }
1040 Printer.formatLine("[{0} occurrences] - {1}", Symbols->getChildCount(),
1041 Name);
1042
1043 AutoIndent Indent(Printer);
1044 Printer.NewLine();
1045
1046 while (auto Symbol = Symbols->getNext()) {
1047 switch (Symbol->getSymTag()) {
1048 case PDB_SymType::Typedef: {
1049 TypedefDumper TD(Printer);
1050 std::unique_ptr<PDBSymbolTypeTypedef> T =
1051 llvm::unique_dyn_cast<PDBSymbolTypeTypedef>(std::move(Symbol));
1052 TD.start(*T);
1053 break;
1054 }
1055 case PDB_SymType::Enum: {
1056 EnumDumper ED(Printer);
1057 std::unique_ptr<PDBSymbolTypeEnum> E =
1058 llvm::unique_dyn_cast<PDBSymbolTypeEnum>(std::move(Symbol));
1059 ED.start(*E);
1060 break;
1061 }
1062 case PDB_SymType::UDT: {
1063 ClassDefinitionDumper CD(Printer);
1064 std::unique_ptr<PDBSymbolTypeUDT> C =
1065 llvm::unique_dyn_cast<PDBSymbolTypeUDT>(std::move(Symbol));
1066 CD.start(*C);
1067 break;
1068 }
1069 case PDB_SymType::BaseClass:
1070 case PDB_SymType::Friend: {
1071 TypeDumper TD(Printer);
1072 Symbol->dump(TD);
1073 break;
1074 }
1075 case PDB_SymType::Function: {
1076 FunctionDumper FD(Printer);
1077 std::unique_ptr<PDBSymbolFunc> F =
1078 llvm::unique_dyn_cast<PDBSymbolFunc>(std::move(Symbol));
1079 FD.start(*F, FunctionDumper::PointerType::None);
1080 break;
1081 }
1082 case PDB_SymType::Data: {
1083 VariableDumper VD(Printer);
1084 std::unique_ptr<PDBSymbolData> D =
1085 llvm::unique_dyn_cast<PDBSymbolData>(std::move(Symbol));
1086 VD.start(*D);
1087 break;
1088 }
1089 case PDB_SymType::PublicSymbol: {
1090 ExternalSymbolDumper ED(Printer);
1091 std::unique_ptr<PDBSymbolPublicSymbol> PS =
1092 llvm::unique_dyn_cast<PDBSymbolPublicSymbol>(std::move(Symbol));
1093 ED.dump(*PS);
1094 break;
1095 }
1096 default:
1097 llvm_unreachable("Unexpected symbol tag!");
1098 }
1099 }
1100 }
1101 llvm::outs().flush();
1102 }
1103
Zachary Turnera30bd1a2016-06-30 17:42:48 +00001104 if (opts::pretty::Compilands) {
Zachary Turner2d11c202015-02-27 09:15:59 +00001105 Printer.NewLine();
1106 WithColor(Printer, PDB_ColorItem::SectionHeader).get()
1107 << "---COMPILANDS---";
Zachary Turner7999b4f2018-09-05 23:30:38 +00001108 auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
1109
1110 if (Compilands) {
Aaron Smitha27b5e92018-03-07 02:23:08 +00001111 Printer.Indent();
1112 CompilandDumper Dumper(Printer);
1113 CompilandDumpFlags options = CompilandDumper::Flags::None;
1114 if (opts::pretty::Lines)
1115 options = options | CompilandDumper::Flags::Lines;
1116 while (auto Compiland = Compilands->getNext())
1117 Dumper.start(*Compiland, options);
1118 Printer.Unindent();
1119 }
Zachary Turnerdb18f5c2015-02-27 09:15:18 +00001120 }
1121
Zachary Turner63230a4e2017-04-06 23:43:12 +00001122 if (opts::pretty::Classes || opts::pretty::Enums || opts::pretty::Typedefs) {
Zachary Turner2d11c202015-02-27 09:15:59 +00001123 Printer.NewLine();
1124 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---";
1125 Printer.Indent();
Zachary Turner65323652015-03-04 06:09:53 +00001126 TypeDumper Dumper(Printer);
Zachary Turnerb52d08d2015-03-01 06:51:29 +00001127 Dumper.start(*GlobalScope);
Zachary Turner2d11c202015-02-27 09:15:59 +00001128 Printer.Unindent();
Zachary Turnerdb18f5c2015-02-27 09:15:18 +00001129 }
1130
Zachary Turnera30bd1a2016-06-30 17:42:48 +00001131 if (opts::pretty::Symbols) {
Zachary Turner2d11c202015-02-27 09:15:59 +00001132 Printer.NewLine();
1133 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---SYMBOLS---";
Aaron Smitha27b5e92018-03-07 02:23:08 +00001134 if (auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>()) {
1135 Printer.Indent();
1136 CompilandDumper Dumper(Printer);
1137 while (auto Compiland = Compilands->getNext())
1138 Dumper.start(*Compiland, true);
1139 Printer.Unindent();
1140 }
Zachary Turnerdb18f5c2015-02-27 09:15:18 +00001141 }
1142
Zachary Turnera30bd1a2016-06-30 17:42:48 +00001143 if (opts::pretty::Globals) {
Zachary Turner2d11c202015-02-27 09:15:59 +00001144 Printer.NewLine();
1145 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---GLOBALS---";
1146 Printer.Indent();
Zachary Turner0683be22017-05-14 01:13:40 +00001147 if (shouldDumpSymLevel(opts::pretty::SymLevel::Functions)) {
Aaron Smitha27b5e92018-03-07 02:23:08 +00001148 if (auto Functions = GlobalScope->findAllChildren<PDBSymbolFunc>()) {
1149 FunctionDumper Dumper(Printer);
1150 if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
1151 while (auto Function = Functions->getNext()) {
1152 Printer.NewLine();
1153 Dumper.start(*Function, FunctionDumper::PointerType::None);
1154 }
1155 } else {
1156 std::vector<std::unique_ptr<PDBSymbolFunc>> Funcs;
1157 while (auto Func = Functions->getNext())
1158 Funcs.push_back(std::move(Func));
Mandeep Singh Grang8db564e2018-04-01 21:24:53 +00001159 llvm::sort(Funcs.begin(), Funcs.end(),
1160 opts::pretty::compareFunctionSymbols);
Aaron Smitha27b5e92018-03-07 02:23:08 +00001161 for (const auto &Func : Funcs) {
1162 Printer.NewLine();
1163 Dumper.start(*Func, FunctionDumper::PointerType::None);
1164 }
Zachary Turner0683be22017-05-14 01:13:40 +00001165 }
Zachary Turner2d11c202015-02-27 09:15:59 +00001166 }
Zachary Turnerdb18f5c2015-02-27 09:15:18 +00001167 }
Zachary Turner0683be22017-05-14 01:13:40 +00001168 if (shouldDumpSymLevel(opts::pretty::SymLevel::Data)) {
Aaron Smitha27b5e92018-03-07 02:23:08 +00001169 if (auto Vars = GlobalScope->findAllChildren<PDBSymbolData>()) {
1170 VariableDumper Dumper(Printer);
1171 if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
1172 while (auto Var = Vars->getNext())
1173 Dumper.start(*Var);
1174 } else {
1175 std::vector<std::unique_ptr<PDBSymbolData>> Datas;
1176 while (auto Var = Vars->getNext())
1177 Datas.push_back(std::move(Var));
Mandeep Singh Grang8db564e2018-04-01 21:24:53 +00001178 llvm::sort(Datas.begin(), Datas.end(),
1179 opts::pretty::compareDataSymbols);
Aaron Smitha27b5e92018-03-07 02:23:08 +00001180 for (const auto &Var : Datas)
1181 Dumper.start(*Var);
1182 }
Zachary Turner0683be22017-05-14 01:13:40 +00001183 }
Zachary Turnerdb18f5c2015-02-27 09:15:18 +00001184 }
Zachary Turner0683be22017-05-14 01:13:40 +00001185 if (shouldDumpSymLevel(opts::pretty::SymLevel::Thunks)) {
Aaron Smitha27b5e92018-03-07 02:23:08 +00001186 if (auto Thunks = GlobalScope->findAllChildren<PDBSymbolThunk>()) {
1187 CompilandDumper Dumper(Printer);
1188 while (auto Thunk = Thunks->getNext())
1189 Dumper.dump(*Thunk);
1190 }
Zachary Turnerdb18f5c2015-02-27 09:15:18 +00001191 }
Zachary Turner2d11c202015-02-27 09:15:59 +00001192 Printer.Unindent();
Zachary Turner7058dfc2015-01-27 22:40:14 +00001193 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +00001194 if (opts::pretty::Externals) {
Zachary Turnere5cb2692015-05-01 20:24:26 +00001195 Printer.NewLine();
1196 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---EXTERNALS---";
1197 Printer.Indent();
1198 ExternalSymbolDumper Dumper(Printer);
1199 Dumper.start(*GlobalScope);
1200 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +00001201 if (opts::pretty::Lines) {
Zachary Turnera99000d2016-03-08 21:42:24 +00001202 Printer.NewLine();
1203 }
Zachary Turner679aead2018-03-13 17:46:06 +00001204 if (opts::pretty::InjectedSources) {
1205 Printer.NewLine();
1206 WithColor(Printer, PDB_ColorItem::SectionHeader).get()
1207 << "---INJECTED SOURCES---";
1208 AutoIndent Indent1(Printer);
1209
1210 if (ReaderType == PDB_ReaderType::Native)
1211 Printer.printLine(
1212 "Injected sources are not supported with the native reader.");
1213 else
1214 dumpInjectedSources(Printer, *Session);
1215 }
1216
Zachary Turnera5549172015-02-10 22:43:25 +00001217 outs().flush();
Zachary Turnerfcb14ad2015-01-27 20:46:21 +00001218}
1219
Zachary Turner8fb441a2017-05-18 23:03:41 +00001220static void mergePdbs() {
1221 BumpPtrAllocator Allocator;
Zachary Turnerca6dbf12017-11-30 18:39:50 +00001222 MergingTypeTableBuilder MergedTpi(Allocator);
1223 MergingTypeTableBuilder MergedIpi(Allocator);
Zachary Turner8fb441a2017-05-18 23:03:41 +00001224
1225 // Create a Tpi and Ipi type table with all types from all input files.
1226 for (const auto &Path : opts::merge::InputFilenames) {
1227 std::unique_ptr<IPDBSession> Session;
1228 auto &File = loadPDB(Path, Session);
Zachary Turnerd4136e92017-05-22 21:07:43 +00001229 SmallVector<TypeIndex, 128> TypeMap;
1230 SmallVector<TypeIndex, 128> IdMap;
Zachary Turner8fb441a2017-05-18 23:03:41 +00001231 if (File.hasPDBTpiStream()) {
1232 auto &Tpi = ExitOnErr(File.getPDBTpiStream());
Reid Klecknera842cd72017-07-17 20:28:06 +00001233 ExitOnErr(
1234 codeview::mergeTypeRecords(MergedTpi, TypeMap, Tpi.typeArray()));
Zachary Turner8fb441a2017-05-18 23:03:41 +00001235 }
1236 if (File.hasPDBIpiStream()) {
1237 auto &Ipi = ExitOnErr(File.getPDBIpiStream());
Zachary Turnerd4136e92017-05-22 21:07:43 +00001238 ExitOnErr(codeview::mergeIdRecords(MergedIpi, TypeMap, IdMap,
Zachary Turnercfd80652017-05-24 00:35:32 +00001239 Ipi.typeArray()));
Zachary Turner8fb441a2017-05-18 23:03:41 +00001240 }
1241 }
1242
1243 // Then write the PDB.
1244 PDBFileBuilder Builder(Allocator);
1245 ExitOnErr(Builder.initialize(4096));
1246 // Add each of the reserved streams. We might not put any data in them,
1247 // but at least they have to be present.
1248 for (uint32_t I = 0; I < kSpecialStreamCount; ++I)
1249 ExitOnErr(Builder.getMsfBuilder().addStream(0));
1250
1251 auto &DestTpi = Builder.getTpiBuilder();
1252 auto &DestIpi = Builder.getIpiBuilder();
Zachary Turner3e3936d2017-11-29 19:35:21 +00001253 MergedTpi.ForEachRecord([&DestTpi](TypeIndex TI, const CVType &Type) {
1254 DestTpi.addTypeRecord(Type.RecordData, None);
Reid Klecknerded38802017-05-23 18:23:59 +00001255 });
Zachary Turner3e3936d2017-11-29 19:35:21 +00001256 MergedIpi.ForEachRecord([&DestIpi](TypeIndex TI, const CVType &Type) {
1257 DestIpi.addTypeRecord(Type.RecordData, None);
Reid Klecknerded38802017-05-23 18:23:59 +00001258 });
Zachary Turner990d0c82017-06-12 21:34:53 +00001259 Builder.getInfoBuilder().addFeature(PdbRaw_FeatureSig::VC140);
Zachary Turner8fb441a2017-05-18 23:03:41 +00001260
Zachary Turnerbdc16ed2017-05-19 06:25:09 +00001261 SmallString<64> OutFile(opts::merge::PdbOutputFile);
Zachary Turner8fb441a2017-05-18 23:03:41 +00001262 if (OutFile.empty()) {
1263 OutFile = opts::merge::InputFilenames[0];
1264 llvm::sys::path::replace_extension(OutFile, "merged.pdb");
1265 }
1266 ExitOnErr(Builder.commit(OutFile));
1267}
1268
Zachary Turnerea40f402018-03-29 16:28:20 +00001269static void explain() {
1270 std::unique_ptr<IPDBSession> Session;
Zachary Turner15b2bdf2018-04-04 17:29:09 +00001271 InputFile IF =
1272 ExitOnErr(InputFile::open(opts::explain::InputFilename.front(), true));
Zachary Turnerea40f402018-03-29 16:28:20 +00001273
Zachary Turnerd5cf5cf2018-03-30 17:16:50 +00001274 for (uint64_t Off : opts::explain::Offsets) {
Zachary Turner15b2bdf2018-04-04 17:29:09 +00001275 auto O = llvm::make_unique<ExplainOutputStyle>(IF, Off);
Zachary Turnerd5cf5cf2018-03-30 17:16:50 +00001276
1277 ExitOnErr(O->dump());
1278 }
Zachary Turnerea40f402018-03-29 16:28:20 +00001279}
1280
Zachary Turnerd11328a2018-04-02 18:35:21 +00001281static void exportStream() {
1282 std::unique_ptr<IPDBSession> Session;
1283 PDBFile &File = loadPDB(opts::exportstream::InputFilename.front(), Session);
1284
1285 std::unique_ptr<MappedBlockStream> SourceStream;
1286 uint32_t Index = 0;
1287 bool Success = false;
1288 std::string OutFileName = opts::exportstream::OutputFile;
1289
1290 if (!opts::exportstream::ForceName) {
1291 // First try to parse it as an integer, if it fails fall back to treating it
1292 // as a named stream.
1293 if (to_integer(opts::exportstream::Stream, Index)) {
1294 if (Index >= File.getNumStreams()) {
1295 errs() << "Error: " << Index << " is not a valid stream index.\n";
1296 exit(1);
1297 }
1298 Success = true;
1299 outs() << "Dumping contents of stream index " << Index << " to file "
1300 << OutFileName << ".\n";
1301 }
1302 }
1303
1304 if (!Success) {
1305 InfoStream &IS = cantFail(File.getPDBInfoStream());
1306 Index = ExitOnErr(IS.getNamedStreamIndex(opts::exportstream::Stream));
1307 outs() << "Dumping contents of stream '" << opts::exportstream::Stream
1308 << "' (index " << Index << ") to file " << OutFileName << ".\n";
1309 }
1310
1311 SourceStream = MappedBlockStream::createIndexedStream(
1312 File.getMsfLayout(), File.getMsfBuffer(), Index, File.getAllocator());
1313 auto OutFile = ExitOnErr(
1314 FileOutputBuffer::create(OutFileName, SourceStream->getLength()));
1315 FileBufferByteStream DestStream(std::move(OutFile), llvm::support::little);
1316 BinaryStreamWriter Writer(DestStream);
1317 ExitOnErr(Writer.writeStreamRef(*SourceStream));
1318 ExitOnErr(DestStream.commit());
1319}
1320
Zachary Turner6b124f22017-06-23 19:54:44 +00001321static bool parseRange(StringRef Str,
1322 Optional<opts::bytes::NumberRange> &Parsed) {
1323 if (Str.empty())
Zachary Turner99402032017-06-22 20:58:11 +00001324 return true;
1325
1326 llvm::Regex R("^([^-]+)(-([^-]+))?$");
1327 llvm::SmallVector<llvm::StringRef, 2> Matches;
Zachary Turner6b124f22017-06-23 19:54:44 +00001328 if (!R.match(Str, &Matches))
Zachary Turner99402032017-06-22 20:58:11 +00001329 return false;
1330
Zachary Turner6b124f22017-06-23 19:54:44 +00001331 Parsed.emplace();
1332 if (!to_integer(Matches[1], Parsed->Min))
Zachary Turner99402032017-06-22 20:58:11 +00001333 return false;
1334
1335 if (!Matches[3].empty()) {
Zachary Turner6b124f22017-06-23 19:54:44 +00001336 Parsed->Max.emplace();
1337 if (!to_integer(Matches[3], *Parsed->Max))
Zachary Turner99402032017-06-22 20:58:11 +00001338 return false;
1339 }
1340 return true;
1341}
1342
Zachary Turnere79b07e2017-06-26 17:22:36 +00001343static void simplifyChunkList(llvm::cl::list<opts::ModuleSubsection> &Chunks) {
1344 // If this list contains "All" plus some other stuff, remove the other stuff
1345 // and just keep "All" in the list.
1346 if (!llvm::is_contained(Chunks, opts::ModuleSubsection::All))
1347 return;
1348 Chunks.reset();
1349 Chunks.push_back(opts::ModuleSubsection::All);
1350}
1351
Rui Ueyama197194b2018-04-13 18:26:06 +00001352int main(int Argc, const char **Argv) {
1353 InitLLVM X(Argc, Argv);
Zachary Turnerbd336e42017-06-09 20:46:17 +00001354 ExitOnErr.setBanner("llvm-pdbutil: ");
David Majnemerc165c882016-05-28 18:25:15 +00001355
Rui Ueyama197194b2018-04-13 18:26:06 +00001356 cl::ParseCommandLineOptions(Argc, Argv, "LLVM PDB Dumper\n");
Zachary Turner6b124f22017-06-23 19:54:44 +00001357
1358 if (opts::BytesSubcommand) {
1359 if (!parseRange(opts::bytes::DumpBlockRangeOpt,
1360 opts::bytes::DumpBlockRange)) {
1361 errs() << "Argument '" << opts::bytes::DumpBlockRangeOpt
1362 << "' invalid format.\n";
1363 errs().flush();
1364 exit(1);
1365 }
1366 if (!parseRange(opts::bytes::DumpByteRangeOpt,
1367 opts::bytes::DumpByteRange)) {
1368 errs() << "Argument '" << opts::bytes::DumpByteRangeOpt
1369 << "' invalid format.\n";
1370 errs().flush();
1371 exit(1);
1372 }
Zachary Turner72c5b642016-09-09 18:17:52 +00001373 }
Zachary Turnera99000d2016-03-08 21:42:24 +00001374
Zachary Turner7df69952017-06-22 20:57:39 +00001375 if (opts::DumpSubcommand) {
1376 if (opts::dump::RawAll) {
Reid Kleckner14d90fd2017-07-26 00:40:36 +00001377 opts::dump::DumpGlobals = true;
Zachary Turner42e7cc1b2018-09-11 22:35:01 +00001378 opts::dump::DumpFpo = true;
Zachary Turner99c69822017-08-31 20:43:22 +00001379 opts::dump::DumpInlineeLines = true;
1380 opts::dump::DumpIds = true;
1381 opts::dump::DumpIdExtras = true;
1382 opts::dump::DumpLines = true;
1383 opts::dump::DumpModules = true;
1384 opts::dump::DumpModuleFiles = true;
Zachary Turner7df69952017-06-22 20:57:39 +00001385 opts::dump::DumpPublics = true;
1386 opts::dump::DumpSectionContribs = true;
Zachary Turner99c69822017-08-31 20:43:22 +00001387 opts::dump::DumpSectionHeaders = true;
Zachary Turner7df69952017-06-22 20:57:39 +00001388 opts::dump::DumpSectionMap = true;
1389 opts::dump::DumpStreams = true;
Zachary Turner5f098522017-06-23 20:28:14 +00001390 opts::dump::DumpStreamBlocks = true;
Zachary Turner7df69952017-06-22 20:57:39 +00001391 opts::dump::DumpStringTable = true;
Zachary Turnera6fb5362018-03-23 18:43:39 +00001392 opts::dump::DumpStringTableDetails = true;
Zachary Turner7df69952017-06-22 20:57:39 +00001393 opts::dump::DumpSummary = true;
1394 opts::dump::DumpSymbols = true;
Zachary Turner99c69822017-08-31 20:43:22 +00001395 opts::dump::DumpSymbolStats = true;
Zachary Turner7df69952017-06-22 20:57:39 +00001396 opts::dump::DumpTypes = true;
1397 opts::dump::DumpTypeExtras = true;
Zachary Turner99c69822017-08-31 20:43:22 +00001398 opts::dump::DumpUdtStats = true;
1399 opts::dump::DumpXme = true;
1400 opts::dump::DumpXmi = true;
Zachary Turner44a643c2017-01-12 22:28:15 +00001401 }
Zachary Turner7797c722015-03-02 04:39:56 +00001402 }
Zachary Turner3eedd162017-06-08 23:39:33 +00001403 if (opts::PdbToYamlSubcommand) {
1404 if (opts::pdb2yaml::All) {
1405 opts::pdb2yaml::StreamMetadata = true;
1406 opts::pdb2yaml::StreamDirectory = true;
1407 opts::pdb2yaml::PdbStream = true;
1408 opts::pdb2yaml::StringTable = true;
1409 opts::pdb2yaml::DbiStream = true;
1410 opts::pdb2yaml::TpiStream = true;
1411 opts::pdb2yaml::IpiStream = true;
Zachary Turner63055452017-06-15 22:24:24 +00001412 opts::pdb2yaml::DumpModules = true;
1413 opts::pdb2yaml::DumpModuleFiles = true;
1414 opts::pdb2yaml::DumpModuleSyms = true;
1415 opts::pdb2yaml::DumpModuleSubsections.push_back(
1416 opts::ModuleSubsection::All);
Zachary Turner3eedd162017-06-08 23:39:33 +00001417 }
Zachary Turnere79b07e2017-06-26 17:22:36 +00001418 simplifyChunkList(opts::pdb2yaml::DumpModuleSubsections);
Zachary Turner63055452017-06-15 22:24:24 +00001419
1420 if (opts::pdb2yaml::DumpModuleSyms || opts::pdb2yaml::DumpModuleFiles)
1421 opts::pdb2yaml::DumpModules = true;
1422
1423 if (opts::pdb2yaml::DumpModules)
1424 opts::pdb2yaml::DbiStream = true;
Zachary Turner3eedd162017-06-08 23:39:33 +00001425 }
Zachary Turnerfcb14ad2015-01-27 20:46:21 +00001426
Zachary Turner93839cb2016-06-02 05:07:49 +00001427 llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
Zachary Turnerfcb14ad2015-01-27 20:46:21 +00001428
Zachary Turnera30bd1a2016-06-30 17:42:48 +00001429 if (opts::PdbToYamlSubcommand) {
Zachary Turner8848a7a2016-07-06 18:05:57 +00001430 pdb2Yaml(opts::pdb2yaml::InputFilename.front());
Zachary Turnera30bd1a2016-06-30 17:42:48 +00001431 } else if (opts::YamlToPdbSubcommand) {
Bob Haarmande33a6372017-05-17 20:46:48 +00001432 if (opts::yaml2pdb::YamlPdbOutputFile.empty()) {
1433 SmallString<16> OutputFilename(opts::yaml2pdb::InputFilename.getValue());
1434 sys::path::replace_extension(OutputFilename, ".pdb");
1435 opts::yaml2pdb::YamlPdbOutputFile = OutputFilename.str();
1436 }
1437 yamlToPdb(opts::yaml2pdb::InputFilename);
Zachary Turnerd50c0132017-02-01 18:30:22 +00001438 } else if (opts::AnalyzeSubcommand) {
1439 dumpAnalysis(opts::analyze::InputFilename.front());
Zachary Turnerda4b63a2018-09-07 23:21:33 +00001440 } else if (opts::DiaDumpSubcommand) {
1441 llvm::for_each(opts::diadump::InputFilenames, dumpDia);
Zachary Turnera30bd1a2016-06-30 17:42:48 +00001442 } else if (opts::PrettySubcommand) {
1443 if (opts::pretty::Lines)
1444 opts::pretty::Compilands = true;
1445
1446 if (opts::pretty::All) {
1447 opts::pretty::Compilands = true;
1448 opts::pretty::Symbols = true;
1449 opts::pretty::Globals = true;
1450 opts::pretty::Types = true;
1451 opts::pretty::Externals = true;
1452 opts::pretty::Lines = true;
1453 }
1454
Zachary Turner63230a4e2017-04-06 23:43:12 +00001455 if (opts::pretty::Types) {
1456 opts::pretty::Classes = true;
1457 opts::pretty::Typedefs = true;
1458 opts::pretty::Enums = true;
1459 }
1460
Zachary Turnera30bd1a2016-06-30 17:42:48 +00001461 // When adding filters for excluded compilands and types, we need to
Zachary Turner72c5b642016-09-09 18:17:52 +00001462 // remember that these are regexes. So special characters such as * and \
1463 // need to be escaped in the regex. In the case of a literal \, this means
1464 // it needs to be escaped again in the C++. So matching a single \ in the
1465 // input requires 4 \es in the C++.
Zachary Turnera30bd1a2016-06-30 17:42:48 +00001466 if (opts::pretty::ExcludeCompilerGenerated) {
1467 opts::pretty::ExcludeTypes.push_back("__vc_attributes");
1468 opts::pretty::ExcludeCompilands.push_back("\\* Linker \\*");
1469 }
1470 if (opts::pretty::ExcludeSystemLibraries) {
1471 opts::pretty::ExcludeCompilands.push_back(
1472 "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
1473 opts::pretty::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
Zachary Turner85082012017-11-29 19:29:25 +00001474 opts::pretty::ExcludeCompilands.push_back(
1475 "d:\\\\th.obj.x86fre\\\\minkernel");
1476 }
1477 llvm::for_each(opts::pretty::InputFilenames, dumpPretty);
1478 } else if (opts::DumpSubcommand) {
1479 llvm::for_each(opts::dump::InputFilenames, dumpRaw);
1480 } else if (opts::BytesSubcommand) {
1481 llvm::for_each(opts::bytes::InputFilenames, dumpBytes);
Zachary Turner8fb441a2017-05-18 23:03:41 +00001482 } else if (opts::MergeSubcommand) {
1483 if (opts::merge::InputFilenames.size() < 2) {
1484 errs() << "merge subcommand requires at least 2 input files.\n";
1485 exit(1);
1486 }
1487 mergePdbs();
Zachary Turnerea40f402018-03-29 16:28:20 +00001488 } else if (opts::ExplainSubcommand) {
1489 explain();
Zachary Turnerd11328a2018-04-02 18:35:21 +00001490 } else if (opts::ExportSubcommand) {
1491 exportStream();
Zachary Turner1dc9fd32016-06-14 20:48:36 +00001492 }
Zachary Turnerfcb14ad2015-01-27 20:46:21 +00001493
Zachary Turner819e77d2016-05-06 20:51:57 +00001494 outs().flush();
Zachary Turnerfcb14ad2015-01-27 20:46:21 +00001495 return 0;
1496}