blob: 1f6b778c4b2f637c7a8374a3201b27670cbeedcc [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 Turner819e77d2016-05-06 20:51:57 +000032#include "llvm/DebugInfo/PDB/GenericError.h"
Zachary Turnera5549172015-02-10 22:43:25 +000033#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
Zachary Turnera5549172015-02-10 22:43:25 +000034#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
Chandler Carruth71f308a2015-02-13 09:09:03 +000035#include "llvm/DebugInfo/PDB/IPDBSession.h"
36#include "llvm/DebugInfo/PDB/PDB.h"
Zachary Turnera5549172015-02-10 22:43:25 +000037#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
Zachary Turnerdb18f5c2015-02-27 09:15:18 +000038#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
Chandler Carruth71f308a2015-02-13 09:09:03 +000039#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
Zachary Turnerdb18f5c2015-02-27 09:15:18 +000040#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
41#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
Zachary Turner0a43efe2016-04-25 17:38:08 +000042#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
Zachary Turnerd3117392016-06-03 19:28:33 +000043#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
Reid Klecknerce5196e2016-05-12 23:26:23 +000044#include "llvm/DebugInfo/PDB/Raw/RawError.h"
Zachary Turner0a43efe2016-04-25 17:38:08 +000045#include "llvm/DebugInfo/PDB/Raw/RawSession.h"
Zachary Turner93839cb2016-06-02 05:07:49 +000046#include "llvm/Support/COM.h"
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000047#include "llvm/Support/CommandLine.h"
48#include "llvm/Support/ConvertUTF.h"
Zachary Turner9a818ad2015-02-22 22:03:38 +000049#include "llvm/Support/FileSystem.h"
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000050#include "llvm/Support/Format.h"
51#include "llvm/Support/ManagedStatic.h"
David Majnemer6e081262015-10-15 01:27:19 +000052#include "llvm/Support/MemoryBuffer.h"
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000053#include "llvm/Support/PrettyStackTrace.h"
Chandler Carruth71f308a2015-02-13 09:09:03 +000054#include "llvm/Support/Process.h"
Reid Klecknerb0345262016-05-04 16:09:04 +000055#include "llvm/Support/ScopedPrinter.h"
Daniel Sandersd41718e2016-04-22 12:04:42 +000056#include "llvm/Support/Signals.h"
Zachary Turner0a43efe2016-04-25 17:38:08 +000057#include "llvm/Support/raw_ostream.h"
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000058
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000059using namespace llvm;
Zachary Turnera96cce62016-06-03 03:25:59 +000060using namespace llvm::codeview;
Zachary Turner2f09b502016-04-29 17:28:47 +000061using namespace llvm::pdb;
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000062
63namespace opts {
Zachary Turnerc0acf682015-02-15 20:27:53 +000064
65enum class PDB_DumpType { ByType, ByObjFile, Both };
66
Zachary Turnerfcb14ad2015-01-27 20:46:21 +000067cl::list<std::string> InputFilenames(cl::Positional,
68 cl::desc("<input PDB files>"),
69 cl::OneOrMore);
70
Zachary Turner7797c722015-03-02 04:39:56 +000071cl::OptionCategory TypeCategory("Symbol Type Options");
72cl::OptionCategory FilterCategory("Filtering Options");
Zachary Turnere5cb2692015-05-01 20:24:26 +000073cl::OptionCategory OtherOptions("Other Options");
Rui Ueyama18695f92016-05-26 23:01:05 +000074cl::OptionCategory NativeOptions("Native Options");
Zachary Turner7797c722015-03-02 04:39:56 +000075
76cl::opt<bool> Compilands("compilands", cl::desc("Display compilands"),
77 cl::cat(TypeCategory));
78cl::opt<bool> Symbols("symbols", cl::desc("Display symbols for each compiland"),
79 cl::cat(TypeCategory));
80cl::opt<bool> Globals("globals", cl::desc("Dump global symbols"),
81 cl::cat(TypeCategory));
Zachary Turnere5cb2692015-05-01 20:24:26 +000082cl::opt<bool> Externals("externals", cl::desc("Dump external symbols"),
83 cl::cat(TypeCategory));
Zachary Turner7797c722015-03-02 04:39:56 +000084cl::opt<bool> Types("types", cl::desc("Display types"), cl::cat(TypeCategory));
Zachary Turnera99000d2016-03-08 21:42:24 +000085cl::opt<bool> Lines("lines", cl::desc("Line tables"), cl::cat(TypeCategory));
Zachary Turner7797c722015-03-02 04:39:56 +000086cl::opt<bool>
Zachary Turner7797c722015-03-02 04:39:56 +000087 All("all", cl::desc("Implies all other options in 'Symbol Types' category"),
88 cl::cat(TypeCategory));
Zachary Turnerf5abda22015-03-01 06:49:49 +000089
Zachary Turnere5cb2692015-05-01 20:24:26 +000090cl::opt<uint64_t> LoadAddress(
91 "load-address",
92 cl::desc("Assume the module is loaded at the specified address"),
93 cl::cat(OtherOptions));
94
Zachary Turnerd3117392016-06-03 19:28:33 +000095cl::opt<OutputStyleTy>
96 RawOutputStyle("raw-output-style", cl::desc("Specify dump outpout style"),
97 cl::values(clEnumVal(LLVM, "LLVM default style"),
98 clEnumVal(YAML, "YAML style"), clEnumValEnd),
99 cl::init(LLVM), cl::cat(NativeOptions));
100
Zachary Turner96e60f72016-05-24 20:31:48 +0000101cl::opt<bool> DumpHeaders("raw-headers", cl::desc("dump PDB headers"),
Rui Ueyama18695f92016-05-26 23:01:05 +0000102 cl::cat(NativeOptions));
Zachary Turner96e60f72016-05-24 20:31:48 +0000103cl::opt<bool> DumpStreamBlocks("raw-stream-blocks",
David Majnemer6e081262015-10-15 01:27:19 +0000104 cl::desc("dump PDB stream blocks"),
Rui Ueyama18695f92016-05-26 23:01:05 +0000105 cl::cat(NativeOptions));
Zachary Turner85ed80b2016-05-25 03:43:17 +0000106cl::opt<bool> DumpStreamSummary("raw-stream-summary",
107 cl::desc("dump summary of the PDB streams"),
Rui Ueyama18695f92016-05-26 23:01:05 +0000108 cl::cat(NativeOptions));
Reid Klecknerb0345262016-05-04 16:09:04 +0000109cl::opt<bool>
Zachary Turnerc9972c62016-05-25 04:35:22 +0000110 DumpTpiRecords("raw-tpi-records",
111 cl::desc("dump CodeView type records from TPI stream"),
Rui Ueyama18695f92016-05-26 23:01:05 +0000112 cl::cat(NativeOptions));
Zachary Turnerc9972c62016-05-25 04:35:22 +0000113cl::opt<bool> DumpTpiRecordBytes(
114 "raw-tpi-record-bytes",
115 cl::desc("dump CodeView type record raw bytes from TPI stream"),
Rui Ueyama18695f92016-05-26 23:01:05 +0000116 cl::cat(NativeOptions));
Rui Ueyamafd97bf12016-06-03 20:48:51 +0000117cl::opt<bool> DumpTpiHash("raw-tpi-hash",
118 cl::desc("dump CodeView TPI hash stream"),
119 cl::cat(NativeOptions));
Zachary Turnerc9972c62016-05-25 04:35:22 +0000120cl::opt<bool>
121 DumpIpiRecords("raw-ipi-records",
122 cl::desc("dump CodeView type records from IPI stream"),
Rui Ueyama18695f92016-05-26 23:01:05 +0000123 cl::cat(NativeOptions));
Zachary Turnerc9972c62016-05-25 04:35:22 +0000124cl::opt<bool> DumpIpiRecordBytes(
125 "raw-ipi-record-bytes",
126 cl::desc("dump CodeView type record raw bytes from IPI stream"),
Rui Ueyama18695f92016-05-26 23:01:05 +0000127 cl::cat(NativeOptions));
Zachary Turner96e60f72016-05-24 20:31:48 +0000128cl::opt<std::string> DumpStreamDataIdx("raw-stream",
129 cl::desc("dump stream data"),
Rui Ueyama18695f92016-05-26 23:01:05 +0000130 cl::cat(NativeOptions));
Zachary Turner96e60f72016-05-24 20:31:48 +0000131cl::opt<std::string> DumpStreamDataName("raw-stream-name",
132 cl::desc("dump stream data"),
Rui Ueyama18695f92016-05-26 23:01:05 +0000133 cl::cat(NativeOptions));
Zachary Turner96e60f72016-05-24 20:31:48 +0000134cl::opt<bool> DumpModules("raw-modules", cl::desc("dump compiland information"),
Rui Ueyama18695f92016-05-26 23:01:05 +0000135 cl::cat(NativeOptions));
Zachary Turner96e60f72016-05-24 20:31:48 +0000136cl::opt<bool> DumpModuleFiles("raw-module-files",
137 cl::desc("dump file information"),
Rui Ueyama18695f92016-05-26 23:01:05 +0000138 cl::cat(NativeOptions));
Zachary Turner96e60f72016-05-24 20:31:48 +0000139cl::opt<bool> DumpModuleSyms("raw-module-syms", cl::desc("dump module symbols"),
Rui Ueyama18695f92016-05-26 23:01:05 +0000140 cl::cat(NativeOptions));
Zachary Turner96e60f72016-05-24 20:31:48 +0000141cl::opt<bool> DumpPublics("raw-publics", cl::desc("dump Publics stream data"),
Rui Ueyama18695f92016-05-26 23:01:05 +0000142 cl::cat(NativeOptions));
Zachary Turner93839cb2016-06-02 05:07:49 +0000143cl::opt<bool> DumpSectionContribs("raw-section-contribs",
144 cl::desc("dump section contributions"),
145 cl::cat(NativeOptions));
Zachary Turner7eb6d352016-06-02 20:11:22 +0000146cl::opt<bool> DumpLineInfo("raw-line-info",
147 cl::desc("dump file and line information"),
148 cl::cat(NativeOptions));
Zachary Turner93839cb2016-06-02 05:07:49 +0000149cl::opt<bool> DumpSectionMap("raw-section-map", cl::desc("dump section map"),
150 cl::cat(NativeOptions));
Zachary Turnercac29ae2016-05-24 17:30:25 +0000151cl::opt<bool>
Zachary Turner96e60f72016-05-24 20:31:48 +0000152 DumpSymRecordBytes("raw-sym-record-bytes",
Zachary Turnercac29ae2016-05-24 17:30:25 +0000153 cl::desc("dump CodeView symbol record raw bytes"),
Rui Ueyama18695f92016-05-26 23:01:05 +0000154 cl::cat(NativeOptions));
Rui Ueyama90db7882016-06-02 18:20:20 +0000155cl::opt<bool> DumpSectionHeaders("raw-section-headers",
156 cl::desc("dump section headers"),
157 cl::cat(NativeOptions));
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000158cl::opt<bool> DumpFpo("raw-fpo", cl::desc("dump FPO records"),
159 cl::cat(NativeOptions));
Rui Ueyama90db7882016-06-02 18:20:20 +0000160
Rui Ueyama9dc034d2016-05-26 23:26:55 +0000161cl::opt<bool>
162 RawAll("raw-all",
163 cl::desc("Implies most other options in 'Native Options' category"),
164 cl::cat(NativeOptions));
David Majnemer6e081262015-10-15 01:27:19 +0000165
Zachary Turnerf5abda22015-03-01 06:49:49 +0000166cl::list<std::string>
167 ExcludeTypes("exclude-types",
168 cl::desc("Exclude types by regular expression"),
Zachary Turner7797c722015-03-02 04:39:56 +0000169 cl::ZeroOrMore, cl::cat(FilterCategory));
Zachary Turnerf5abda22015-03-01 06:49:49 +0000170cl::list<std::string>
171 ExcludeSymbols("exclude-symbols",
172 cl::desc("Exclude symbols by regular expression"),
Zachary Turner7797c722015-03-02 04:39:56 +0000173 cl::ZeroOrMore, cl::cat(FilterCategory));
Zachary Turnerf5abda22015-03-01 06:49:49 +0000174cl::list<std::string>
175 ExcludeCompilands("exclude-compilands",
176 cl::desc("Exclude compilands by regular expression"),
Zachary Turner7797c722015-03-02 04:39:56 +0000177 cl::ZeroOrMore, cl::cat(FilterCategory));
Zachary Turner4dddcc62015-09-29 19:49:06 +0000178
179cl::list<std::string> IncludeTypes(
180 "include-types",
181 cl::desc("Include only types which match a regular expression"),
182 cl::ZeroOrMore, cl::cat(FilterCategory));
183cl::list<std::string> IncludeSymbols(
184 "include-symbols",
185 cl::desc("Include only symbols which match a regular expression"),
186 cl::ZeroOrMore, cl::cat(FilterCategory));
187cl::list<std::string> IncludeCompilands(
188 "include-compilands",
189 cl::desc("Include only compilands those which match a regular expression"),
190 cl::ZeroOrMore, cl::cat(FilterCategory));
191
Zachary Turner7797c722015-03-02 04:39:56 +0000192cl::opt<bool> ExcludeCompilerGenerated(
193 "no-compiler-generated",
194 cl::desc("Don't show compiler generated types and symbols"),
195 cl::cat(FilterCategory));
196cl::opt<bool>
197 ExcludeSystemLibraries("no-system-libs",
198 cl::desc("Don't show symbols from system libraries"),
199 cl::cat(FilterCategory));
Zachary Turner65323652015-03-04 06:09:53 +0000200cl::opt<bool> NoClassDefs("no-class-definitions",
201 cl::desc("Don't display full class definitions"),
202 cl::cat(FilterCategory));
203cl::opt<bool> NoEnumDefs("no-enum-definitions",
204 cl::desc("Don't display full enum definitions"),
205 cl::cat(FilterCategory));
Zachary Turner49693b42015-01-28 01:22:33 +0000206}
207
David Majnemerc165c882016-05-28 18:25:15 +0000208static ExitOnError ExitOnErr;
209
Zachary Turner819e77d2016-05-06 20:51:57 +0000210static Error dumpStructure(RawSession &RS) {
Reid Klecknerb0345262016-05-04 16:09:04 +0000211 PDBFile &File = RS.getPDBFile();
Zachary Turnerd3117392016-06-03 19:28:33 +0000212 std::unique_ptr<OutputStyle> O;
213 if (opts::RawOutputStyle == opts::OutputStyleTy::LLVM)
214 O = llvm::make_unique<LLVMOutputStyle>(File);
Zachary Turner7120a472016-06-06 20:37:05 +0000215 else if (opts::RawOutputStyle == opts::OutputStyleTy::YAML)
216 O = llvm::make_unique<YAMLOutputStyle>(File);
Zachary Turnerd3117392016-06-03 19:28:33 +0000217 else
218 return make_error<RawError>(raw_error_code::feature_unsupported,
219 "Requested output style unsupported");
Reid Klecknerb0345262016-05-04 16:09:04 +0000220
Zachary Turnerd3117392016-06-03 19:28:33 +0000221 if (auto EC = O->dumpFileHeaders())
Zachary Turner819e77d2016-05-06 20:51:57 +0000222 return EC;
Reid Klecknerb0345262016-05-04 16:09:04 +0000223
Zachary Turnerd3117392016-06-03 19:28:33 +0000224 if (auto EC = O->dumpStreamSummary())
Zachary Turner819e77d2016-05-06 20:51:57 +0000225 return EC;
Reid Klecknerb0345262016-05-04 16:09:04 +0000226
Zachary Turnerd3117392016-06-03 19:28:33 +0000227 if (auto EC = O->dumpStreamBlocks())
Zachary Turner819e77d2016-05-06 20:51:57 +0000228 return EC;
Reid Klecknerb0345262016-05-04 16:09:04 +0000229
Zachary Turnerd3117392016-06-03 19:28:33 +0000230 if (auto EC = O->dumpStreamData())
Zachary Turner819e77d2016-05-06 20:51:57 +0000231 return EC;
Reid Klecknerb0345262016-05-04 16:09:04 +0000232
Zachary Turnerd3117392016-06-03 19:28:33 +0000233 if (auto EC = O->dumpInfoStream())
Zachary Turner819e77d2016-05-06 20:51:57 +0000234 return EC;
Reid Klecknerb0345262016-05-04 16:09:04 +0000235
Zachary Turnerd3117392016-06-03 19:28:33 +0000236 if (auto EC = O->dumpNamedStream())
Zachary Turner819e77d2016-05-06 20:51:57 +0000237 return EC;
Reid Klecknerb0345262016-05-04 16:09:04 +0000238
Zachary Turnerd3117392016-06-03 19:28:33 +0000239 if (auto EC = O->dumpTpiStream(StreamTPI))
Zachary Turnerc9972c62016-05-25 04:35:22 +0000240 return EC;
Rui Ueyama90db7882016-06-02 18:20:20 +0000241
Zachary Turnerd3117392016-06-03 19:28:33 +0000242 if (auto EC = O->dumpTpiStream(StreamIPI))
Zachary Turner819e77d2016-05-06 20:51:57 +0000243 return EC;
Reid Klecknerb0345262016-05-04 16:09:04 +0000244
Zachary Turnerd3117392016-06-03 19:28:33 +0000245 if (auto EC = O->dumpDbiStream())
Zachary Turner819e77d2016-05-06 20:51:57 +0000246 return EC;
Rui Ueyama1f6b6e22016-05-13 21:21:53 +0000247
Zachary Turnerd3117392016-06-03 19:28:33 +0000248 if (auto EC = O->dumpSectionContribs())
Zachary Turner93839cb2016-06-02 05:07:49 +0000249 return EC;
250
Zachary Turnerd3117392016-06-03 19:28:33 +0000251 if (auto EC = O->dumpSectionMap())
Zachary Turner93839cb2016-06-02 05:07:49 +0000252 return EC;
253
Zachary Turnerd3117392016-06-03 19:28:33 +0000254 if (auto EC = O->dumpPublicsStream())
Rui Ueyama1f6b6e22016-05-13 21:21:53 +0000255 return EC;
Zachary Turner93839cb2016-06-02 05:07:49 +0000256
Zachary Turnerd3117392016-06-03 19:28:33 +0000257 if (auto EC = O->dumpSectionHeaders())
Rui Ueyama90db7882016-06-02 18:20:20 +0000258 return EC;
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000259
260 if (auto EC = O->dumpFpoStream())
261 return EC;
Zachary Turner7120a472016-06-06 20:37:05 +0000262 O->flush();
Zachary Turner96e60f72016-05-24 20:31:48 +0000263 return Error::success();
264}
265
266bool isRawDumpEnabled() {
267 if (opts::DumpHeaders)
268 return true;
269 if (opts::DumpModules)
270 return true;
271 if (opts::DumpModuleFiles)
272 return true;
273 if (opts::DumpModuleSyms)
274 return true;
275 if (!opts::DumpStreamDataIdx.empty())
276 return true;
277 if (!opts::DumpStreamDataName.empty())
278 return true;
279 if (opts::DumpPublics)
280 return true;
Zachary Turner85ed80b2016-05-25 03:43:17 +0000281 if (opts::DumpStreamSummary)
Zachary Turner96e60f72016-05-24 20:31:48 +0000282 return true;
Zachary Turner85ed80b2016-05-25 03:43:17 +0000283 if (opts::DumpStreamBlocks)
Zachary Turner96e60f72016-05-24 20:31:48 +0000284 return true;
285 if (opts::DumpSymRecordBytes)
286 return true;
287 if (opts::DumpTpiRecordBytes)
288 return true;
289 if (opts::DumpTpiRecords)
290 return true;
Rui Ueyamafd97bf12016-06-03 20:48:51 +0000291 if (opts::DumpTpiHash)
292 return true;
Zachary Turnerc9972c62016-05-25 04:35:22 +0000293 if (opts::DumpIpiRecords)
294 return true;
295 if (opts::DumpIpiRecordBytes)
296 return true;
Zachary Turnerd2b2bfe2016-06-08 00:25:08 +0000297 if (opts::DumpSectionHeaders)
298 return true;
Zachary Turner93839cb2016-06-02 05:07:49 +0000299 if (opts::DumpSectionContribs)
300 return true;
301 if (opts::DumpSectionMap)
302 return true;
Zachary Turner7eb6d352016-06-02 20:11:22 +0000303 if (opts::DumpLineInfo)
304 return true;
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000305 if (opts::DumpFpo)
306 return true;
Zachary Turner96e60f72016-05-24 20:31:48 +0000307 return false;
David Majnemer1573b242016-04-28 23:47:27 +0000308}
309
310static void dumpInput(StringRef Path) {
311 std::unique_ptr<IPDBSession> Session;
Zachary Turner96e60f72016-05-24 20:31:48 +0000312 if (isRawDumpEnabled()) {
David Majnemerc165c882016-05-28 18:25:15 +0000313 ExitOnErr(loadDataForPDB(PDB_ReaderType::Raw, Path, Session));
David Majnemer1573b242016-04-28 23:47:27 +0000314
David Majnemerc165c882016-05-28 18:25:15 +0000315 RawSession *RS = static_cast<RawSession *>(Session.get());
316 ExitOnErr(dumpStructure(*RS));
David Majnemer1573b242016-04-28 23:47:27 +0000317 return;
318 }
319
David Majnemerc165c882016-05-28 18:25:15 +0000320 ExitOnErr(loadDataForPDB(PDB_ReaderType::DIA, Path, Session));
David Majnemer1573b242016-04-28 23:47:27 +0000321
Zachary Turnere5cb2692015-05-01 20:24:26 +0000322 if (opts::LoadAddress)
323 Session->setLoadAddress(opts::LoadAddress);
Zachary Turner7058dfc2015-01-27 22:40:14 +0000324
Zachary Turner2d11c202015-02-27 09:15:59 +0000325 LinePrinter Printer(2, outs());
326
Zachary Turnera5549172015-02-10 22:43:25 +0000327 auto GlobalScope(Session->getGlobalScope());
Zachary Turner9a818ad2015-02-22 22:03:38 +0000328 std::string FileName(GlobalScope->getSymbolsFileName());
329
Zachary Turner2d11c202015-02-27 09:15:59 +0000330 WithColor(Printer, PDB_ColorItem::None).get() << "Summary for ";
331 WithColor(Printer, PDB_ColorItem::Path).get() << FileName;
332 Printer.Indent();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000333 uint64_t FileSize = 0;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000334
Zachary Turner2d11c202015-02-27 09:15:59 +0000335 Printer.NewLine();
336 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Size";
David Majnemer6e081262015-10-15 01:27:19 +0000337 if (!sys::fs::file_size(FileName, FileSize)) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000338 Printer << ": " << FileSize << " bytes";
339 } else {
340 Printer << ": (Unable to obtain file size)";
341 }
342
343 Printer.NewLine();
344 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Guid";
345 Printer << ": " << GlobalScope->getGuid();
346
347 Printer.NewLine();
348 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Age";
349 Printer << ": " << GlobalScope->getAge();
350
351 Printer.NewLine();
352 WithColor(Printer, PDB_ColorItem::Identifier).get() << "Attributes";
353 Printer << ": ";
Zachary Turner9a818ad2015-02-22 22:03:38 +0000354 if (GlobalScope->hasCTypes())
355 outs() << "HasCTypes ";
356 if (GlobalScope->hasPrivateSymbols())
357 outs() << "HasPrivateSymbols ";
Zachary Turner2d11c202015-02-27 09:15:59 +0000358 Printer.Unindent();
Zachary Turner9a818ad2015-02-22 22:03:38 +0000359
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000360 if (opts::Compilands) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000361 Printer.NewLine();
362 WithColor(Printer, PDB_ColorItem::SectionHeader).get()
363 << "---COMPILANDS---";
364 Printer.Indent();
Zachary Turnerc074de02015-02-12 21:09:24 +0000365 auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
Zachary Turner2d11c202015-02-27 09:15:59 +0000366 CompilandDumper Dumper(Printer);
Zachary Turnera99000d2016-03-08 21:42:24 +0000367 CompilandDumpFlags options = CompilandDumper::Flags::None;
368 if (opts::Lines)
369 options = options | CompilandDumper::Flags::Lines;
Zachary Turner9a818ad2015-02-22 22:03:38 +0000370 while (auto Compiland = Compilands->getNext())
Zachary Turnera99000d2016-03-08 21:42:24 +0000371 Dumper.start(*Compiland, options);
Zachary Turner2d11c202015-02-27 09:15:59 +0000372 Printer.Unindent();
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000373 }
374
375 if (opts::Types) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000376 Printer.NewLine();
377 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---";
378 Printer.Indent();
Zachary Turner65323652015-03-04 06:09:53 +0000379 TypeDumper Dumper(Printer);
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000380 Dumper.start(*GlobalScope);
Zachary Turner2d11c202015-02-27 09:15:59 +0000381 Printer.Unindent();
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000382 }
383
384 if (opts::Symbols) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000385 Printer.NewLine();
386 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---SYMBOLS---";
387 Printer.Indent();
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000388 auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
Zachary Turner2d11c202015-02-27 09:15:59 +0000389 CompilandDumper Dumper(Printer);
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000390 while (auto Compiland = Compilands->getNext())
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000391 Dumper.start(*Compiland, true);
Zachary Turner2d11c202015-02-27 09:15:59 +0000392 Printer.Unindent();
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000393 }
394
395 if (opts::Globals) {
Zachary Turner2d11c202015-02-27 09:15:59 +0000396 Printer.NewLine();
397 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---GLOBALS---";
398 Printer.Indent();
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000399 {
Zachary Turner2d11c202015-02-27 09:15:59 +0000400 FunctionDumper Dumper(Printer);
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000401 auto Functions = GlobalScope->findAllChildren<PDBSymbolFunc>();
Zachary Turner2d11c202015-02-27 09:15:59 +0000402 while (auto Function = Functions->getNext()) {
403 Printer.NewLine();
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000404 Dumper.start(*Function, FunctionDumper::PointerType::None);
Zachary Turner2d11c202015-02-27 09:15:59 +0000405 }
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000406 }
407 {
408 auto Vars = GlobalScope->findAllChildren<PDBSymbolData>();
Zachary Turner2d11c202015-02-27 09:15:59 +0000409 VariableDumper Dumper(Printer);
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000410 while (auto Var = Vars->getNext())
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000411 Dumper.start(*Var);
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000412 }
413 {
414 auto Thunks = GlobalScope->findAllChildren<PDBSymbolThunk>();
Zachary Turner2d11c202015-02-27 09:15:59 +0000415 CompilandDumper Dumper(Printer);
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000416 while (auto Thunk = Thunks->getNext())
Zachary Turnerb52d08d2015-03-01 06:51:29 +0000417 Dumper.dump(*Thunk);
Zachary Turnerdb18f5c2015-02-27 09:15:18 +0000418 }
Zachary Turner2d11c202015-02-27 09:15:59 +0000419 Printer.Unindent();
Zachary Turner7058dfc2015-01-27 22:40:14 +0000420 }
Zachary Turnere5cb2692015-05-01 20:24:26 +0000421 if (opts::Externals) {
422 Printer.NewLine();
423 WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---EXTERNALS---";
424 Printer.Indent();
425 ExternalSymbolDumper Dumper(Printer);
426 Dumper.start(*GlobalScope);
427 }
Zachary Turnera99000d2016-03-08 21:42:24 +0000428 if (opts::Lines) {
429 Printer.NewLine();
430 }
Zachary Turnera5549172015-02-10 22:43:25 +0000431 outs().flush();
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000432}
433
434int main(int argc_, const char *argv_[]) {
435 // Print a stack trace if we signal out.
Richard Smith2ad6d482016-06-09 00:53:21 +0000436 sys::PrintStackTraceOnErrorSignal(argv_[0]);
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000437 PrettyStackTraceProgram X(argc_, argv_);
438
David Majnemerc165c882016-05-28 18:25:15 +0000439 ExitOnErr.setBanner("llvm-pdbdump: ");
440
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000441 SmallVector<const char *, 256> argv;
David Majnemer6e081262015-10-15 01:27:19 +0000442 SpecificBumpPtrAllocator<char> ArgAllocator;
David Majnemerc165c882016-05-28 18:25:15 +0000443 ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector(
444 argv, makeArrayRef(argv_, argc_), ArgAllocator)));
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000445
446 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
447
448 cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n");
Zachary Turnera99000d2016-03-08 21:42:24 +0000449 if (opts::Lines)
450 opts::Compilands = true;
451
Zachary Turner7797c722015-03-02 04:39:56 +0000452 if (opts::All) {
453 opts::Compilands = true;
454 opts::Symbols = true;
455 opts::Globals = true;
456 opts::Types = true;
Zachary Turnere5cb2692015-05-01 20:24:26 +0000457 opts::Externals = true;
Zachary Turnera99000d2016-03-08 21:42:24 +0000458 opts::Lines = true;
Zachary Turner7797c722015-03-02 04:39:56 +0000459 }
Zachary Turnera99000d2016-03-08 21:42:24 +0000460
Rui Ueyama9dc034d2016-05-26 23:26:55 +0000461 if (opts::RawAll) {
462 opts::DumpHeaders = true;
463 opts::DumpModules = true;
464 opts::DumpModuleFiles = true;
465 opts::DumpModuleSyms = true;
466 opts::DumpPublics = true;
Rui Ueyama90db7882016-06-02 18:20:20 +0000467 opts::DumpSectionHeaders = true;
Rui Ueyama9dc034d2016-05-26 23:26:55 +0000468 opts::DumpStreamSummary = true;
469 opts::DumpStreamBlocks = true;
470 opts::DumpTpiRecords = true;
Rui Ueyamafd97bf12016-06-03 20:48:51 +0000471 opts::DumpTpiHash = true;
Rui Ueyama9dc034d2016-05-26 23:26:55 +0000472 opts::DumpIpiRecords = true;
Zachary Turner93839cb2016-06-02 05:07:49 +0000473 opts::DumpSectionMap = true;
474 opts::DumpSectionContribs = true;
Zachary Turner7eb6d352016-06-02 20:11:22 +0000475 opts::DumpLineInfo = true;
Rui Ueyamaef2b4882016-06-06 18:39:21 +0000476 opts::DumpFpo = true;
Rui Ueyama9dc034d2016-05-26 23:26:55 +0000477 }
478
Zachary Turnera99000d2016-03-08 21:42:24 +0000479 // When adding filters for excluded compilands and types, we need to remember
480 // that these are regexes. So special characters such as * and \ need to be
481 // escaped in the regex. In the case of a literal \, this means it needs to
482 // be escaped again in the C++. So matching a single \ in the input requires
483 // 4 \es in the C++.
Zachary Turner7797c722015-03-02 04:39:56 +0000484 if (opts::ExcludeCompilerGenerated) {
485 opts::ExcludeTypes.push_back("__vc_attributes");
Zachary Turnera99000d2016-03-08 21:42:24 +0000486 opts::ExcludeCompilands.push_back("\\* Linker \\*");
Zachary Turner7797c722015-03-02 04:39:56 +0000487 }
488 if (opts::ExcludeSystemLibraries) {
489 opts::ExcludeCompilands.push_back(
Zachary Turnera99000d2016-03-08 21:42:24 +0000490 "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld");
491 opts::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt");
492 opts::ExcludeCompilands.push_back("d:\\\\th.obj.x86fre\\\\minkernel");
Zachary Turner7797c722015-03-02 04:39:56 +0000493 }
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000494
Zachary Turner93839cb2016-06-02 05:07:49 +0000495 llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000496
497 std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
498 dumpInput);
499
Zachary Turner819e77d2016-05-06 20:51:57 +0000500 outs().flush();
Zachary Turnerfcb14ad2015-01-27 20:46:21 +0000501 return 0;
502}