Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 1 | //===- CompilandDumper.cpp - llvm-pdbdump compiland symbol dumper *- 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 | #include "CompilandDumper.h" |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 11 | #include "LinePrinter.h" |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 12 | #include "llvm-pdbdump.h" |
| 13 | |
| 14 | #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" |
| 15 | #include "llvm/DebugInfo/PDB/IPDBSession.h" |
| 16 | #include "llvm/DebugInfo/PDB/PDBExtras.h" |
| 17 | #include "llvm/DebugInfo/PDB/PDBSymbol.h" |
| 18 | #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" |
| 19 | #include "llvm/DebugInfo/PDB/PDBSymbolData.h" |
| 20 | #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" |
| 21 | #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h" |
| 22 | #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h" |
| 23 | #include "llvm/DebugInfo/PDB/PDBSymbolLabel.h" |
| 24 | #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h" |
| 25 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" |
| 26 | #include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h" |
| 27 | #include "llvm/Support/Format.h" |
| 28 | #include "llvm/Support/Path.h" |
| 29 | #include "llvm/Support/raw_ostream.h" |
| 30 | |
| 31 | #include "FunctionDumper.h" |
| 32 | |
| 33 | #include <utility> |
| 34 | #include <vector> |
| 35 | |
| 36 | using namespace llvm; |
| 37 | |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 38 | CompilandDumper::CompilandDumper(LinePrinter &P) |
Zachary Turner | 9411828 | 2015-02-27 09:53:55 +0000 | [diff] [blame^] | 39 | : PDBSymDumper(true), Printer(P) {} |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 40 | |
| 41 | void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol, |
| 42 | raw_ostream &OS, int Indent) {} |
| 43 | |
| 44 | void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol, raw_ostream &OS, |
| 45 | int Indent) {} |
| 46 | |
| 47 | void CompilandDumper::start(const PDBSymbolCompiland &Symbol, raw_ostream &OS, |
| 48 | int Indent, bool Children) { |
| 49 | std::string FullName = Symbol.getName(); |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 50 | Printer.NewLine(); |
| 51 | WithColor(Printer, PDB_ColorItem::Path).get() << FullName; |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 52 | if (!Children) |
| 53 | return; |
| 54 | |
| 55 | auto ChildrenEnum = Symbol.findAllChildren(); |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 56 | Printer.Indent(); |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 57 | while (auto Child = ChildrenEnum->getNext()) |
| 58 | Child->dump(OS, Indent + 2, *this); |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 59 | Printer.Unindent(); |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void CompilandDumper::dump(const PDBSymbolData &Symbol, raw_ostream &OS, |
| 63 | int Indent) { |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 64 | Printer.NewLine(); |
| 65 | |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 66 | switch (auto LocType = Symbol.getLocationType()) { |
| 67 | case PDB_LocType::Static: |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 68 | Printer << "data: "; |
| 69 | WithColor(Printer, PDB_ColorItem::Address).get() |
| 70 | << "[" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "]"; |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 71 | break; |
| 72 | case PDB_LocType::Constant: |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 73 | Printer << "constant: "; |
| 74 | WithColor(Printer, PDB_ColorItem::LiteralValue).get() |
| 75 | << "[" << Symbol.getValue() << "]"; |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 76 | break; |
| 77 | default: |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 78 | Printer << "data(unexpected type=" << LocType << ")"; |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 81 | Printer << " "; |
| 82 | WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName(); |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void CompilandDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS, |
| 86 | int Indent) { |
Zachary Turner | 29c6910 | 2015-02-23 05:58:34 +0000 | [diff] [blame] | 87 | if (Symbol.getLength() == 0) |
| 88 | return; |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 89 | |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 90 | Printer.NewLine(); |
| 91 | FunctionDumper Dumper(Printer); |
Zachary Turner | 29c6910 | 2015-02-23 05:58:34 +0000 | [diff] [blame] | 92 | Dumper.start(Symbol, FunctionDumper::PointerType::None, OS, Indent); |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void CompilandDumper::dump(const PDBSymbolLabel &Symbol, raw_ostream &OS, |
| 96 | int Indent) { |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 97 | Printer.NewLine(); |
| 98 | Printer << "label "; |
| 99 | WithColor(Printer, PDB_ColorItem::Address).get() |
| 100 | << "[" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "] "; |
| 101 | WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName(); |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | void CompilandDumper::dump(const PDBSymbolThunk &Symbol, raw_ostream &OS, |
| 105 | int Indent) { |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 106 | Printer.NewLine(); |
| 107 | Printer << "thunk "; |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 108 | PDB_ThunkOrdinal Ordinal = Symbol.getThunkOrdinal(); |
| 109 | uint32_t RVA = Symbol.getRelativeVirtualAddress(); |
| 110 | if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) { |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 111 | uint32_t Target = Symbol.getTargetRelativeVirtualAddress(); |
| 112 | WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(RVA, 10); |
| 113 | Printer << " -> "; |
| 114 | WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10); |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 115 | } else { |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 116 | WithColor(Printer, PDB_ColorItem::Address).get() |
| 117 | << "[" << format_hex(RVA, 10) << " - " |
| 118 | << format_hex(RVA + Symbol.getLength(), 10) << "]"; |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 119 | } |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 120 | Printer << " (" << Ordinal << ") "; |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 121 | std::string Name = Symbol.getName(); |
| 122 | if (!Name.empty()) |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 123 | WithColor(Printer, PDB_ColorItem::Identifier).get() << Name; |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, |
| 127 | int Indent) {} |
| 128 | |
| 129 | void CompilandDumper::dump(const PDBSymbolUnknown &Symbol, raw_ostream &OS, |
| 130 | int Indent) { |
Zachary Turner | 2d11c20 | 2015-02-27 09:15:59 +0000 | [diff] [blame] | 131 | Printer.NewLine(); |
| 132 | Printer << "unknown (" << Symbol.getSymTag() << ")"; |
Zachary Turner | 9a818ad | 2015-02-22 22:03:38 +0000 | [diff] [blame] | 133 | } |