Zachary Turner | 21473f7 | 2015-02-08 00:29:29 +0000 | [diff] [blame] | 1 | //===- PDBSymbolExe.cpp - ---------------------------------------*- 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 | |
Zachary Turner | 52c9f88 | 2015-02-14 03:53:56 +0000 | [diff] [blame] | 10 | #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" |
| 11 | |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" |
| 13 | #include "llvm/DebugInfo/PDB/PDBExtras.h" |
Zachary Turner | 21473f7 | 2015-02-08 00:29:29 +0000 | [diff] [blame] | 14 | #include "llvm/DebugInfo/PDB/PDBSymbol.h" |
Zachary Turner | 21473f7 | 2015-02-08 00:29:29 +0000 | [diff] [blame] | 15 | #include "llvm/Support/ConvertUTF.h" |
| 16 | #include "llvm/Support/FileSystem.h" |
| 17 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | 71f308a | 2015-02-13 09:09:03 +0000 | [diff] [blame] | 18 | #include <utility> |
Zachary Turner | 21473f7 | 2015-02-08 00:29:29 +0000 | [diff] [blame] | 19 | |
Zachary Turner | 52c9f88 | 2015-02-14 03:53:56 +0000 | [diff] [blame] | 20 | #include <utility> |
| 21 | |
Zachary Turner | 21473f7 | 2015-02-08 00:29:29 +0000 | [diff] [blame] | 22 | using namespace llvm; |
| 23 | |
Zachary Turner | c0acf68 | 2015-02-15 20:27:53 +0000 | [diff] [blame] | 24 | #define SKIP_SYMBOL_IF_FLAG_UNSET(Tag, Flag) \ |
| 25 | case PDB_SymType::Tag: \ |
| 26 | if ((Flags & Flag) == 0) \ |
| 27 | continue; \ |
| 28 | break; |
| 29 | |
Zachary Turner | 98571ed | 2015-02-08 22:53:53 +0000 | [diff] [blame] | 30 | PDBSymbolExe::PDBSymbolExe(const IPDBSession &PDBSession, |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 31 | std::unique_ptr<IPDBRawSymbol> Symbol) |
| 32 | : PDBSymbol(PDBSession, std::move(Symbol)) {} |
Zachary Turner | 21473f7 | 2015-02-08 00:29:29 +0000 | [diff] [blame] | 33 | |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 34 | void PDBSymbolExe::dump(raw_ostream &OS, int Indent, |
Zachary Turner | c0acf68 | 2015-02-15 20:27:53 +0000 | [diff] [blame] | 35 | PDB_DumpLevel Level, PDB_DumpFlags Flags) const { |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 36 | std::string FileName(getSymbolsFileName()); |
| 37 | |
Zachary Turner | a952c49 | 2015-02-13 07:40:03 +0000 | [diff] [blame] | 38 | OS << stream_indent(Indent) << "Summary for " << FileName << "\n"; |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 39 | |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 40 | uint64_t FileSize = 0; |
| 41 | if (!llvm::sys::fs::file_size(FileName, FileSize)) |
Zachary Turner | a952c49 | 2015-02-13 07:40:03 +0000 | [diff] [blame] | 42 | OS << stream_indent(Indent + 2) << "Size: " << FileSize << " bytes\n"; |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 43 | else |
Zachary Turner | a952c49 | 2015-02-13 07:40:03 +0000 | [diff] [blame] | 44 | OS << stream_indent(Indent + 2) << "Size: (Unable to obtain file size)\n"; |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 45 | PDB_UniqueId Guid = getGuid(); |
Zachary Turner | a952c49 | 2015-02-13 07:40:03 +0000 | [diff] [blame] | 46 | OS << stream_indent(Indent + 2) << "Guid: " << Guid << "\n"; |
| 47 | OS << stream_indent(Indent + 2) << "Age: " << getAge() << "\n"; |
| 48 | OS << stream_indent(Indent + 2) << "Attributes: "; |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 49 | if (hasCTypes()) |
| 50 | OS << "HasCTypes "; |
| 51 | if (hasPrivateSymbols()) |
| 52 | OS << "HasPrivateSymbols "; |
| 53 | OS << "\n"; |
Zachary Turner | 2a5c0a2 | 2015-02-13 01:23:51 +0000 | [diff] [blame] | 54 | |
Zachary Turner | c0acf68 | 2015-02-15 20:27:53 +0000 | [diff] [blame] | 55 | if (Flags & PDB_DF_Children) { |
Zachary Turner | fc4eced | 2015-02-22 21:45:38 +0000 | [diff] [blame] | 56 | OS << stream_indent(Indent + 2) << "Dumping types\n"; |
Zachary Turner | c0acf68 | 2015-02-15 20:27:53 +0000 | [diff] [blame] | 57 | if (Flags & PDB_DF_Hidden) { |
| 58 | // For some reason, for each SymTag T, this dumps more items of type T |
| 59 | // than are dumped by calling dumpChildren(T). In other words, there are |
| 60 | // "hidden" symbols. For example, it causes functions to be dumped which |
| 61 | // have no address information, whereas specifically dumping only |
| 62 | // functions will not find those symbols. |
| 63 | // |
| 64 | // My suspicion is that in the underlying DIA call, when you call |
| 65 | // findChildren, passing a value of SymTagNone means all children |
| 66 | // recursively, whereas passing a concrete tag value means only immediate |
| 67 | // children of the global scope. So perhaps we need to find these |
| 68 | // mysterious missing values by recursing through the hierarchy. |
| 69 | // |
| 70 | // On the other hand, there may just be some symbols that DIA tries to |
| 71 | // hide from you because it thinks you don't care about them. However |
| 72 | // experimentation shows that even vtables, for example, can't be found |
| 73 | // without an exhaustive search. |
| 74 | auto ChildrenEnum = findAllChildren(); |
| 75 | OS << stream_indent(Indent + 2) << ChildrenEnum->getChildCount() |
| 76 | << " symbols"; |
| 77 | |
| 78 | while (auto Child = ChildrenEnum->getNext()) { |
| 79 | switch (Child->getSymTag()) { |
| 80 | SKIP_SYMBOL_IF_FLAG_UNSET(Function, PDB_DF_Functions) |
| 81 | SKIP_SYMBOL_IF_FLAG_UNSET(Data, PDB_DF_Data) |
| 82 | SKIP_SYMBOL_IF_FLAG_UNSET(Label, PDB_DF_Labels) |
| 83 | SKIP_SYMBOL_IF_FLAG_UNSET(PublicSymbol, PDB_DF_PublicSyms) |
| 84 | SKIP_SYMBOL_IF_FLAG_UNSET(UDT, PDB_DF_Classes) |
| 85 | SKIP_SYMBOL_IF_FLAG_UNSET(Enum, PDB_DF_Enums) |
| 86 | SKIP_SYMBOL_IF_FLAG_UNSET(FunctionSig, PDB_DF_Funcsigs) |
| 87 | SKIP_SYMBOL_IF_FLAG_UNSET(VTable, PDB_DF_VTables) |
| 88 | SKIP_SYMBOL_IF_FLAG_UNSET(Thunk, PDB_DF_Thunks) |
| 89 | SKIP_SYMBOL_IF_FLAG_UNSET(Compiland, PDB_DF_ObjFiles) |
| 90 | default: |
| 91 | continue; |
| 92 | } |
| 93 | PDB_DumpLevel ChildLevel = (Level == PDB_DumpLevel::Detailed) |
| 94 | ? PDB_DumpLevel::Normal |
| 95 | : PDB_DumpLevel::Compact; |
| 96 | OS << "\n"; |
| 97 | Child->dump(OS, Indent + 4, ChildLevel, PDB_DF_Children); |
| 98 | } |
| 99 | } else { |
| 100 | if (Flags & PDB_DF_ObjFiles) |
| 101 | dumpChildren(OS, "Compilands", PDB_SymType::Compiland, Indent + 4); |
| 102 | if (Flags & PDB_DF_Functions) |
| 103 | dumpChildren(OS, "Functions", PDB_SymType::Function, Indent + 4); |
| 104 | if (Flags & PDB_DF_Data) |
| 105 | dumpChildren(OS, "Data", PDB_SymType::Data, Indent + 4); |
| 106 | if (Flags & PDB_DF_Labels) |
| 107 | dumpChildren(OS, "Labels", PDB_SymType::Label, Indent + 4); |
| 108 | if (Flags & PDB_DF_PublicSyms) |
| 109 | dumpChildren(OS, "Public Symbols", PDB_SymType::PublicSymbol, |
| 110 | Indent + 4); |
| 111 | if (Flags & PDB_DF_Classes) |
| 112 | dumpChildren(OS, "UDTs", PDB_SymType::UDT, Indent + 4); |
| 113 | if (Flags & PDB_DF_Enums) |
| 114 | dumpChildren(OS, "Enums", PDB_SymType::Enum, Indent + 4); |
| 115 | if (Flags & PDB_DF_Funcsigs) |
| 116 | dumpChildren(OS, "Function Signatures", PDB_SymType::FunctionSig, |
| 117 | Indent + 4); |
| 118 | if (Flags & PDB_DF_Typedefs) |
| 119 | dumpChildren(OS, "Typedefs", PDB_SymType::Typedef, Indent + 4); |
| 120 | if (Flags & PDB_DF_VTables) |
| 121 | dumpChildren(OS, "VTables", PDB_SymType::VTable, Indent + 4); |
| 122 | if (Flags & PDB_DF_Thunks) |
| 123 | dumpChildren(OS, "Thunks", PDB_SymType::Thunk, Indent + 4); |
| 124 | } |
| 125 | } |
Zachary Turner | 26ebe3f | 2015-02-14 03:54:28 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void PDBSymbolExe::dumpChildren(raw_ostream &OS, StringRef Label, |
| 129 | PDB_SymType ChildType, int Indent) const { |
| 130 | auto ChildrenEnum = findAllChildren(ChildType); |
| 131 | OS << stream_indent(Indent) << Label << ": (" << ChildrenEnum->getChildCount() |
| 132 | << " items)\n"; |
Zachary Turner | 2a5c0a2 | 2015-02-13 01:23:51 +0000 | [diff] [blame] | 133 | while (auto Child = ChildrenEnum->getNext()) { |
Zachary Turner | c0acf68 | 2015-02-15 20:27:53 +0000 | [diff] [blame] | 134 | Child->dump(OS, Indent + 2, PDB_DumpLevel::Normal, PDB_DF_None); |
Zachary Turner | a952c49 | 2015-02-13 07:40:03 +0000 | [diff] [blame] | 135 | OS << "\n"; |
Zachary Turner | 2a5c0a2 | 2015-02-13 01:23:51 +0000 | [diff] [blame] | 136 | } |
Zachary Turner | 21473f7 | 2015-02-08 00:29:29 +0000 | [diff] [blame] | 137 | } |