blob: efd28bca4696322d0256eeda399ed186bfd29bd0 [file] [log] [blame]
Zachary Turner21473f72015-02-08 00:29:29 +00001//===- 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 Turner52c9f882015-02-14 03:53:56 +000010#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
11
Zachary Turnera5549172015-02-10 22:43:25 +000012#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
13#include "llvm/DebugInfo/PDB/PDBExtras.h"
Zachary Turner21473f72015-02-08 00:29:29 +000014#include "llvm/DebugInfo/PDB/PDBSymbol.h"
Zachary Turner21473f72015-02-08 00:29:29 +000015#include "llvm/Support/ConvertUTF.h"
16#include "llvm/Support/FileSystem.h"
17#include "llvm/Support/raw_ostream.h"
Chandler Carruth71f308a2015-02-13 09:09:03 +000018#include <utility>
Zachary Turner21473f72015-02-08 00:29:29 +000019
Zachary Turner52c9f882015-02-14 03:53:56 +000020#include <utility>
21
Zachary Turner21473f72015-02-08 00:29:29 +000022using namespace llvm;
23
Zachary Turnerc0acf682015-02-15 20:27:53 +000024#define SKIP_SYMBOL_IF_FLAG_UNSET(Tag, Flag) \
25 case PDB_SymType::Tag: \
26 if ((Flags & Flag) == 0) \
27 continue; \
28 break;
29
Zachary Turner98571ed2015-02-08 22:53:53 +000030PDBSymbolExe::PDBSymbolExe(const IPDBSession &PDBSession,
Zachary Turnerbae16b32015-02-08 20:58:09 +000031 std::unique_ptr<IPDBRawSymbol> Symbol)
32 : PDBSymbol(PDBSession, std::move(Symbol)) {}
Zachary Turner21473f72015-02-08 00:29:29 +000033
Zachary Turnera5549172015-02-10 22:43:25 +000034void PDBSymbolExe::dump(raw_ostream &OS, int Indent,
Zachary Turnerc0acf682015-02-15 20:27:53 +000035 PDB_DumpLevel Level, PDB_DumpFlags Flags) const {
Zachary Turnera5549172015-02-10 22:43:25 +000036 std::string FileName(getSymbolsFileName());
37
Zachary Turnera952c492015-02-13 07:40:03 +000038 OS << stream_indent(Indent) << "Summary for " << FileName << "\n";
Zachary Turnera5549172015-02-10 22:43:25 +000039
Zachary Turnera5549172015-02-10 22:43:25 +000040 uint64_t FileSize = 0;
41 if (!llvm::sys::fs::file_size(FileName, FileSize))
Zachary Turnera952c492015-02-13 07:40:03 +000042 OS << stream_indent(Indent + 2) << "Size: " << FileSize << " bytes\n";
Zachary Turnera5549172015-02-10 22:43:25 +000043 else
Zachary Turnera952c492015-02-13 07:40:03 +000044 OS << stream_indent(Indent + 2) << "Size: (Unable to obtain file size)\n";
Zachary Turnera5549172015-02-10 22:43:25 +000045 PDB_UniqueId Guid = getGuid();
Zachary Turnera952c492015-02-13 07:40:03 +000046 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 Turnera5549172015-02-10 22:43:25 +000049 if (hasCTypes())
50 OS << "HasCTypes ";
51 if (hasPrivateSymbols())
52 OS << "HasPrivateSymbols ";
53 OS << "\n";
Zachary Turner2a5c0a22015-02-13 01:23:51 +000054
Zachary Turnerc0acf682015-02-15 20:27:53 +000055 if (Flags & PDB_DF_Children) {
Zachary Turnerfc4eced2015-02-22 21:45:38 +000056 OS << stream_indent(Indent + 2) << "Dumping types\n";
Zachary Turnerc0acf682015-02-15 20:27:53 +000057 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 Turner26ebe3f2015-02-14 03:54:28 +0000126}
127
128void 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 Turner2a5c0a22015-02-13 01:23:51 +0000133 while (auto Child = ChildrenEnum->getNext()) {
Zachary Turnerc0acf682015-02-15 20:27:53 +0000134 Child->dump(OS, Indent + 2, PDB_DumpLevel::Normal, PDB_DF_None);
Zachary Turnera952c492015-02-13 07:40:03 +0000135 OS << "\n";
Zachary Turner2a5c0a22015-02-13 01:23:51 +0000136 }
Zachary Turner21473f72015-02-08 00:29:29 +0000137}