Zachary Turner | fcb14ad | 2015-01-27 20:46:21 +0000 | [diff] [blame] | 1 | //===- llvm-pdbdump.cpp - Dump debug info from a PDB file -------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 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 |
| 12 | // platforms. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Zachary Turner | fcb14ad | 2015-01-27 20:46:21 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/ArrayRef.h" |
Zachary Turner | fcb14ad | 2015-01-27 20:46:21 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/StringExtras.h" |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame^] | 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" |
Zachary Turner | fcb14ad | 2015-01-27 20:46:21 +0000 | [diff] [blame] | 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" |
| 32 | |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame^] | 33 | #include <Windows.h> |
Zachary Turner | fcb14ad | 2015-01-27 20:46:21 +0000 | [diff] [blame] | 34 | |
| 35 | using namespace llvm; |
Zachary Turner | fcb14ad | 2015-01-27 20:46:21 +0000 | [diff] [blame] | 36 | |
| 37 | namespace opts { |
| 38 | cl::list<std::string> InputFilenames(cl::Positional, |
| 39 | cl::desc("<input PDB files>"), |
| 40 | cl::OneOrMore); |
| 41 | |
Zachary Turner | 4287b94 | 2015-01-28 00:33:00 +0000 | [diff] [blame] | 42 | cl::opt<bool> Compilands("compilands", |
| 43 | cl::desc("Display a list of compilands (e.g. object " |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame^] | 44 | "files) and symbols for each one.")); |
Zachary Turner | 4287b94 | 2015-01-28 00:33:00 +0000 | [diff] [blame] | 45 | cl::alias CompilandsShort("c", cl::desc("Alias for --compilands"), |
| 46 | cl::aliasopt(Compilands)); |
Zachary Turner | 49693b4 | 2015-01-28 01:22:33 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Zachary Turner | fcb14ad | 2015-01-27 20:46:21 +0000 | [diff] [blame] | 49 | static void dumpInput(StringRef Path) { |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame^] | 50 | std::unique_ptr<IPDBSession> Session( |
| 51 | llvm::createPDBReader(PDB_ReaderType::DIA, Path)); |
| 52 | if (!Session) { |
| 53 | outs() << "Unable to create PDB reader. Check that a valid implementation"; |
| 54 | outs() << " is available for your platform."; |
Zachary Turner | fcb14ad | 2015-01-27 20:46:21 +0000 | [diff] [blame] | 55 | return; |
Zachary Turner | fcb14ad | 2015-01-27 20:46:21 +0000 | [diff] [blame] | 56 | } |
Zachary Turner | 7058dfc | 2015-01-27 22:40:14 +0000 | [diff] [blame] | 57 | |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame^] | 58 | auto GlobalScope(Session->getGlobalScope()); |
| 59 | GlobalScope->dump(outs(), 0, PDB_DumpLevel::Normal); |
| 60 | outs().flush(); |
Zachary Turner | 4287b94 | 2015-01-28 00:33:00 +0000 | [diff] [blame] | 61 | |
| 62 | if (opts::Compilands) { |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame^] | 63 | auto Compilands = GlobalScope->findChildren(PDB_SymType::Compiland); |
| 64 | if (Compilands) { |
| 65 | while (auto Compiland = Compilands->getNext()) { |
| 66 | Compiland->dump(outs(), 0, PDB_DumpLevel::Normal); |
| 67 | } |
| 68 | } |
Zachary Turner | 7058dfc | 2015-01-27 22:40:14 +0000 | [diff] [blame] | 69 | } |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame^] | 70 | outs().flush(); |
Zachary Turner | fcb14ad | 2015-01-27 20:46:21 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 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_); |
| 77 | |
| 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); |
| 82 | if (EC) { |
| 83 | llvm::errs() << "error: couldn't get arguments: " << EC.message() << '\n'; |
| 84 | return 1; |
| 85 | } |
| 86 | |
| 87 | llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
| 88 | |
| 89 | cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n"); |
| 90 | |
| 91 | CoInitializeEx(nullptr, COINIT_MULTITHREADED); |
| 92 | |
| 93 | std::for_each(opts::InputFilenames.begin(), opts::InputFilenames.end(), |
| 94 | dumpInput); |
| 95 | |
| 96 | CoUninitialize(); |
| 97 | return 0; |
| 98 | } |