1 //===- llvm-pdbdump.cpp - Dump debug info from a PDB file -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
14 //===----------------------------------------------------------------------===//
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/DebugInfo/PDB/PDB.h"
19 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
20 #include "llvm/DebugInfo/PDB/IPDBSession.h"
21 #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
24 #include "llvm/Support/CommandLine.h"
25 #include "llvm/Support/ConvertUTF.h"
26 #include "llvm/Support/Format.h"
27 #include "llvm/Support/ManagedStatic.h"
28 #include "llvm/Support/raw_ostream.h"
29 #include "llvm/Support/Process.h"
30 #include "llvm/Support/PrettyStackTrace.h"
31 #include "llvm/Support/Signals.h"
38 cl::list<std::string> InputFilenames(cl::Positional,
39 cl::desc("<input PDB files>"),
42 cl::opt<bool> Compilands("compilands",
43 cl::desc("Display a list of compilands (e.g. object "
44 "files) and symbols for each one."));
45 cl::alias CompilandsShort("c", cl::desc("Alias for --compilands"),
46 cl::aliasopt(Compilands));
49 static void dumpInput(StringRef Path) {
50 std::unique_ptr<IPDBSession> Session(
51 llvm::createPDBReader(PDB_ReaderType::DIA, Path));
53 outs() << "Unable to create PDB reader. Check that a valid implementation";
54 outs() << " is available for your platform.";
58 auto GlobalScope(Session->getGlobalScope());
59 GlobalScope->dump(outs(), 0, PDB_DumpLevel::Normal);
62 if (opts::Compilands) {
63 auto Compilands = GlobalScope->findChildren(PDB_SymType::Compiland);
65 while (auto Compiland = Compilands->getNext()) {
66 Compiland->dump(outs(), 0, PDB_DumpLevel::Normal);
73 int main(int argc_, const char *argv_[]) {
74 // Print a stack trace if we signal out.
75 sys::PrintStackTraceOnErrorSignal();
76 PrettyStackTraceProgram X(argc_, argv_);
78 SmallVector<const char *, 256> argv;
79 llvm::SpecificBumpPtrAllocator<char> ArgAllocator;
80 std::error_code EC = llvm::sys::Process::GetArgumentVector(
81 argv, llvm::makeArrayRef(argv_, argc_), ArgAllocator);
83 llvm::errs() << "error: couldn't get arguments: " << EC.message() << '\n';
87 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
89 cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n");
91 CoInitializeEx(nullptr, COINIT_MULTITHREADED);
93 std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),