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/Config/config.h"
19 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
20 #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
21 #include "llvm/DebugInfo/PDB/IPDBSession.h"
22 #include "llvm/DebugInfo/PDB/PDB.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
25 #include "llvm/Support/CommandLine.h"
26 #include "llvm/Support/ConvertUTF.h"
27 #include "llvm/Support/Format.h"
28 #include "llvm/Support/ManagedStatic.h"
29 #include "llvm/Support/PrettyStackTrace.h"
30 #include "llvm/Support/Process.h"
31 #include "llvm/Support/Signals.h"
32 #include "llvm/Support/raw_ostream.h"
34 #if defined(HAVE_DIA_SDK)
41 cl::list<std::string> InputFilenames(cl::Positional,
42 cl::desc("<input PDB files>"),
45 cl::opt<bool> Compilands("compilands",
46 cl::desc("Display a list of compilands (e.g. object "
47 "files) and symbols for each one."));
48 cl::alias CompilandsShort("c", cl::desc("Alias for --compilands"),
49 cl::aliasopt(Compilands));
52 static void dumpInput(StringRef Path) {
53 std::unique_ptr<IPDBSession> Session(
54 llvm::createPDBReader(PDB_ReaderType::DIA, Path));
56 outs() << "Unable to create PDB reader. Check that a valid implementation";
57 outs() << " is available for your platform.";
61 auto GlobalScope(Session->getGlobalScope());
62 GlobalScope->dump(outs(), 0, PDB_DumpLevel::Normal);
65 if (opts::Compilands) {
66 auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
67 while (auto Compiland = Compilands->getNext()) {
68 Compiland->dump(outs(), 0, PDB_DumpLevel::Detailed);
75 int main(int argc_, const char *argv_[]) {
76 // Print a stack trace if we signal out.
77 sys::PrintStackTraceOnErrorSignal();
78 PrettyStackTraceProgram X(argc_, argv_);
80 SmallVector<const char *, 256> argv;
81 llvm::SpecificBumpPtrAllocator<char> ArgAllocator;
82 std::error_code EC = llvm::sys::Process::GetArgumentVector(
83 argv, llvm::makeArrayRef(argv_, argc_), ArgAllocator);
85 llvm::errs() << "error: couldn't get arguments: " << EC.message() << '\n';
89 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
91 cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n");
93 #if defined(HAVE_DIA_SDK)
94 CoInitializeEx(nullptr, COINIT_MULTITHREADED);
97 std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
100 #if defined(HAVE_DIA_SDK)