1 //===- llvm-pdbutil.cpp - Dump debug info from a PDB file -------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Dumps debug information present in PDB files.
11 //===----------------------------------------------------------------------===//
13 #include "llvm-pdbutil.h"
15 #include "BytesOutputStyle.h"
16 #include "DumpOutputStyle.h"
17 #include "ExplainOutputStyle.h"
18 #include "OutputStyle.h"
19 #include "PrettyClassDefinitionDumper.h"
20 #include "PrettyCompilandDumper.h"
21 #include "PrettyEnumDumper.h"
22 #include "PrettyExternalSymbolDumper.h"
23 #include "PrettyFunctionDumper.h"
24 #include "PrettyTypeDumper.h"
25 #include "PrettyTypedefDumper.h"
26 #include "PrettyVariableDumper.h"
27 #include "YAMLOutputStyle.h"
29 #include "llvm/ADT/ArrayRef.h"
30 #include "llvm/ADT/STLExtras.h"
31 #include "llvm/ADT/StringExtras.h"
32 #include "llvm/BinaryFormat/Magic.h"
33 #include "llvm/Config/config.h"
34 #include "llvm/DebugInfo/CodeView/AppendingTypeTableBuilder.h"
35 #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
36 #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
37 #include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
38 #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
39 #include "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h"
40 #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
41 #include "llvm/DebugInfo/CodeView/TypeStreamMerger.h"
42 #include "llvm/DebugInfo/MSF/MSFBuilder.h"
43 #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
44 #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
45 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
46 #include "llvm/DebugInfo/PDB/IPDBInjectedSource.h"
47 #include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
48 #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
49 #include "llvm/DebugInfo/PDB/IPDBSession.h"
50 #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h"
51 #include "llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h"
52 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
53 #include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h"
54 #include "llvm/DebugInfo/PDB/Native/InputFile.h"
55 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
56 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
57 #include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
58 #include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
59 #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
60 #include "llvm/DebugInfo/PDB/Native/RawError.h"
61 #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
62 #include "llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h"
63 #include "llvm/DebugInfo/PDB/PDB.h"
64 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
65 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
66 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
67 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
68 #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
69 #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
70 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
71 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
72 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
73 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
74 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
75 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
76 #include "llvm/Support/BinaryByteStream.h"
77 #include "llvm/Support/COM.h"
78 #include "llvm/Support/CommandLine.h"
79 #include "llvm/Support/ConvertUTF.h"
80 #include "llvm/Support/FileOutputBuffer.h"
81 #include "llvm/Support/FileSystem.h"
82 #include "llvm/Support/Format.h"
83 #include "llvm/Support/InitLLVM.h"
84 #include "llvm/Support/LineIterator.h"
85 #include "llvm/Support/MemoryBuffer.h"
86 #include "llvm/Support/Path.h"
87 #include "llvm/Support/PrettyStackTrace.h"
88 #include "llvm/Support/Process.h"
89 #include "llvm/Support/Regex.h"
90 #include "llvm/Support/ScopedPrinter.h"
91 #include "llvm/Support/Signals.h"
92 #include "llvm/Support/raw_ostream.h"
95 using namespace llvm::codeview
;
96 using namespace llvm::msf
;
97 using namespace llvm::pdb
;
101 cl::SubCommand
DumpSubcommand("dump", "Dump MSF and CodeView debug info");
102 cl::SubCommand
BytesSubcommand("bytes", "Dump raw bytes from the PDB file");
104 cl::SubCommand
DiaDumpSubcommand("diadump",
105 "Dump debug information using a DIA-like API");
108 PrettySubcommand("pretty",
109 "Dump semantic information about types and symbols");
112 YamlToPdbSubcommand("yaml2pdb",
113 "Generate a PDB file from a YAML description");
115 PdbToYamlSubcommand("pdb2yaml",
116 "Generate a detailed YAML description of a PDB File");
118 cl::SubCommand
MergeSubcommand("merge",
119 "Merge multiple PDBs into a single PDB");
121 cl::SubCommand
ExplainSubcommand("explain",
122 "Explain the meaning of a file offset");
124 cl::SubCommand
ExportSubcommand("export",
125 "Write binary data from a stream to a file");
127 cl::OptionCategory
TypeCategory("Symbol Type Options");
128 cl::OptionCategory
FilterCategory("Filtering and Sorting Options");
129 cl::OptionCategory
OtherOptions("Other Options");
131 cl::ValuesClass ChunkValues
= cl::values(
132 clEnumValN(ModuleSubsection::CrossScopeExports
, "cme",
133 "Cross module exports (DEBUG_S_CROSSSCOPEEXPORTS subsection)"),
134 clEnumValN(ModuleSubsection::CrossScopeImports
, "cmi",
135 "Cross module imports (DEBUG_S_CROSSSCOPEIMPORTS subsection)"),
136 clEnumValN(ModuleSubsection::FileChecksums
, "fc",
137 "File checksums (DEBUG_S_CHECKSUMS subsection)"),
138 clEnumValN(ModuleSubsection::InlineeLines
, "ilines",
139 "Inlinee lines (DEBUG_S_INLINEELINES subsection)"),
140 clEnumValN(ModuleSubsection::Lines
, "lines",
141 "Lines (DEBUG_S_LINES subsection)"),
142 clEnumValN(ModuleSubsection::StringTable
, "strings",
143 "String Table (DEBUG_S_STRINGTABLE subsection) (not "
144 "typically present in PDB file)"),
145 clEnumValN(ModuleSubsection::FrameData
, "frames",
146 "Frame Data (DEBUG_S_FRAMEDATA subsection)"),
147 clEnumValN(ModuleSubsection::Symbols
, "symbols",
148 "Symbols (DEBUG_S_SYMBOLS subsection) (not typically "
149 "present in PDB file)"),
150 clEnumValN(ModuleSubsection::CoffSymbolRVAs
, "rvas",
151 "COFF Symbol RVAs (DEBUG_S_COFF_SYMBOL_RVA subsection)"),
152 clEnumValN(ModuleSubsection::Unknown
, "unknown",
153 "Any subsection not covered by another option"),
154 clEnumValN(ModuleSubsection::All
, "all", "All known subsections"));
157 cl::list
<std::string
> InputFilenames(cl::Positional
,
158 cl::desc("<input PDB files>"),
159 cl::OneOrMore
, cl::sub(DiaDumpSubcommand
));
161 cl::opt
<bool> Native("native", cl::desc("Use native PDB reader instead of DIA"),
162 cl::sub(DiaDumpSubcommand
));
165 ShowClassHierarchy("hierarchy", cl::desc("Show lexical and class parents"),
166 cl::sub(DiaDumpSubcommand
));
167 static cl::opt
<bool> NoSymIndexIds(
169 cl::desc("Don't show any SymIndexId fields (overrides -hierarchy)"),
170 cl::sub(DiaDumpSubcommand
));
174 cl::desc("When dumping a SymIndexId, dump the full details of the "
175 "corresponding record"),
176 cl::sub(DiaDumpSubcommand
));
178 static cl::opt
<bool> Enums("enums", cl::desc("Dump enum types"),
179 cl::sub(DiaDumpSubcommand
));
180 static cl::opt
<bool> Pointers("pointers", cl::desc("Dump enum types"),
181 cl::sub(DiaDumpSubcommand
));
182 static cl::opt
<bool> UDTs("udts", cl::desc("Dump udt types"),
183 cl::sub(DiaDumpSubcommand
));
184 static cl::opt
<bool> Compilands("compilands",
185 cl::desc("Dump compiland information"),
186 cl::sub(DiaDumpSubcommand
));
187 static cl::opt
<bool> Funcsigs("funcsigs",
188 cl::desc("Dump function signature information"),
189 cl::sub(DiaDumpSubcommand
));
190 static cl::opt
<bool> Arrays("arrays", cl::desc("Dump array types"),
191 cl::sub(DiaDumpSubcommand
));
192 static cl::opt
<bool> VTShapes("vtshapes", cl::desc("Dump virtual table shapes"),
193 cl::sub(DiaDumpSubcommand
));
194 static cl::opt
<bool> Typedefs("typedefs", cl::desc("Dump typedefs"),
195 cl::sub(DiaDumpSubcommand
));
196 } // namespace diadump
198 FilterOptions Filters
;
201 cl::list
<std::string
> InputFilenames(cl::Positional
,
202 cl::desc("<input PDB files>"),
203 cl::OneOrMore
, cl::sub(PrettySubcommand
));
205 cl::opt
<bool> InjectedSources("injected-sources",
206 cl::desc("Display injected sources"),
207 cl::cat(OtherOptions
), cl::sub(PrettySubcommand
));
208 cl::opt
<bool> ShowInjectedSourceContent(
209 "injected-source-content",
210 cl::desc("When displaying an injected source, display the file content"),
211 cl::cat(OtherOptions
), cl::sub(PrettySubcommand
));
213 cl::list
<std::string
> WithName(
215 cl::desc("Display any symbol or type with the specified exact name"),
216 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
218 cl::opt
<bool> Compilands("compilands", cl::desc("Display compilands"),
219 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
220 cl::opt
<bool> Symbols("module-syms",
221 cl::desc("Display symbols for each compiland"),
222 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
223 cl::opt
<bool> Globals("globals", cl::desc("Dump global symbols"),
224 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
225 cl::opt
<bool> Externals("externals", cl::desc("Dump external symbols"),
226 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
227 cl::list
<SymLevel
> SymTypes(
228 "sym-types", cl::desc("Type of symbols to dump (default all)"),
229 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
),
231 clEnumValN(SymLevel::Thunks
, "thunks", "Display thunk symbols"),
232 clEnumValN(SymLevel::Data
, "data", "Display data symbols"),
233 clEnumValN(SymLevel::Functions
, "funcs", "Display function symbols"),
234 clEnumValN(SymLevel::All
, "all", "Display all symbols (default)")));
238 cl::desc("Display all types (implies -classes, -enums, -typedefs)"),
239 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
240 cl::opt
<bool> Classes("classes", cl::desc("Display class types"),
241 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
242 cl::opt
<bool> Enums("enums", cl::desc("Display enum types"),
243 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
244 cl::opt
<bool> Typedefs("typedefs", cl::desc("Display typedef types"),
245 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
246 cl::opt
<bool> Funcsigs("funcsigs", cl::desc("Display function signatures"),
247 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
248 cl::opt
<bool> Pointers("pointers", cl::desc("Display pointer types"),
249 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
250 cl::opt
<bool> Arrays("arrays", cl::desc("Display arrays"),
251 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
252 cl::opt
<bool> VTShapes("vtshapes", cl::desc("Display vftable shapes"),
253 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
255 cl::opt
<SymbolSortMode
> SymbolOrder(
256 "symbol-order", cl::desc("symbol sort order"),
257 cl::init(SymbolSortMode::None
),
258 cl::values(clEnumValN(SymbolSortMode::None
, "none",
259 "Undefined / no particular sort order"),
260 clEnumValN(SymbolSortMode::Name
, "name", "Sort symbols by name"),
261 clEnumValN(SymbolSortMode::Size
, "size",
262 "Sort symbols by size")),
263 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
265 cl::opt
<ClassSortMode
> ClassOrder(
266 "class-order", cl::desc("Class sort order"), cl::init(ClassSortMode::None
),
268 clEnumValN(ClassSortMode::None
, "none",
269 "Undefined / no particular sort order"),
270 clEnumValN(ClassSortMode::Name
, "name", "Sort classes by name"),
271 clEnumValN(ClassSortMode::Size
, "size", "Sort classes by size"),
272 clEnumValN(ClassSortMode::Padding
, "padding",
273 "Sort classes by amount of padding"),
274 clEnumValN(ClassSortMode::PaddingPct
, "padding-pct",
275 "Sort classes by percentage of space consumed by padding"),
276 clEnumValN(ClassSortMode::PaddingImmediate
, "padding-imm",
277 "Sort classes by amount of immediate padding"),
278 clEnumValN(ClassSortMode::PaddingPctImmediate
, "padding-pct-imm",
279 "Sort classes by percentage of space consumed by immediate "
281 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
283 cl::opt
<ClassDefinitionFormat
> ClassFormat(
284 "class-definitions", cl::desc("Class definition format"),
285 cl::init(ClassDefinitionFormat::All
),
287 clEnumValN(ClassDefinitionFormat::All
, "all",
288 "Display all class members including data, constants, "
289 "typedefs, functions, etc"),
290 clEnumValN(ClassDefinitionFormat::Layout
, "layout",
291 "Only display members that contribute to class size."),
292 clEnumValN(ClassDefinitionFormat::None
, "none",
293 "Don't display class definitions")),
294 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
295 cl::opt
<uint32_t> ClassRecursionDepth(
296 "class-recurse-depth", cl::desc("Class recursion depth (0=no limit)"),
297 cl::init(0), cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
299 cl::opt
<bool> Lines("lines", cl::desc("Line tables"), cl::cat(TypeCategory
),
300 cl::sub(PrettySubcommand
));
302 All("all", cl::desc("Implies all other options in 'Symbol Types' category"),
303 cl::cat(TypeCategory
), cl::sub(PrettySubcommand
));
305 cl::opt
<uint64_t> LoadAddress(
307 cl::desc("Assume the module is loaded at the specified address"),
308 cl::cat(OtherOptions
), cl::sub(PrettySubcommand
));
309 cl::opt
<bool> Native("native", cl::desc("Use native PDB reader instead of DIA"),
310 cl::cat(OtherOptions
), cl::sub(PrettySubcommand
));
311 cl::opt
<cl::boolOrDefault
>
312 ColorOutput("color-output",
313 cl::desc("Override use of color (default = isatty)"),
314 cl::cat(OtherOptions
), cl::sub(PrettySubcommand
));
315 cl::list
<std::string
>
316 ExcludeTypes("exclude-types",
317 cl::desc("Exclude types by regular expression"),
318 cl::cat(FilterCategory
), cl::sub(PrettySubcommand
));
319 cl::list
<std::string
>
320 ExcludeSymbols("exclude-symbols",
321 cl::desc("Exclude symbols by regular expression"),
322 cl::cat(FilterCategory
), cl::sub(PrettySubcommand
));
323 cl::list
<std::string
>
324 ExcludeCompilands("exclude-compilands",
325 cl::desc("Exclude compilands by regular expression"),
326 cl::cat(FilterCategory
), cl::sub(PrettySubcommand
));
328 cl::list
<std::string
> IncludeTypes(
330 cl::desc("Include only types which match a regular expression"),
331 cl::cat(FilterCategory
), cl::sub(PrettySubcommand
));
332 cl::list
<std::string
> IncludeSymbols(
334 cl::desc("Include only symbols which match a regular expression"),
335 cl::cat(FilterCategory
), cl::sub(PrettySubcommand
));
336 cl::list
<std::string
> IncludeCompilands(
337 "include-compilands",
338 cl::desc("Include only compilands those which match a regular expression"),
339 cl::cat(FilterCategory
), cl::sub(PrettySubcommand
));
340 cl::opt
<uint32_t> SizeThreshold(
341 "min-type-size", cl::desc("Displays only those types which are greater "
342 "than or equal to the specified size."),
343 cl::init(0), cl::cat(FilterCategory
), cl::sub(PrettySubcommand
));
344 cl::opt
<uint32_t> PaddingThreshold(
345 "min-class-padding", cl::desc("Displays only those classes which have at "
346 "least the specified amount of padding."),
347 cl::init(0), cl::cat(FilterCategory
), cl::sub(PrettySubcommand
));
348 cl::opt
<uint32_t> ImmediatePaddingThreshold(
349 "min-class-padding-imm",
350 cl::desc("Displays only those classes which have at least the specified "
351 "amount of immediate padding, ignoring padding internal to bases "
353 cl::init(0), cl::cat(FilterCategory
), cl::sub(PrettySubcommand
));
355 cl::opt
<bool> ExcludeCompilerGenerated(
356 "no-compiler-generated",
357 cl::desc("Don't show compiler generated types and symbols"),
358 cl::cat(FilterCategory
), cl::sub(PrettySubcommand
));
360 ExcludeSystemLibraries("no-system-libs",
361 cl::desc("Don't show symbols from system libraries"),
362 cl::cat(FilterCategory
), cl::sub(PrettySubcommand
));
364 cl::opt
<bool> NoEnumDefs("no-enum-definitions",
365 cl::desc("Don't display full enum definitions"),
366 cl::cat(FilterCategory
), cl::sub(PrettySubcommand
));
369 cl::OptionCategory
FileOptions("Module & File Options");
372 cl::OptionCategory
MsfBytes("MSF File Options");
373 cl::OptionCategory
DbiBytes("Dbi Stream Options");
374 cl::OptionCategory
PdbBytes("PDB Stream Options");
375 cl::OptionCategory
Types("Type Options");
376 cl::OptionCategory
ModuleCategory("Module Options");
378 std::optional
<NumberRange
> DumpBlockRange
;
379 std::optional
<NumberRange
> DumpByteRange
;
381 cl::opt
<std::string
> DumpBlockRangeOpt(
382 "block-range", cl::value_desc("start[-end]"),
383 cl::desc("Dump binary data from specified range of blocks."),
384 cl::sub(BytesSubcommand
), cl::cat(MsfBytes
));
387 DumpByteRangeOpt("byte-range", cl::value_desc("start[-end]"),
388 cl::desc("Dump binary data from specified range of bytes"),
389 cl::sub(BytesSubcommand
), cl::cat(MsfBytes
));
391 cl::list
<std::string
>
392 DumpStreamData("stream-data", cl::CommaSeparated
,
393 cl::desc("Dump binary data from specified streams. Format "
394 "is SN[:Start][@Size]"),
395 cl::sub(BytesSubcommand
), cl::cat(MsfBytes
));
397 cl::opt
<bool> NameMap("name-map", cl::desc("Dump bytes of PDB Name Map"),
398 cl::sub(BytesSubcommand
), cl::cat(PdbBytes
));
399 cl::opt
<bool> Fpm("fpm", cl::desc("Dump free page map"),
400 cl::sub(BytesSubcommand
), cl::cat(MsfBytes
));
402 cl::opt
<bool> SectionContributions("sc", cl::desc("Dump section contributions"),
403 cl::sub(BytesSubcommand
), cl::cat(DbiBytes
));
404 cl::opt
<bool> SectionMap("sm", cl::desc("Dump section map"),
405 cl::sub(BytesSubcommand
), cl::cat(DbiBytes
));
406 cl::opt
<bool> ModuleInfos("modi", cl::desc("Dump module info"),
407 cl::sub(BytesSubcommand
), cl::cat(DbiBytes
));
408 cl::opt
<bool> FileInfo("files", cl::desc("Dump source file info"),
409 cl::sub(BytesSubcommand
), cl::cat(DbiBytes
));
410 cl::opt
<bool> TypeServerMap("type-server", cl::desc("Dump type server map"),
411 cl::sub(BytesSubcommand
), cl::cat(DbiBytes
));
412 cl::opt
<bool> ECData("ec", cl::desc("Dump edit and continue map"),
413 cl::sub(BytesSubcommand
), cl::cat(DbiBytes
));
415 cl::list
<uint32_t> TypeIndex(
416 "type", cl::desc("Dump the type record with the given type index"),
417 cl::CommaSeparated
, cl::sub(BytesSubcommand
), cl::cat(TypeCategory
));
419 IdIndex("id", cl::desc("Dump the id record with the given type index"),
420 cl::CommaSeparated
, cl::sub(BytesSubcommand
),
421 cl::cat(TypeCategory
));
423 cl::opt
<uint32_t> ModuleIndex(
426 "Limit options in the Modules category to the specified module index"),
427 cl::Optional
, cl::sub(BytesSubcommand
), cl::cat(ModuleCategory
));
428 cl::opt
<bool> ModuleSyms("syms", cl::desc("Dump symbol record substream"),
429 cl::sub(BytesSubcommand
), cl::cat(ModuleCategory
));
430 cl::opt
<bool> ModuleC11("c11-chunks", cl::Hidden
,
431 cl::desc("Dump C11 CodeView debug chunks"),
432 cl::sub(BytesSubcommand
), cl::cat(ModuleCategory
));
433 cl::opt
<bool> ModuleC13("chunks",
434 cl::desc("Dump C13 CodeView debug chunk subsection"),
435 cl::sub(BytesSubcommand
), cl::cat(ModuleCategory
));
436 cl::opt
<bool> SplitChunks(
439 "When dumping debug chunks, show a different section for each chunk"),
440 cl::sub(BytesSubcommand
), cl::cat(ModuleCategory
));
441 cl::list
<std::string
> InputFilenames(cl::Positional
,
442 cl::desc("<input PDB files>"),
443 cl::OneOrMore
, cl::sub(BytesSubcommand
));
449 cl::OptionCategory
MsfOptions("MSF Container Options");
450 cl::OptionCategory
TypeOptions("Type Record Options");
451 cl::OptionCategory
SymbolOptions("Symbol Options");
452 cl::OptionCategory
MiscOptions("Miscellaneous Options");
455 cl::opt
<bool> DumpSummary("summary", cl::desc("dump file summary"),
456 cl::cat(MsfOptions
), cl::sub(DumpSubcommand
));
457 cl::opt
<bool> DumpStreams("streams",
458 cl::desc("dump summary of the PDB streams"),
459 cl::cat(MsfOptions
), cl::sub(DumpSubcommand
));
460 cl::opt
<bool> DumpStreamBlocks(
462 cl::desc("Add block information to the output of -streams"),
463 cl::cat(MsfOptions
), cl::sub(DumpSubcommand
));
464 cl::opt
<bool> DumpSymbolStats(
466 cl::desc("Dump a detailed breakdown of symbol usage/size for each module"),
467 cl::cat(MsfOptions
), cl::sub(DumpSubcommand
));
468 cl::opt
<bool> DumpTypeStats(
470 cl::desc("Dump a detailed breakdown of type usage/size"),
471 cl::cat(MsfOptions
), cl::sub(DumpSubcommand
));
472 cl::opt
<bool> DumpIDStats(
474 cl::desc("Dump a detailed breakdown of IPI types usage/size"),
475 cl::cat(MsfOptions
), cl::sub(DumpSubcommand
));
476 cl::opt
<bool> DumpUdtStats(
478 cl::desc("Dump a detailed breakdown of S_UDT record usage / stats"),
479 cl::cat(MsfOptions
), cl::sub(DumpSubcommand
));
482 cl::opt
<bool> DumpTypes("types",
483 cl::desc("dump CodeView type records from TPI stream"),
484 cl::cat(TypeOptions
), cl::sub(DumpSubcommand
));
485 cl::opt
<bool> DumpTypeData(
487 cl::desc("dump CodeView type record raw bytes from TPI stream"),
488 cl::cat(TypeOptions
), cl::sub(DumpSubcommand
));
490 DumpTypeRefStats("type-ref-stats",
491 cl::desc("dump statistics on the number and size of types "
492 "transitively referenced by symbol records"),
493 cl::cat(TypeOptions
), cl::sub(DumpSubcommand
));
495 cl::opt
<bool> DumpTypeExtras("type-extras",
496 cl::desc("dump type hashes and index offsets"),
497 cl::cat(TypeOptions
), cl::sub(DumpSubcommand
));
499 cl::opt
<bool> DontResolveForwardRefs(
500 "dont-resolve-forward-refs",
501 cl::desc("When dumping type records for classes, unions, enums, and "
502 "structs, don't try to resolve forward references"),
503 cl::cat(TypeOptions
), cl::sub(DumpSubcommand
));
505 cl::list
<uint32_t> DumpTypeIndex(
506 "type-index", cl::CommaSeparated
,
507 cl::desc("only dump types with the specified hexadecimal type index"),
508 cl::cat(TypeOptions
), cl::sub(DumpSubcommand
));
510 cl::opt
<bool> DumpIds("ids",
511 cl::desc("dump CodeView type records from IPI stream"),
512 cl::cat(TypeOptions
), cl::sub(DumpSubcommand
));
514 DumpIdData("id-data",
515 cl::desc("dump CodeView type record raw bytes from IPI stream"),
516 cl::cat(TypeOptions
), cl::sub(DumpSubcommand
));
518 cl::opt
<bool> DumpIdExtras("id-extras",
519 cl::desc("dump id hashes and index offsets"),
520 cl::cat(TypeOptions
), cl::sub(DumpSubcommand
));
521 cl::list
<uint32_t> DumpIdIndex(
522 "id-index", cl::CommaSeparated
,
523 cl::desc("only dump ids with the specified hexadecimal type index"),
524 cl::cat(TypeOptions
), cl::sub(DumpSubcommand
));
526 cl::opt
<bool> DumpTypeDependents(
528 cl::desc("In conjunection with -type-index and -id-index, dumps the entire "
529 "dependency graph for the specified index instead of "
530 "just the single record with the specified index"),
531 cl::cat(TypeOptions
), cl::sub(DumpSubcommand
));
534 cl::opt
<bool> DumpGlobals("globals", cl::desc("dump Globals symbol records"),
535 cl::cat(SymbolOptions
), cl::sub(DumpSubcommand
));
536 cl::opt
<bool> DumpGlobalExtras("global-extras", cl::desc("dump Globals hashes"),
537 cl::cat(SymbolOptions
), cl::sub(DumpSubcommand
));
538 cl::list
<std::string
> DumpGlobalNames(
541 "With -globals, only dump globals whose name matches the given value"),
542 cl::cat(SymbolOptions
), cl::sub(DumpSubcommand
));
543 cl::opt
<bool> DumpPublics("publics", cl::desc("dump Publics stream data"),
544 cl::cat(SymbolOptions
), cl::sub(DumpSubcommand
));
545 cl::opt
<bool> DumpPublicExtras("public-extras",
546 cl::desc("dump Publics hashes and address maps"),
547 cl::cat(SymbolOptions
), cl::sub(DumpSubcommand
));
549 DumpGSIRecords("gsi-records",
550 cl::desc("dump public / global common record stream"),
551 cl::cat(SymbolOptions
), cl::sub(DumpSubcommand
));
552 cl::opt
<bool> DumpSymbols("symbols", cl::desc("dump module symbols"),
553 cl::cat(SymbolOptions
), cl::sub(DumpSubcommand
));
556 DumpSymRecordBytes("sym-data",
557 cl::desc("dump CodeView symbol record raw bytes"),
558 cl::cat(SymbolOptions
), cl::sub(DumpSubcommand
));
560 cl::opt
<bool> DumpFpo("fpo", cl::desc("dump FPO records"),
561 cl::cat(SymbolOptions
), cl::sub(DumpSubcommand
));
563 cl::opt
<uint32_t> DumpSymbolOffset(
564 "symbol-offset", cl::Optional
,
565 cl::desc("only dump symbol record with the specified symbol offset"),
566 cl::cat(SymbolOptions
), cl::sub(DumpSubcommand
));
567 cl::opt
<bool> DumpParents("show-parents",
568 cl::desc("dump the symbols record's all parents."),
569 cl::cat(SymbolOptions
), cl::sub(DumpSubcommand
));
571 DumpParentDepth("parent-recurse-depth", cl::Optional
, cl::init(-1U),
572 cl::desc("only recurse to a depth of N when displaying "
573 "parents of a symbol record."),
574 cl::cat(SymbolOptions
), cl::sub(DumpSubcommand
));
575 cl::opt
<bool> DumpChildren("show-children",
576 cl::desc("dump the symbols record's all children."),
577 cl::cat(SymbolOptions
), cl::sub(DumpSubcommand
));
579 DumpChildrenDepth("children-recurse-depth", cl::Optional
, cl::init(-1U),
580 cl::desc("only recurse to a depth of N when displaying "
581 "children of a symbol record."),
582 cl::cat(SymbolOptions
), cl::sub(DumpSubcommand
));
584 // MODULE & FILE OPTIONS
585 cl::opt
<bool> DumpModules("modules", cl::desc("dump compiland information"),
586 cl::cat(FileOptions
), cl::sub(DumpSubcommand
));
587 cl::opt
<bool> DumpModuleFiles(
589 cl::desc("Dump the source files that contribute to each module's."),
590 cl::cat(FileOptions
), cl::sub(DumpSubcommand
));
591 cl::opt
<bool> DumpLines(
593 cl::desc("dump source file/line information (DEBUG_S_LINES subsection)"),
594 cl::cat(FileOptions
), cl::sub(DumpSubcommand
));
595 cl::opt
<bool> DumpInlineeLines(
597 cl::desc("dump inlinee line information (DEBUG_S_INLINEELINES subsection)"),
598 cl::cat(FileOptions
), cl::sub(DumpSubcommand
));
599 cl::opt
<bool> DumpXmi(
602 "dump cross module imports (DEBUG_S_CROSSSCOPEIMPORTS subsection)"),
603 cl::cat(FileOptions
), cl::sub(DumpSubcommand
));
604 cl::opt
<bool> DumpXme(
607 "dump cross module exports (DEBUG_S_CROSSSCOPEEXPORTS subsection)"),
608 cl::cat(FileOptions
), cl::sub(DumpSubcommand
));
609 cl::opt
<uint32_t> DumpModi("modi", cl::Optional
,
610 cl::desc("For all options that iterate over "
611 "modules, limit to the specified module"),
612 cl::cat(FileOptions
), cl::sub(DumpSubcommand
));
613 cl::opt
<bool> JustMyCode("jmc", cl::Optional
,
614 cl::desc("For all options that iterate over modules, "
615 "ignore modules from system libraries"),
616 cl::cat(FileOptions
), cl::sub(DumpSubcommand
));
618 // MISCELLANEOUS OPTIONS
619 cl::opt
<bool> DumpNamedStreams("named-streams",
620 cl::desc("dump PDB named stream table"),
621 cl::cat(MiscOptions
), cl::sub(DumpSubcommand
));
623 cl::opt
<bool> DumpStringTable("string-table", cl::desc("dump PDB String Table"),
624 cl::cat(MiscOptions
), cl::sub(DumpSubcommand
));
625 cl::opt
<bool> DumpStringTableDetails("string-table-details",
626 cl::desc("dump PDB String Table Details"),
627 cl::cat(MiscOptions
),
628 cl::sub(DumpSubcommand
));
630 cl::opt
<bool> DumpSectionContribs("section-contribs",
631 cl::desc("dump section contributions"),
632 cl::cat(MiscOptions
),
633 cl::sub(DumpSubcommand
));
634 cl::opt
<bool> DumpSectionMap("section-map", cl::desc("dump section map"),
635 cl::cat(MiscOptions
), cl::sub(DumpSubcommand
));
636 cl::opt
<bool> DumpSectionHeaders("section-headers",
637 cl::desc("Dump image section headers"),
638 cl::cat(MiscOptions
), cl::sub(DumpSubcommand
));
640 cl::opt
<bool> RawAll("all", cl::desc("Implies most other options."),
641 cl::cat(MiscOptions
), cl::sub(DumpSubcommand
));
643 cl::list
<std::string
> InputFilenames(cl::Positional
,
644 cl::desc("<input PDB files>"),
645 cl::OneOrMore
, cl::sub(DumpSubcommand
));
650 YamlPdbOutputFile("pdb", cl::desc("the name of the PDB file to write"),
651 cl::sub(YamlToPdbSubcommand
));
653 cl::opt
<std::string
> InputFilename(cl::Positional
,
654 cl::desc("<input YAML file>"), cl::Required
,
655 cl::sub(YamlToPdbSubcommand
));
659 cl::opt
<bool> All("all",
660 cl::desc("Dump everything we know how to dump."),
661 cl::sub(PdbToYamlSubcommand
), cl::init(false));
662 cl::opt
<bool> NoFileHeaders("no-file-headers",
663 cl::desc("Do not dump MSF file headers"),
664 cl::sub(PdbToYamlSubcommand
), cl::init(false));
665 cl::opt
<bool> Minimal("minimal",
666 cl::desc("Don't write fields with default values"),
667 cl::sub(PdbToYamlSubcommand
), cl::init(false));
669 cl::opt
<bool> StreamMetadata(
671 cl::desc("Dump the number of streams and each stream's size"),
672 cl::sub(PdbToYamlSubcommand
), cl::init(false));
673 cl::opt
<bool> StreamDirectory(
675 cl::desc("Dump each stream's block map (implies -stream-metadata)"),
676 cl::sub(PdbToYamlSubcommand
), cl::init(false));
677 cl::opt
<bool> PdbStream("pdb-stream",
678 cl::desc("Dump the PDB Stream (Stream 1)"),
679 cl::sub(PdbToYamlSubcommand
), cl::init(false));
681 cl::opt
<bool> StringTable("string-table", cl::desc("Dump the PDB String Table"),
682 cl::sub(PdbToYamlSubcommand
), cl::init(false));
684 cl::opt
<bool> DbiStream("dbi-stream",
685 cl::desc("Dump the DBI Stream Headers (Stream 2)"),
686 cl::sub(PdbToYamlSubcommand
), cl::init(false));
688 cl::opt
<bool> TpiStream("tpi-stream",
689 cl::desc("Dump the TPI Stream (Stream 3)"),
690 cl::sub(PdbToYamlSubcommand
), cl::init(false));
692 cl::opt
<bool> IpiStream("ipi-stream",
693 cl::desc("Dump the IPI Stream (Stream 5)"),
694 cl::sub(PdbToYamlSubcommand
), cl::init(false));
696 cl::opt
<bool> PublicsStream("publics-stream",
697 cl::desc("Dump the Publics Stream"),
698 cl::sub(PdbToYamlSubcommand
), cl::init(false));
700 // MODULE & FILE OPTIONS
701 cl::opt
<bool> DumpModules("modules", cl::desc("dump compiland information"),
702 cl::cat(FileOptions
), cl::sub(PdbToYamlSubcommand
));
703 cl::opt
<bool> DumpModuleFiles("module-files", cl::desc("dump file information"),
704 cl::cat(FileOptions
),
705 cl::sub(PdbToYamlSubcommand
));
706 cl::list
<ModuleSubsection
> DumpModuleSubsections(
707 "subsections", cl::CommaSeparated
,
708 cl::desc("dump subsections from each module's debug stream"), ChunkValues
,
709 cl::cat(FileOptions
), cl::sub(PdbToYamlSubcommand
));
710 cl::opt
<bool> DumpModuleSyms("module-syms", cl::desc("dump module symbols"),
711 cl::cat(FileOptions
),
712 cl::sub(PdbToYamlSubcommand
));
714 cl::list
<std::string
> InputFilename(cl::Positional
,
715 cl::desc("<input PDB file>"), cl::Required
,
716 cl::sub(PdbToYamlSubcommand
));
717 } // namespace pdb2yaml
720 cl::list
<std::string
> InputFilenames(cl::Positional
,
721 cl::desc("<input PDB files>"),
722 cl::OneOrMore
, cl::sub(MergeSubcommand
));
724 PdbOutputFile("pdb", cl::desc("the name of the PDB file to write"),
725 cl::sub(MergeSubcommand
));
729 cl::list
<std::string
> InputFilename(cl::Positional
,
730 cl::desc("<input PDB file>"), cl::Required
,
731 cl::sub(ExplainSubcommand
));
733 cl::list
<uint64_t> Offsets("offset", cl::desc("The file offset to explain"),
734 cl::sub(ExplainSubcommand
), cl::OneOrMore
);
736 cl::opt
<InputFileType
> InputType(
737 "input-type", cl::desc("Specify how to interpret the input file"),
738 cl::init(InputFileType::PDBFile
), cl::Optional
, cl::sub(ExplainSubcommand
),
739 cl::values(clEnumValN(InputFileType::PDBFile
, "pdb-file",
740 "Treat input as a PDB file (default)"),
741 clEnumValN(InputFileType::PDBStream
, "pdb-stream",
742 "Treat input as raw contents of PDB stream"),
743 clEnumValN(InputFileType::DBIStream
, "dbi-stream",
744 "Treat input as raw contents of DBI stream"),
745 clEnumValN(InputFileType::Names
, "names-stream",
746 "Treat input as raw contents of /names named stream"),
747 clEnumValN(InputFileType::ModuleStream
, "mod-stream",
748 "Treat input as raw contents of a module stream")));
749 } // namespace explain
751 namespace exportstream
{
752 cl::list
<std::string
> InputFilename(cl::Positional
,
753 cl::desc("<input PDB file>"), cl::Required
,
754 cl::sub(ExportSubcommand
));
755 cl::opt
<std::string
> OutputFile("out",
756 cl::desc("The file to write the stream to"),
757 cl::Required
, cl::sub(ExportSubcommand
));
759 Stream("stream", cl::Required
,
760 cl::desc("The index or name of the stream whose contents to export"),
761 cl::sub(ExportSubcommand
));
762 cl::opt
<bool> ForceName("name",
763 cl::desc("Force the interpretation of -stream as a "
764 "string, even if it is a valid integer"),
765 cl::sub(ExportSubcommand
), cl::Optional
,
767 } // namespace exportstream
770 static ExitOnError ExitOnErr
;
772 static void yamlToPdb(StringRef Path
) {
773 BumpPtrAllocator Allocator
;
774 ErrorOr
<std::unique_ptr
<MemoryBuffer
>> ErrorOrBuffer
=
775 MemoryBuffer::getFileOrSTDIN(Path
, /*IsText=*/false,
776 /*RequiresNullTerminator=*/false);
778 if (ErrorOrBuffer
.getError()) {
779 ExitOnErr(createFileError(Path
, errorCodeToError(ErrorOrBuffer
.getError())));
782 std::unique_ptr
<MemoryBuffer
> &Buffer
= ErrorOrBuffer
.get();
784 llvm::yaml::Input
In(Buffer
->getBuffer());
785 pdb::yaml::PdbObject
YamlObj(Allocator
);
788 PDBFileBuilder
Builder(Allocator
);
790 uint32_t BlockSize
= 4096;
792 BlockSize
= YamlObj
.Headers
->SuperBlock
.BlockSize
;
793 ExitOnErr(Builder
.initialize(BlockSize
));
794 // Add each of the reserved streams. We ignore stream metadata in the
795 // yaml, because we will reconstruct our own view of the streams. For
796 // example, the YAML may say that there were 20 streams in the original
797 // PDB, but maybe we only dump a subset of those 20 streams, so we will
798 // have fewer, and the ones we do have may end up with different indices
799 // than the ones in the original PDB. So we just start with a clean slate.
800 for (uint32_t I
= 0; I
< kSpecialStreamCount
; ++I
)
801 ExitOnErr(Builder
.getMsfBuilder().addStream(0));
803 StringsAndChecksums Strings
;
804 Strings
.setStrings(std::make_shared
<DebugStringTableSubsection
>());
806 if (YamlObj
.StringTable
) {
807 for (auto S
: *YamlObj
.StringTable
)
808 Strings
.strings()->insert(S
);
811 pdb::yaml::PdbInfoStream DefaultInfoStream
;
812 pdb::yaml::PdbDbiStream DefaultDbiStream
;
813 pdb::yaml::PdbTpiStream DefaultTpiStream
;
814 pdb::yaml::PdbTpiStream DefaultIpiStream
;
816 const auto &Info
= YamlObj
.PdbStream
.value_or(DefaultInfoStream
);
818 auto &InfoBuilder
= Builder
.getInfoBuilder();
819 InfoBuilder
.setAge(Info
.Age
);
820 InfoBuilder
.setGuid(Info
.Guid
);
821 InfoBuilder
.setSignature(Info
.Signature
);
822 InfoBuilder
.setVersion(Info
.Version
);
823 for (auto F
: Info
.Features
)
824 InfoBuilder
.addFeature(F
);
826 const auto &Dbi
= YamlObj
.DbiStream
.value_or(DefaultDbiStream
);
827 auto &DbiBuilder
= Builder
.getDbiBuilder();
828 DbiBuilder
.setAge(Dbi
.Age
);
829 DbiBuilder
.setBuildNumber(Dbi
.BuildNumber
);
830 DbiBuilder
.setFlags(Dbi
.Flags
);
831 DbiBuilder
.setMachineType(Dbi
.MachineType
);
832 DbiBuilder
.setPdbDllRbld(Dbi
.PdbDllRbld
);
833 DbiBuilder
.setPdbDllVersion(Dbi
.PdbDllVersion
);
834 DbiBuilder
.setVersionHeader(Dbi
.VerHeader
);
835 for (const auto &MI
: Dbi
.ModInfos
) {
836 auto &ModiBuilder
= ExitOnErr(DbiBuilder
.addModuleInfo(MI
.Mod
));
837 ModiBuilder
.setObjFileName(MI
.Obj
);
839 for (auto S
: MI
.SourceFiles
)
840 ExitOnErr(DbiBuilder
.addModuleSourceFile(ModiBuilder
, S
));
842 const auto &ModiStream
= *MI
.Modi
;
843 for (const auto &Symbol
: ModiStream
.Symbols
) {
844 ModiBuilder
.addSymbol(
845 Symbol
.toCodeViewSymbol(Allocator
, CodeViewContainer::Pdb
));
849 // Each module has its own checksum subsection, so scan for it every time.
850 Strings
.setChecksums(nullptr);
851 CodeViewYAML::initializeStringsAndChecksums(MI
.Subsections
, Strings
);
853 auto CodeViewSubsections
= ExitOnErr(CodeViewYAML::toCodeViewSubsectionList(
854 Allocator
, MI
.Subsections
, Strings
));
855 for (auto &SS
: CodeViewSubsections
) {
856 ModiBuilder
.addDebugSubsection(SS
);
860 auto &TpiBuilder
= Builder
.getTpiBuilder();
861 const auto &Tpi
= YamlObj
.TpiStream
.value_or(DefaultTpiStream
);
862 TpiBuilder
.setVersionHeader(Tpi
.Version
);
863 AppendingTypeTableBuilder
TS(Allocator
);
864 for (const auto &R
: Tpi
.Records
) {
865 CVType Type
= R
.toCodeViewRecord(TS
);
866 TpiBuilder
.addTypeRecord(Type
.RecordData
, std::nullopt
);
869 const auto &Ipi
= YamlObj
.IpiStream
.value_or(DefaultIpiStream
);
870 auto &IpiBuilder
= Builder
.getIpiBuilder();
871 IpiBuilder
.setVersionHeader(Ipi
.Version
);
872 for (const auto &R
: Ipi
.Records
) {
873 CVType Type
= R
.toCodeViewRecord(TS
);
874 IpiBuilder
.addTypeRecord(Type
.RecordData
, std::nullopt
);
877 Builder
.getStringTableBuilder().setStrings(*Strings
.strings());
879 codeview::GUID IgnoredOutGuid
;
880 ExitOnErr(Builder
.commit(opts::yaml2pdb::YamlPdbOutputFile
, &IgnoredOutGuid
));
883 static PDBFile
&loadPDB(StringRef Path
, std::unique_ptr
<IPDBSession
> &Session
) {
884 ExitOnErr(loadDataForPDB(PDB_ReaderType::Native
, Path
, Session
));
886 NativeSession
*NS
= static_cast<NativeSession
*>(Session
.get());
887 return NS
->getPDBFile();
890 static void pdb2Yaml(StringRef Path
) {
891 std::unique_ptr
<IPDBSession
> Session
;
892 auto &File
= loadPDB(Path
, Session
);
894 auto O
= std::make_unique
<YAMLOutputStyle
>(File
);
896 ExitOnErr(O
->dump());
899 static void dumpRaw(StringRef Path
) {
900 InputFile IF
= ExitOnErr(InputFile::open(Path
));
902 auto O
= std::make_unique
<DumpOutputStyle
>(IF
);
903 ExitOnErr(O
->dump());
906 static void dumpBytes(StringRef Path
) {
907 std::unique_ptr
<IPDBSession
> Session
;
908 auto &File
= loadPDB(Path
, Session
);
910 auto O
= std::make_unique
<BytesOutputStyle
>(File
);
912 ExitOnErr(O
->dump());
915 bool opts::pretty::shouldDumpSymLevel(SymLevel Search
) {
916 if (SymTypes
.empty())
918 if (llvm::is_contained(SymTypes
, Search
))
920 if (llvm::is_contained(SymTypes
, SymLevel::All
))
925 uint32_t llvm::pdb::getTypeLength(const PDBSymbolData
&Symbol
) {
926 auto SymbolType
= Symbol
.getType();
927 const IPDBRawSymbol
&RawType
= SymbolType
->getRawSymbol();
929 return RawType
.getLength();
932 bool opts::pretty::compareFunctionSymbols(
933 const std::unique_ptr
<PDBSymbolFunc
> &F1
,
934 const std::unique_ptr
<PDBSymbolFunc
> &F2
) {
935 assert(opts::pretty::SymbolOrder
!= opts::pretty::SymbolSortMode::None
);
937 if (opts::pretty::SymbolOrder
== opts::pretty::SymbolSortMode::Name
)
938 return F1
->getName() < F2
->getName();
940 // Note that we intentionally sort in descending order on length, since
941 // long functions are more interesting than short functions.
942 return F1
->getLength() > F2
->getLength();
945 bool opts::pretty::compareDataSymbols(
946 const std::unique_ptr
<PDBSymbolData
> &F1
,
947 const std::unique_ptr
<PDBSymbolData
> &F2
) {
948 assert(opts::pretty::SymbolOrder
!= opts::pretty::SymbolSortMode::None
);
950 if (opts::pretty::SymbolOrder
== opts::pretty::SymbolSortMode::Name
)
951 return F1
->getName() < F2
->getName();
953 // Note that we intentionally sort in descending order on length, since
954 // large types are more interesting than short ones.
955 return getTypeLength(*F1
) > getTypeLength(*F2
);
958 static std::string
stringOr(std::string Str
, std::string IfEmpty
) {
959 return (Str
.empty()) ? IfEmpty
: Str
;
962 static void dumpInjectedSources(LinePrinter
&Printer
, IPDBSession
&Session
) {
963 auto Sources
= Session
.getInjectedSources();
964 if (!Sources
|| !Sources
->getChildCount()) {
965 Printer
.printLine("There are no injected sources.");
969 while (auto IS
= Sources
->getNext()) {
971 std::string File
= stringOr(IS
->getFileName(), "<null>");
972 uint64_t Size
= IS
->getCodeByteSize();
973 std::string Obj
= stringOr(IS
->getObjectFileName(), "<null>");
974 std::string VFName
= stringOr(IS
->getVirtualFileName(), "<null>");
975 uint32_t CRC
= IS
->getCrc32();
977 WithColor(Printer
, PDB_ColorItem::Path
).get() << File
;
979 WithColor(Printer
, PDB_ColorItem::LiteralValue
).get() << Size
;
980 Printer
<< " bytes): ";
981 WithColor(Printer
, PDB_ColorItem::Keyword
).get() << "obj";
983 WithColor(Printer
, PDB_ColorItem::Path
).get() << Obj
;
985 WithColor(Printer
, PDB_ColorItem::Keyword
).get() << "vname";
987 WithColor(Printer
, PDB_ColorItem::Path
).get() << VFName
;
989 WithColor(Printer
, PDB_ColorItem::Keyword
).get() << "crc";
991 WithColor(Printer
, PDB_ColorItem::LiteralValue
).get() << CRC
;
993 WithColor(Printer
, PDB_ColorItem::Keyword
).get() << "compression";
995 dumpPDBSourceCompression(
996 WithColor(Printer
, PDB_ColorItem::LiteralValue
).get(),
997 IS
->getCompression());
999 if (!opts::pretty::ShowInjectedSourceContent
)
1002 // Set the indent level to 0 when printing file content.
1003 int Indent
= Printer
.getIndentLevel();
1004 Printer
.Unindent(Indent
);
1006 if (IS
->getCompression() == PDB_SourceCompression::None
)
1007 Printer
.printLine(IS
->getCode());
1009 Printer
.formatBinary("Compressed data",
1010 arrayRefFromStringRef(IS
->getCode()),
1013 // Re-indent back to the original level.
1014 Printer
.Indent(Indent
);
1018 template <typename OuterT
, typename ChildT
>
1019 void diaDumpChildren(PDBSymbol
&Outer
, PdbSymbolIdField Ids
,
1020 PdbSymbolIdField Recurse
) {
1021 OuterT
*ConcreteOuter
= dyn_cast
<OuterT
>(&Outer
);
1025 auto Children
= ConcreteOuter
->template findAllChildren
<ChildT
>();
1026 while (auto Child
= Children
->getNext()) {
1028 Child
->defaultDump(outs(), 4, Ids
, Recurse
);
1033 static void dumpDia(StringRef Path
) {
1034 std::unique_ptr
<IPDBSession
> Session
;
1036 const auto ReaderType
=
1037 opts::diadump::Native
? PDB_ReaderType::Native
: PDB_ReaderType::DIA
;
1038 ExitOnErr(loadDataForPDB(ReaderType
, Path
, Session
));
1040 auto GlobalScope
= Session
->getGlobalScope();
1042 std::vector
<PDB_SymType
> SymTypes
;
1044 if (opts::diadump::Compilands
)
1045 SymTypes
.push_back(PDB_SymType::Compiland
);
1046 if (opts::diadump::Enums
)
1047 SymTypes
.push_back(PDB_SymType::Enum
);
1048 if (opts::diadump::Pointers
)
1049 SymTypes
.push_back(PDB_SymType::PointerType
);
1050 if (opts::diadump::UDTs
)
1051 SymTypes
.push_back(PDB_SymType::UDT
);
1052 if (opts::diadump::Funcsigs
)
1053 SymTypes
.push_back(PDB_SymType::FunctionSig
);
1054 if (opts::diadump::Arrays
)
1055 SymTypes
.push_back(PDB_SymType::ArrayType
);
1056 if (opts::diadump::VTShapes
)
1057 SymTypes
.push_back(PDB_SymType::VTableShape
);
1058 if (opts::diadump::Typedefs
)
1059 SymTypes
.push_back(PDB_SymType::Typedef
);
1060 PdbSymbolIdField Ids
= opts::diadump::NoSymIndexIds
? PdbSymbolIdField::None
1061 : PdbSymbolIdField::All
;
1063 PdbSymbolIdField Recurse
= PdbSymbolIdField::None
;
1064 if (opts::diadump::Recurse
)
1065 Recurse
= PdbSymbolIdField::All
;
1066 if (!opts::diadump::ShowClassHierarchy
)
1067 Ids
&= ~(PdbSymbolIdField::ClassParent
| PdbSymbolIdField::LexicalParent
);
1069 for (PDB_SymType ST
: SymTypes
) {
1070 auto Children
= GlobalScope
->findAllChildren(ST
);
1071 while (auto Child
= Children
->getNext()) {
1073 Child
->defaultDump(outs(), 2, Ids
, Recurse
);
1075 diaDumpChildren
<PDBSymbolTypeEnum
, PDBSymbolData
>(*Child
, Ids
, Recurse
);
1081 static void dumpPretty(StringRef Path
) {
1082 std::unique_ptr
<IPDBSession
> Session
;
1084 const auto ReaderType
=
1085 opts::pretty::Native
? PDB_ReaderType::Native
: PDB_ReaderType::DIA
;
1086 ExitOnErr(loadDataForPDB(ReaderType
, Path
, Session
));
1088 if (opts::pretty::LoadAddress
)
1089 Session
->setLoadAddress(opts::pretty::LoadAddress
);
1091 auto &Stream
= outs();
1092 const bool UseColor
= opts::pretty::ColorOutput
== cl::BOU_UNSET
1093 ? Stream
.has_colors()
1094 : opts::pretty::ColorOutput
== cl::BOU_TRUE
;
1095 LinePrinter
Printer(2, UseColor
, Stream
, opts::Filters
);
1097 auto GlobalScope(Session
->getGlobalScope());
1100 std::string
FileName(GlobalScope
->getSymbolsFileName());
1102 WithColor(Printer
, PDB_ColorItem::None
).get() << "Summary for ";
1103 WithColor(Printer
, PDB_ColorItem::Path
).get() << FileName
;
1105 uint64_t FileSize
= 0;
1108 WithColor(Printer
, PDB_ColorItem::Identifier
).get() << "Size";
1109 if (!sys::fs::file_size(FileName
, FileSize
)) {
1110 Printer
<< ": " << FileSize
<< " bytes";
1112 Printer
<< ": (Unable to obtain file size)";
1116 WithColor(Printer
, PDB_ColorItem::Identifier
).get() << "Guid";
1117 Printer
<< ": " << GlobalScope
->getGuid();
1120 WithColor(Printer
, PDB_ColorItem::Identifier
).get() << "Age";
1121 Printer
<< ": " << GlobalScope
->getAge();
1124 WithColor(Printer
, PDB_ColorItem::Identifier
).get() << "Attributes";
1126 if (GlobalScope
->hasCTypes())
1127 outs() << "HasCTypes ";
1128 if (GlobalScope
->hasPrivateSymbols())
1129 outs() << "HasPrivateSymbols ";
1132 if (!opts::pretty::WithName
.empty()) {
1134 WithColor(Printer
, PDB_ColorItem::SectionHeader
).get()
1135 << "---SYMBOLS & TYPES BY NAME---";
1137 for (StringRef Name
: opts::pretty::WithName
) {
1138 auto Symbols
= GlobalScope
->findChildren(
1139 PDB_SymType::None
, Name
, PDB_NameSearchFlags::NS_CaseSensitive
);
1140 if (!Symbols
|| Symbols
->getChildCount() == 0) {
1141 Printer
.formatLine("[not found] - {0}", Name
);
1144 Printer
.formatLine("[{0} occurrences] - {1}", Symbols
->getChildCount(),
1147 AutoIndent
Indent(Printer
);
1150 while (auto Symbol
= Symbols
->getNext()) {
1151 switch (Symbol
->getSymTag()) {
1152 case PDB_SymType::Typedef
: {
1153 TypedefDumper
TD(Printer
);
1154 std::unique_ptr
<PDBSymbolTypeTypedef
> T
=
1155 llvm::unique_dyn_cast
<PDBSymbolTypeTypedef
>(std::move(Symbol
));
1159 case PDB_SymType::Enum
: {
1160 EnumDumper
ED(Printer
);
1161 std::unique_ptr
<PDBSymbolTypeEnum
> E
=
1162 llvm::unique_dyn_cast
<PDBSymbolTypeEnum
>(std::move(Symbol
));
1166 case PDB_SymType::UDT
: {
1167 ClassDefinitionDumper
CD(Printer
);
1168 std::unique_ptr
<PDBSymbolTypeUDT
> C
=
1169 llvm::unique_dyn_cast
<PDBSymbolTypeUDT
>(std::move(Symbol
));
1173 case PDB_SymType::BaseClass
:
1174 case PDB_SymType::Friend
: {
1175 TypeDumper
TD(Printer
);
1179 case PDB_SymType::Function
: {
1180 FunctionDumper
FD(Printer
);
1181 std::unique_ptr
<PDBSymbolFunc
> F
=
1182 llvm::unique_dyn_cast
<PDBSymbolFunc
>(std::move(Symbol
));
1183 FD
.start(*F
, FunctionDumper::PointerType::None
);
1186 case PDB_SymType::Data
: {
1187 VariableDumper
VD(Printer
);
1188 std::unique_ptr
<PDBSymbolData
> D
=
1189 llvm::unique_dyn_cast
<PDBSymbolData
>(std::move(Symbol
));
1193 case PDB_SymType::PublicSymbol
: {
1194 ExternalSymbolDumper
ED(Printer
);
1195 std::unique_ptr
<PDBSymbolPublicSymbol
> PS
=
1196 llvm::unique_dyn_cast
<PDBSymbolPublicSymbol
>(std::move(Symbol
));
1201 llvm_unreachable("Unexpected symbol tag!");
1205 llvm::outs().flush();
1208 if (opts::pretty::Compilands
) {
1210 WithColor(Printer
, PDB_ColorItem::SectionHeader
).get()
1211 << "---COMPILANDS---";
1212 auto Compilands
= GlobalScope
->findAllChildren
<PDBSymbolCompiland
>();
1216 CompilandDumper
Dumper(Printer
);
1217 CompilandDumpFlags options
= CompilandDumper::Flags::None
;
1218 if (opts::pretty::Lines
)
1219 options
= options
| CompilandDumper::Flags::Lines
;
1220 while (auto Compiland
= Compilands
->getNext())
1221 Dumper
.start(*Compiland
, options
);
1226 if (opts::pretty::Classes
|| opts::pretty::Enums
|| opts::pretty::Typedefs
||
1227 opts::pretty::Funcsigs
|| opts::pretty::Pointers
||
1228 opts::pretty::Arrays
|| opts::pretty::VTShapes
) {
1230 WithColor(Printer
, PDB_ColorItem::SectionHeader
).get() << "---TYPES---";
1232 TypeDumper
Dumper(Printer
);
1233 Dumper
.start(*GlobalScope
);
1237 if (opts::pretty::Symbols
) {
1239 WithColor(Printer
, PDB_ColorItem::SectionHeader
).get() << "---SYMBOLS---";
1240 if (auto Compilands
= GlobalScope
->findAllChildren
<PDBSymbolCompiland
>()) {
1242 CompilandDumper
Dumper(Printer
);
1243 while (auto Compiland
= Compilands
->getNext())
1244 Dumper
.start(*Compiland
, true);
1249 if (opts::pretty::Globals
) {
1251 WithColor(Printer
, PDB_ColorItem::SectionHeader
).get() << "---GLOBALS---";
1253 if (shouldDumpSymLevel(opts::pretty::SymLevel::Functions
)) {
1254 if (auto Functions
= GlobalScope
->findAllChildren
<PDBSymbolFunc
>()) {
1255 FunctionDumper
Dumper(Printer
);
1256 if (opts::pretty::SymbolOrder
== opts::pretty::SymbolSortMode::None
) {
1257 while (auto Function
= Functions
->getNext()) {
1259 Dumper
.start(*Function
, FunctionDumper::PointerType::None
);
1262 std::vector
<std::unique_ptr
<PDBSymbolFunc
>> Funcs
;
1263 while (auto Func
= Functions
->getNext())
1264 Funcs
.push_back(std::move(Func
));
1265 llvm::sort(Funcs
, opts::pretty::compareFunctionSymbols
);
1266 for (const auto &Func
: Funcs
) {
1268 Dumper
.start(*Func
, FunctionDumper::PointerType::None
);
1273 if (shouldDumpSymLevel(opts::pretty::SymLevel::Data
)) {
1274 if (auto Vars
= GlobalScope
->findAllChildren
<PDBSymbolData
>()) {
1275 VariableDumper
Dumper(Printer
);
1276 if (opts::pretty::SymbolOrder
== opts::pretty::SymbolSortMode::None
) {
1277 while (auto Var
= Vars
->getNext())
1280 std::vector
<std::unique_ptr
<PDBSymbolData
>> Datas
;
1281 while (auto Var
= Vars
->getNext())
1282 Datas
.push_back(std::move(Var
));
1283 llvm::sort(Datas
, opts::pretty::compareDataSymbols
);
1284 for (const auto &Var
: Datas
)
1289 if (shouldDumpSymLevel(opts::pretty::SymLevel::Thunks
)) {
1290 if (auto Thunks
= GlobalScope
->findAllChildren
<PDBSymbolThunk
>()) {
1291 CompilandDumper
Dumper(Printer
);
1292 while (auto Thunk
= Thunks
->getNext())
1293 Dumper
.dump(*Thunk
);
1298 if (opts::pretty::Externals
) {
1300 WithColor(Printer
, PDB_ColorItem::SectionHeader
).get() << "---EXTERNALS---";
1302 ExternalSymbolDumper
Dumper(Printer
);
1303 Dumper
.start(*GlobalScope
);
1305 if (opts::pretty::Lines
) {
1308 if (opts::pretty::InjectedSources
) {
1310 WithColor(Printer
, PDB_ColorItem::SectionHeader
).get()
1311 << "---INJECTED SOURCES---";
1312 AutoIndent
Indent1(Printer
);
1313 dumpInjectedSources(Printer
, *Session
);
1320 static void mergePdbs() {
1321 BumpPtrAllocator Allocator
;
1322 MergingTypeTableBuilder
MergedTpi(Allocator
);
1323 MergingTypeTableBuilder
MergedIpi(Allocator
);
1325 // Create a Tpi and Ipi type table with all types from all input files.
1326 for (const auto &Path
: opts::merge::InputFilenames
) {
1327 std::unique_ptr
<IPDBSession
> Session
;
1328 auto &File
= loadPDB(Path
, Session
);
1329 SmallVector
<TypeIndex
, 128> TypeMap
;
1330 SmallVector
<TypeIndex
, 128> IdMap
;
1331 if (File
.hasPDBTpiStream()) {
1332 auto &Tpi
= ExitOnErr(File
.getPDBTpiStream());
1334 codeview::mergeTypeRecords(MergedTpi
, TypeMap
, Tpi
.typeArray()));
1336 if (File
.hasPDBIpiStream()) {
1337 auto &Ipi
= ExitOnErr(File
.getPDBIpiStream());
1338 ExitOnErr(codeview::mergeIdRecords(MergedIpi
, TypeMap
, IdMap
,
1343 // Then write the PDB.
1344 PDBFileBuilder
Builder(Allocator
);
1345 ExitOnErr(Builder
.initialize(4096));
1346 // Add each of the reserved streams. We might not put any data in them,
1347 // but at least they have to be present.
1348 for (uint32_t I
= 0; I
< kSpecialStreamCount
; ++I
)
1349 ExitOnErr(Builder
.getMsfBuilder().addStream(0));
1351 auto &DestTpi
= Builder
.getTpiBuilder();
1352 auto &DestIpi
= Builder
.getIpiBuilder();
1353 MergedTpi
.ForEachRecord([&DestTpi
](TypeIndex TI
, const CVType
&Type
) {
1354 DestTpi
.addTypeRecord(Type
.RecordData
, std::nullopt
);
1356 MergedIpi
.ForEachRecord([&DestIpi
](TypeIndex TI
, const CVType
&Type
) {
1357 DestIpi
.addTypeRecord(Type
.RecordData
, std::nullopt
);
1359 Builder
.getInfoBuilder().addFeature(PdbRaw_FeatureSig::VC140
);
1361 SmallString
<64> OutFile(opts::merge::PdbOutputFile
);
1362 if (OutFile
.empty()) {
1363 OutFile
= opts::merge::InputFilenames
[0];
1364 llvm::sys::path::replace_extension(OutFile
, "merged.pdb");
1367 codeview::GUID IgnoredOutGuid
;
1368 ExitOnErr(Builder
.commit(OutFile
, &IgnoredOutGuid
));
1371 static void explain() {
1372 std::unique_ptr
<IPDBSession
> Session
;
1374 ExitOnErr(InputFile::open(opts::explain::InputFilename
.front(), true));
1376 for (uint64_t Off
: opts::explain::Offsets
) {
1377 auto O
= std::make_unique
<ExplainOutputStyle
>(IF
, Off
);
1379 ExitOnErr(O
->dump());
1383 static void exportStream() {
1384 std::unique_ptr
<IPDBSession
> Session
;
1385 PDBFile
&File
= loadPDB(opts::exportstream::InputFilename
.front(), Session
);
1387 std::unique_ptr
<MappedBlockStream
> SourceStream
;
1389 bool Success
= false;
1390 std::string OutFileName
= opts::exportstream::OutputFile
;
1392 if (!opts::exportstream::ForceName
) {
1393 // First try to parse it as an integer, if it fails fall back to treating it
1394 // as a named stream.
1395 if (to_integer(opts::exportstream::Stream
, Index
)) {
1396 if (Index
>= File
.getNumStreams()) {
1397 errs() << "Error: " << Index
<< " is not a valid stream index.\n";
1401 outs() << "Dumping contents of stream index " << Index
<< " to file "
1402 << OutFileName
<< ".\n";
1407 InfoStream
&IS
= cantFail(File
.getPDBInfoStream());
1408 Index
= ExitOnErr(IS
.getNamedStreamIndex(opts::exportstream::Stream
));
1409 outs() << "Dumping contents of stream '" << opts::exportstream::Stream
1410 << "' (index " << Index
<< ") to file " << OutFileName
<< ".\n";
1413 SourceStream
= File
.createIndexedStream(Index
);
1414 auto OutFile
= ExitOnErr(
1415 FileOutputBuffer::create(OutFileName
, SourceStream
->getLength()));
1416 FileBufferByteStream
DestStream(std::move(OutFile
), llvm::endianness::little
);
1417 BinaryStreamWriter
Writer(DestStream
);
1418 ExitOnErr(Writer
.writeStreamRef(*SourceStream
));
1419 ExitOnErr(DestStream
.commit());
1422 static bool parseRange(StringRef Str
,
1423 std::optional
<opts::bytes::NumberRange
> &Parsed
) {
1427 llvm::Regex
R("^([^-]+)(-([^-]+))?$");
1428 llvm::SmallVector
<llvm::StringRef
, 2> Matches
;
1429 if (!R
.match(Str
, &Matches
))
1433 if (!to_integer(Matches
[1], Parsed
->Min
))
1436 if (!Matches
[3].empty()) {
1437 Parsed
->Max
.emplace();
1438 if (!to_integer(Matches
[3], *Parsed
->Max
))
1444 static void simplifyChunkList(llvm::cl::list
<opts::ModuleSubsection
> &Chunks
) {
1445 // If this list contains "All" plus some other stuff, remove the other stuff
1446 // and just keep "All" in the list.
1447 if (!llvm::is_contained(Chunks
, opts::ModuleSubsection::All
))
1450 Chunks
.push_back(opts::ModuleSubsection::All
);
1453 int main(int Argc
, const char **Argv
) {
1454 InitLLVM
X(Argc
, Argv
);
1455 ExitOnErr
.setBanner("llvm-pdbutil: ");
1457 cl::HideUnrelatedOptions(
1458 {&opts::TypeCategory
, &opts::FilterCategory
, &opts::OtherOptions
});
1459 cl::ParseCommandLineOptions(Argc
, Argv
, "LLVM PDB Dumper\n");
1461 if (opts::BytesSubcommand
) {
1462 if (!parseRange(opts::bytes::DumpBlockRangeOpt
,
1463 opts::bytes::DumpBlockRange
)) {
1464 errs() << "Argument '" << opts::bytes::DumpBlockRangeOpt
1465 << "' invalid format.\n";
1469 if (!parseRange(opts::bytes::DumpByteRangeOpt
,
1470 opts::bytes::DumpByteRange
)) {
1471 errs() << "Argument '" << opts::bytes::DumpByteRangeOpt
1472 << "' invalid format.\n";
1478 if (opts::DumpSubcommand
) {
1479 if (opts::dump::RawAll
) {
1480 opts::dump::DumpGlobals
= true;
1481 opts::dump::DumpFpo
= true;
1482 opts::dump::DumpInlineeLines
= true;
1483 opts::dump::DumpIds
= true;
1484 opts::dump::DumpIdExtras
= true;
1485 opts::dump::DumpLines
= true;
1486 opts::dump::DumpModules
= true;
1487 opts::dump::DumpModuleFiles
= true;
1488 opts::dump::DumpPublics
= true;
1489 opts::dump::DumpSectionContribs
= true;
1490 opts::dump::DumpSectionHeaders
= true;
1491 opts::dump::DumpSectionMap
= true;
1492 opts::dump::DumpStreams
= true;
1493 opts::dump::DumpStreamBlocks
= true;
1494 opts::dump::DumpStringTable
= true;
1495 opts::dump::DumpStringTableDetails
= true;
1496 opts::dump::DumpSummary
= true;
1497 opts::dump::DumpSymbols
= true;
1498 opts::dump::DumpSymbolStats
= true;
1499 opts::dump::DumpTypes
= true;
1500 opts::dump::DumpTypeExtras
= true;
1501 opts::dump::DumpUdtStats
= true;
1502 opts::dump::DumpXme
= true;
1503 opts::dump::DumpXmi
= true;
1506 if (opts::PdbToYamlSubcommand
) {
1507 if (opts::pdb2yaml::All
) {
1508 opts::pdb2yaml::StreamMetadata
= true;
1509 opts::pdb2yaml::StreamDirectory
= true;
1510 opts::pdb2yaml::PdbStream
= true;
1511 opts::pdb2yaml::StringTable
= true;
1512 opts::pdb2yaml::DbiStream
= true;
1513 opts::pdb2yaml::TpiStream
= true;
1514 opts::pdb2yaml::IpiStream
= true;
1515 opts::pdb2yaml::PublicsStream
= true;
1516 opts::pdb2yaml::DumpModules
= true;
1517 opts::pdb2yaml::DumpModuleFiles
= true;
1518 opts::pdb2yaml::DumpModuleSyms
= true;
1519 opts::pdb2yaml::DumpModuleSubsections
.push_back(
1520 opts::ModuleSubsection::All
);
1522 simplifyChunkList(opts::pdb2yaml::DumpModuleSubsections
);
1524 if (opts::pdb2yaml::DumpModuleSyms
|| opts::pdb2yaml::DumpModuleFiles
)
1525 opts::pdb2yaml::DumpModules
= true;
1527 if (opts::pdb2yaml::DumpModules
)
1528 opts::pdb2yaml::DbiStream
= true;
1531 llvm::sys::InitializeCOMRAII
COM(llvm::sys::COMThreadingMode::MultiThreaded
);
1533 // Initialize the filters for LinePrinter.
1534 auto propagate
= [&](auto &Target
, auto &Reference
) {
1535 for (std::string
&Option
: Reference
)
1536 Target
.push_back(Option
);
1539 propagate(opts::Filters
.ExcludeTypes
, opts::pretty::ExcludeTypes
);
1540 propagate(opts::Filters
.ExcludeTypes
, opts::pretty::ExcludeTypes
);
1541 propagate(opts::Filters
.ExcludeSymbols
, opts::pretty::ExcludeSymbols
);
1542 propagate(opts::Filters
.ExcludeCompilands
, opts::pretty::ExcludeCompilands
);
1543 propagate(opts::Filters
.IncludeTypes
, opts::pretty::IncludeTypes
);
1544 propagate(opts::Filters
.IncludeSymbols
, opts::pretty::IncludeSymbols
);
1545 propagate(opts::Filters
.IncludeCompilands
, opts::pretty::IncludeCompilands
);
1546 opts::Filters
.PaddingThreshold
= opts::pretty::PaddingThreshold
;
1547 opts::Filters
.SizeThreshold
= opts::pretty::SizeThreshold
;
1548 opts::Filters
.JustMyCode
= opts::dump::JustMyCode
;
1549 if (opts::dump::DumpModi
.getNumOccurrences() > 0) {
1550 if (opts::dump::DumpModi
.getNumOccurrences() != 1) {
1551 errs() << "argument '-modi' specified more than once.\n";
1555 opts::Filters
.DumpModi
= opts::dump::DumpModi
;
1557 if (opts::dump::DumpSymbolOffset
) {
1558 if (opts::dump::DumpModi
.getNumOccurrences() != 1) {
1560 << "need to specify argument '-modi' when using '-symbol-offset'.\n";
1564 opts::Filters
.SymbolOffset
= opts::dump::DumpSymbolOffset
;
1565 if (opts::dump::DumpParents
)
1566 opts::Filters
.ParentRecurseDepth
= opts::dump::DumpParentDepth
;
1567 if (opts::dump::DumpChildren
)
1568 opts::Filters
.ChildrenRecurseDepth
= opts::dump::DumpChildrenDepth
;
1571 if (opts::PdbToYamlSubcommand
) {
1572 pdb2Yaml(opts::pdb2yaml::InputFilename
.front());
1573 } else if (opts::YamlToPdbSubcommand
) {
1574 if (opts::yaml2pdb::YamlPdbOutputFile
.empty()) {
1575 SmallString
<16> OutputFilename(opts::yaml2pdb::InputFilename
.getValue());
1576 sys::path::replace_extension(OutputFilename
, ".pdb");
1577 opts::yaml2pdb::YamlPdbOutputFile
= std::string(OutputFilename
);
1579 yamlToPdb(opts::yaml2pdb::InputFilename
);
1580 } else if (opts::DiaDumpSubcommand
) {
1581 llvm::for_each(opts::diadump::InputFilenames
, dumpDia
);
1582 } else if (opts::PrettySubcommand
) {
1583 if (opts::pretty::Lines
)
1584 opts::pretty::Compilands
= true;
1586 if (opts::pretty::All
) {
1587 opts::pretty::Compilands
= true;
1588 opts::pretty::Symbols
= true;
1589 opts::pretty::Globals
= true;
1590 opts::pretty::Types
= true;
1591 opts::pretty::Externals
= true;
1592 opts::pretty::Lines
= true;
1595 if (opts::pretty::Types
) {
1596 opts::pretty::Classes
= true;
1597 opts::pretty::Typedefs
= true;
1598 opts::pretty::Enums
= true;
1599 opts::pretty::Pointers
= true;
1600 opts::pretty::Funcsigs
= true;
1603 // When adding filters for excluded compilands and types, we need to
1604 // remember that these are regexes. So special characters such as * and \
1605 // need to be escaped in the regex. In the case of a literal \, this means
1606 // it needs to be escaped again in the C++. So matching a single \ in the
1607 // input requires 4 \es in the C++.
1608 if (opts::pretty::ExcludeCompilerGenerated
) {
1609 opts::Filters
.ExcludeTypes
.push_back("__vc_attributes");
1610 opts::Filters
.ExcludeCompilands
.push_back("\\* Linker \\*");
1612 if (opts::pretty::ExcludeSystemLibraries
) {
1613 opts::Filters
.ExcludeCompilands
.push_back(
1614 "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
1615 opts::Filters
.ExcludeCompilands
.push_back("f:\\\\dd\\\\vctools\\\\crt");
1616 opts::Filters
.ExcludeCompilands
.push_back(
1617 "d:\\\\th.obj.x86fre\\\\minkernel");
1619 llvm::for_each(opts::pretty::InputFilenames
, dumpPretty
);
1620 } else if (opts::DumpSubcommand
) {
1621 llvm::for_each(opts::dump::InputFilenames
, dumpRaw
);
1622 } else if (opts::BytesSubcommand
) {
1623 llvm::for_each(opts::bytes::InputFilenames
, dumpBytes
);
1624 } else if (opts::MergeSubcommand
) {
1625 if (opts::merge::InputFilenames
.size() < 2) {
1626 errs() << "merge subcommand requires at least 2 input files.\n";
1630 } else if (opts::ExplainSubcommand
) {
1632 } else if (opts::ExportSubcommand
) {