blob: 76f61a2a95a79ae7a2513075856dfdea1ebc40fe [file] [log] [blame]
Zachary Turnercfb13562017-06-09 20:46:17 +00001//===- llvm-pdbutil.cpp - Dump debug info from a PDB file -------*- C++ -*-===//
Zachary Turnerc1592bc2015-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 Turner435ba4a2017-03-13 23:28:25 +000010// Dumps debug information present in PDB files.
Zachary Turnerc1592bc2015-01-27 20:46:21 +000011//
12//===----------------------------------------------------------------------===//
13
Zachary Turnercfb13562017-06-09 20:46:17 +000014#include "llvm-pdbutil.h"
Zachary Turner8d4b01e2017-02-01 18:30:22 +000015
Zachary Turner08bb54f2017-06-22 20:58:11 +000016#include "BytesOutputStyle.h"
Zachary Turner08950322017-06-22 20:57:39 +000017#include "DumpOutputStyle.h"
Zachary Turner0ebcf2f2018-03-29 16:28:20 +000018#include "ExplainOutputStyle.h"
Zachary Turner6ef51e82017-09-01 20:06:56 +000019#include "InputFile.h"
Zachary Turner756b8232015-02-27 09:15:59 +000020#include "LinePrinter.h"
Zachary Turner041e9f22016-06-03 19:28:33 +000021#include "OutputStyle.h"
Zachary Turnerc779b362018-07-06 21:01:42 +000022#include "PrettyClassDefinitionDumper.h"
Zachary Turnereb6ab042017-01-11 00:35:43 +000023#include "PrettyCompilandDumper.h"
Zachary Turnerc779b362018-07-06 21:01:42 +000024#include "PrettyEnumDumper.h"
Zachary Turnereb6ab042017-01-11 00:35:43 +000025#include "PrettyExternalSymbolDumper.h"
26#include "PrettyFunctionDumper.h"
27#include "PrettyTypeDumper.h"
Zachary Turnerc779b362018-07-06 21:01:42 +000028#include "PrettyTypedefDumper.h"
Zachary Turnereb6ab042017-01-11 00:35:43 +000029#include "PrettyVariableDumper.h"
Zachary Turner61e0e272016-06-06 20:37:05 +000030#include "YAMLOutputStyle.h"
Zachary Turner395adf92015-02-22 22:03:38 +000031
Zachary Turnerc1592bc2015-01-27 20:46:21 +000032#include "llvm/ADT/ArrayRef.h"
David Majnemer4e486b62015-10-15 01:27:19 +000033#include "llvm/ADT/BitVector.h"
34#include "llvm/ADT/DenseMap.h"
Zachary Turner4c78c0e2017-05-01 23:27:42 +000035#include "llvm/ADT/STLExtras.h"
Zachary Turnerc1592bc2015-01-27 20:46:21 +000036#include "llvm/ADT/StringExtras.h"
Zachary Turner6ef51e82017-09-01 20:06:56 +000037#include "llvm/BinaryFormat/Magic.h"
Zachary Turnerb7c34eb2015-02-10 22:47:14 +000038#include "llvm/Config/config.h"
Zachary Turner47856b22017-11-30 18:39:50 +000039#include "llvm/DebugInfo/CodeView/AppendingTypeTableBuilder.h"
Zachary Turner4b1845a2017-05-30 16:36:15 +000040#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
41#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
42#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
Zachary Turnerd32a3822017-05-19 19:26:58 +000043#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
Zachary Turner47856b22017-11-30 18:39:50 +000044#include "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h"
Zachary Turner63d2fab2017-06-14 15:59:27 +000045#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
Zachary Turner47b13b02017-05-18 23:03:41 +000046#include "llvm/DebugInfo/CodeView/TypeStreamMerger.h"
Zachary Turner5e117852016-07-29 20:56:36 +000047#include "llvm/DebugInfo/MSF/MSFBuilder.h"
Zachary Turner1e708542015-02-10 22:43:25 +000048#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
Zachary Turner3eda0062018-03-13 17:46:06 +000049#include "llvm/DebugInfo/PDB/IPDBInjectedSource.h"
Zachary Turner1e708542015-02-10 22:43:25 +000050#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
Chandler Carruth02d62882015-02-13 09:09:03 +000051#include "llvm/DebugInfo/PDB/IPDBSession.h"
Zachary Turner3220dd02017-04-27 16:11:19 +000052#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h"
Adrian McCarthy11e1d832017-01-25 22:38:55 +000053#include "llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h"
Zachary Turner55ff94d2018-04-02 18:35:21 +000054#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
Adrian McCarthy11e1d832017-01-25 22:38:55 +000055#include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h"
56#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
57#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
58#include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
Zachary Turner479f5fd2017-05-02 18:00:13 +000059#include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
Adrian McCarthy11e1d832017-01-25 22:38:55 +000060#include "llvm/DebugInfo/PDB/Native/RawConstants.h"
61#include "llvm/DebugInfo/PDB/Native/RawError.h"
Adrian McCarthy11e1d832017-01-25 22:38:55 +000062#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
63#include "llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h"
Chandler Carruth02d62882015-02-13 09:09:03 +000064#include "llvm/DebugInfo/PDB/PDB.h"
Zachary Turner1e708542015-02-10 22:43:25 +000065#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
Zachary Turner964a6192015-02-27 09:15:18 +000066#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
Chandler Carruth02d62882015-02-13 09:09:03 +000067#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
Zachary Turner964a6192015-02-27 09:15:18 +000068#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
Zachary Turnerc779b362018-07-06 21:01:42 +000069#include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
Zachary Turner964a6192015-02-27 09:15:18 +000070#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
Zachary Turnerc779b362018-07-06 21:01:42 +000071#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
Zachary Turner2adab772018-09-21 22:36:28 +000072#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
73#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
Zachary Turnerc779b362018-07-06 21:01:42 +000074#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
75#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
Zachary Turnerf3491b22017-03-02 20:52:51 +000076#include "llvm/Support/BinaryByteStream.h"
Zachary Turner8839a0f2016-06-02 05:07:49 +000077#include "llvm/Support/COM.h"
Zachary Turnerc1592bc2015-01-27 20:46:21 +000078#include "llvm/Support/CommandLine.h"
79#include "llvm/Support/ConvertUTF.h"
Zachary Turner7d35b2d2016-06-14 20:48:36 +000080#include "llvm/Support/FileOutputBuffer.h"
Zachary Turner395adf92015-02-22 22:03:38 +000081#include "llvm/Support/FileSystem.h"
Zachary Turnerc1592bc2015-01-27 20:46:21 +000082#include "llvm/Support/Format.h"
Rui Ueyama0b9d56a2018-04-13 18:26:06 +000083#include "llvm/Support/InitLLVM.h"
Zachary Turnerb6d8c582017-08-21 14:53:25 +000084#include "llvm/Support/LineIterator.h"
Zachary Turnerc1592bc2015-01-27 20:46:21 +000085#include "llvm/Support/ManagedStatic.h"
David Majnemer4e486b62015-10-15 01:27:19 +000086#include "llvm/Support/MemoryBuffer.h"
Bob Haarmandc3197d2017-05-17 20:46:48 +000087#include "llvm/Support/Path.h"
Zachary Turnerc1592bc2015-01-27 20:46:21 +000088#include "llvm/Support/PrettyStackTrace.h"
Chandler Carruth02d62882015-02-13 09:09:03 +000089#include "llvm/Support/Process.h"
Zachary Turner892ff5d2016-09-09 18:17:52 +000090#include "llvm/Support/Regex.h"
Reid Klecknerd1310b72016-05-04 16:09:04 +000091#include "llvm/Support/ScopedPrinter.h"
Daniel Sanderscd2984f2016-04-22 12:04:42 +000092#include "llvm/Support/Signals.h"
Zachary Turner8ba06b52016-04-25 17:38:08 +000093#include "llvm/Support/raw_ostream.h"
Zachary Turnerc1592bc2015-01-27 20:46:21 +000094
Zachary Turnerc1592bc2015-01-27 20:46:21 +000095using namespace llvm;
Zachary Turner7e17f482016-06-03 03:25:59 +000096using namespace llvm::codeview;
Zachary Turner4ab13f52016-07-22 19:56:05 +000097using namespace llvm::msf;
Zachary Turnera91bcf52016-04-29 17:28:47 +000098using namespace llvm::pdb;
Zachary Turnerc1592bc2015-01-27 20:46:21 +000099
100namespace opts {
Zachary Turner7f6d93f2015-02-15 20:27:53 +0000101
Zachary Turner08950322017-06-22 20:57:39 +0000102cl::SubCommand DumpSubcommand("dump", "Dump MSF and CodeView debug info");
Zachary Turner08bb54f2017-06-22 20:58:11 +0000103cl::SubCommand BytesSubcommand("bytes", "Dump raw bytes from the PDB file");
104
Zachary Turner25ccaa72018-09-07 23:21:33 +0000105cl::SubCommand DiaDumpSubcommand("diadump",
106 "Dump debug information using a DIA-like API");
107
Zachary Turner3a4681d2016-06-30 17:42:48 +0000108cl::SubCommand
109 PrettySubcommand("pretty",
110 "Dump semantic information about types and symbols");
Zachary Turner435ba4a2017-03-13 23:28:25 +0000111
Zachary Turner91d41f92016-06-30 17:43:00 +0000112cl::SubCommand
113 YamlToPdbSubcommand("yaml2pdb",
114 "Generate a PDB file from a YAML description");
Zachary Turner3a4681d2016-06-30 17:42:48 +0000115cl::SubCommand
116 PdbToYamlSubcommand("pdb2yaml",
117 "Generate a detailed YAML description of a PDB File");
Zachary Turnerc1592bc2015-01-27 20:46:21 +0000118
Zachary Turner47b13b02017-05-18 23:03:41 +0000119cl::SubCommand MergeSubcommand("merge",
120 "Merge multiple PDBs into a single PDB");
121
Zachary Turner0ebcf2f2018-03-29 16:28:20 +0000122cl::SubCommand ExplainSubcommand("explain",
123 "Explain the meaning of a file offset");
124
Zachary Turner55ff94d2018-04-02 18:35:21 +0000125cl::SubCommand ExportSubcommand("export",
126 "Write binary data from a stream to a file");
127
Zachary Turner0c7c98a2015-03-02 04:39:56 +0000128cl::OptionCategory TypeCategory("Symbol Type Options");
Zachary Turner7724dc62017-04-12 23:18:21 +0000129cl::OptionCategory FilterCategory("Filtering and Sorting Options");
Zachary Turner7c69a582015-05-01 20:24:26 +0000130cl::OptionCategory OtherOptions("Other Options");
Zachary Turner3a4681d2016-06-30 17:42:48 +0000131
Zachary Turner72267192017-06-26 17:22:36 +0000132cl::ValuesClass ChunkValues = cl::values(
133 clEnumValN(ModuleSubsection::CrossScopeExports, "cme",
134 "Cross module exports (DEBUG_S_CROSSSCOPEEXPORTS subsection)"),
135 clEnumValN(ModuleSubsection::CrossScopeImports, "cmi",
136 "Cross module imports (DEBUG_S_CROSSSCOPEIMPORTS subsection)"),
137 clEnumValN(ModuleSubsection::FileChecksums, "fc",
138 "File checksums (DEBUG_S_CHECKSUMS subsection)"),
139 clEnumValN(ModuleSubsection::InlineeLines, "ilines",
140 "Inlinee lines (DEBUG_S_INLINEELINES subsection)"),
141 clEnumValN(ModuleSubsection::Lines, "lines",
142 "Lines (DEBUG_S_LINES subsection)"),
143 clEnumValN(ModuleSubsection::StringTable, "strings",
144 "String Table (DEBUG_S_STRINGTABLE subsection) (not "
145 "typically present in PDB file)"),
146 clEnumValN(ModuleSubsection::FrameData, "frames",
147 "Frame Data (DEBUG_S_FRAMEDATA subsection)"),
148 clEnumValN(ModuleSubsection::Symbols, "symbols",
149 "Symbols (DEBUG_S_SYMBOLS subsection) (not typically "
150 "present in PDB file)"),
151 clEnumValN(ModuleSubsection::CoffSymbolRVAs, "rvas",
152 "COFF Symbol RVAs (DEBUG_S_COFF_SYMBOL_RVA subsection)"),
153 clEnumValN(ModuleSubsection::Unknown, "unknown",
154 "Any subsection not covered by another option"),
155 clEnumValN(ModuleSubsection::All, "all", "All known subsections"));
156
Zachary Turner25ccaa72018-09-07 23:21:33 +0000157namespace diadump {
158cl::list<std::string> InputFilenames(cl::Positional,
159 cl::desc("<input PDB files>"),
160 cl::OneOrMore, cl::sub(DiaDumpSubcommand));
161
162cl::opt<bool> Native("native", cl::desc("Use native PDB reader instead of DIA"),
163 cl::sub(DiaDumpSubcommand));
164
Zachary Turner0c5ced82018-09-18 16:35:05 +0000165static cl::opt<bool>
166 ShowClassHierarchy("hierarchy", cl::desc("Show lexical and class parents"),
167 cl::sub(DiaDumpSubcommand));
168static cl::opt<bool> NoSymIndexIds(
169 "no-ids",
170 cl::desc("Don't show any SymIndexId fields (overrides -hierarchy)"),
171 cl::sub(DiaDumpSubcommand));
172
173static cl::opt<bool>
174 Recurse("recurse",
175 cl::desc("When dumping a SymIndexId, dump the full details of the "
176 "corresponding record"),
177 cl::sub(DiaDumpSubcommand));
178
Zachary Turner25ccaa72018-09-07 23:21:33 +0000179static cl::opt<bool> Enums("enums", cl::desc("Dump enum types"),
180 cl::sub(DiaDumpSubcommand));
181static cl::opt<bool> Pointers("pointers", cl::desc("Dump enum types"),
182 cl::sub(DiaDumpSubcommand));
Zachary Turnerb17277e2018-09-20 15:50:13 +0000183static cl::opt<bool> UDTs("udts", cl::desc("Dump udt types"),
184 cl::sub(DiaDumpSubcommand));
Zachary Turner25ccaa72018-09-07 23:21:33 +0000185static cl::opt<bool> Compilands("compilands",
186 cl::desc("Dump compiland information"),
187 cl::sub(DiaDumpSubcommand));
Zachary Turner2adab772018-09-21 22:36:28 +0000188static cl::opt<bool> Funcsigs("funcsigs",
189 cl::desc("Dump function signature information"),
190 cl::sub(DiaDumpSubcommand));
Zachary Turnere1b020a2018-09-30 16:19:18 +0000191static cl::opt<bool> Arrays("arrays", cl::desc("Dump array types"),
192 cl::sub(DiaDumpSubcommand));
Zachary Turnera93560b2018-10-01 17:55:16 +0000193static cl::opt<bool> VTShapes("vtshapes", cl::desc("Dump virtual table shapes"),
194 cl::sub(DiaDumpSubcommand));
Zachary Turnerb4781092018-10-01 17:55:38 +0000195static cl::opt<bool> Typedefs("typedefs", cl::desc("Dump typedefs"),
196 cl::sub(DiaDumpSubcommand));
Zachary Turner25ccaa72018-09-07 23:21:33 +0000197} // namespace diadump
198
Zachary Turner3a4681d2016-06-30 17:42:48 +0000199namespace pretty {
200cl::list<std::string> InputFilenames(cl::Positional,
201 cl::desc("<input PDB files>"),
202 cl::OneOrMore, cl::sub(PrettySubcommand));
Zachary Turner0c7c98a2015-03-02 04:39:56 +0000203
Zachary Turner3eda0062018-03-13 17:46:06 +0000204cl::opt<bool> InjectedSources("injected-sources",
205 cl::desc("Display injected sources"),
206 cl::cat(OtherOptions), cl::sub(PrettySubcommand));
207cl::opt<bool> ShowInjectedSourceContent(
208 "injected-source-content",
209 cl::desc("When displaying an injected source, display the file content"),
210 cl::cat(OtherOptions), cl::sub(PrettySubcommand));
211
Zachary Turnerc779b362018-07-06 21:01:42 +0000212cl::list<std::string> WithName(
213 "with-name",
214 cl::desc("Display any symbol or type with the specified exact name"),
215 cl::cat(TypeCategory), cl::ZeroOrMore, cl::sub(PrettySubcommand));
216
Zachary Turner0c7c98a2015-03-02 04:39:56 +0000217cl::opt<bool> Compilands("compilands", cl::desc("Display compilands"),
Zachary Turner3a4681d2016-06-30 17:42:48 +0000218 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turner4afda8f2017-05-14 01:13:40 +0000219cl::opt<bool> Symbols("module-syms",
220 cl::desc("Display symbols for each compiland"),
Zachary Turner3a4681d2016-06-30 17:42:48 +0000221 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turner0c7c98a2015-03-02 04:39:56 +0000222cl::opt<bool> Globals("globals", cl::desc("Dump global symbols"),
Zachary Turner3a4681d2016-06-30 17:42:48 +0000223 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turner7c69a582015-05-01 20:24:26 +0000224cl::opt<bool> Externals("externals", cl::desc("Dump external symbols"),
Zachary Turner3a4681d2016-06-30 17:42:48 +0000225 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turner4afda8f2017-05-14 01:13:40 +0000226cl::list<SymLevel> SymTypes(
227 "sym-types", cl::desc("Type of symbols to dump (default all)"),
228 cl::cat(TypeCategory), cl::sub(PrettySubcommand), cl::ZeroOrMore,
229 cl::values(
230 clEnumValN(SymLevel::Thunks, "thunks", "Display thunk symbols"),
231 clEnumValN(SymLevel::Data, "data", "Display data symbols"),
232 clEnumValN(SymLevel::Functions, "funcs", "Display function symbols"),
233 clEnumValN(SymLevel::All, "all", "Display all symbols (default)")));
234
Zachary Turnerdbbede12017-04-06 23:43:12 +0000235cl::opt<bool>
236 Types("types",
237 cl::desc("Display all types (implies -classes, -enums, -typedefs)"),
238 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
239cl::opt<bool> Classes("classes", cl::desc("Display class types"),
240 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
241cl::opt<bool> Enums("enums", cl::desc("Display enum types"),
242 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
243cl::opt<bool> Typedefs("typedefs", cl::desc("Display typedef types"),
244 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turner2adab772018-09-21 22:36:28 +0000245cl::opt<bool> Funcsigs("funcsigs", cl::desc("Display function signatures"),
246 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turnerefac3732018-09-29 23:28:19 +0000247cl::opt<bool> Pointers("pointers", cl::desc("Display pointer types"),
248 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turnere1b020a2018-09-30 16:19:18 +0000249cl::opt<bool> Arrays("arrays", cl::desc("Display arrays"),
250 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turnera93560b2018-10-01 17:55:16 +0000251cl::opt<bool> VTShapes("vtshapes", cl::desc("Display vftable shapes"),
252 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turnerefac3732018-09-29 23:28:19 +0000253
Zachary Turner4afda8f2017-05-14 01:13:40 +0000254cl::opt<SymbolSortMode> SymbolOrder(
255 "symbol-order", cl::desc("symbol sort order"),
256 cl::init(SymbolSortMode::None),
257 cl::values(clEnumValN(SymbolSortMode::None, "none",
258 "Undefined / no particular sort order"),
259 clEnumValN(SymbolSortMode::Name, "name", "Sort symbols by name"),
260 clEnumValN(SymbolSortMode::Size, "size",
261 "Sort symbols by size")),
262 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
263
Zachary Turner10683342017-04-13 21:11:00 +0000264cl::opt<ClassSortMode> ClassOrder(
265 "class-order", cl::desc("Class sort order"), cl::init(ClassSortMode::None),
Zachary Turner0e8b7072017-04-24 17:47:24 +0000266 cl::values(
267 clEnumValN(ClassSortMode::None, "none",
268 "Undefined / no particular sort order"),
269 clEnumValN(ClassSortMode::Name, "name", "Sort classes by name"),
270 clEnumValN(ClassSortMode::Size, "size", "Sort classes by size"),
271 clEnumValN(ClassSortMode::Padding, "padding",
272 "Sort classes by amount of padding"),
273 clEnumValN(ClassSortMode::PaddingPct, "padding-pct",
Zachary Turner5cec42a2017-04-25 20:22:29 +0000274 "Sort classes by percentage of space consumed by padding"),
275 clEnumValN(ClassSortMode::PaddingImmediate, "padding-imm",
276 "Sort classes by amount of immediate padding"),
277 clEnumValN(ClassSortMode::PaddingPctImmediate, "padding-pct-imm",
278 "Sort classes by percentage of space consumed by immediate "
279 "padding")),
Zachary Turner10683342017-04-13 21:11:00 +0000280 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
281
Zachary Turner7724dc62017-04-12 23:18:21 +0000282cl::opt<ClassDefinitionFormat> ClassFormat(
283 "class-definitions", cl::desc("Class definition format"),
Zachary Turner41374872017-04-24 17:47:52 +0000284 cl::init(ClassDefinitionFormat::All),
Zachary Turner7724dc62017-04-12 23:18:21 +0000285 cl::values(
Zachary Turner41374872017-04-24 17:47:52 +0000286 clEnumValN(ClassDefinitionFormat::All, "all",
Zachary Turner67dcd802017-04-12 23:18:51 +0000287 "Display all class members including data, constants, "
Zachary Turner10683342017-04-13 21:11:00 +0000288 "typedefs, functions, etc"),
Zachary Turner41374872017-04-24 17:47:52 +0000289 clEnumValN(ClassDefinitionFormat::Layout, "layout",
Zachary Turner7724dc62017-04-12 23:18:21 +0000290 "Only display members that contribute to class size."),
291 clEnumValN(ClassDefinitionFormat::None, "none",
292 "Don't display class definitions")),
293 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turner41374872017-04-24 17:47:52 +0000294cl::opt<uint32_t> ClassRecursionDepth(
295 "class-recurse-depth", cl::desc("Class recursion depth (0=no limit)"),
296 cl::init(0), cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turnerdbbede12017-04-06 23:43:12 +0000297
Zachary Turner3a4681d2016-06-30 17:42:48 +0000298cl::opt<bool> Lines("lines", cl::desc("Line tables"), cl::cat(TypeCategory),
299 cl::sub(PrettySubcommand));
Zachary Turner0c7c98a2015-03-02 04:39:56 +0000300cl::opt<bool>
Zachary Turner0c7c98a2015-03-02 04:39:56 +0000301 All("all", cl::desc("Implies all other options in 'Symbol Types' category"),
Zachary Turner3a4681d2016-06-30 17:42:48 +0000302 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turner91491392015-03-01 06:49:49 +0000303
Zachary Turner7c69a582015-05-01 20:24:26 +0000304cl::opt<uint64_t> LoadAddress(
305 "load-address",
306 cl::desc("Assume the module is loaded at the specified address"),
Zachary Turner3a4681d2016-06-30 17:42:48 +0000307 cl::cat(OtherOptions), cl::sub(PrettySubcommand));
Adrian McCarthy38f8b962017-03-15 20:17:58 +0000308cl::opt<bool> Native("native", cl::desc("Use native PDB reader instead of DIA"),
Adrian McCarthy99f73dd2017-03-23 15:28:15 +0000309 cl::cat(OtherOptions), cl::sub(PrettySubcommand));
310cl::opt<cl::boolOrDefault>
311 ColorOutput("color-output",
312 cl::desc("Override use of color (default = isatty)"),
313 cl::cat(OtherOptions), cl::sub(PrettySubcommand));
Zachary Turner3a4681d2016-06-30 17:42:48 +0000314cl::list<std::string> ExcludeTypes(
315 "exclude-types", cl::desc("Exclude types by regular expression"),
316 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
317cl::list<std::string> ExcludeSymbols(
318 "exclude-symbols", cl::desc("Exclude symbols by regular expression"),
319 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
320cl::list<std::string> ExcludeCompilands(
321 "exclude-compilands", cl::desc("Exclude compilands by regular expression"),
322 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turnerc9736fb2015-09-29 19:49:06 +0000323
324cl::list<std::string> IncludeTypes(
325 "include-types",
326 cl::desc("Include only types which match a regular expression"),
Zachary Turner3a4681d2016-06-30 17:42:48 +0000327 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turnerc9736fb2015-09-29 19:49:06 +0000328cl::list<std::string> IncludeSymbols(
329 "include-symbols",
330 cl::desc("Include only symbols which match a regular expression"),
Zachary Turner3a4681d2016-06-30 17:42:48 +0000331 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turnerc9736fb2015-09-29 19:49:06 +0000332cl::list<std::string> IncludeCompilands(
333 "include-compilands",
334 cl::desc("Include only compilands those which match a regular expression"),
Zachary Turner3a4681d2016-06-30 17:42:48 +0000335 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner10683342017-04-13 21:11:00 +0000336cl::opt<uint32_t> SizeThreshold(
337 "min-type-size", cl::desc("Displays only those types which are greater "
338 "than or equal to the specified size."),
339 cl::init(0), cl::cat(FilterCategory), cl::sub(PrettySubcommand));
340cl::opt<uint32_t> PaddingThreshold(
341 "min-class-padding", cl::desc("Displays only those classes which have at "
342 "least the specified amount of padding."),
343 cl::init(0), cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner5cec42a2017-04-25 20:22:29 +0000344cl::opt<uint32_t> ImmediatePaddingThreshold(
345 "min-class-padding-imm",
346 cl::desc("Displays only those classes which have at least the specified "
347 "amount of immediate padding, ignoring padding internal to bases "
348 "and aggregates."),
349 cl::init(0), cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turnerc9736fb2015-09-29 19:49:06 +0000350
Zachary Turner0c7c98a2015-03-02 04:39:56 +0000351cl::opt<bool> ExcludeCompilerGenerated(
352 "no-compiler-generated",
353 cl::desc("Don't show compiler generated types and symbols"),
Zachary Turner3a4681d2016-06-30 17:42:48 +0000354 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner0c7c98a2015-03-02 04:39:56 +0000355cl::opt<bool>
356 ExcludeSystemLibraries("no-system-libs",
357 cl::desc("Don't show symbols from system libraries"),
Zachary Turner3a4681d2016-06-30 17:42:48 +0000358 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turnerb4706102017-04-06 23:43:39 +0000359
Zachary Turnerb9c28bc2015-03-04 06:09:53 +0000360cl::opt<bool> NoEnumDefs("no-enum-definitions",
361 cl::desc("Don't display full enum definitions"),
Zachary Turner3a4681d2016-06-30 17:42:48 +0000362 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
363}
364
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000365cl::OptionCategory FileOptions("Module & File Options");
366
Zachary Turner08bb54f2017-06-22 20:58:11 +0000367namespace bytes {
Zachary Turner777bbb52017-06-23 21:11:54 +0000368cl::OptionCategory MsfBytes("MSF File Options");
369cl::OptionCategory DbiBytes("Dbi Stream Options");
370cl::OptionCategory PdbBytes("PDB Stream Options");
Zachary Turner5d2c9172017-06-23 21:50:54 +0000371cl::OptionCategory Types("Type Options");
Zachary Turner554302a2017-06-23 23:08:57 +0000372cl::OptionCategory ModuleCategory("Module Options");
Zachary Turner777bbb52017-06-23 21:11:54 +0000373
Zachary Turner87f3ec22017-06-23 19:54:44 +0000374llvm::Optional<NumberRange> DumpBlockRange;
375llvm::Optional<NumberRange> DumpByteRange;
376
377cl::opt<std::string> DumpBlockRangeOpt(
378 "block-range", cl::value_desc("start[-end]"),
379 cl::desc("Dump binary data from specified range of blocks."),
Zachary Turner777bbb52017-06-23 21:11:54 +0000380 cl::sub(BytesSubcommand), cl::cat(MsfBytes));
Zachary Turner08bb54f2017-06-22 20:58:11 +0000381
382cl::opt<std::string>
Zachary Turner87f3ec22017-06-23 19:54:44 +0000383 DumpByteRangeOpt("byte-range", cl::value_desc("start[-end]"),
384 cl::desc("Dump binary data from specified range of bytes"),
Zachary Turner777bbb52017-06-23 21:11:54 +0000385 cl::sub(BytesSubcommand), cl::cat(MsfBytes));
Zachary Turner08bb54f2017-06-22 20:58:11 +0000386
387cl::list<std::string>
388 DumpStreamData("stream-data", cl::CommaSeparated, cl::ZeroOrMore,
389 cl::desc("Dump binary data from specified streams. Format "
390 "is SN[:Start][@Size]"),
Zachary Turner777bbb52017-06-23 21:11:54 +0000391 cl::sub(BytesSubcommand), cl::cat(MsfBytes));
Zachary Turner08bb54f2017-06-22 20:58:11 +0000392
Zachary Turnera77c3fd2017-06-23 20:18:38 +0000393cl::opt<bool> NameMap("name-map", cl::desc("Dump bytes of PDB Name Map"),
Zachary Turner777bbb52017-06-23 21:11:54 +0000394 cl::sub(BytesSubcommand), cl::cat(PdbBytes));
Zachary Turner34173de2017-08-02 22:25:52 +0000395cl::opt<bool> Fpm("fpm", cl::desc("Dump free page map"),
396 cl::sub(BytesSubcommand), cl::cat(MsfBytes));
Zachary Turner777bbb52017-06-23 21:11:54 +0000397
398cl::opt<bool> SectionContributions("sc", cl::desc("Dump section contributions"),
399 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
400cl::opt<bool> SectionMap("sm", cl::desc("Dump section map"),
401 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
402cl::opt<bool> ModuleInfos("modi", cl::desc("Dump module info"),
403 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
404cl::opt<bool> FileInfo("files", cl::desc("Dump source file info"),
405 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
406cl::opt<bool> TypeServerMap("type-server", cl::desc("Dump type server map"),
407 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
408cl::opt<bool> ECData("ec", cl::desc("Dump edit and continue map"),
409 cl::sub(BytesSubcommand), cl::cat(DbiBytes));
Zachary Turnera77c3fd2017-06-23 20:18:38 +0000410
Zachary Turner5d2c9172017-06-23 21:50:54 +0000411cl::list<uint32_t>
412 TypeIndex("type",
413 cl::desc("Dump the type record with the given type index"),
414 cl::ZeroOrMore, cl::CommaSeparated, cl::sub(BytesSubcommand),
415 cl::cat(TypeCategory));
416cl::list<uint32_t>
417 IdIndex("id", cl::desc("Dump the id record with the given type index"),
418 cl::ZeroOrMore, cl::CommaSeparated, cl::sub(BytesSubcommand),
419 cl::cat(TypeCategory));
420
Zachary Turner554302a2017-06-23 23:08:57 +0000421cl::opt<uint32_t> ModuleIndex(
422 "mod",
423 cl::desc(
424 "Limit options in the Modules category to the specified module index"),
425 cl::Optional, cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
426cl::opt<bool> ModuleSyms("syms", cl::desc("Dump symbol record substream"),
427 cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
428cl::opt<bool> ModuleC11("c11-chunks", cl::Hidden,
429 cl::desc("Dump C11 CodeView debug chunks"),
430 cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
Zachary Turner72267192017-06-26 17:22:36 +0000431cl::opt<bool> ModuleC13("chunks",
432 cl::desc("Dump C13 CodeView debug chunk subsection"),
Zachary Turner554302a2017-06-23 23:08:57 +0000433 cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
Zachary Turner72267192017-06-26 17:22:36 +0000434cl::opt<bool> SplitChunks(
435 "split-chunks",
436 cl::desc(
437 "When dumping debug chunks, show a different section for each chunk"),
438 cl::sub(BytesSubcommand), cl::cat(ModuleCategory));
Zachary Turner08bb54f2017-06-22 20:58:11 +0000439cl::list<std::string> InputFilenames(cl::Positional,
440 cl::desc("<input PDB files>"),
441 cl::OneOrMore, cl::sub(BytesSubcommand));
442
443} // namespace bytes
444
Zachary Turner08950322017-06-22 20:57:39 +0000445namespace dump {
Zachary Turner3a4681d2016-06-30 17:42:48 +0000446
447cl::OptionCategory MsfOptions("MSF Container Options");
448cl::OptionCategory TypeOptions("Type Record Options");
Zachary Turner3a4681d2016-06-30 17:42:48 +0000449cl::OptionCategory SymbolOptions("Symbol Options");
450cl::OptionCategory MiscOptions("Miscellaneous Options");
451
452// MSF OPTIONS
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000453cl::opt<bool> DumpSummary("summary", cl::desc("dump file summary"),
Zachary Turner08950322017-06-22 20:57:39 +0000454 cl::cat(MsfOptions), cl::sub(DumpSubcommand));
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000455cl::opt<bool> DumpStreams("streams",
456 cl::desc("dump summary of the PDB streams"),
Zachary Turner08950322017-06-22 20:57:39 +0000457 cl::cat(MsfOptions), cl::sub(DumpSubcommand));
Zachary Turner055ae722017-06-23 20:28:14 +0000458cl::opt<bool> DumpStreamBlocks(
459 "stream-blocks",
460 cl::desc("Add block information to the output of -streams"),
461 cl::cat(MsfOptions), cl::sub(DumpSubcommand));
Zachary Turnerae734ae2017-08-31 20:43:22 +0000462cl::opt<bool> DumpSymbolStats(
463 "sym-stats",
464 cl::desc("Dump a detailed breakdown of symbol usage/size for each module"),
465 cl::cat(MsfOptions), cl::sub(DumpSubcommand));
466
467cl::opt<bool> DumpUdtStats(
468 "udt-stats",
469 cl::desc("Dump a detailed breakdown of S_UDT record usage / stats"),
470 cl::cat(MsfOptions), cl::sub(DumpSubcommand));
Zachary Turner3a4681d2016-06-30 17:42:48 +0000471
472// TYPE OPTIONS
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000473cl::opt<bool> DumpTypes("types",
474 cl::desc("dump CodeView type records from TPI stream"),
Zachary Turner08950322017-06-22 20:57:39 +0000475 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000476cl::opt<bool> DumpTypeData(
477 "type-data",
Zachary Turner3a4681d2016-06-30 17:42:48 +0000478 cl::desc("dump CodeView type record raw bytes from TPI stream"),
Zachary Turner08950322017-06-22 20:57:39 +0000479 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000480
Zachary Turner4d56b5f2017-06-15 23:04:42 +0000481cl::opt<bool> DumpTypeExtras("type-extras",
482 cl::desc("dump type hashes and index offsets"),
Zachary Turner08950322017-06-22 20:57:39 +0000483 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000484
Zachary Turnerb17277e2018-09-20 15:50:13 +0000485cl::opt<bool> DontResolveForwardRefs(
486 "dont-resolve-forward-refs",
487 cl::desc("When dumping type records for classes, unions, enums, and "
488 "structs, don't try to resolve forward references"),
489 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
490
Zachary Turnerbd5fe952017-06-16 23:42:15 +0000491cl::list<uint32_t> DumpTypeIndex(
Zachary Turner57f9d8e2017-07-05 18:43:25 +0000492 "type-index", cl::ZeroOrMore, cl::CommaSeparated,
Zachary Turnerbd5fe952017-06-16 23:42:15 +0000493 cl::desc("only dump types with the specified hexadecimal type index"),
Zachary Turner08950322017-06-22 20:57:39 +0000494 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turnerbd5fe952017-06-16 23:42:15 +0000495
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000496cl::opt<bool> DumpIds("ids",
497 cl::desc("dump CodeView type records from IPI stream"),
Zachary Turner08950322017-06-22 20:57:39 +0000498 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turner3a4681d2016-06-30 17:42:48 +0000499cl::opt<bool>
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000500 DumpIdData("id-data",
501 cl::desc("dump CodeView type record raw bytes from IPI stream"),
Zachary Turner08950322017-06-22 20:57:39 +0000502 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turner3a4681d2016-06-30 17:42:48 +0000503
Zachary Turner4d56b5f2017-06-15 23:04:42 +0000504cl::opt<bool> DumpIdExtras("id-extras",
505 cl::desc("dump id hashes and index offsets"),
Zachary Turner08950322017-06-22 20:57:39 +0000506 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turnerbd5fe952017-06-16 23:42:15 +0000507cl::list<uint32_t> DumpIdIndex(
Zachary Turner57f9d8e2017-07-05 18:43:25 +0000508 "id-index", cl::ZeroOrMore, cl::CommaSeparated,
Zachary Turnerbd5fe952017-06-16 23:42:15 +0000509 cl::desc("only dump ids with the specified hexadecimal type index"),
Zachary Turner08950322017-06-22 20:57:39 +0000510 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
Zachary Turner4d56b5f2017-06-15 23:04:42 +0000511
Zachary Turnerf330d3e2017-06-30 18:15:47 +0000512cl::opt<bool> DumpTypeDependents(
513 "dependents",
514 cl::desc("In conjunection with -type-index and -id-index, dumps the entire "
515 "dependency graph for the specified index instead of "
516 "just the single record with the specified index"),
517 cl::cat(TypeOptions), cl::sub(DumpSubcommand));
518
Zachary Turner3a4681d2016-06-30 17:42:48 +0000519// SYMBOL OPTIONS
Reid Kleckner4a753bd2017-07-26 00:40:36 +0000520cl::opt<bool> DumpGlobals("globals", cl::desc("dump Globals symbol records"),
521 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
522cl::opt<bool> DumpGlobalExtras("global-extras", cl::desc("dump Globals hashes"),
523 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
Zachary Turnercffc8762018-10-08 04:19:16 +0000524cl::list<std::string> DumpGlobalNames(
525 "global-name",
526 cl::desc(
527 "With -globals, only dump globals whose name matches the given value"),
528 cl::cat(SymbolOptions), cl::sub(DumpSubcommand), cl::ZeroOrMore);
Zachary Turner3a4681d2016-06-30 17:42:48 +0000529cl::opt<bool> DumpPublics("publics", cl::desc("dump Publics stream data"),
Zachary Turner08950322017-06-22 20:57:39 +0000530 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
Reid Klecknercf6f6502017-07-21 18:28:55 +0000531cl::opt<bool> DumpPublicExtras("public-extras",
532 cl::desc("dump Publics hashes and address maps"),
533 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
Zachary Turner7f08d4a2018-07-06 02:59:25 +0000534cl::opt<bool>
535 DumpGSIRecords("gsi-records",
536 cl::desc("dump public / global common record stream"),
537 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000538cl::opt<bool> DumpSymbols("symbols", cl::desc("dump module symbols"),
Zachary Turner08950322017-06-22 20:57:39 +0000539 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000540
Zachary Turner3a4681d2016-06-30 17:42:48 +0000541cl::opt<bool>
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000542 DumpSymRecordBytes("sym-data",
Zachary Turner3a4681d2016-06-30 17:42:48 +0000543 cl::desc("dump CodeView symbol record raw bytes"),
Zachary Turner08950322017-06-22 20:57:39 +0000544 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
Zachary Turner3a4681d2016-06-30 17:42:48 +0000545
Zachary Turner77a68882018-09-11 22:35:01 +0000546cl::opt<bool> DumpFpo("fpo", cl::desc("dump FPO records"),
547 cl::cat(SymbolOptions), cl::sub(DumpSubcommand));
548
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000549// MODULE & FILE OPTIONS
550cl::opt<bool> DumpModules("modules", cl::desc("dump compiland information"),
Zachary Turner08950322017-06-22 20:57:39 +0000551 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000552cl::opt<bool> DumpModuleFiles(
553 "files",
Zachary Turner7b1eb002017-06-15 23:56:19 +0000554 cl::desc("Dump the source files that contribute to each module's."),
Zachary Turner08950322017-06-22 20:57:39 +0000555 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turner7b1eb002017-06-15 23:56:19 +0000556cl::opt<bool> DumpLines(
557 "l",
558 cl::desc("dump source file/line information (DEBUG_S_LINES subsection)"),
Zachary Turner08950322017-06-22 20:57:39 +0000559 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turner7b1eb002017-06-15 23:56:19 +0000560cl::opt<bool> DumpInlineeLines(
561 "il",
562 cl::desc("dump inlinee line information (DEBUG_S_INLINEELINES subsection)"),
Zachary Turner08950322017-06-22 20:57:39 +0000563 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turner68e216b2017-06-16 00:04:24 +0000564cl::opt<bool> DumpXmi(
565 "xmi",
566 cl::desc(
567 "dump cross module imports (DEBUG_S_CROSSSCOPEIMPORTS subsection)"),
Zachary Turner08950322017-06-22 20:57:39 +0000568 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turner68e216b2017-06-16 00:04:24 +0000569cl::opt<bool> DumpXme(
570 "xme",
571 cl::desc(
572 "dump cross module exports (DEBUG_S_CROSSSCOPEEXPORTS subsection)"),
Zachary Turner08950322017-06-22 20:57:39 +0000573 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turner7f318ae2017-08-03 23:11:52 +0000574cl::opt<uint32_t> DumpModi("modi", cl::Optional,
575 cl::desc("For all options that iterate over "
576 "modules, limit to the specified module"),
577 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turnerb6d8c582017-08-21 14:53:25 +0000578cl::opt<bool> JustMyCode("jmc", cl::Optional,
579 cl::desc("For all options that iterate over modules, "
580 "ignore modules from system libraries"),
581 cl::cat(FileOptions), cl::sub(DumpSubcommand));
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000582
Zachary Turner3a4681d2016-06-30 17:42:48 +0000583// MISCELLANEOUS OPTIONS
Zachary Turner0995a922018-03-23 18:43:39 +0000584cl::opt<bool> DumpNamedStreams("named-streams",
585 cl::desc("dump PDB named stream table"),
586 cl::cat(MiscOptions), cl::sub(DumpSubcommand));
587
Zachary Turner9c1e7a62017-01-20 22:42:09 +0000588cl::opt<bool> DumpStringTable("string-table", cl::desc("dump PDB String Table"),
Zachary Turner08950322017-06-22 20:57:39 +0000589 cl::cat(MiscOptions), cl::sub(DumpSubcommand));
Zachary Turner0995a922018-03-23 18:43:39 +0000590cl::opt<bool> DumpStringTableDetails("string-table-details",
591 cl::desc("dump PDB String Table Details"),
592 cl::cat(MiscOptions),
593 cl::sub(DumpSubcommand));
Zachary Turner9c1e7a62017-01-20 22:42:09 +0000594
Zachary Turner3a4681d2016-06-30 17:42:48 +0000595cl::opt<bool> DumpSectionContribs("section-contribs",
596 cl::desc("dump section contributions"),
Zachary Turner08950322017-06-22 20:57:39 +0000597 cl::cat(MiscOptions),
598 cl::sub(DumpSubcommand));
Zachary Turner3a4681d2016-06-30 17:42:48 +0000599cl::opt<bool> DumpSectionMap("section-map", cl::desc("dump section map"),
Zachary Turner08950322017-06-22 20:57:39 +0000600 cl::cat(MiscOptions), cl::sub(DumpSubcommand));
Zachary Turner6c8e8ae2017-08-04 20:02:38 +0000601cl::opt<bool> DumpSectionHeaders("section-headers",
602 cl::desc("Dump image section headers"),
603 cl::cat(MiscOptions), cl::sub(DumpSubcommand));
Zachary Turner3a4681d2016-06-30 17:42:48 +0000604
Zachary Turner91d41f92016-06-30 17:43:00 +0000605cl::opt<bool> RawAll("all", cl::desc("Implies most other options."),
Zachary Turner08950322017-06-22 20:57:39 +0000606 cl::cat(MiscOptions), cl::sub(DumpSubcommand));
Zachary Turner3a4681d2016-06-30 17:42:48 +0000607
608cl::list<std::string> InputFilenames(cl::Positional,
609 cl::desc("<input PDB files>"),
Zachary Turner08950322017-06-22 20:57:39 +0000610 cl::OneOrMore, cl::sub(DumpSubcommand));
Zachary Turner3a4681d2016-06-30 17:42:48 +0000611}
612
613namespace yaml2pdb {
614cl::opt<std::string>
615 YamlPdbOutputFile("pdb", cl::desc("the name of the PDB file to write"),
616 cl::sub(YamlToPdbSubcommand));
617
Bob Haarmandc3197d2017-05-17 20:46:48 +0000618cl::opt<std::string> InputFilename(cl::Positional,
619 cl::desc("<input YAML file>"), cl::Required,
620 cl::sub(YamlToPdbSubcommand));
Zachary Turner3a4681d2016-06-30 17:42:48 +0000621}
622
623namespace pdb2yaml {
Bob Haarman83c5dbf2017-05-26 23:46:20 +0000624cl::opt<bool> All("all",
625 cl::desc("Dump everything we know how to dump."),
626 cl::sub(PdbToYamlSubcommand), cl::init(false));
Zachary Turner86c47632017-06-08 23:39:33 +0000627cl::opt<bool> NoFileHeaders("no-file-headers",
628 cl::desc("Do not dump MSF file headers"),
629 cl::sub(PdbToYamlSubcommand), cl::init(false));
Zachary Turnerbbf96062017-03-15 22:18:53 +0000630cl::opt<bool> Minimal("minimal",
631 cl::desc("Don't write fields with default values"),
632 cl::sub(PdbToYamlSubcommand), cl::init(false));
Zachary Turner35e1d102016-07-11 21:45:09 +0000633
Zachary Turner91d41f92016-06-30 17:43:00 +0000634cl::opt<bool> StreamMetadata(
635 "stream-metadata",
636 cl::desc("Dump the number of streams and each stream's size"),
Zachary Turner35e1d102016-07-11 21:45:09 +0000637 cl::sub(PdbToYamlSubcommand), cl::init(false));
Zachary Turner91d41f92016-06-30 17:43:00 +0000638cl::opt<bool> StreamDirectory(
639 "stream-directory",
640 cl::desc("Dump each stream's block map (implies -stream-metadata)"),
Zachary Turner35e1d102016-07-11 21:45:09 +0000641 cl::sub(PdbToYamlSubcommand), cl::init(false));
Zachary Turner6be3e7c2016-07-15 22:16:56 +0000642cl::opt<bool> PdbStream("pdb-stream",
643 cl::desc("Dump the PDB Stream (Stream 1)"),
644 cl::sub(PdbToYamlSubcommand), cl::init(false));
Zachary Turner9c1e7a62017-01-20 22:42:09 +0000645
646cl::opt<bool> StringTable("string-table", cl::desc("Dump the PDB String Table"),
647 cl::sub(PdbToYamlSubcommand), cl::init(false));
648
Zachary Turner6be3e7c2016-07-15 22:16:56 +0000649cl::opt<bool> DbiStream("dbi-stream",
Zachary Turner86c47632017-06-08 23:39:33 +0000650 cl::desc("Dump the DBI Stream Headers (Stream 2)"),
Zachary Turner6be3e7c2016-07-15 22:16:56 +0000651 cl::sub(PdbToYamlSubcommand), cl::init(false));
Zachary Turnera3ca9302017-04-25 20:22:02 +0000652
Zachary Turner3fe902e2016-08-18 16:49:29 +0000653cl::opt<bool> TpiStream("tpi-stream",
654 cl::desc("Dump the TPI Stream (Stream 3)"),
655 cl::sub(PdbToYamlSubcommand), cl::init(false));
656
Zachary Turner5fa3c522016-09-15 18:22:31 +0000657cl::opt<bool> IpiStream("ipi-stream",
658 cl::desc("Dump the IPI Stream (Stream 5)"),
659 cl::sub(PdbToYamlSubcommand), cl::init(false));
660
Zachary Turnerf3aabb02018-10-26 00:17:31 +0000661cl::opt<bool> PublicsStream("publics-stream",
662 cl::desc("Dump the Publics Stream"),
663 cl::sub(PdbToYamlSubcommand), cl::init(false));
664
Zachary Turner86c47632017-06-08 23:39:33 +0000665// MODULE & FILE OPTIONS
666cl::opt<bool> DumpModules("modules", cl::desc("dump compiland information"),
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000667 cl::cat(FileOptions), cl::sub(PdbToYamlSubcommand));
Zachary Turner86c47632017-06-08 23:39:33 +0000668cl::opt<bool> DumpModuleFiles("module-files", cl::desc("dump file information"),
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000669 cl::cat(FileOptions),
Zachary Turner86c47632017-06-08 23:39:33 +0000670 cl::sub(PdbToYamlSubcommand));
671cl::list<ModuleSubsection> DumpModuleSubsections(
672 "subsections", cl::ZeroOrMore, cl::CommaSeparated,
Zachary Turner72267192017-06-26 17:22:36 +0000673 cl::desc("dump subsections from each module's debug stream"), ChunkValues,
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000674 cl::cat(FileOptions), cl::sub(PdbToYamlSubcommand));
Zachary Turner86c47632017-06-08 23:39:33 +0000675cl::opt<bool> DumpModuleSyms("module-syms", cl::desc("dump module symbols"),
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000676 cl::cat(FileOptions),
Zachary Turner86c47632017-06-08 23:39:33 +0000677 cl::sub(PdbToYamlSubcommand));
Zachary Turner7e5d31e2017-06-15 22:24:24 +0000678
679cl::list<std::string> InputFilename(cl::Positional,
680 cl::desc("<input PDB file>"), cl::Required,
681 cl::sub(PdbToYamlSubcommand));
682} // namespace pdb2yaml
Zachary Turner86c47632017-06-08 23:39:33 +0000683
Zachary Turner47b13b02017-05-18 23:03:41 +0000684namespace merge {
685cl::list<std::string> InputFilenames(cl::Positional,
686 cl::desc("<input PDB files>"),
687 cl::OneOrMore, cl::sub(MergeSubcommand));
688cl::opt<std::string>
689 PdbOutputFile("pdb", cl::desc("the name of the PDB file to write"),
690 cl::sub(MergeSubcommand));
691}
Zachary Turner0ebcf2f2018-03-29 16:28:20 +0000692
693namespace explain {
694cl::list<std::string> InputFilename(cl::Positional,
695 cl::desc("<input PDB file>"), cl::Required,
696 cl::sub(ExplainSubcommand));
697
Zachary Turner21ff13f2018-03-30 17:16:50 +0000698cl::list<uint64_t> Offsets("offset", cl::desc("The file offset to explain"),
699 cl::sub(ExplainSubcommand), cl::OneOrMore);
Zachary Turner06e4df32018-04-04 17:29:09 +0000700
701cl::opt<InputFileType> InputType(
702 "input-type", cl::desc("Specify how to interpret the input file"),
703 cl::init(InputFileType::PDBFile), cl::Optional, cl::sub(ExplainSubcommand),
704 cl::values(clEnumValN(InputFileType::PDBFile, "pdb-file",
705 "Treat input as a PDB file (default)"),
706 clEnumValN(InputFileType::PDBStream, "pdb-stream",
707 "Treat input as raw contents of PDB stream"),
708 clEnumValN(InputFileType::DBIStream, "dbi-stream",
709 "Treat input as raw contents of DBI stream"),
710 clEnumValN(InputFileType::Names, "names-stream",
711 "Treat input as raw contents of /names named stream"),
712 clEnumValN(InputFileType::ModuleStream, "mod-stream",
713 "Treat input as raw contents of a module stream")));
Zachary Turner0ebcf2f2018-03-29 16:28:20 +0000714} // namespace explain
Zachary Turner55ff94d2018-04-02 18:35:21 +0000715
716namespace exportstream {
717cl::list<std::string> InputFilename(cl::Positional,
718 cl::desc("<input PDB file>"), cl::Required,
719 cl::sub(ExportSubcommand));
720cl::opt<std::string> OutputFile("out",
721 cl::desc("The file to write the stream to"),
722 cl::Required, cl::sub(ExportSubcommand));
723cl::opt<std::string>
724 Stream("stream", cl::Required,
725 cl::desc("The index or name of the stream whose contents to export"),
726 cl::sub(ExportSubcommand));
727cl::opt<bool> ForceName("name",
728 cl::desc("Force the interpretation of -stream as a "
729 "string, even if it is a valid integer"),
730 cl::sub(ExportSubcommand), cl::Optional,
731 cl::init(false));
732} // namespace exportstream
Zachary Turnere0f25c22015-01-28 01:22:33 +0000733}
734
David Majnemer872acbc2016-05-28 18:25:15 +0000735static ExitOnError ExitOnErr;
736
Zachary Turner7d35b2d2016-06-14 20:48:36 +0000737static void yamlToPdb(StringRef Path) {
Zachary Turner9a3129a2016-07-22 19:56:26 +0000738 BumpPtrAllocator Allocator;
Zachary Turner7d35b2d2016-06-14 20:48:36 +0000739 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
740 MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
741 /*RequiresNullTerminator=*/false);
742
743 if (ErrorOrBuffer.getError()) {
Alexandre Ganea0444f572018-08-31 17:41:58 +0000744 ExitOnErr(createFileError(Path, errorCodeToError(ErrorOrBuffer.getError())));
Zachary Turner7d35b2d2016-06-14 20:48:36 +0000745 }
746
747 std::unique_ptr<MemoryBuffer> &Buffer = ErrorOrBuffer.get();
748
749 llvm::yaml::Input In(Buffer->getBuffer());
Zachary Turnerbe73fbc2016-09-09 17:46:17 +0000750 pdb::yaml::PdbObject YamlObj(Allocator);
Zachary Turner7d35b2d2016-06-14 20:48:36 +0000751 In >> YamlObj;
752
Zachary Turner9a3129a2016-07-22 19:56:26 +0000753 PDBFileBuilder Builder(Allocator);
Zachary Turnerae108ee2016-07-11 21:45:26 +0000754
Zachary Turnerbbf96062017-03-15 22:18:53 +0000755 uint32_t BlockSize = 4096;
756 if (YamlObj.Headers.hasValue())
757 BlockSize = YamlObj.Headers->SuperBlock.BlockSize;
758 ExitOnErr(Builder.initialize(BlockSize));
Zachary Turnera9d16c92016-09-14 23:00:02 +0000759 // Add each of the reserved streams. We ignore stream metadata in the
760 // yaml, because we will reconstruct our own view of the streams. For
761 // example, the YAML may say that there were 20 streams in the original
762 // PDB, but maybe we only dump a subset of those 20 streams, so we will
763 // have fewer, and the ones we do have may end up with different indices
764 // than the ones in the original PDB. So we just start with a clean slate.
765 for (uint32_t I = 0; I < kSpecialStreamCount; ++I)
766 ExitOnErr(Builder.getMsfBuilder().addStream(0));
Zachary Turner8bf0aed2016-07-06 18:05:57 +0000767
Zachary Turner63d2fab2017-06-14 15:59:27 +0000768 StringsAndChecksums Strings;
769 Strings.setStrings(std::make_shared<DebugStringTableSubsection>());
770
Zachary Turner9c1e7a62017-01-20 22:42:09 +0000771 if (YamlObj.StringTable.hasValue()) {
Zachary Turner9c1e7a62017-01-20 22:42:09 +0000772 for (auto S : *YamlObj.StringTable)
Zachary Turner63d2fab2017-06-14 15:59:27 +0000773 Strings.strings()->insert(S);
Zachary Turner9c1e7a62017-01-20 22:42:09 +0000774 }
775
Zachary Turnerbbf96062017-03-15 22:18:53 +0000776 pdb::yaml::PdbInfoStream DefaultInfoStream;
777 pdb::yaml::PdbDbiStream DefaultDbiStream;
778 pdb::yaml::PdbTpiStream DefaultTpiStream;
Zachary Turner0897ebf2017-05-22 21:07:43 +0000779 pdb::yaml::PdbTpiStream DefaultIpiStream;
Zachary Turner7d35b2d2016-06-14 20:48:36 +0000780
Zachary Turnerbbf96062017-03-15 22:18:53 +0000781 const auto &Info = YamlObj.PdbStream.getValueOr(DefaultInfoStream);
782
783 auto &InfoBuilder = Builder.getInfoBuilder();
784 InfoBuilder.setAge(Info.Age);
785 InfoBuilder.setGuid(Info.Guid);
786 InfoBuilder.setSignature(Info.Signature);
787 InfoBuilder.setVersion(Info.Version);
Zachary Turner7ba63562017-03-16 20:19:11 +0000788 for (auto F : Info.Features)
789 InfoBuilder.addFeature(F);
Zachary Turnerbbf96062017-03-15 22:18:53 +0000790
791 const auto &Dbi = YamlObj.DbiStream.getValueOr(DefaultDbiStream);
792 auto &DbiBuilder = Builder.getDbiBuilder();
793 DbiBuilder.setAge(Dbi.Age);
794 DbiBuilder.setBuildNumber(Dbi.BuildNumber);
795 DbiBuilder.setFlags(Dbi.Flags);
796 DbiBuilder.setMachineType(Dbi.MachineType);
797 DbiBuilder.setPdbDllRbld(Dbi.PdbDllRbld);
798 DbiBuilder.setPdbDllVersion(Dbi.PdbDllVersion);
799 DbiBuilder.setVersionHeader(Dbi.VerHeader);
800 for (const auto &MI : Dbi.ModInfos) {
Zachary Turner7ba63562017-03-16 20:19:11 +0000801 auto &ModiBuilder = ExitOnErr(DbiBuilder.addModuleInfo(MI.Mod));
Bob Haarmanecda7b12017-05-25 18:04:17 +0000802 ModiBuilder.setObjFileName(MI.Obj);
Zachary Turnerbbf96062017-03-15 22:18:53 +0000803
804 for (auto S : MI.SourceFiles)
Peter Collingbourne95137e42017-09-07 20:39:46 +0000805 ExitOnErr(DbiBuilder.addModuleSourceFile(ModiBuilder, S));
Zachary Turnerbbf96062017-03-15 22:18:53 +0000806 if (MI.Modi.hasValue()) {
807 const auto &ModiStream = *MI.Modi;
Zachary Turner6a330c62017-06-01 21:52:41 +0000808 for (auto Symbol : ModiStream.Symbols) {
809 ModiBuilder.addSymbol(
810 Symbol.toCodeViewSymbol(Allocator, CodeViewContainer::Pdb));
811 }
Zachary Turner6406b602016-07-22 15:46:37 +0000812 }
Zachary Turner4c78c0e2017-05-01 23:27:42 +0000813
Zachary Turner63d2fab2017-06-14 15:59:27 +0000814 // Each module has its own checksum subsection, so scan for it every time.
815 Strings.setChecksums(nullptr);
816 CodeViewYAML::initializeStringsAndChecksums(MI.Subsections, Strings);
817
Zachary Turner68ca30a2017-06-09 00:28:08 +0000818 auto CodeViewSubsections = ExitOnErr(CodeViewYAML::toCodeViewSubsectionList(
819 Allocator, MI.Subsections, Strings));
Zachary Turner42d60ef2017-06-02 19:49:14 +0000820 for (auto &SS : CodeViewSubsections) {
Zachary Turner63d2fab2017-06-14 15:59:27 +0000821 ModiBuilder.addDebugSubsection(SS);
Zachary Turner4c78c0e2017-05-01 23:27:42 +0000822 }
Zachary Turnerae108ee2016-07-11 21:45:26 +0000823 }
824
Zachary Turnerbbf96062017-03-15 22:18:53 +0000825 auto &TpiBuilder = Builder.getTpiBuilder();
826 const auto &Tpi = YamlObj.TpiStream.getValueOr(DefaultTpiStream);
827 TpiBuilder.setVersionHeader(Tpi.Version);
Zachary Turner47856b22017-11-30 18:39:50 +0000828 AppendingTypeTableBuilder TS(Allocator);
Zachary Turnerea64a9b2017-05-30 21:53:05 +0000829 for (const auto &R : Tpi.Records) {
Zachary Turnerab45c062017-11-28 18:33:17 +0000830 CVType Type = R.toCodeViewRecord(TS);
Zachary Turnerea64a9b2017-05-30 21:53:05 +0000831 TpiBuilder.addTypeRecord(Type.RecordData, None);
832 }
Zachary Turnerbe73fbc2016-09-09 17:46:17 +0000833
Zachary Turner0897ebf2017-05-22 21:07:43 +0000834 const auto &Ipi = YamlObj.IpiStream.getValueOr(DefaultIpiStream);
Zachary Turnerbbf96062017-03-15 22:18:53 +0000835 auto &IpiBuilder = Builder.getIpiBuilder();
836 IpiBuilder.setVersionHeader(Ipi.Version);
Zachary Turnerea64a9b2017-05-30 21:53:05 +0000837 for (const auto &R : Ipi.Records) {
Zachary Turnerab45c062017-11-28 18:33:17 +0000838 CVType Type = R.toCodeViewRecord(TS);
Zachary Turnerea64a9b2017-05-30 21:53:05 +0000839 IpiBuilder.addTypeRecord(Type.RecordData, None);
840 }
Zachary Turner5fa3c522016-09-15 18:22:31 +0000841
Zachary Turner63d2fab2017-06-14 15:59:27 +0000842 Builder.getStringTableBuilder().setStrings(*Strings.strings());
843
Nico Weber23d68902018-09-15 18:35:51 +0000844 codeview::GUID IgnoredOutGuid;
845 ExitOnErr(Builder.commit(opts::yaml2pdb::YamlPdbOutputFile, &IgnoredOutGuid));
Zachary Turner7d35b2d2016-06-14 20:48:36 +0000846}
847
Zachary Turner435ba4a2017-03-13 23:28:25 +0000848static PDBFile &loadPDB(StringRef Path, std::unique_ptr<IPDBSession> &Session) {
Adrian McCarthyba78b902017-01-27 00:01:55 +0000849 ExitOnErr(loadDataForPDB(PDB_ReaderType::Native, Path, Session));
Zachary Turner8bf0aed2016-07-06 18:05:57 +0000850
Zachary Turner435ba4a2017-03-13 23:28:25 +0000851 NativeSession *NS = static_cast<NativeSession *>(Session.get());
852 return NS->getPDBFile();
853}
854
855static void pdb2Yaml(StringRef Path) {
856 std::unique_ptr<IPDBSession> Session;
857 auto &File = loadPDB(Path, Session);
858
Zachary Turner8bf0aed2016-07-06 18:05:57 +0000859 auto O = llvm::make_unique<YAMLOutputStyle>(File);
860 O = llvm::make_unique<YAMLOutputStyle>(File);
861
862 ExitOnErr(O->dump());
863}
864
Zachary Turner3a4681d2016-06-30 17:42:48 +0000865static void dumpRaw(StringRef Path) {
Zachary Turner6ef51e82017-09-01 20:06:56 +0000866 InputFile IF = ExitOnErr(InputFile::open(Path));
Zachary Turner3a4681d2016-06-30 17:42:48 +0000867
Zachary Turner6ef51e82017-09-01 20:06:56 +0000868 auto O = llvm::make_unique<DumpOutputStyle>(IF);
Zachary Turner3a4681d2016-06-30 17:42:48 +0000869 ExitOnErr(O->dump());
870}
871
Zachary Turner08bb54f2017-06-22 20:58:11 +0000872static void dumpBytes(StringRef Path) {
873 std::unique_ptr<IPDBSession> Session;
874 auto &File = loadPDB(Path, Session);
875
876 auto O = llvm::make_unique<BytesOutputStyle>(File);
877
878 ExitOnErr(O->dump());
879}
880
Zachary Turner4afda8f2017-05-14 01:13:40 +0000881bool opts::pretty::shouldDumpSymLevel(SymLevel Search) {
882 if (SymTypes.empty())
883 return true;
884 if (llvm::find(SymTypes, Search) != SymTypes.end())
885 return true;
886 if (llvm::find(SymTypes, SymLevel::All) != SymTypes.end())
887 return true;
888 return false;
889}
890
891uint32_t llvm::pdb::getTypeLength(const PDBSymbolData &Symbol) {
892 auto SymbolType = Symbol.getType();
893 const IPDBRawSymbol &RawType = SymbolType->getRawSymbol();
894
895 return RawType.getLength();
896}
897
898bool opts::pretty::compareFunctionSymbols(
899 const std::unique_ptr<PDBSymbolFunc> &F1,
900 const std::unique_ptr<PDBSymbolFunc> &F2) {
901 assert(opts::pretty::SymbolOrder != opts::pretty::SymbolSortMode::None);
902
903 if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::Name)
904 return F1->getName() < F2->getName();
905
906 // Note that we intentionally sort in descending order on length, since
907 // long functions are more interesting than short functions.
908 return F1->getLength() > F2->getLength();
909}
910
911bool opts::pretty::compareDataSymbols(
912 const std::unique_ptr<PDBSymbolData> &F1,
913 const std::unique_ptr<PDBSymbolData> &F2) {
914 assert(opts::pretty::SymbolOrder != opts::pretty::SymbolSortMode::None);
915
916 if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::Name)
917 return F1->getName() < F2->getName();
918
919 // Note that we intentionally sort in descending order on length, since
920 // large types are more interesting than short ones.
921 return getTypeLength(*F1) > getTypeLength(*F2);
922}
923
Zachary Turner3eda0062018-03-13 17:46:06 +0000924static std::string stringOr(std::string Str, std::string IfEmpty) {
925 return (Str.empty()) ? IfEmpty : Str;
926}
927
928static void dumpInjectedSources(LinePrinter &Printer, IPDBSession &Session) {
929 auto Sources = Session.getInjectedSources();
930 if (0 == Sources->getChildCount()) {
931 Printer.printLine("There are no injected sources.");
932 return;
933 }
934
935 while (auto IS = Sources->getNext()) {
936 Printer.NewLine();
937 std::string File = stringOr(IS->getFileName(), "<null>");
938 uint64_t Size = IS->getCodeByteSize();
939 std::string Obj = stringOr(IS->getObjectFileName(), "<null>");
940 std::string VFName = stringOr(IS->getVirtualFileName(), "<null>");
941 uint32_t CRC = IS->getCrc32();
942
943 std::string CompressionStr;
944 llvm::raw_string_ostream Stream(CompressionStr);
945 Stream << IS->getCompression();
946 WithColor(Printer, PDB_ColorItem::Path).get() << File;
947 Printer << " (";
948 WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Size;
949 Printer << " bytes): ";
950 WithColor(Printer, PDB_ColorItem::Keyword).get() << "obj";
951 Printer << "=";
952 WithColor(Printer, PDB_ColorItem::Path).get() << Obj;
953 Printer << ", ";
954 WithColor(Printer, PDB_ColorItem::Keyword).get() << "vname";
955 Printer << "=";
956 WithColor(Printer, PDB_ColorItem::Path).get() << VFName;
957 Printer << ", ";
958 WithColor(Printer, PDB_ColorItem::Keyword).get() << "crc";
959 Printer << "=";
960 WithColor(Printer, PDB_ColorItem::LiteralValue).get() << CRC;
961 Printer << ", ";
962 WithColor(Printer, PDB_ColorItem::Keyword).get() << "compression";
963 Printer << "=";
964 WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Stream.str();
965
966 if (!opts::pretty::ShowInjectedSourceContent)
967 continue;
968
969 // Set the indent level to 0 when printing file content.
970 int Indent = Printer.getIndentLevel();
971 Printer.Unindent(Indent);
972
973 Printer.printLine(IS->getCode());
974
975 // Re-indent back to the original level.
976 Printer.Indent(Indent);
977 }
978}
979
Zachary Turner2adab772018-09-21 22:36:28 +0000980template <typename OuterT, typename ChildT>
981void diaDumpChildren(PDBSymbol &Outer, PdbSymbolIdField Ids,
982 PdbSymbolIdField Recurse) {
983 OuterT *ConcreteOuter = dyn_cast<OuterT>(&Outer);
984 if (!ConcreteOuter)
985 return;
986
987 auto Children = ConcreteOuter->template findAllChildren<ChildT>();
988 while (auto Child = Children->getNext()) {
989 outs() << " {";
990 Child->defaultDump(outs(), 4, Ids, Recurse);
991 outs() << "\n }\n";
992 }
993}
994
Zachary Turner25ccaa72018-09-07 23:21:33 +0000995static void dumpDia(StringRef Path) {
996 std::unique_ptr<IPDBSession> Session;
997
998 const auto ReaderType =
999 opts::diadump::Native ? PDB_ReaderType::Native : PDB_ReaderType::DIA;
1000 ExitOnErr(loadDataForPDB(ReaderType, Path, Session));
1001
1002 auto GlobalScope = Session->getGlobalScope();
1003
1004 std::vector<PDB_SymType> SymTypes;
1005
1006 if (opts::diadump::Compilands)
1007 SymTypes.push_back(PDB_SymType::Compiland);
1008 if (opts::diadump::Enums)
1009 SymTypes.push_back(PDB_SymType::Enum);
1010 if (opts::diadump::Pointers)
1011 SymTypes.push_back(PDB_SymType::PointerType);
Zachary Turner9b6c4942018-09-21 22:36:04 +00001012 if (opts::diadump::UDTs)
1013 SymTypes.push_back(PDB_SymType::UDT);
Zachary Turner2adab772018-09-21 22:36:28 +00001014 if (opts::diadump::Funcsigs)
1015 SymTypes.push_back(PDB_SymType::FunctionSig);
Zachary Turnere1b020a2018-09-30 16:19:18 +00001016 if (opts::diadump::Arrays)
1017 SymTypes.push_back(PDB_SymType::ArrayType);
Zachary Turnera93560b2018-10-01 17:55:16 +00001018 if (opts::diadump::VTShapes)
1019 SymTypes.push_back(PDB_SymType::VTableShape);
Zachary Turnerb4781092018-10-01 17:55:38 +00001020 if (opts::diadump::Typedefs)
1021 SymTypes.push_back(PDB_SymType::Typedef);
Zachary Turner0c5ced82018-09-18 16:35:05 +00001022 PdbSymbolIdField Ids = opts::diadump::NoSymIndexIds ? PdbSymbolIdField::None
1023 : PdbSymbolIdField::All;
Zachary Turnera93560b2018-10-01 17:55:16 +00001024
Zachary Turner0c5ced82018-09-18 16:35:05 +00001025 PdbSymbolIdField Recurse = PdbSymbolIdField::None;
1026 if (opts::diadump::Recurse)
1027 Recurse = PdbSymbolIdField::All;
1028 if (!opts::diadump::ShowClassHierarchy)
1029 Ids &= ~(PdbSymbolIdField::ClassParent | PdbSymbolIdField::LexicalParent);
1030
Zachary Turner25ccaa72018-09-07 23:21:33 +00001031 for (PDB_SymType ST : SymTypes) {
1032 auto Children = GlobalScope->findAllChildren(ST);
1033 while (auto Child = Children->getNext()) {
1034 outs() << "{";
Zachary Turner0c5ced82018-09-18 16:35:05 +00001035 Child->defaultDump(outs(), 2, Ids, Recurse);
Zachary Turner2adab772018-09-21 22:36:28 +00001036
1037 diaDumpChildren<PDBSymbolTypeEnum, PDBSymbolData>(*Child, Ids, Recurse);
Zachary Turner25ccaa72018-09-07 23:21:33 +00001038 outs() << "\n}\n";
1039 }
1040 }
1041}
1042
Zachary Turner3a4681d2016-06-30 17:42:48 +00001043static void dumpPretty(StringRef Path) {
1044 std::unique_ptr<IPDBSession> Session;
David Majnemer00a50292016-04-28 23:47:27 +00001045
Adrian McCarthy38f8b962017-03-15 20:17:58 +00001046 const auto ReaderType =
1047 opts::pretty::Native ? PDB_ReaderType::Native : PDB_ReaderType::DIA;
1048 ExitOnErr(loadDataForPDB(ReaderType, Path, Session));
David Majnemer00a50292016-04-28 23:47:27 +00001049
Zachary Turner3a4681d2016-06-30 17:42:48 +00001050 if (opts::pretty::LoadAddress)
1051 Session->setLoadAddress(opts::pretty::LoadAddress);
Zachary Turner0f9950e2015-01-27 22:40:14 +00001052
Adrian McCarthy99f73dd2017-03-23 15:28:15 +00001053 auto &Stream = outs();
1054 const bool UseColor = opts::pretty::ColorOutput == cl::BOU_UNSET
1055 ? Stream.has_colors()
1056 : opts::pretty::ColorOutput == cl::BOU_TRUE;
1057 LinePrinter Printer(2, UseColor, Stream);
Zachary Turner756b8232015-02-27 09:15:59 +00001058
Zachary Turner1e708542015-02-10 22:43:25 +00001059 auto GlobalScope(Session->getGlobalScope());
Aaron Smith71e93df2018-03-07 02:23:08 +00001060 if (!GlobalScope)
1061 return;
Zachary Turner395adf92015-02-22 22:03:38 +00001062 std::string FileName(GlobalScope->getSymbolsFileName());
1063
Zachary Turner756b8232015-02-27 09:15:59 +00001064 WithColor(Printer, PDB_ColorItem::None).get() << "Summary for ";
1065 WithColor(Printer, PDB_ColorItem::Path).get() << FileName;
1066 Printer.Indent();
Zachary Turner395adf92015-02-22 22:03:38 +00001067 uint64_t FileSize = 0;
Zachary Turner395adf92015-02-22 22:03:38 +00001068
Zachary Turner756b8232015-02-27 09:15:59 +00001069 Printer.NewLine();
1070 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Size";
David Majnemer4e486b62015-10-15 01:27:19 +00001071 if (!sys::fs::file_size(FileName, FileSize)) {
Zachary Turner756b8232015-02-27 09:15:59 +00001072 Printer << ": " << FileSize << " bytes";
1073 } else {
1074 Printer << ": (Unable to obtain file size)";
1075 }
1076
1077 Printer.NewLine();
1078 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Guid";
1079 Printer << ": " << GlobalScope->getGuid();
1080
1081 Printer.NewLine();
1082 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Age";
1083 Printer << ": " << GlobalScope->getAge();
1084
1085 Printer.NewLine();
1086 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Attributes";
1087 Printer << ": ";
Zachary Turner395adf92015-02-22 22:03:38 +00001088 if (GlobalScope->hasCTypes())
1089 outs() << "HasCTypes ";
1090 if (GlobalScope->hasPrivateSymbols())
1091 outs() << "HasPrivateSymbols ";
Zachary Turner756b8232015-02-27 09:15:59 +00001092 Printer.Unindent();
Zachary Turner395adf92015-02-22 22:03:38 +00001093
Zachary Turnerc779b362018-07-06 21:01:42 +00001094 if (!opts::pretty::WithName.empty()) {
1095 Printer.NewLine();
1096 WithColor(Printer, PDB_ColorItem::SectionHeader).get()
1097 << "---SYMBOLS & TYPES BY NAME---";
1098
1099 for (StringRef Name : opts::pretty::WithName) {
1100 auto Symbols = GlobalScope->findChildren(
1101 PDB_SymType::None, Name, PDB_NameSearchFlags::NS_CaseSensitive);
1102 if (!Symbols || Symbols->getChildCount() == 0) {
1103 Printer.formatLine("[not found] - {0}", Name);
1104 continue;
1105 }
1106 Printer.formatLine("[{0} occurrences] - {1}", Symbols->getChildCount(),
1107 Name);
1108
1109 AutoIndent Indent(Printer);
1110 Printer.NewLine();
1111
1112 while (auto Symbol = Symbols->getNext()) {
1113 switch (Symbol->getSymTag()) {
1114 case PDB_SymType::Typedef: {
1115 TypedefDumper TD(Printer);
1116 std::unique_ptr<PDBSymbolTypeTypedef> T =
1117 llvm::unique_dyn_cast<PDBSymbolTypeTypedef>(std::move(Symbol));
1118 TD.start(*T);
1119 break;
1120 }
1121 case PDB_SymType::Enum: {
1122 EnumDumper ED(Printer);
1123 std::unique_ptr<PDBSymbolTypeEnum> E =
1124 llvm::unique_dyn_cast<PDBSymbolTypeEnum>(std::move(Symbol));
1125 ED.start(*E);
1126 break;
1127 }
1128 case PDB_SymType::UDT: {
1129 ClassDefinitionDumper CD(Printer);
1130 std::unique_ptr<PDBSymbolTypeUDT> C =
1131 llvm::unique_dyn_cast<PDBSymbolTypeUDT>(std::move(Symbol));
1132 CD.start(*C);
1133 break;
1134 }
1135 case PDB_SymType::BaseClass:
1136 case PDB_SymType::Friend: {
1137 TypeDumper TD(Printer);
1138 Symbol->dump(TD);
1139 break;
1140 }
1141 case PDB_SymType::Function: {
1142 FunctionDumper FD(Printer);
1143 std::unique_ptr<PDBSymbolFunc> F =
1144 llvm::unique_dyn_cast<PDBSymbolFunc>(std::move(Symbol));
1145 FD.start(*F, FunctionDumper::PointerType::None);
1146 break;
1147 }
1148 case PDB_SymType::Data: {
1149 VariableDumper VD(Printer);
1150 std::unique_ptr<PDBSymbolData> D =
1151 llvm::unique_dyn_cast<PDBSymbolData>(std::move(Symbol));
1152 VD.start(*D);
1153 break;
1154 }
1155 case PDB_SymType::PublicSymbol: {
1156 ExternalSymbolDumper ED(Printer);
1157 std::unique_ptr<PDBSymbolPublicSymbol> PS =
1158 llvm::unique_dyn_cast<PDBSymbolPublicSymbol>(std::move(Symbol));
1159 ED.dump(*PS);
1160 break;
1161 }
1162 default:
1163 llvm_unreachable("Unexpected symbol tag!");
1164 }
1165 }
1166 }
1167 llvm::outs().flush();
1168 }
1169
Zachary Turner3a4681d2016-06-30 17:42:48 +00001170 if (opts::pretty::Compilands) {
Zachary Turner756b8232015-02-27 09:15:59 +00001171 Printer.NewLine();
1172 WithColor(Printer, PDB_ColorItem::SectionHeader).get()
1173 << "---COMPILANDS---";
Zachary Turneraf026c12018-09-05 23:30:38 +00001174 auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
1175
1176 if (Compilands) {
Aaron Smith71e93df2018-03-07 02:23:08 +00001177 Printer.Indent();
1178 CompilandDumper Dumper(Printer);
1179 CompilandDumpFlags options = CompilandDumper::Flags::None;
1180 if (opts::pretty::Lines)
1181 options = options | CompilandDumper::Flags::Lines;
1182 while (auto Compiland = Compilands->getNext())
1183 Dumper.start(*Compiland, options);
1184 Printer.Unindent();
1185 }
Zachary Turner964a6192015-02-27 09:15:18 +00001186 }
1187
Zachary Turner2adab772018-09-21 22:36:28 +00001188 if (opts::pretty::Classes || opts::pretty::Enums || opts::pretty::Typedefs ||
Zachary Turnere1b020a2018-09-30 16:19:18 +00001189 opts::pretty::Funcsigs || opts::pretty::Pointers ||
Zachary Turnera93560b2018-10-01 17:55:16 +00001190 opts::pretty::Arrays || opts::pretty::VTShapes) {
Zachary Turner756b8232015-02-27 09:15:59 +00001191 Printer.NewLine();
1192 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---";
1193 Printer.Indent();
Zachary Turnerb9c28bc2015-03-04 06:09:53 +00001194 TypeDumper Dumper(Printer);
Zachary Turner53e4b562015-03-01 06:51:29 +00001195 Dumper.start(*GlobalScope);
Zachary Turner756b8232015-02-27 09:15:59 +00001196 Printer.Unindent();
Zachary Turner964a6192015-02-27 09:15:18 +00001197 }
1198
Zachary Turner3a4681d2016-06-30 17:42:48 +00001199 if (opts::pretty::Symbols) {
Zachary Turner756b8232015-02-27 09:15:59 +00001200 Printer.NewLine();
1201 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---SYMBOLS---";
Aaron Smith71e93df2018-03-07 02:23:08 +00001202 if (auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>()) {
1203 Printer.Indent();
1204 CompilandDumper Dumper(Printer);
1205 while (auto Compiland = Compilands->getNext())
1206 Dumper.start(*Compiland, true);
1207 Printer.Unindent();
1208 }
Zachary Turner964a6192015-02-27 09:15:18 +00001209 }
1210
Zachary Turner3a4681d2016-06-30 17:42:48 +00001211 if (opts::pretty::Globals) {
Zachary Turner756b8232015-02-27 09:15:59 +00001212 Printer.NewLine();
1213 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---GLOBALS---";
1214 Printer.Indent();
Zachary Turner4afda8f2017-05-14 01:13:40 +00001215 if (shouldDumpSymLevel(opts::pretty::SymLevel::Functions)) {
Aaron Smith71e93df2018-03-07 02:23:08 +00001216 if (auto Functions = GlobalScope->findAllChildren<PDBSymbolFunc>()) {
1217 FunctionDumper Dumper(Printer);
1218 if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
1219 while (auto Function = Functions->getNext()) {
1220 Printer.NewLine();
1221 Dumper.start(*Function, FunctionDumper::PointerType::None);
1222 }
1223 } else {
1224 std::vector<std::unique_ptr<PDBSymbolFunc>> Funcs;
1225 while (auto Func = Functions->getNext())
1226 Funcs.push_back(std::move(Func));
Fangrui Song3b35e172018-09-27 02:13:45 +00001227 llvm::sort(Funcs, opts::pretty::compareFunctionSymbols);
Aaron Smith71e93df2018-03-07 02:23:08 +00001228 for (const auto &Func : Funcs) {
1229 Printer.NewLine();
1230 Dumper.start(*Func, FunctionDumper::PointerType::None);
1231 }
Zachary Turner4afda8f2017-05-14 01:13:40 +00001232 }
Zachary Turner756b8232015-02-27 09:15:59 +00001233 }
Zachary Turner964a6192015-02-27 09:15:18 +00001234 }
Zachary Turner4afda8f2017-05-14 01:13:40 +00001235 if (shouldDumpSymLevel(opts::pretty::SymLevel::Data)) {
Aaron Smith71e93df2018-03-07 02:23:08 +00001236 if (auto Vars = GlobalScope->findAllChildren<PDBSymbolData>()) {
1237 VariableDumper Dumper(Printer);
1238 if (opts::pretty::SymbolOrder == opts::pretty::SymbolSortMode::None) {
1239 while (auto Var = Vars->getNext())
1240 Dumper.start(*Var);
1241 } else {
1242 std::vector<std::unique_ptr<PDBSymbolData>> Datas;
1243 while (auto Var = Vars->getNext())
1244 Datas.push_back(std::move(Var));
Fangrui Song3b35e172018-09-27 02:13:45 +00001245 llvm::sort(Datas, opts::pretty::compareDataSymbols);
Aaron Smith71e93df2018-03-07 02:23:08 +00001246 for (const auto &Var : Datas)
1247 Dumper.start(*Var);
1248 }
Zachary Turner4afda8f2017-05-14 01:13:40 +00001249 }
Zachary Turner964a6192015-02-27 09:15:18 +00001250 }
Zachary Turner4afda8f2017-05-14 01:13:40 +00001251 if (shouldDumpSymLevel(opts::pretty::SymLevel::Thunks)) {
Aaron Smith71e93df2018-03-07 02:23:08 +00001252 if (auto Thunks = GlobalScope->findAllChildren<PDBSymbolThunk>()) {
1253 CompilandDumper Dumper(Printer);
1254 while (auto Thunk = Thunks->getNext())
1255 Dumper.dump(*Thunk);
1256 }
Zachary Turner964a6192015-02-27 09:15:18 +00001257 }
Zachary Turner756b8232015-02-27 09:15:59 +00001258 Printer.Unindent();
Zachary Turner0f9950e2015-01-27 22:40:14 +00001259 }
Zachary Turner3a4681d2016-06-30 17:42:48 +00001260 if (opts::pretty::Externals) {
Zachary Turner7c69a582015-05-01 20:24:26 +00001261 Printer.NewLine();
1262 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---EXTERNALS---";
1263 Printer.Indent();
1264 ExternalSymbolDumper Dumper(Printer);
1265 Dumper.start(*GlobalScope);
1266 }
Zachary Turner3a4681d2016-06-30 17:42:48 +00001267 if (opts::pretty::Lines) {
Zachary Turnera20f3bc2016-03-08 21:42:24 +00001268 Printer.NewLine();
1269 }
Zachary Turner3eda0062018-03-13 17:46:06 +00001270 if (opts::pretty::InjectedSources) {
1271 Printer.NewLine();
1272 WithColor(Printer, PDB_ColorItem::SectionHeader).get()
1273 << "---INJECTED SOURCES---";
1274 AutoIndent Indent1(Printer);
1275
1276 if (ReaderType == PDB_ReaderType::Native)
1277 Printer.printLine(
1278 "Injected sources are not supported with the native reader.");
1279 else
1280 dumpInjectedSources(Printer, *Session);
1281 }
1282
Zachary Turnere1b020a2018-09-30 16:19:18 +00001283 Printer.NewLine();
Zachary Turner1e708542015-02-10 22:43:25 +00001284 outs().flush();
Zachary Turnerc1592bc2015-01-27 20:46:21 +00001285}
1286
Zachary Turner47b13b02017-05-18 23:03:41 +00001287static void mergePdbs() {
1288 BumpPtrAllocator Allocator;
Zachary Turner47856b22017-11-30 18:39:50 +00001289 MergingTypeTableBuilder MergedTpi(Allocator);
1290 MergingTypeTableBuilder MergedIpi(Allocator);
Zachary Turner47b13b02017-05-18 23:03:41 +00001291
1292 // Create a Tpi and Ipi type table with all types from all input files.
1293 for (const auto &Path : opts::merge::InputFilenames) {
1294 std::unique_ptr<IPDBSession> Session;
1295 auto &File = loadPDB(Path, Session);
Zachary Turner0897ebf2017-05-22 21:07:43 +00001296 SmallVector<TypeIndex, 128> TypeMap;
1297 SmallVector<TypeIndex, 128> IdMap;
Zachary Turner47b13b02017-05-18 23:03:41 +00001298 if (File.hasPDBTpiStream()) {
1299 auto &Tpi = ExitOnErr(File.getPDBTpiStream());
Reid Kleckner53034fb2017-07-17 20:28:06 +00001300 ExitOnErr(
1301 codeview::mergeTypeRecords(MergedTpi, TypeMap, Tpi.typeArray()));
Zachary Turner47b13b02017-05-18 23:03:41 +00001302 }
1303 if (File.hasPDBIpiStream()) {
1304 auto &Ipi = ExitOnErr(File.getPDBIpiStream());
Zachary Turner0897ebf2017-05-22 21:07:43 +00001305 ExitOnErr(codeview::mergeIdRecords(MergedIpi, TypeMap, IdMap,
Zachary Turner819a5c62017-05-24 00:35:32 +00001306 Ipi.typeArray()));
Zachary Turner47b13b02017-05-18 23:03:41 +00001307 }
1308 }
1309
1310 // Then write the PDB.
1311 PDBFileBuilder Builder(Allocator);
1312 ExitOnErr(Builder.initialize(4096));
1313 // Add each of the reserved streams. We might not put any data in them,
1314 // but at least they have to be present.
1315 for (uint32_t I = 0; I < kSpecialStreamCount; ++I)
1316 ExitOnErr(Builder.getMsfBuilder().addStream(0));
1317
1318 auto &DestTpi = Builder.getTpiBuilder();
1319 auto &DestIpi = Builder.getIpiBuilder();
Zachary Turner7fe0c002017-11-29 19:35:21 +00001320 MergedTpi.ForEachRecord([&DestTpi](TypeIndex TI, const CVType &Type) {
1321 DestTpi.addTypeRecord(Type.RecordData, None);
Reid Kleckner9d053872017-05-23 18:23:59 +00001322 });
Zachary Turner7fe0c002017-11-29 19:35:21 +00001323 MergedIpi.ForEachRecord([&DestIpi](TypeIndex TI, const CVType &Type) {
1324 DestIpi.addTypeRecord(Type.RecordData, None);
Reid Kleckner9d053872017-05-23 18:23:59 +00001325 });
Zachary Turneraaa081a2017-06-12 21:34:53 +00001326 Builder.getInfoBuilder().addFeature(PdbRaw_FeatureSig::VC140);
Zachary Turner47b13b02017-05-18 23:03:41 +00001327
Zachary Turnera269f902017-05-19 06:25:09 +00001328 SmallString<64> OutFile(opts::merge::PdbOutputFile);
Zachary Turner47b13b02017-05-18 23:03:41 +00001329 if (OutFile.empty()) {
1330 OutFile = opts::merge::InputFilenames[0];
1331 llvm::sys::path::replace_extension(OutFile, "merged.pdb");
1332 }
Nico Weber23d68902018-09-15 18:35:51 +00001333
1334 codeview::GUID IgnoredOutGuid;
1335 ExitOnErr(Builder.commit(OutFile, &IgnoredOutGuid));
Zachary Turner47b13b02017-05-18 23:03:41 +00001336}
1337
Zachary Turner0ebcf2f2018-03-29 16:28:20 +00001338static void explain() {
1339 std::unique_ptr<IPDBSession> Session;
Zachary Turner06e4df32018-04-04 17:29:09 +00001340 InputFile IF =
1341 ExitOnErr(InputFile::open(opts::explain::InputFilename.front(), true));
Zachary Turner0ebcf2f2018-03-29 16:28:20 +00001342
Zachary Turner21ff13f2018-03-30 17:16:50 +00001343 for (uint64_t Off : opts::explain::Offsets) {
Zachary Turner06e4df32018-04-04 17:29:09 +00001344 auto O = llvm::make_unique<ExplainOutputStyle>(IF, Off);
Zachary Turner21ff13f2018-03-30 17:16:50 +00001345
1346 ExitOnErr(O->dump());
1347 }
Zachary Turner0ebcf2f2018-03-29 16:28:20 +00001348}
1349
Zachary Turner55ff94d2018-04-02 18:35:21 +00001350static void exportStream() {
1351 std::unique_ptr<IPDBSession> Session;
1352 PDBFile &File = loadPDB(opts::exportstream::InputFilename.front(), Session);
1353
1354 std::unique_ptr<MappedBlockStream> SourceStream;
1355 uint32_t Index = 0;
1356 bool Success = false;
1357 std::string OutFileName = opts::exportstream::OutputFile;
1358
1359 if (!opts::exportstream::ForceName) {
1360 // First try to parse it as an integer, if it fails fall back to treating it
1361 // as a named stream.
1362 if (to_integer(opts::exportstream::Stream, Index)) {
1363 if (Index >= File.getNumStreams()) {
1364 errs() << "Error: " << Index << " is not a valid stream index.\n";
1365 exit(1);
1366 }
1367 Success = true;
1368 outs() << "Dumping contents of stream index " << Index << " to file "
1369 << OutFileName << ".\n";
1370 }
1371 }
1372
1373 if (!Success) {
1374 InfoStream &IS = cantFail(File.getPDBInfoStream());
1375 Index = ExitOnErr(IS.getNamedStreamIndex(opts::exportstream::Stream));
1376 outs() << "Dumping contents of stream '" << opts::exportstream::Stream
1377 << "' (index " << Index << ") to file " << OutFileName << ".\n";
1378 }
1379
1380 SourceStream = MappedBlockStream::createIndexedStream(
1381 File.getMsfLayout(), File.getMsfBuffer(), Index, File.getAllocator());
1382 auto OutFile = ExitOnErr(
1383 FileOutputBuffer::create(OutFileName, SourceStream->getLength()));
1384 FileBufferByteStream DestStream(std::move(OutFile), llvm::support::little);
1385 BinaryStreamWriter Writer(DestStream);
1386 ExitOnErr(Writer.writeStreamRef(*SourceStream));
1387 ExitOnErr(DestStream.commit());
1388}
1389
Zachary Turner87f3ec22017-06-23 19:54:44 +00001390static bool parseRange(StringRef Str,
1391 Optional<opts::bytes::NumberRange> &Parsed) {
1392 if (Str.empty())
Zachary Turner08bb54f2017-06-22 20:58:11 +00001393 return true;
1394
1395 llvm::Regex R("^([^-]+)(-([^-]+))?$");
1396 llvm::SmallVector<llvm::StringRef, 2> Matches;
Zachary Turner87f3ec22017-06-23 19:54:44 +00001397 if (!R.match(Str, &Matches))
Zachary Turner08bb54f2017-06-22 20:58:11 +00001398 return false;
1399
Zachary Turner87f3ec22017-06-23 19:54:44 +00001400 Parsed.emplace();
1401 if (!to_integer(Matches[1], Parsed->Min))
Zachary Turner08bb54f2017-06-22 20:58:11 +00001402 return false;
1403
1404 if (!Matches[3].empty()) {
Zachary Turner87f3ec22017-06-23 19:54:44 +00001405 Parsed->Max.emplace();
1406 if (!to_integer(Matches[3], *Parsed->Max))
Zachary Turner08bb54f2017-06-22 20:58:11 +00001407 return false;
1408 }
1409 return true;
1410}
1411
Zachary Turner72267192017-06-26 17:22:36 +00001412static void simplifyChunkList(llvm::cl::list<opts::ModuleSubsection> &Chunks) {
1413 // If this list contains "All" plus some other stuff, remove the other stuff
1414 // and just keep "All" in the list.
1415 if (!llvm::is_contained(Chunks, opts::ModuleSubsection::All))
1416 return;
1417 Chunks.reset();
1418 Chunks.push_back(opts::ModuleSubsection::All);
1419}
1420
Rui Ueyama0b9d56a2018-04-13 18:26:06 +00001421int main(int Argc, const char **Argv) {
1422 InitLLVM X(Argc, Argv);
Zachary Turnercfb13562017-06-09 20:46:17 +00001423 ExitOnErr.setBanner("llvm-pdbutil: ");
David Majnemer872acbc2016-05-28 18:25:15 +00001424
Rui Ueyama0b9d56a2018-04-13 18:26:06 +00001425 cl::ParseCommandLineOptions(Argc, Argv, "LLVM PDB Dumper\n");
Zachary Turner87f3ec22017-06-23 19:54:44 +00001426
1427 if (opts::BytesSubcommand) {
1428 if (!parseRange(opts::bytes::DumpBlockRangeOpt,
1429 opts::bytes::DumpBlockRange)) {
1430 errs() << "Argument '" << opts::bytes::DumpBlockRangeOpt
1431 << "' invalid format.\n";
1432 errs().flush();
1433 exit(1);
1434 }
1435 if (!parseRange(opts::bytes::DumpByteRangeOpt,
1436 opts::bytes::DumpByteRange)) {
1437 errs() << "Argument '" << opts::bytes::DumpByteRangeOpt
1438 << "' invalid format.\n";
1439 errs().flush();
1440 exit(1);
1441 }
Zachary Turner892ff5d2016-09-09 18:17:52 +00001442 }
Zachary Turnera20f3bc2016-03-08 21:42:24 +00001443
Zachary Turner08950322017-06-22 20:57:39 +00001444 if (opts::DumpSubcommand) {
1445 if (opts::dump::RawAll) {
Reid Kleckner4a753bd2017-07-26 00:40:36 +00001446 opts::dump::DumpGlobals = true;
Zachary Turner77a68882018-09-11 22:35:01 +00001447 opts::dump::DumpFpo = true;
Zachary Turnerae734ae2017-08-31 20:43:22 +00001448 opts::dump::DumpInlineeLines = true;
1449 opts::dump::DumpIds = true;
1450 opts::dump::DumpIdExtras = true;
1451 opts::dump::DumpLines = true;
1452 opts::dump::DumpModules = true;
1453 opts::dump::DumpModuleFiles = true;
Zachary Turner08950322017-06-22 20:57:39 +00001454 opts::dump::DumpPublics = true;
1455 opts::dump::DumpSectionContribs = true;
Zachary Turnerae734ae2017-08-31 20:43:22 +00001456 opts::dump::DumpSectionHeaders = true;
Zachary Turner08950322017-06-22 20:57:39 +00001457 opts::dump::DumpSectionMap = true;
1458 opts::dump::DumpStreams = true;
Zachary Turner055ae722017-06-23 20:28:14 +00001459 opts::dump::DumpStreamBlocks = true;
Zachary Turner08950322017-06-22 20:57:39 +00001460 opts::dump::DumpStringTable = true;
Zachary Turner0995a922018-03-23 18:43:39 +00001461 opts::dump::DumpStringTableDetails = true;
Zachary Turner08950322017-06-22 20:57:39 +00001462 opts::dump::DumpSummary = true;
1463 opts::dump::DumpSymbols = true;
Zachary Turnerae734ae2017-08-31 20:43:22 +00001464 opts::dump::DumpSymbolStats = true;
Zachary Turner08950322017-06-22 20:57:39 +00001465 opts::dump::DumpTypes = true;
1466 opts::dump::DumpTypeExtras = true;
Zachary Turnerae734ae2017-08-31 20:43:22 +00001467 opts::dump::DumpUdtStats = true;
1468 opts::dump::DumpXme = true;
1469 opts::dump::DumpXmi = true;
Zachary Turner233ecbd2017-01-12 22:28:15 +00001470 }
Zachary Turner0c7c98a2015-03-02 04:39:56 +00001471 }
Zachary Turner86c47632017-06-08 23:39:33 +00001472 if (opts::PdbToYamlSubcommand) {
1473 if (opts::pdb2yaml::All) {
1474 opts::pdb2yaml::StreamMetadata = true;
1475 opts::pdb2yaml::StreamDirectory = true;
1476 opts::pdb2yaml::PdbStream = true;
1477 opts::pdb2yaml::StringTable = true;
1478 opts::pdb2yaml::DbiStream = true;
1479 opts::pdb2yaml::TpiStream = true;
1480 opts::pdb2yaml::IpiStream = true;
Zachary Turnerf3aabb02018-10-26 00:17:31 +00001481 opts::pdb2yaml::PublicsStream = true;
Zachary Turner7e5d31e2017-06-15 22:24:24 +00001482 opts::pdb2yaml::DumpModules = true;
1483 opts::pdb2yaml::DumpModuleFiles = true;
1484 opts::pdb2yaml::DumpModuleSyms = true;
1485 opts::pdb2yaml::DumpModuleSubsections.push_back(
1486 opts::ModuleSubsection::All);
Zachary Turner86c47632017-06-08 23:39:33 +00001487 }
Zachary Turner72267192017-06-26 17:22:36 +00001488 simplifyChunkList(opts::pdb2yaml::DumpModuleSubsections);
Zachary Turner7e5d31e2017-06-15 22:24:24 +00001489
1490 if (opts::pdb2yaml::DumpModuleSyms || opts::pdb2yaml::DumpModuleFiles)
1491 opts::pdb2yaml::DumpModules = true;
1492
1493 if (opts::pdb2yaml::DumpModules)
1494 opts::pdb2yaml::DbiStream = true;
Zachary Turner86c47632017-06-08 23:39:33 +00001495 }
Zachary Turnerc1592bc2015-01-27 20:46:21 +00001496
Zachary Turner8839a0f2016-06-02 05:07:49 +00001497 llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
Zachary Turnerc1592bc2015-01-27 20:46:21 +00001498
Zachary Turner3a4681d2016-06-30 17:42:48 +00001499 if (opts::PdbToYamlSubcommand) {
Zachary Turner8bf0aed2016-07-06 18:05:57 +00001500 pdb2Yaml(opts::pdb2yaml::InputFilename.front());
Zachary Turner3a4681d2016-06-30 17:42:48 +00001501 } else if (opts::YamlToPdbSubcommand) {
Bob Haarmandc3197d2017-05-17 20:46:48 +00001502 if (opts::yaml2pdb::YamlPdbOutputFile.empty()) {
1503 SmallString<16> OutputFilename(opts::yaml2pdb::InputFilename.getValue());
1504 sys::path::replace_extension(OutputFilename, ".pdb");
1505 opts::yaml2pdb::YamlPdbOutputFile = OutputFilename.str();
1506 }
1507 yamlToPdb(opts::yaml2pdb::InputFilename);
Zachary Turner25ccaa72018-09-07 23:21:33 +00001508 } else if (opts::DiaDumpSubcommand) {
1509 llvm::for_each(opts::diadump::InputFilenames, dumpDia);
Zachary Turner3a4681d2016-06-30 17:42:48 +00001510 } else if (opts::PrettySubcommand) {
1511 if (opts::pretty::Lines)
1512 opts::pretty::Compilands = true;
1513
1514 if (opts::pretty::All) {
1515 opts::pretty::Compilands = true;
1516 opts::pretty::Symbols = true;
1517 opts::pretty::Globals = true;
1518 opts::pretty::Types = true;
1519 opts::pretty::Externals = true;
1520 opts::pretty::Lines = true;
1521 }
1522
Zachary Turnerdbbede12017-04-06 23:43:12 +00001523 if (opts::pretty::Types) {
1524 opts::pretty::Classes = true;
1525 opts::pretty::Typedefs = true;
1526 opts::pretty::Enums = true;
Zachary Turnerefac3732018-09-29 23:28:19 +00001527 opts::pretty::Pointers = true;
1528 opts::pretty::Funcsigs = true;
Zachary Turnerdbbede12017-04-06 23:43:12 +00001529 }
1530
Zachary Turner3a4681d2016-06-30 17:42:48 +00001531 // When adding filters for excluded compilands and types, we need to
Zachary Turner892ff5d2016-09-09 18:17:52 +00001532 // remember that these are regexes. So special characters such as * and \
1533 // need to be escaped in the regex. In the case of a literal \, this means
1534 // it needs to be escaped again in the C++. So matching a single \ in the
1535 // input requires 4 \es in the C++.
Zachary Turner3a4681d2016-06-30 17:42:48 +00001536 if (opts::pretty::ExcludeCompilerGenerated) {
1537 opts::pretty::ExcludeTypes.push_back("__vc_attributes");
1538 opts::pretty::ExcludeCompilands.push_back("\\* Linker \\*");
1539 }
1540 if (opts::pretty::ExcludeSystemLibraries) {
1541 opts::pretty::ExcludeCompilands.push_back(
1542 "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
1543 opts::pretty::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
Zachary Turner4c205742017-11-29 19:29:25 +00001544 opts::pretty::ExcludeCompilands.push_back(
1545 "d:\\\\th.obj.x86fre\\\\minkernel");
1546 }
1547 llvm::for_each(opts::pretty::InputFilenames, dumpPretty);
1548 } else if (opts::DumpSubcommand) {
1549 llvm::for_each(opts::dump::InputFilenames, dumpRaw);
1550 } else if (opts::BytesSubcommand) {
1551 llvm::for_each(opts::bytes::InputFilenames, dumpBytes);
Zachary Turner47b13b02017-05-18 23:03:41 +00001552 } else if (opts::MergeSubcommand) {
1553 if (opts::merge::InputFilenames.size() < 2) {
1554 errs() << "merge subcommand requires at least 2 input files.\n";
1555 exit(1);
1556 }
1557 mergePdbs();
Zachary Turner0ebcf2f2018-03-29 16:28:20 +00001558 } else if (opts::ExplainSubcommand) {
1559 explain();
Zachary Turner55ff94d2018-04-02 18:35:21 +00001560 } else if (opts::ExportSubcommand) {
1561 exportStream();
Zachary Turner7d35b2d2016-06-14 20:48:36 +00001562 }
Zachary Turnerc1592bc2015-01-27 20:46:21 +00001563
Zachary Turnerfdb6da32016-05-06 20:51:57 +00001564 outs().flush();
Zachary Turnerc1592bc2015-01-27 20:46:21 +00001565 return 0;
1566}