From ebe69fe11e48d322045d5949c83283927a0d790b Mon Sep 17 00:00:00 2001 From: Stephen Hines Date: Mon, 23 Mar 2015 12:10:34 -0700 Subject: Update aosp/master LLVM for rebase to r230699. Change-Id: I2b5be30509658cb8266be782de0ab24f9099f9b9 --- tools/llvm-pdbdump/llvm-pdbdump.cpp | 134 ++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 tools/llvm-pdbdump/llvm-pdbdump.cpp (limited to 'tools/llvm-pdbdump/llvm-pdbdump.cpp') diff --git a/tools/llvm-pdbdump/llvm-pdbdump.cpp b/tools/llvm-pdbdump/llvm-pdbdump.cpp new file mode 100644 index 0000000..e33e715 --- /dev/null +++ b/tools/llvm-pdbdump/llvm-pdbdump.cpp @@ -0,0 +1,134 @@ +//===- 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. +// +//===----------------------------------------------------------------------===// + +#include "llvm-pdbdump.h" +#include "CompilandDumper.h" +#include "TypeDumper.h" + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/Config/config.h" +#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" +#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" +#include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/PDB.h" +#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" +#include "llvm/DebugInfo/PDB/PDBSymbolExe.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Format.h" +#include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/Process.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/Signals.h" + +#if defined(HAVE_DIA_SDK) +#include +#endif + +using namespace llvm; + +namespace opts { + +enum class PDB_DumpType { ByType, ByObjFile, Both }; + +cl::list InputFilenames(cl::Positional, + cl::desc(""), + cl::OneOrMore); + +cl::opt DumpCompilands("compilands", cl::desc("Display compilands")); +cl::opt DumpSymbols("symbols", + cl::desc("Display symbols (implies --compilands")); +cl::opt DumpTypes("types", cl::desc("Display types")); +cl::opt DumpClassDefs("class-definitions", + cl::desc("Display full class definitions")); +} + +static void dumpInput(StringRef Path) { + std::unique_ptr Session( + llvm::createPDBReader(PDB_ReaderType::DIA, Path)); + if (!Session) { + outs() << "Unable to create PDB reader. Check that a valid implementation"; + outs() << " is available for your platform."; + return; + } + + auto GlobalScope(Session->getGlobalScope()); + std::string FileName(GlobalScope->getSymbolsFileName()); + + outs() << "Summary for " << FileName; + uint64_t FileSize = 0; + if (!llvm::sys::fs::file_size(FileName, FileSize)) + outs() << newline(2) << "Size: " << FileSize << " bytes"; + else + outs() << newline(2) << "Size: (Unable to obtain file size)"; + + outs() << newline(2) << "Guid: " << GlobalScope->getGuid(); + outs() << newline(2) << "Age: " << GlobalScope->getAge(); + outs() << newline(2) << "Attributes: "; + if (GlobalScope->hasCTypes()) + outs() << "HasCTypes "; + if (GlobalScope->hasPrivateSymbols()) + outs() << "HasPrivateSymbols "; + + if (opts::DumpTypes) { + outs() << "\nDumping types"; + TypeDumper Dumper(false, opts::DumpClassDefs); + Dumper.start(*GlobalScope, outs(), 2); + } + + if (opts::DumpSymbols || opts::DumpCompilands) { + outs() << "\nDumping compilands"; + auto Compilands = GlobalScope->findAllChildren(); + CompilandDumper Dumper; + while (auto Compiland = Compilands->getNext()) + Dumper.start(*Compiland, outs(), 2, opts::DumpSymbols); + } + outs().flush(); +} + +int main(int argc_, const char *argv_[]) { + // Print a stack trace if we signal out. + sys::PrintStackTraceOnErrorSignal(); + PrettyStackTraceProgram X(argc_, argv_); + + SmallVector argv; + llvm::SpecificBumpPtrAllocator 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"); + +#if defined(HAVE_DIA_SDK) + CoInitializeEx(nullptr, COINIT_MULTITHREADED); +#endif + + std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(), + dumpInput); + +#if defined(HAVE_DIA_SDK) + CoUninitialize(); +#endif + + return 0; +} -- cgit v1.1