2015-01-27 21:46:21 +01:00
|
|
|
//===- llvm-pdbdump.cpp - Dump debug info from a PDB file -------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Dumps debug information present in PDB files. This utility makes use of
|
|
|
|
// the Microsoft Windows SDK, so will not compile or run on non-Windows
|
|
|
|
// platforms.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-02-22 23:03:38 +01:00
|
|
|
#include "llvm-pdbdump.h"
|
|
|
|
#include "CompilandDumper.h"
|
2015-05-01 22:24:26 +02:00
|
|
|
#include "ExternalSymbolDumper.h"
|
2015-02-27 10:15:18 +01:00
|
|
|
#include "FunctionDumper.h"
|
2015-02-27 10:15:59 +01:00
|
|
|
#include "LinePrinter.h"
|
2015-02-22 23:03:38 +01:00
|
|
|
#include "TypeDumper.h"
|
2015-02-27 10:15:18 +01:00
|
|
|
#include "VariableDumper.h"
|
2015-02-22 23:03:38 +01:00
|
|
|
|
2015-01-27 21:46:21 +01:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2015-02-10 23:47:14 +01:00
|
|
|
#include "llvm/Config/config.h"
|
2015-02-10 23:43:25 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
|
2015-02-13 10:09:03 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/IPDBSession.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDB.h"
|
2015-02-10 23:43:25 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
|
2015-02-27 10:15:18 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
|
2015-02-13 10:09:03 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
|
2015-02-27 10:15:18 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
|
2015-01-27 21:46:21 +01:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/ConvertUTF.h"
|
2015-02-22 23:03:38 +01:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2015-01-27 21:46:21 +01:00
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
2015-02-13 10:09:03 +01:00
|
|
|
#include "llvm/Support/Process.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2015-02-22 23:03:38 +01:00
|
|
|
#include "llvm/Support/Signals.h"
|
2015-01-27 21:46:21 +01:00
|
|
|
|
2015-02-10 23:47:14 +01:00
|
|
|
#if defined(HAVE_DIA_SDK)
|
2015-02-10 23:43:25 +01:00
|
|
|
#include <Windows.h>
|
2015-02-10 23:47:14 +01:00
|
|
|
#endif
|
2015-01-27 21:46:21 +01:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace opts {
|
2015-02-15 21:27:53 +01:00
|
|
|
|
|
|
|
enum class PDB_DumpType { ByType, ByObjFile, Both };
|
|
|
|
|
2015-01-27 21:46:21 +01:00
|
|
|
cl::list<std::string> InputFilenames(cl::Positional,
|
|
|
|
cl::desc("<input PDB files>"),
|
|
|
|
cl::OneOrMore);
|
|
|
|
|
2015-03-02 05:39:56 +01:00
|
|
|
cl::OptionCategory TypeCategory("Symbol Type Options");
|
|
|
|
cl::OptionCategory FilterCategory("Filtering Options");
|
2015-05-01 22:24:26 +02:00
|
|
|
cl::OptionCategory OtherOptions("Other Options");
|
2015-03-02 05:39:56 +01:00
|
|
|
|
|
|
|
cl::opt<bool> Compilands("compilands", cl::desc("Display compilands"),
|
|
|
|
cl::cat(TypeCategory));
|
|
|
|
cl::opt<bool> Symbols("symbols", cl::desc("Display symbols for each compiland"),
|
|
|
|
cl::cat(TypeCategory));
|
|
|
|
cl::opt<bool> Globals("globals", cl::desc("Dump global symbols"),
|
|
|
|
cl::cat(TypeCategory));
|
2015-05-01 22:24:26 +02:00
|
|
|
cl::opt<bool> Externals("externals", cl::desc("Dump external symbols"),
|
|
|
|
cl::cat(TypeCategory));
|
2015-03-02 05:39:56 +01:00
|
|
|
cl::opt<bool> Types("types", cl::desc("Display types"), cl::cat(TypeCategory));
|
|
|
|
cl::opt<bool>
|
|
|
|
All("all", cl::desc("Implies all other options in 'Symbol Types' category"),
|
|
|
|
cl::cat(TypeCategory));
|
2015-03-01 07:49:49 +01:00
|
|
|
|
2015-05-01 22:24:26 +02:00
|
|
|
cl::opt<uint64_t> LoadAddress(
|
|
|
|
"load-address",
|
|
|
|
cl::desc("Assume the module is loaded at the specified address"),
|
|
|
|
cl::cat(OtherOptions));
|
|
|
|
|
2015-03-01 07:49:49 +01:00
|
|
|
cl::list<std::string>
|
|
|
|
ExcludeTypes("exclude-types",
|
|
|
|
cl::desc("Exclude types by regular expression"),
|
2015-03-02 05:39:56 +01:00
|
|
|
cl::ZeroOrMore, cl::cat(FilterCategory));
|
2015-03-01 07:49:49 +01:00
|
|
|
cl::list<std::string>
|
|
|
|
ExcludeSymbols("exclude-symbols",
|
|
|
|
cl::desc("Exclude symbols by regular expression"),
|
2015-03-02 05:39:56 +01:00
|
|
|
cl::ZeroOrMore, cl::cat(FilterCategory));
|
2015-03-01 07:49:49 +01:00
|
|
|
cl::list<std::string>
|
|
|
|
ExcludeCompilands("exclude-compilands",
|
|
|
|
cl::desc("Exclude compilands by regular expression"),
|
2015-03-02 05:39:56 +01:00
|
|
|
cl::ZeroOrMore, cl::cat(FilterCategory));
|
|
|
|
cl::opt<bool> ExcludeCompilerGenerated(
|
|
|
|
"no-compiler-generated",
|
|
|
|
cl::desc("Don't show compiler generated types and symbols"),
|
|
|
|
cl::cat(FilterCategory));
|
|
|
|
cl::opt<bool>
|
|
|
|
ExcludeSystemLibraries("no-system-libs",
|
|
|
|
cl::desc("Don't show symbols from system libraries"),
|
|
|
|
cl::cat(FilterCategory));
|
2015-03-04 07:09:53 +01:00
|
|
|
cl::opt<bool> NoClassDefs("no-class-definitions",
|
|
|
|
cl::desc("Don't display full class definitions"),
|
|
|
|
cl::cat(FilterCategory));
|
|
|
|
cl::opt<bool> NoEnumDefs("no-enum-definitions",
|
|
|
|
cl::desc("Don't display full enum definitions"),
|
|
|
|
cl::cat(FilterCategory));
|
2015-01-27 21:46:21 +01:00
|
|
|
}
|
|
|
|
|
2015-02-10 23:43:25 +01:00
|
|
|
static void dumpInput(StringRef Path) {
|
2015-02-28 21:23:18 +01:00
|
|
|
std::unique_ptr<IPDBSession> Session;
|
|
|
|
PDB_ErrorCode Error =
|
2015-04-18 00:40:36 +02:00
|
|
|
llvm::loadDataForPDB(PDB_ReaderType::DIA, Path, Session);
|
2015-02-28 21:23:18 +01:00
|
|
|
switch (Error) {
|
|
|
|
case PDB_ErrorCode::Success:
|
|
|
|
break;
|
|
|
|
case PDB_ErrorCode::NoPdbImpl:
|
|
|
|
outs() << "Reading PDBs is not supported on this platform.\n";
|
|
|
|
return;
|
|
|
|
case PDB_ErrorCode::InvalidPath:
|
|
|
|
outs() << "Unable to load PDB at '" << Path
|
|
|
|
<< "'. Check that the file exists and is readable.\n";
|
|
|
|
return;
|
|
|
|
case PDB_ErrorCode::InvalidFileFormat:
|
|
|
|
outs() << "Unable to load PDB at '" << Path
|
|
|
|
<< "'. The file has an unrecognized format.\n";
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
outs() << "Unable to load PDB at '" << Path
|
|
|
|
<< "'. An unknown error occured.\n";
|
2015-01-27 21:46:21 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-05-01 22:24:26 +02:00
|
|
|
if (opts::LoadAddress)
|
|
|
|
Session->setLoadAddress(opts::LoadAddress);
|
2015-01-27 23:40:14 +01:00
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
LinePrinter Printer(2, outs());
|
|
|
|
|
2015-02-10 23:43:25 +01:00
|
|
|
auto GlobalScope(Session->getGlobalScope());
|
2015-02-22 23:03:38 +01:00
|
|
|
std::string FileName(GlobalScope->getSymbolsFileName());
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::None).get() << "Summary for ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Path).get() << FileName;
|
|
|
|
Printer.Indent();
|
2015-02-22 23:03:38 +01:00
|
|
|
uint64_t FileSize = 0;
|
2015-02-27 10:15:59 +01:00
|
|
|
|
|
|
|
Printer.NewLine();
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << "Size";
|
|
|
|
if (!llvm::sys::fs::file_size(FileName, FileSize)) {
|
|
|
|
Printer << ": " << FileSize << " bytes";
|
|
|
|
} else {
|
|
|
|
Printer << ": (Unable to obtain file size)";
|
|
|
|
}
|
|
|
|
|
|
|
|
Printer.NewLine();
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << "Guid";
|
|
|
|
Printer << ": " << GlobalScope->getGuid();
|
|
|
|
|
|
|
|
Printer.NewLine();
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << "Age";
|
|
|
|
Printer << ": " << GlobalScope->getAge();
|
|
|
|
|
|
|
|
Printer.NewLine();
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << "Attributes";
|
|
|
|
Printer << ": ";
|
2015-02-22 23:03:38 +01:00
|
|
|
if (GlobalScope->hasCTypes())
|
|
|
|
outs() << "HasCTypes ";
|
|
|
|
if (GlobalScope->hasPrivateSymbols())
|
|
|
|
outs() << "HasPrivateSymbols ";
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.Unindent();
|
2015-02-22 23:03:38 +01:00
|
|
|
|
2015-02-27 10:15:18 +01:00
|
|
|
if (opts::Compilands) {
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.NewLine();
|
|
|
|
WithColor(Printer, PDB_ColorItem::SectionHeader).get()
|
|
|
|
<< "---COMPILANDS---";
|
|
|
|
Printer.Indent();
|
2015-02-27 10:15:18 +01:00
|
|
|
auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
|
2015-02-27 10:15:59 +01:00
|
|
|
CompilandDumper Dumper(Printer);
|
2015-02-27 10:15:18 +01:00
|
|
|
while (auto Compiland = Compilands->getNext())
|
2015-03-01 07:51:29 +01:00
|
|
|
Dumper.start(*Compiland, false);
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.Unindent();
|
2015-02-27 10:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (opts::Types) {
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.NewLine();
|
|
|
|
WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---";
|
|
|
|
Printer.Indent();
|
2015-03-04 07:09:53 +01:00
|
|
|
TypeDumper Dumper(Printer);
|
2015-03-01 07:51:29 +01:00
|
|
|
Dumper.start(*GlobalScope);
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.Unindent();
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
2015-01-28 01:33:00 +01:00
|
|
|
|
2015-02-27 10:15:18 +01:00
|
|
|
if (opts::Symbols) {
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.NewLine();
|
|
|
|
WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---SYMBOLS---";
|
|
|
|
Printer.Indent();
|
2015-02-12 22:09:24 +01:00
|
|
|
auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>();
|
2015-02-27 10:15:59 +01:00
|
|
|
CompilandDumper Dumper(Printer);
|
2015-02-22 23:03:38 +01:00
|
|
|
while (auto Compiland = Compilands->getNext())
|
2015-03-01 07:51:29 +01:00
|
|
|
Dumper.start(*Compiland, true);
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.Unindent();
|
2015-02-27 10:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (opts::Globals) {
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.NewLine();
|
|
|
|
WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---GLOBALS---";
|
|
|
|
Printer.Indent();
|
2015-02-27 10:15:18 +01:00
|
|
|
{
|
2015-02-27 10:15:59 +01:00
|
|
|
FunctionDumper Dumper(Printer);
|
2015-02-27 10:15:18 +01:00
|
|
|
auto Functions = GlobalScope->findAllChildren<PDBSymbolFunc>();
|
2015-02-27 10:15:59 +01:00
|
|
|
while (auto Function = Functions->getNext()) {
|
|
|
|
Printer.NewLine();
|
2015-03-01 07:51:29 +01:00
|
|
|
Dumper.start(*Function, FunctionDumper::PointerType::None);
|
2015-02-27 10:15:59 +01:00
|
|
|
}
|
2015-02-27 10:15:18 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
auto Vars = GlobalScope->findAllChildren<PDBSymbolData>();
|
2015-02-27 10:15:59 +01:00
|
|
|
VariableDumper Dumper(Printer);
|
2015-02-27 10:15:18 +01:00
|
|
|
while (auto Var = Vars->getNext())
|
2015-03-01 07:51:29 +01:00
|
|
|
Dumper.start(*Var);
|
2015-02-27 10:15:18 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
auto Thunks = GlobalScope->findAllChildren<PDBSymbolThunk>();
|
2015-02-27 10:15:59 +01:00
|
|
|
CompilandDumper Dumper(Printer);
|
2015-02-27 10:15:18 +01:00
|
|
|
while (auto Thunk = Thunks->getNext())
|
2015-03-01 07:51:29 +01:00
|
|
|
Dumper.dump(*Thunk);
|
2015-02-27 10:15:18 +01:00
|
|
|
}
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.Unindent();
|
2015-01-28 01:33:00 +01:00
|
|
|
}
|
2015-05-01 22:24:26 +02:00
|
|
|
if (opts::Externals) {
|
|
|
|
Printer.NewLine();
|
|
|
|
WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---EXTERNALS---";
|
|
|
|
Printer.Indent();
|
|
|
|
ExternalSymbolDumper Dumper(Printer);
|
|
|
|
Dumper.start(*GlobalScope);
|
|
|
|
}
|
2015-01-28 01:33:00 +01:00
|
|
|
outs().flush();
|
|
|
|
}
|
|
|
|
|
2015-01-27 21:46:21 +01:00
|
|
|
int main(int argc_, const char *argv_[]) {
|
|
|
|
// Print a stack trace if we signal out.
|
|
|
|
sys::PrintStackTraceOnErrorSignal();
|
|
|
|
PrettyStackTraceProgram X(argc_, argv_);
|
|
|
|
|
|
|
|
SmallVector<const char *, 256> argv;
|
|
|
|
llvm::SpecificBumpPtrAllocator<char> ArgAllocator;
|
|
|
|
std::error_code EC = llvm::sys::Process::GetArgumentVector(
|
|
|
|
argv, llvm::makeArrayRef(argv_, argc_), ArgAllocator);
|
|
|
|
if (EC) {
|
|
|
|
llvm::errs() << "error: couldn't get arguments: " << EC.message() << '\n';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
|
|
|
|
|
|
|
cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n");
|
2015-03-02 05:39:56 +01:00
|
|
|
if (opts::All) {
|
|
|
|
opts::Compilands = true;
|
|
|
|
opts::Symbols = true;
|
|
|
|
opts::Globals = true;
|
|
|
|
opts::Types = true;
|
2015-05-01 22:24:26 +02:00
|
|
|
opts::Externals = true;
|
2015-03-02 05:39:56 +01:00
|
|
|
}
|
|
|
|
if (opts::ExcludeCompilerGenerated) {
|
|
|
|
opts::ExcludeTypes.push_back("__vc_attributes");
|
|
|
|
opts::ExcludeCompilands.push_back("* Linker *");
|
|
|
|
}
|
|
|
|
if (opts::ExcludeSystemLibraries) {
|
|
|
|
opts::ExcludeCompilands.push_back(
|
|
|
|
"f:\\binaries\\Intermediate\\vctools\\crt_bld");
|
|
|
|
}
|
2015-01-27 21:46:21 +01:00
|
|
|
|
2015-02-10 23:47:14 +01:00
|
|
|
#if defined(HAVE_DIA_SDK)
|
2015-01-27 21:46:21 +01:00
|
|
|
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
2015-02-10 23:47:14 +01:00
|
|
|
#endif
|
2015-01-27 21:46:21 +01:00
|
|
|
|
|
|
|
std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(),
|
|
|
|
dumpInput);
|
|
|
|
|
2015-02-10 23:47:14 +01:00
|
|
|
#if defined(HAVE_DIA_SDK)
|
2015-01-27 21:46:21 +01:00
|
|
|
CoUninitialize();
|
2015-02-10 23:47:14 +01:00
|
|
|
#endif
|
|
|
|
|
2015-01-27 21:46:21 +01:00
|
|
|
return 0;
|
|
|
|
}
|