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)
42 enum class PDB_DumpType { ByType, ByObjFile, Both };
44 cl::list<std::string> InputFilenames(cl::Positional,
45 cl::desc("<input PDB files>"),
48 cl::opt<bool> DumpCompilands("compilands", cl::desc("Display compilands"));
49 cl::opt<bool> DumpSymbols("symbols",
50 cl::desc("Display symbols (implies --compilands"));
51 cl::opt<bool> DumpTypes("types", cl::desc("Display types"));
54 static void dumpInput(StringRef Path) {
55 std::unique_ptr<IPDBSession> Session(
56 llvm::createPDBReader(PDB_ReaderType::DIA, Path));
58 outs() << "Unable to create PDB reader. Check that a valid implementation";
59 outs() << " is available for your platform.";
63 auto GlobalScope(Session->getGlobalScope());
64 PDB_DumpFlags Flags = PDB_DF_None;
66 Flags |= PDB_DF_Children | PDB_DF_Enums | PDB_DF_Funcsigs |
67 PDB_DF_Typedefs | PDB_DF_VTables;
68 GlobalScope->dump(outs(), 0, PDB_DumpLevel::Normal, Flags);
71 if (opts::DumpSymbols || opts::DumpCompilands) {
72 outs() << "Dumping compilands\n";
73 auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
75 if (opts::DumpSymbols)
76 Flags |= PDB_DF_Children | PDB_DF_Data | PDB_DF_Functions |
77 PDB_DF_Thunks | PDB_DF_Labels;
78 while (auto Compiland = Compilands->getNext()) {
79 Compiland->dump(outs(), 2, PDB_DumpLevel::Detailed, Flags);
86 int main(int argc_, const char *argv_[]) {
87 // Print a stack trace if we signal out.
88 sys::PrintStackTraceOnErrorSignal();
89 PrettyStackTraceProgram X(argc_, argv_);
91 SmallVector<const char *, 256> argv;
92 llvm::SpecificBumpPtrAllocator<char> ArgAllocator;
93 std::error_code EC = llvm::sys::Process::GetArgumentVector(
94 argv, llvm::makeArrayRef(argv_, argc_), ArgAllocator);
96 llvm::errs() << "error: couldn't get arguments: " << EC.message() << '\n';
100 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
102 cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n");
104 #if defined(HAVE_DIA_SDK)
105 CoInitializeEx(nullptr, COINIT_MULTITHREADED);
108 std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
111 #if defined(HAVE_DIA_SDK)