blob: a92e59bc81115a0f0b5e3962e06ac1a49f9fd11c [file] [log] [blame]
Zachary Turnerfcb14ad2015-01-27 20:46:21 +00001//===- llvm-pdbdump.cpp - Dump debug info from a PDB file -------*- C++ -*-===//
2//
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//
10// Dumps debug information present in PDB files. This utility makes use of
11// the Microsoft Windows SDK, so will not compile or run on non-Windows
12// platforms.
13//
14//===----------------------------------------------------------------------===//
15
Zachary Turner9a818ad2015-02-22 22:03:38 +000016#include "llvm-pdbdump.h"
17#include "CompilandDumper.h"
Zachary Turnere5cb2692015-05-01 20:24:26 +000018#include "ExternalSymbolDumper.h"
Zachary Turnerdb18f5c2015-02-27 09:15:18 +000019#include "FunctionDumper.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000020#include "LLVMOutputStyle.h"
Zachary Turner2d11c202015-02-27 09:15:59 +000021#include "LinePrinter.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000022#include "OutputStyle.h"
Zachary Turner9a818ad2015-02-22 22:03:38 +000023#include "TypeDumper.h"
Zachary Turnerdb18f5c2015-02-27 09:15:18 +000024#include "VariableDumper.h"
Zachary Turner7120a472016-06-06 20:37:05 +000025#include "YAMLOutputStyle.h"
Zachary Turner9a818ad2015-02-22 22:03:38 +000026
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000027#include "llvm/ADT/ArrayRef.h"
David Majnemer6e081262015-10-15 01:27:19 +000028#include "llvm/ADT/BitVector.h"
29#include "llvm/ADT/DenseMap.h"
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000030#include "llvm/ADT/StringExtras.h"
Zachary Turner8d7fa9b2015-02-10 22:47:14 +000031#include "llvm/Config/config.h"
Zachary Turner1dc9fd32016-06-14 20:48:36 +000032#include "llvm/DebugInfo/CodeView/ByteStream.h"
Zachary Turner819e77d2016-05-06 20:51:57 +000033#include "llvm/DebugInfo/PDB/GenericError.h"
Zachary Turnera5549172015-02-10 22:43:25 +000034#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
Zachary Turnera5549172015-02-10 22:43:25 +000035#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
Chandler Carruth71f308a2015-02-13 09:09:03 +000036#include "llvm/DebugInfo/PDB/IPDBSession.h"
37#include "llvm/DebugInfo/PDB/PDB.h"
Zachary Turnera5549172015-02-10 22:43:25 +000038#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
Zachary Turnerdb18f5c2015-02-27 09:15:18 +000039#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
Chandler Carruth71f308a2015-02-13 09:09:03 +000040#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
Zachary Turnerdb18f5c2015-02-27 09:15:18 +000041#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
42#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
Zachary Turner0a43efe2016-04-25 17:38:08 +000043#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000044#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
Reid Klecknerce5196e2016-05-12 23:26:23 +000045#include "llvm/DebugInfo/PDB/Raw/RawError.h"
Zachary Turner0a43efe2016-04-25 17:38:08 +000046#include "llvm/DebugInfo/PDB/Raw/RawSession.h"
Zachary Turner93839cb2016-06-02 05:07:49 +000047#include "llvm/Support/COM.h"
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000048#include "llvm/Support/CommandLine.h"
49#include "llvm/Support/ConvertUTF.h"
Zachary Turner1dc9fd32016-06-14 20:48:36 +000050#include "llvm/Support/FileOutputBuffer.h"
Zachary Turner9a818ad2015-02-22 22:03:38 +000051#include "llvm/Support/FileSystem.h"
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000052#include "llvm/Support/Format.h"
53#include "llvm/Support/ManagedStatic.h"
David Majnemer6e081262015-10-15 01:27:19 +000054#include "llvm/Support/MemoryBuffer.h"
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000055#include "llvm/Support/PrettyStackTrace.h"
Chandler Carruth71f308a2015-02-13 09:09:03 +000056#include "llvm/Support/Process.h"
Reid Klecknerb0345262016-05-04 16:09:04 +000057#include "llvm/Support/ScopedPrinter.h"
Daniel Sandersd41718e2016-04-22 12:04:42 +000058#include "llvm/Support/Signals.h"
Zachary Turner0a43efe2016-04-25 17:38:08 +000059#include "llvm/Support/raw_ostream.h"
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000060
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000061using namespace llvm;
Zachary Turnera96cce62016-06-03 03:25:59 +000062using namespace llvm::codeview;
Zachary Turner2f09b502016-04-29 17:28:47 +000063using namespace llvm::pdb;
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000064
Zachary Turner1dc9fd32016-06-14 20:48:36 +000065namespace {
66// A simple adapter that acts like a ByteStream but holds ownership over
67// and underlying FileOutputBuffer.
68class FileBufferByteStream : public ByteStream<true> {
69public:
70 FileBufferByteStream(std::unique_ptr<FileOutputBuffer> Buffer)
71 : ByteStream(MutableArrayRef<uint8_t>(Buffer->getBufferStart(),
72 Buffer->getBufferEnd())),
73 FileBuffer(std::move(Buffer)) {}
74
75private:
76 std::unique_ptr<FileOutputBuffer> FileBuffer;
77};
78}
79
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000080namespace opts {
Zachary Turnerc0acf682015-02-15 20:27:53 +000081
Zachary Turnera30bd1a2016-06-30 17:42:48 +000082cl::SubCommand RawSubcommand("raw", "Dump raw structure of the PDB file");
83cl::SubCommand
84 PrettySubcommand("pretty",
85 "Dump semantic information about types and symbols");
86cl::SubCommand YamlToPdbSubcommand("yaml2pdb", "Generate a PDB file from a YAML description");
87cl::SubCommand
88 PdbToYamlSubcommand("pdb2yaml",
89 "Generate a detailed YAML description of a PDB File");
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000090
Zachary Turner7797c722015-03-02 04:39:56 +000091cl::OptionCategory TypeCategory("Symbol Type Options");
92cl::OptionCategory FilterCategory("Filtering Options");
Zachary Turnere5cb2692015-05-01 20:24:26 +000093cl::OptionCategory OtherOptions("Other Options");
Zachary Turnera30bd1a2016-06-30 17:42:48 +000094
95namespace pretty {
96cl::list<std::string> InputFilenames(cl::Positional,
97 cl::desc("<input PDB files>"),
98 cl::OneOrMore, cl::sub(PrettySubcommand));
Zachary Turner7797c722015-03-02 04:39:56 +000099
100cl::opt<bool> Compilands("compilands", cl::desc("Display compilands"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000101 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turner7797c722015-03-02 04:39:56 +0000102cl::opt<bool> Symbols("symbols", cl::desc("Display symbols for each compiland"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000103 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turner7797c722015-03-02 04:39:56 +0000104cl::opt<bool> Globals("globals", cl::desc("Dump global symbols"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000105 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turnere5cb2692015-05-01 20:24:26 +0000106cl::opt<bool> Externals("externals", cl::desc("Dump external symbols"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000107 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
108cl::opt<bool> Types("types", cl::desc("Display types"), cl::cat(TypeCategory),
109 cl::sub(PrettySubcommand));
110cl::opt<bool> Lines("lines", cl::desc("Line tables"), cl::cat(TypeCategory),
111 cl::sub(PrettySubcommand));
Zachary Turner7797c722015-03-02 04:39:56 +0000112cl::opt<bool>
Zachary Turner7797c722015-03-02 04:39:56 +0000113 All("all", cl::desc("Implies all other options in 'Symbol Types' category"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000114 cl::cat(TypeCategory), cl::sub(PrettySubcommand));
Zachary Turnerf5abda22015-03-01 06:49:49 +0000115
Zachary Turnere5cb2692015-05-01 20:24:26 +0000116cl::opt<uint64_t> LoadAddress(
117 "load-address",
118 cl::desc("Assume the module is loaded at the specified address"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000119 cl::cat(OtherOptions), cl::sub(PrettySubcommand));
120cl::list<std::string> ExcludeTypes(
121 "exclude-types", cl::desc("Exclude types by regular expression"),
122 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
123cl::list<std::string> ExcludeSymbols(
124 "exclude-symbols", cl::desc("Exclude symbols by regular expression"),
125 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
126cl::list<std::string> ExcludeCompilands(
127 "exclude-compilands", cl::desc("Exclude compilands by regular expression"),
128 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner4dddcc62015-09-29 19:49:06 +0000129
130cl::list<std::string> IncludeTypes(
131 "include-types",
132 cl::desc("Include only types which match a regular expression"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000133 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner4dddcc62015-09-29 19:49:06 +0000134cl::list<std::string> IncludeSymbols(
135 "include-symbols",
136 cl::desc("Include only symbols which match a regular expression"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000137 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner4dddcc62015-09-29 19:49:06 +0000138cl::list<std::string> IncludeCompilands(
139 "include-compilands",
140 cl::desc("Include only compilands those which match a regular expression"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000141 cl::ZeroOrMore, cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner4dddcc62015-09-29 19:49:06 +0000142
Zachary Turner7797c722015-03-02 04:39:56 +0000143cl::opt<bool> ExcludeCompilerGenerated(
144 "no-compiler-generated",
145 cl::desc("Don't show compiler generated types and symbols"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000146 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner7797c722015-03-02 04:39:56 +0000147cl::opt<bool>
148 ExcludeSystemLibraries("no-system-libs",
149 cl::desc("Don't show symbols from system libraries"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000150 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner65323652015-03-04 06:09:53 +0000151cl::opt<bool> NoClassDefs("no-class-definitions",
152 cl::desc("Don't display full class definitions"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000153 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
Zachary Turner65323652015-03-04 06:09:53 +0000154cl::opt<bool> NoEnumDefs("no-enum-definitions",
155 cl::desc("Don't display full enum definitions"),
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000156 cl::cat(FilterCategory), cl::sub(PrettySubcommand));
157}
158
159namespace raw {
160
161cl::OptionCategory MsfOptions("MSF Container Options");
162cl::OptionCategory TypeOptions("Type Record Options");
163cl::OptionCategory FileOptions("Module & File Options");
164cl::OptionCategory SymbolOptions("Symbol Options");
165cl::OptionCategory MiscOptions("Miscellaneous Options");
166
167// MSF OPTIONS
168cl::opt<bool> DumpHeaders("headers", cl::desc("dump PDB headers"),
169 cl::cat(MsfOptions), cl::sub(RawSubcommand));
170cl::opt<bool> DumpStreamBlocks("stream-blocks",
171 cl::desc("dump PDB stream blocks"),
172 cl::cat(MsfOptions), cl::sub(RawSubcommand));
173cl::opt<bool> DumpStreamSummary("stream-summary",
174 cl::desc("dump summary of the PDB streams"),
175 cl::cat(MsfOptions), cl::sub(RawSubcommand));
176
177// TYPE OPTIONS
178cl::opt<bool>
179 DumpTpiRecords("tpi-records",
180 cl::desc("dump CodeView type records from TPI stream"),
181 cl::cat(TypeOptions), cl::sub(RawSubcommand));
182cl::opt<bool> DumpTpiRecordBytes(
183 "tpi-record-bytes",
184 cl::desc("dump CodeView type record raw bytes from TPI stream"),
185 cl::cat(TypeOptions), cl::sub(RawSubcommand));
186cl::opt<bool> DumpTpiHash("tpi-hash", cl::desc("dump CodeView TPI hash stream"),
187 cl::cat(TypeOptions), cl::sub(RawSubcommand));
188cl::opt<bool>
189 DumpIpiRecords("ipi-records",
190 cl::desc("dump CodeView type records from IPI stream"),
191 cl::cat(TypeOptions), cl::sub(RawSubcommand));
192cl::opt<bool> DumpIpiRecordBytes(
193 "ipi-record-bytes",
194 cl::desc("dump CodeView type record raw bytes from IPI stream"),
195 cl::cat(TypeOptions), cl::sub(RawSubcommand));
196
197// MODULE & FILE OPTIONS
198cl::opt<bool> DumpModules("modules", cl::desc("dump compiland information"),
199 cl::cat(FileOptions), cl::sub(RawSubcommand));
200cl::opt<bool> DumpModuleFiles("module-files", cl::desc("dump file information"),
201 cl::cat(FileOptions), cl::sub(RawSubcommand));
202cl::opt<bool> DumpLineInfo("line-info",
203 cl::desc("dump file and line information"),
204 cl::cat(FileOptions), cl::sub(RawSubcommand));
205
206// SYMBOL OPTIONS
207cl::opt<bool> DumpModuleSyms("module-syms", cl::desc("dump module symbols"),
208 cl::cat(SymbolOptions), cl::sub(RawSubcommand));
209cl::opt<bool> DumpPublics("publics", cl::desc("dump Publics stream data"),
210 cl::cat(SymbolOptions), cl::sub(RawSubcommand));
211cl::opt<bool>
212 DumpSymRecordBytes("sym-record-bytes",
213 cl::desc("dump CodeView symbol record raw bytes"),
214 cl::cat(SymbolOptions), cl::sub(RawSubcommand));
215
216// MISCELLANEOUS OPTIONS
217cl::opt<bool> DumpSectionContribs("section-contribs",
218 cl::desc("dump section contributions"),
219 cl::cat(MiscOptions),
220 cl::sub(RawSubcommand));
221cl::opt<bool> DumpSectionMap("section-map", cl::desc("dump section map"),
222 cl::cat(MiscOptions), cl::sub(RawSubcommand));
223cl::opt<bool> DumpSectionHeaders("section-headers",
224 cl::desc("dump section headers"),
225 cl::cat(MiscOptions),
226 cl::sub(RawSubcommand));
227cl::opt<bool> DumpFpo("fpo", cl::desc("dump FPO records"),
228 cl::cat(MiscOptions), cl::sub(RawSubcommand));
229
230cl::opt<std::string> DumpStreamDataIdx("stream", cl::desc("dump stream data"),
231 cl::cat(MiscOptions),
232 cl::sub(RawSubcommand));
233cl::opt<std::string> DumpStreamDataName("stream-name",
234 cl::desc("dump stream data"),
235 cl::cat(MiscOptions),
236 cl::sub(RawSubcommand));
237
238cl::opt<bool>
239 RawAll("all",
240 cl::desc("Implies most other options."),
241 cl::cat(MiscOptions), cl::sub(RawSubcommand));
242
243cl::list<std::string> InputFilenames(cl::Positional,
244 cl::desc("<input PDB files>"),
245 cl::OneOrMore, cl::sub(RawSubcommand));
246}
247
248namespace yaml2pdb {
249cl::opt<std::string>
250 YamlPdbOutputFile("pdb", cl::desc("the name of the PDB file to write"),
251 cl::sub(YamlToPdbSubcommand));
252
253cl::list<std::string> InputFilename(cl::Positional,
254 cl::desc("<input YAML file>"), cl::Required,
255 cl::sub(YamlToPdbSubcommand));
256}
257
258namespace pdb2yaml {
259 cl::opt<bool> StreamMetadata("stream-metadata", cl::desc("Dump the number of streams and each stream's size"), cl::sub(PdbToYamlSubcommand));
260 cl::opt<bool> StreamDirectory("stream-directory", cl::desc("Dump each stream's block map (implies -stream-metadata)"), cl::sub(PdbToYamlSubcommand));
261
262cl::list<std::string> InputFilename(cl::Positional,
263 cl::desc("<input PDB file>"), cl::Required,
264 cl::sub(PdbToYamlSubcommand));
265}
Zachary Turner49693b42015-01-28 01:22:33 +0000266}
267
David Majnemerc165c882016-05-28 18:25:15 +0000268static ExitOnError ExitOnErr;
269
Zachary Turner1dc9fd32016-06-14 20:48:36 +0000270static void yamlToPdb(StringRef Path) {
271 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
272 MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
273 /*RequiresNullTerminator=*/false);
274
275 if (ErrorOrBuffer.getError()) {
276 ExitOnErr(make_error<GenericError>(generic_error_code::invalid_path, Path));
277 }
278
279 std::unique_ptr<MemoryBuffer> &Buffer = ErrorOrBuffer.get();
280
281 llvm::yaml::Input In(Buffer->getBuffer());
282 pdb::yaml::PdbObject YamlObj;
283 In >> YamlObj;
284
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000285 auto OutFileOrError = FileOutputBuffer::create(
286 opts::yaml2pdb::YamlPdbOutputFile, YamlObj.Headers.FileSize);
Zachary Turner1dc9fd32016-06-14 20:48:36 +0000287 if (OutFileOrError.getError())
288 ExitOnErr(make_error<GenericError>(generic_error_code::invalid_path,
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000289 opts::yaml2pdb::YamlPdbOutputFile));
Zachary Turner1dc9fd32016-06-14 20:48:36 +0000290
291 auto FileByteStream =
292 llvm::make_unique<FileBufferByteStream>(std::move(*OutFileOrError));
293 PDBFile Pdb(std::move(FileByteStream));
294 Pdb.setSuperBlock(&YamlObj.Headers.SuperBlock);
295 if (YamlObj.StreamMap.hasValue()) {
296 std::vector<ArrayRef<support::ulittle32_t>> StreamMap;
297 for (auto &E : YamlObj.StreamMap.getValue()) {
298 StreamMap.push_back(E.Blocks);
299 }
300 Pdb.setStreamMap(StreamMap);
301 }
302 if (YamlObj.StreamSizes.hasValue()) {
303 Pdb.setStreamSizes(YamlObj.StreamSizes.getValue());
304 }
305
306 Pdb.commit();
307}
308
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000309static void dumpRaw(StringRef Path) {
David Majnemer1573b242016-04-28 23:47:27 +0000310 std::unique_ptr<IPDBSession> Session;
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000311 ExitOnErr(loadDataForPDB(PDB_ReaderType::Raw, Path, Session));
David Majnemer1573b242016-04-28 23:47:27 +0000312
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000313 RawSession *RS = static_cast<RawSession *>(Session.get());
314 PDBFile &File = RS->getPDBFile();
315 std::unique_ptr<OutputStyle> O;
316 if (opts::PdbToYamlSubcommand)
317 O = llvm::make_unique<YAMLOutputStyle>(File);
318 else
319 O = llvm::make_unique<LLVMOutputStyle>(File);
320
321 ExitOnErr(O->dump());
322}
323
324static void dumpPretty(StringRef Path) {
325 std::unique_ptr<IPDBSession> Session;
David Majnemer1573b242016-04-28 23:47:27 +0000326
David Majnemerc165c882016-05-28 18:25:15 +0000327 ExitOnErr(loadDataForPDB(PDB_ReaderType::DIA, Path, Session));
David Majnemer1573b242016-04-28 23:47:27 +0000328
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000329 if (opts::pretty::LoadAddress)
330 Session->setLoadAddress(opts::pretty::LoadAddress);
Zachary Turner7058dfc2015-01-27 22:40:14 +0000331
Zachary Turner2d11c202015-02-27 09:15:59 +0000332 LinePrinter Printer(2, outs());
333
Zachary Turnera5549172015-02-10 22:43:25 +0000334 auto GlobalScope(Session->getGlobalScope());
Zachary Turner9a818ad2015-02-22 22:03:38 +0000335 std::string FileName(GlobalScope->getSymbolsFileName());
336
Zachary Turner2d11c202015-02-27 09:15:59 +0000337 WithColor(Printer, PDB_ColorItem::None).get() << "Summary for ";
338 WithColor(Printer, PDB_ColorItem::Path).get() << FileName;
339 Printer.Indent();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000340 uint64_t FileSize = 0;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000341
Zachary Turner2d11c202015-02-27 09:15:59 +0000342 Printer.NewLine();
343 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Size";
David Majnemer6e081262015-10-15 01:27:19 +0000344 if (!sys::fs::file_size(FileName, FileSize)) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000345 Printer << ": " << FileSize << " bytes";
346 } else {
347 Printer << ": (Unable to obtain file size)";
348 }
349
350 Printer.NewLine();
351 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Guid";
352 Printer << ": " << GlobalScope->getGuid();
353
354 Printer.NewLine();
355 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Age";
356 Printer << ": " << GlobalScope->getAge();
357
358 Printer.NewLine();
359 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Attributes";
360 Printer << ": ";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000361 if (GlobalScope->hasCTypes())
362 outs() << "HasCTypes ";
363 if (GlobalScope->hasPrivateSymbols())
364 outs() << "HasPrivateSymbols ";
Zachary Turner2d11c202015-02-27 09:15:59 +0000365 Printer.Unindent();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000366
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000367 if (opts::pretty::Compilands) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000368 Printer.NewLine();
369 WithColor(Printer, PDB_ColorItem::SectionHeader).get()
370 << "---COMPILANDS---";
371 Printer.Indent();
Zachary Turnerc074de02015-02-12 21:09:24 +0000372 auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
Zachary Turner2d11c202015-02-27 09:15:59 +0000373 CompilandDumper Dumper(Printer);
Zachary Turnera99000d2016-03-08 21:42:24 +0000374 CompilandDumpFlags options = CompilandDumper::Flags::None;
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000375 if (opts::pretty::Lines)
Zachary Turnera99000d2016-03-08 21:42:24 +0000376 options = options | CompilandDumper::Flags::Lines;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000377 while (auto Compiland = Compilands->getNext())
Zachary Turnera99000d2016-03-08 21:42:24 +0000378 Dumper.start(*Compiland, options);
Zachary Turner2d11c202015-02-27 09:15:59 +0000379 Printer.Unindent();
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000380 }
381
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000382 if (opts::pretty::Types) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000383 Printer.NewLine();
384 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---";
385 Printer.Indent();
Zachary Turner65323652015-03-04 06:09:53 +0000386 TypeDumper Dumper(Printer);
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000387 Dumper.start(*GlobalScope);
Zachary Turner2d11c202015-02-27 09:15:59 +0000388 Printer.Unindent();
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000389 }
390
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000391 if (opts::pretty::Symbols) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000392 Printer.NewLine();
393 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---SYMBOLS---";
394 Printer.Indent();
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000395 auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
Zachary Turner2d11c202015-02-27 09:15:59 +0000396 CompilandDumper Dumper(Printer);
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000397 while (auto Compiland = Compilands->getNext())
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000398 Dumper.start(*Compiland, true);
Zachary Turner2d11c202015-02-27 09:15:59 +0000399 Printer.Unindent();
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000400 }
401
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000402 if (opts::pretty::Globals) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000403 Printer.NewLine();
404 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---GLOBALS---";
405 Printer.Indent();
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000406 {
Zachary Turner2d11c202015-02-27 09:15:59 +0000407 FunctionDumper Dumper(Printer);
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000408 auto Functions = GlobalScope->findAllChildren<PDBSymbolFunc>();
Zachary Turner2d11c202015-02-27 09:15:59 +0000409 while (auto Function = Functions->getNext()) {
410 Printer.NewLine();
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000411 Dumper.start(*Function, FunctionDumper::PointerType::None);
Zachary Turner2d11c202015-02-27 09:15:59 +0000412 }
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000413 }
414 {
415 auto Vars = GlobalScope->findAllChildren<PDBSymbolData>();
Zachary Turner2d11c202015-02-27 09:15:59 +0000416 VariableDumper Dumper(Printer);
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000417 while (auto Var = Vars->getNext())
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000418 Dumper.start(*Var);
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000419 }
420 {
421 auto Thunks = GlobalScope->findAllChildren<PDBSymbolThunk>();
Zachary Turner2d11c202015-02-27 09:15:59 +0000422 CompilandDumper Dumper(Printer);
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000423 while (auto Thunk = Thunks->getNext())
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000424 Dumper.dump(*Thunk);
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000425 }
Zachary Turner2d11c202015-02-27 09:15:59 +0000426 Printer.Unindent();
Zachary Turner7058dfc2015-01-27 22:40:14 +0000427 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000428 if (opts::pretty::Externals) {
Zachary Turnere5cb2692015-05-01 20:24:26 +0000429 Printer.NewLine();
430 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---EXTERNALS---";
431 Printer.Indent();
432 ExternalSymbolDumper Dumper(Printer);
433 Dumper.start(*GlobalScope);
434 }
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000435 if (opts::pretty::Lines) {
Zachary Turnera99000d2016-03-08 21:42:24 +0000436 Printer.NewLine();
437 }
Zachary Turnera5549172015-02-10 22:43:25 +0000438 outs().flush();
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000439}
440
441int main(int argc_, const char *argv_[]) {
442 // Print a stack trace if we signal out.
Richard Smith2ad6d482016-06-09 00:53:21 +0000443 sys::PrintStackTraceOnErrorSignal(argv_[0]);
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000444 PrettyStackTraceProgram X(argc_, argv_);
445
David Majnemerc165c882016-05-28 18:25:15 +0000446 ExitOnErr.setBanner("llvm-pdbdump: ");
447
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000448 SmallVector<const char *, 256> argv;
David Majnemer6e081262015-10-15 01:27:19 +0000449 SpecificBumpPtrAllocator<char> ArgAllocator;
David Majnemerc165c882016-05-28 18:25:15 +0000450 ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector(
451 argv, makeArrayRef(argv_, argc_), ArgAllocator)));
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000452
453 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
454
455 cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n");
Zachary Turnera99000d2016-03-08 21:42:24 +0000456
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000457 // These options are shared by two subcommands.
458 if ((opts::PdbToYamlSubcommand || opts::RawSubcommand) && opts::raw::RawAll) {
459 opts::raw::DumpHeaders = true;
460 opts::raw::DumpModules = true;
461 opts::raw::DumpModuleFiles = true;
462 opts::raw::DumpModuleSyms = true;
463 opts::raw::DumpPublics = true;
464 opts::raw::DumpSectionHeaders = true;
465 opts::raw::DumpStreamSummary = true;
466 opts::raw::DumpStreamBlocks = true;
467 opts::raw::DumpTpiRecords = true;
468 opts::raw::DumpTpiHash = true;
469 opts::raw::DumpIpiRecords = true;
470 opts::raw::DumpSectionMap = true;
471 opts::raw::DumpSectionContribs = true;
472 opts::raw::DumpLineInfo = true;
473 opts::raw::DumpFpo = true;
Zachary Turner7797c722015-03-02 04:39:56 +0000474 }
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000475
Zachary Turner93839cb2016-06-02 05:07:49 +0000476 llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000477
Zachary Turnera30bd1a2016-06-30 17:42:48 +0000478 if (opts::PdbToYamlSubcommand) {
479 dumpRaw(opts::pdb2yaml::InputFilename.front());
480 } else if (opts::YamlToPdbSubcommand) {
481 yamlToPdb(opts::yaml2pdb::InputFilename.front());
482 } else if (opts::PrettySubcommand) {
483 if (opts::pretty::Lines)
484 opts::pretty::Compilands = true;
485
486 if (opts::pretty::All) {
487 opts::pretty::Compilands = true;
488 opts::pretty::Symbols = true;
489 opts::pretty::Globals = true;
490 opts::pretty::Types = true;
491 opts::pretty::Externals = true;
492 opts::pretty::Lines = true;
493 }
494
495 // When adding filters for excluded compilands and types, we need to
496 // remember
497 // that these are regexes. So special characters such as * and \ need to be
498 // escaped in the regex. In the case of a literal \, this means it needs to
499 // be escaped again in the C++. So matching a single \ in the input
500 // requires
501 // 4 \es in the C++.
502 if (opts::pretty::ExcludeCompilerGenerated) {
503 opts::pretty::ExcludeTypes.push_back("__vc_attributes");
504 opts::pretty::ExcludeCompilands.push_back("\\* Linker \\*");
505 }
506 if (opts::pretty::ExcludeSystemLibraries) {
507 opts::pretty::ExcludeCompilands.push_back(
508 "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
509 opts::pretty::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
510 opts::pretty::ExcludeCompilands.push_back(
511 "d:\\\\th.obj.x86fre\\\\minkernel");
512 }
513 std::for_each(opts::pretty::InputFilenames.begin(),
514 opts::pretty::InputFilenames.end(), dumpPretty);
515 } else if (opts::RawSubcommand) {
516 std::for_each(opts::raw::InputFilenames.begin(),
517 opts::raw::InputFilenames.end(), dumpRaw);
Zachary Turner1dc9fd32016-06-14 20:48:36 +0000518 }
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000519
Zachary Turner819e77d2016-05-06 20:51:57 +0000520 outs().flush();
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000521 return 0;
522}